| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_ |
| 6 #define CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_ | 6 #define CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| 11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "chrome/common/notification_observer.h" | 13 #include "chrome/common/notification_observer.h" |
| 14 #include "net/proxy/proxy_config.h" | 14 #include "net/proxy/proxy_config.h" |
| 15 #include "net/proxy/proxy_config_service.h" | 15 #include "net/proxy/proxy_config_service.h" |
| 16 | 16 |
| 17 class PrefService; | 17 class PrefService; |
| 18 class PrefSetObserver; | 18 class PrefSetObserver; |
| 19 | 19 |
| 20 // A helper class that tracks proxy preferences. It translates the configuration | 20 // A helper class that tracks proxy preferences. It translates the configuration |
| 21 // to net::ProxyConfig and proxies the result over to the IO thread for | 21 // to net::ProxyConfig and proxies the result over to the IO thread for |
| 22 // PrefProxyConfigService to use. | 22 // PrefProxyConfigService to use. |
| 23 class PrefProxyConfigTracker | 23 class PrefProxyConfigTracker |
| 24 : public base::RefCountedThreadSafe<PrefProxyConfigTracker>, | 24 : public base::RefCountedThreadSafe<PrefProxyConfigTracker>, |
| 25 public NotificationObserver { | 25 public NotificationObserver { |
| 26 public: | 26 public: |
| 27 // Observer interface used to send out notifications on the IO thread about | 27 // Observer interface used to send out notifications on the IO thread about |
| 28 // changes to the proxy configuration. | 28 // changes to the proxy configuration. |
| 29 class ObserverInterface { | 29 class Observer { |
| 30 public: | 30 public: |
| 31 virtual ~ObserverInterface() {} | 31 virtual ~Observer() {} |
| 32 virtual void OnPrefProxyConfigChanged() = 0; | 32 virtual void OnPrefProxyConfigChanged() = 0; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 explicit PrefProxyConfigTracker(PrefService* pref_service); | 35 explicit PrefProxyConfigTracker(PrefService* pref_service); |
| 36 virtual ~PrefProxyConfigTracker(); | 36 virtual ~PrefProxyConfigTracker(); |
| 37 | 37 |
| 38 // Observer manipulation is only valid on the IO thread. | 38 // Observer manipulation is only valid on the IO thread. |
| 39 void AddObserver(ObserverInterface* observer); | 39 void AddObserver(Observer* observer); |
| 40 void RemoveObserver(ObserverInterface* observer); | 40 void RemoveObserver(Observer* observer); |
| 41 | 41 |
| 42 // Get the proxy configuration currently defined by preferences. Writes the | 42 // Get the proxy configuration currently defined by preferences. Writes the |
| 43 // configuration to |config| and returns true on success. |config| is not | 43 // configuration to |config| and returns true on success. |config| is not |
| 44 // touched and false is returned if there is no configuration defined. This | 44 // touched and false is returned if there is no configuration defined. This |
| 45 // must be called on the IO thread. | 45 // must be called on the IO thread. |
| 46 bool GetProxyConfig(net::ProxyConfig* config); | 46 bool GetProxyConfig(net::ProxyConfig* config); |
| 47 | 47 |
| 48 // Notifies the tracker that the pref service passed upon construction is | 48 // Notifies the tracker that the pref service passed upon construction is |
| 49 // about to go away. This must be called from the UI thread. | 49 // about to go away. This must be called from the UI thread. |
| 50 void DetachFromPrefService(); | 50 void DetachFromPrefService(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 61 // which case this configuration is given by |config|. |config| is ignored if | 61 // which case this configuration is given by |config|. |config| is ignored if |
| 62 // |valid| is false. | 62 // |valid| is false. |
| 63 void InstallProxyConfig(const net::ProxyConfig& config, bool valid); | 63 void InstallProxyConfig(const net::ProxyConfig& config, bool valid); |
| 64 | 64 |
| 65 // Creates a proxy configuration from proxy-related preferences. Configuration | 65 // Creates a proxy configuration from proxy-related preferences. Configuration |
| 66 // is stored in |config| and the return value indicates whether the | 66 // is stored in |config| and the return value indicates whether the |
| 67 // configuration is valid. | 67 // configuration is valid. |
| 68 bool ReadPrefConfig(net::ProxyConfig* config); | 68 bool ReadPrefConfig(net::ProxyConfig* config); |
| 69 | 69 |
| 70 // Configuration as defined by prefs. Only to be accessed from the IO thread | 70 // Configuration as defined by prefs. Only to be accessed from the IO thread |
| 71 // (expect for construction). | 71 // (except for construction). |
| 72 net::ProxyConfig pref_config_; | 72 net::ProxyConfig pref_config_; |
| 73 | 73 |
| 74 // Whether |pref_config_| is valid. Only accessed from the IO thread. | 74 // Whether |pref_config_| is valid. Only accessed from the IO thread. |
| 75 bool valid_; | 75 bool valid_; |
| 76 | 76 |
| 77 // List of observers, accessed exclusively from the IO thread. | 77 // List of observers, accessed exclusively from the IO thread. |
| 78 ObserverList<ObserverInterface, true> observers_; | 78 ObserverList<Observer, true> observers_; |
| 79 | 79 |
| 80 // Pref-related members that should only be accessed from the UI thread. | 80 // Pref-related members that should only be accessed from the UI thread. |
| 81 PrefService* pref_service_; | 81 PrefService* pref_service_; |
| 82 scoped_ptr<PrefSetObserver> proxy_prefs_observer_; | 82 scoped_ptr<PrefSetObserver> proxy_prefs_observer_; |
| 83 | 83 |
| 84 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigTracker); | 84 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigTracker); |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 // A net::ProxyConfigService implementation that applies preference proxy | 87 // A net::ProxyConfigService implementation that applies preference proxy |
| 88 // settings as overrides to the proxy configuration determined by a baseline | 88 // settings as overrides to the proxy configuration determined by a baseline |
| 89 // delegate ProxyConfigService. | 89 // delegate ProxyConfigService. |
| 90 class PrefProxyConfigService | 90 class PrefProxyConfigService |
| 91 : public net::ProxyConfigService, | 91 : public net::ProxyConfigService, |
| 92 public net::ProxyConfigService::Observer, | 92 public net::ProxyConfigService::Observer, |
| 93 public PrefProxyConfigTracker::ObserverInterface { | 93 public PrefProxyConfigTracker::Observer { |
| 94 public: | 94 public: |
| 95 // Takes ownership of the passed |base_service|. | 95 // Takes ownership of the passed |base_service|. |
| 96 PrefProxyConfigService(PrefProxyConfigTracker* tracker, | 96 PrefProxyConfigService(PrefProxyConfigTracker* tracker, |
| 97 net::ProxyConfigService* base_service); | 97 net::ProxyConfigService* base_service); |
| 98 virtual ~PrefProxyConfigService(); | 98 virtual ~PrefProxyConfigService(); |
| 99 | 99 |
| 100 // ProxyConfigService implementation: | 100 // ProxyConfigService implementation: |
| 101 virtual void AddObserver(net::ProxyConfigService::Observer* observer); | 101 virtual void AddObserver(net::ProxyConfigService::Observer* observer); |
| 102 virtual void RemoveObserver(net::ProxyConfigService::Observer* observer); | 102 virtual void RemoveObserver(net::ProxyConfigService::Observer* observer); |
| 103 virtual bool GetLatestProxyConfig(net::ProxyConfig* config); | 103 virtual bool GetLatestProxyConfig(net::ProxyConfig* config); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 118 ObserverList<net::ProxyConfigService::Observer, true> observers_; | 118 ObserverList<net::ProxyConfigService::Observer, true> observers_; |
| 119 scoped_refptr<PrefProxyConfigTracker> pref_config_tracker_; | 119 scoped_refptr<PrefProxyConfigTracker> pref_config_tracker_; |
| 120 | 120 |
| 121 // Indicates whether the base service and tracker registrations are done. | 121 // Indicates whether the base service and tracker registrations are done. |
| 122 bool registered_observers_; | 122 bool registered_observers_; |
| 123 | 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigService); | 124 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigService); |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 #endif // CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_ | 127 #endif // CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_ |
| OLD | NEW |