Home | History | Annotate | Download | only in proxy
      1 // Copyright (c) 2011 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 #pragma once
      8 
      9 #include "base/basictypes.h"
     10 #include "base/memory/ref_counted.h"
     11 #include "base/observer_list.h"
     12 #include "net/base/network_config_watcher_mac.h"
     13 #include "net/proxy/proxy_config.h"
     14 #include "net/proxy/proxy_config_service.h"
     15 
     16 namespace net {
     17 
     18 class ProxyConfigServiceMac : public ProxyConfigService {
     19  public:
     20   // Constructs a ProxyConfigService that watches the Mac OS system settings.
     21   // This instance is expected to be operated and deleted on |io_loop|
     22   // (however it may be constructed from a different thread).
     23   explicit ProxyConfigServiceMac(MessageLoop* io_loop);
     24   virtual ~ProxyConfigServiceMac();
     25 
     26  public:
     27   // ProxyConfigService implementation:
     28   virtual void AddObserver(Observer* observer);
     29   virtual void RemoveObserver(Observer* observer);
     30   virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config);
     31 
     32  private:
     33   class Helper;
     34 
     35   // Forwarder just exists to keep the NetworkConfigWatcherMac API out of
     36   // ProxyConfigServiceMac's public API.
     37   class Forwarder : public NetworkConfigWatcherMac::Delegate {
     38    public:
     39     explicit Forwarder(ProxyConfigServiceMac* net_config_watcher)
     40         : net_config_watcher_(net_config_watcher) {}
     41 
     42     // NetworkConfigWatcherMac::Delegate implementation:
     43     virtual void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store) {
     44       net_config_watcher_->SetDynamicStoreNotificationKeys(store);
     45     }
     46     virtual void OnNetworkConfigChange(CFArrayRef changed_keys) {
     47       net_config_watcher_->OnNetworkConfigChange(changed_keys);
     48     }
     49 
     50    private:
     51     ProxyConfigServiceMac* const net_config_watcher_;
     52     DISALLOW_COPY_AND_ASSIGN(Forwarder);
     53   };
     54 
     55   // NetworkConfigWatcherMac::Delegate implementation:
     56   void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store);
     57   void OnNetworkConfigChange(CFArrayRef changed_keys);
     58 
     59   // Called when the proxy configuration has changed, to notify the observers.
     60   void OnProxyConfigChanged(const ProxyConfig& new_config);
     61 
     62   Forwarder forwarder_;
     63   const NetworkConfigWatcherMac config_watcher_;
     64 
     65   ObserverList<Observer> observers_;
     66 
     67   // Holds the last system proxy settings that we fetched.
     68   bool has_fetched_config_;
     69   ProxyConfig last_config_fetched_;
     70 
     71   scoped_refptr<Helper> helper_;
     72 
     73   // The thread that we expect to be operated on.
     74   MessageLoop* io_loop_;
     75 
     76   DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceMac);
     77 };
     78 
     79 }  // namespace net
     80 
     81 #endif  // NET_PROXY_PROXY_CONFIG_SERVICE_MAC_H_
     82