• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef NET_PROXY_PROXY_CONFIG_SERVICE_MAC_H_
6 #define NET_PROXY_PROXY_CONFIG_SERVICE_MAC_H_
7 
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"
16 
17 namespace base {
18 class SingleThreadTaskRunner;
19 }  // namespace base
20 
21 namespace net {
22 
23 // TODO(sergeyu): This class needs to be exported because remoting code
24 // creates it directly. Fix that and remove NET_EXPORT here.
25 // crbug.com/125104
26 class NET_EXPORT ProxyConfigServiceMac : public ProxyConfigService {
27  public:
28   // Constructs a ProxyConfigService that watches the Mac OS system settings.
29   // This instance is expected to be operated and deleted on the same thread
30   // (however it may be constructed from a different thread).
31   explicit ProxyConfigServiceMac(
32       base::SingleThreadTaskRunner* io_thread_task_runner);
33   virtual ~ProxyConfigServiceMac();
34 
35  public:
36   // ProxyConfigService implementation:
37   virtual void AddObserver(Observer* observer) OVERRIDE;
38   virtual void RemoveObserver(Observer* observer) OVERRIDE;
39   virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) OVERRIDE;
40 
41  private:
42   class Helper;
43 
44   // Forwarder just exists to keep the NetworkConfigWatcherMac API out of
45   // ProxyConfigServiceMac's public API.
46   class Forwarder : public NetworkConfigWatcherMac::Delegate {
47    public:
Forwarder(ProxyConfigServiceMac * proxy_config_service)48     explicit Forwarder(ProxyConfigServiceMac* proxy_config_service)
49         : proxy_config_service_(proxy_config_service) {}
50 
51     // NetworkConfigWatcherMac::Delegate implementation:
StartReachabilityNotifications()52     virtual void StartReachabilityNotifications() OVERRIDE {}
53     virtual void SetDynamicStoreNotificationKeys(
54         SCDynamicStoreRef store) OVERRIDE;
55     virtual void OnNetworkConfigChange(CFArrayRef changed_keys) OVERRIDE;
56 
57    private:
58     ProxyConfigServiceMac* const proxy_config_service_;
59     DISALLOW_COPY_AND_ASSIGN(Forwarder);
60   };
61 
62   // Methods directly called by the NetworkConfigWatcherMac::Delegate:
63   void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store);
64   void OnNetworkConfigChange(CFArrayRef changed_keys);
65 
66   // Called when the proxy configuration has changed, to notify the observers.
67   void OnProxyConfigChanged(const ProxyConfig& new_config);
68 
69   Forwarder forwarder_;
70   scoped_ptr<const NetworkConfigWatcherMac> config_watcher_;
71 
72   ObserverList<Observer> observers_;
73 
74   // Holds the last system proxy settings that we fetched.
75   bool has_fetched_config_;
76   ProxyConfig last_config_fetched_;
77 
78   scoped_refptr<Helper> helper_;
79 
80   // The thread that we expect to be operated on.
81   const scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_;
82 
83   DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceMac);
84 };
85 
86 }  // namespace net
87 
88 #endif  // NET_PROXY_PROXY_CONFIG_SERVICE_MAC_H_
89