Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / net / proxy / proxy_config_service_mac.h
blob01a0e26b0f373930fce520651d10b6621c376809
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_PROXY_PROXY_CONFIG_SERVICE_MAC_H_
6 #define NET_PROXY_PROXY_CONFIG_SERVICE_MAC_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h"
13 #include "net/base/network_config_watcher_mac.h"
14 #include "net/proxy/proxy_config.h"
15 #include "net/proxy/proxy_config_service.h"
17 namespace base {
18 class SingleThreadTaskRunner;
19 } // namespace base
21 namespace net {
23 class ProxyConfigServiceMac : public ProxyConfigService {
24 public:
25 // Constructs a ProxyConfigService that watches the Mac OS system settings.
26 // This instance is expected to be operated and deleted on the same thread
27 // (however it may be constructed from a different thread).
28 explicit ProxyConfigServiceMac(
29 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_task_runner);
30 ~ProxyConfigServiceMac() override;
32 public:
33 // ProxyConfigService implementation:
34 void AddObserver(Observer* observer) override;
35 void RemoveObserver(Observer* observer) override;
36 ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) override;
38 private:
39 class Helper;
41 // Forwarder just exists to keep the NetworkConfigWatcherMac API out of
42 // ProxyConfigServiceMac's public API.
43 class Forwarder : public NetworkConfigWatcherMac::Delegate {
44 public:
45 explicit Forwarder(ProxyConfigServiceMac* proxy_config_service)
46 : proxy_config_service_(proxy_config_service) {}
48 // NetworkConfigWatcherMac::Delegate implementation:
49 void StartReachabilityNotifications() override {}
50 void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store) override;
51 void OnNetworkConfigChange(CFArrayRef changed_keys) override;
53 private:
54 ProxyConfigServiceMac* const proxy_config_service_;
55 DISALLOW_COPY_AND_ASSIGN(Forwarder);
58 // Methods directly called by the NetworkConfigWatcherMac::Delegate:
59 void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store);
60 void OnNetworkConfigChange(CFArrayRef changed_keys);
62 // Called when the proxy configuration has changed, to notify the observers.
63 void OnProxyConfigChanged(const ProxyConfig& new_config);
65 Forwarder forwarder_;
66 scoped_ptr<const NetworkConfigWatcherMac> config_watcher_;
68 base::ObserverList<Observer> observers_;
70 // Holds the last system proxy settings that we fetched.
71 bool has_fetched_config_;
72 ProxyConfig last_config_fetched_;
74 scoped_refptr<Helper> helper_;
76 // The thread that we expect to be operated on.
77 const scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_;
79 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceMac);
82 } // namespace net
84 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_MAC_H_