15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NET_PROXY_PROXY_CONFIG_SERVICE_MAC_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NET_PROXY_PROXY_CONFIG_SERVICE_MAC_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "base/basictypes.h" 9116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "base/compiler_specific.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/observer_list.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/network_config_watcher_mac.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/proxy/proxy_config.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/proxy/proxy_config_service.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base { 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SingleThreadTaskRunner; 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace base 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 21116680a4aac90f2aa7413d9095a592090648e557Ben Murdochnamespace net { 22116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ProxyConfigServiceMac : public ProxyConfigService { 241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci public: 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Constructs a ProxyConfigService that watches the Mac OS system settings. 26116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // This instance is expected to be operated and deleted on the same thread 27116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // (however it may be constructed from a different thread). 28116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch explicit ProxyConfigServiceMac( 29116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_task_runner); 30116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual ~ProxyConfigServiceMac(); 31116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 32116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch public: 33116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // ProxyConfigService implementation: 34116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void AddObserver(Observer* observer) OVERRIDE; 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void RemoveObserver(Observer* observer) OVERRIDE; 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) OVERRIDE; 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 39116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch class Helper; 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Forwarder just exists to keep the NetworkConfigWatcherMac API out of 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ProxyConfigServiceMac's public API. 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class Forwarder : public NetworkConfigWatcherMac::Delegate { 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit Forwarder(ProxyConfigServiceMac* proxy_config_service) 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : proxy_config_service_(proxy_config_service) {} 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NetworkConfigWatcherMac::Delegate implementation: 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void StartReachabilityNotifications() OVERRIDE {} 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetDynamicStoreNotificationKeys( 51 SCDynamicStoreRef store) OVERRIDE; 52 virtual void OnNetworkConfigChange(CFArrayRef changed_keys) OVERRIDE; 53 54 private: 55 ProxyConfigServiceMac* const proxy_config_service_; 56 DISALLOW_COPY_AND_ASSIGN(Forwarder); 57 }; 58 59 // Methods directly called by the NetworkConfigWatcherMac::Delegate: 60 void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store); 61 void OnNetworkConfigChange(CFArrayRef changed_keys); 62 63 // Called when the proxy configuration has changed, to notify the observers. 64 void OnProxyConfigChanged(const ProxyConfig& new_config); 65 66 Forwarder forwarder_; 67 scoped_ptr<const NetworkConfigWatcherMac> config_watcher_; 68 69 ObserverList<Observer> observers_; 70 71 // Holds the last system proxy settings that we fetched. 72 bool has_fetched_config_; 73 ProxyConfig last_config_fetched_; 74 75 scoped_refptr<Helper> helper_; 76 77 // The thread that we expect to be operated on. 78 const scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_; 79 80 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceMac); 81}; 82 83} // namespace net 84 85#endif // NET_PROXY_PROXY_CONFIG_SERVICE_MAC_H_ 86