Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 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 Observer { | 29 class Observer { |
| 30 public: | 30 public: |
| 31 virtual ~Observer() {} | 31 virtual ~Observer() {} |
| 32 virtual void OnPrefProxyConfigChanged() = 0; | 32 virtual void OnPrefProxyConfigChanged() = 0; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 explicit PrefProxyConfigTracker(PrefService* pref_service); | 35 // Initialize a tracker that will retrieve the configuration from |
| 36 // |pref_service|. |fallback_pref_service| may be NULL. If specfied, it is | |
| 37 // consulted for a user pref (and only that!) if the user preference is | |
| 38 // missing in the main |pref_service|. This allows us to default the user | |
| 39 // preference to the |local_state| preference if there is no user preference | |
| 40 // for the profile. | |
| 41 PrefProxyConfigTracker(PrefService* pref_service, | |
| 42 PrefService* fallback_pref_service); | |
| 36 virtual ~PrefProxyConfigTracker(); | 43 virtual ~PrefProxyConfigTracker(); |
| 37 | 44 |
| 38 // Observer manipulation is only valid on the IO thread. | 45 // Observer manipulation is only valid on the IO thread. |
| 39 void AddObserver(Observer* observer); | 46 void AddObserver(Observer* observer); |
| 40 void RemoveObserver(Observer* observer); | 47 void RemoveObserver(Observer* observer); |
| 41 | 48 |
| 42 // Get the proxy configuration currently defined by preferences. Writes the | 49 // Get the proxy configuration currently defined by preferences. Writes the |
| 43 // configuration to |config| and returns true on success. |config| is not | 50 // configuration to |config| and returns true on success. |config| is not |
| 44 // touched and false is returned if there is no configuration defined. This | 51 // touched and false is returned if there is no configuration defined. This |
| 45 // must be called on the IO thread. | 52 // must be called on the IO thread. |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 74 // Whether |pref_config_| is valid. Only accessed from the IO thread. | 81 // Whether |pref_config_| is valid. Only accessed from the IO thread. |
| 75 bool valid_; | 82 bool valid_; |
| 76 | 83 |
| 77 // List of observers, accessed exclusively from the IO thread. | 84 // List of observers, accessed exclusively from the IO thread. |
| 78 ObserverList<Observer, true> observers_; | 85 ObserverList<Observer, true> observers_; |
| 79 | 86 |
| 80 // Pref-related members that should only be accessed from the UI thread. | 87 // Pref-related members that should only be accessed from the UI thread. |
| 81 PrefService* pref_service_; | 88 PrefService* pref_service_; |
| 82 scoped_ptr<PrefSetObserver> proxy_prefs_observer_; | 89 scoped_ptr<PrefSetObserver> proxy_prefs_observer_; |
| 83 | 90 |
| 91 // A fallback PrefSerice that is checked for user preferences if | |
|
kuan
2011/02/22 22:20:25
nit: typo: PrefService
Mattias Nissler (ping if slow)
2011/03/01 15:19:20
Done.
| |
| 92 // |pref_service| doesn't have any user preference. | |
| 93 PrefService* fallback_pref_service_; | |
| 94 scoped_ptr<PrefSetObserver> fallback_proxy_prefs_observer_; | |
| 95 | |
| 84 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigTracker); | 96 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigTracker); |
| 85 }; | 97 }; |
| 86 | 98 |
| 87 // A net::ProxyConfigService implementation that applies preference proxy | 99 // A net::ProxyConfigService implementation that applies preference proxy |
| 88 // settings as overrides to the proxy configuration determined by a baseline | 100 // settings as overrides to the proxy configuration determined by a baseline |
| 89 // delegate ProxyConfigService. | 101 // delegate ProxyConfigService. |
| 90 class PrefProxyConfigService | 102 class PrefProxyConfigService |
| 91 : public net::ProxyConfigService, | 103 : public net::ProxyConfigService, |
| 92 public net::ProxyConfigService::Observer, | 104 public net::ProxyConfigService::Observer, |
| 93 public PrefProxyConfigTracker::Observer { | 105 public PrefProxyConfigTracker::Observer { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 120 ObserverList<net::ProxyConfigService::Observer, true> observers_; | 132 ObserverList<net::ProxyConfigService::Observer, true> observers_; |
| 121 scoped_refptr<PrefProxyConfigTracker> pref_config_tracker_; | 133 scoped_refptr<PrefProxyConfigTracker> pref_config_tracker_; |
| 122 | 134 |
| 123 // Indicates whether the base service and tracker registrations are done. | 135 // Indicates whether the base service and tracker registrations are done. |
| 124 bool registered_observers_; | 136 bool registered_observers_; |
| 125 | 137 |
| 126 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigService); | 138 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigService); |
| 127 }; | 139 }; |
| 128 | 140 |
| 129 #endif // CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_ | 141 #endif // CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_ |
| OLD | NEW |