OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_TRACKER_IMPL_H_ | 5 #ifndef CHROME_BROWSER_NET_PREF_PROXY_CONFIG_TRACKER_IMPL_H_ |
6 #define CHROME_BROWSER_NET_PREF_PROXY_CONFIG_TRACKER_IMPL_H_ | 6 #define CHROME_BROWSER_NET_PREF_PROXY_CONFIG_TRACKER_IMPL_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
12 #include "base/prefs/public/pref_change_registrar.h" | 12 #include "base/prefs/public/pref_change_registrar.h" |
| 13 #include "base/prefs/public/pref_observer.h" |
13 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 14 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
14 #include "content/public/browser/notification_observer.h" | |
15 #include "net/proxy/proxy_config.h" | 15 #include "net/proxy/proxy_config.h" |
16 #include "net/proxy/proxy_config_service.h" | 16 #include "net/proxy/proxy_config_service.h" |
17 | 17 |
18 class PrefService; | 18 class PrefService; |
19 | 19 |
20 // A net::ProxyConfigService implementation that applies preference proxy | 20 // A net::ProxyConfigService implementation that applies preference proxy |
21 // settings (pushed from PrefProxyConfigTrackerImpl) as overrides to the proxy | 21 // settings (pushed from PrefProxyConfigTrackerImpl) as overrides to the proxy |
22 // configuration determined by a baseline delegate ProxyConfigService on | 22 // configuration determined by a baseline delegate ProxyConfigService on |
23 // non-ChromeOS platforms. ChromeOS has its own implementation of overrides in | 23 // non-ChromeOS platforms. ChromeOS has its own implementation of overrides in |
24 // chromeos::ProxyConfigServiceImpl. | 24 // chromeos::ProxyConfigServiceImpl. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 71 |
72 // Indicates whether the base service registration is done. | 72 // Indicates whether the base service registration is done. |
73 bool registered_observer_; | 73 bool registered_observer_; |
74 | 74 |
75 DISALLOW_COPY_AND_ASSIGN(ChromeProxyConfigService); | 75 DISALLOW_COPY_AND_ASSIGN(ChromeProxyConfigService); |
76 }; | 76 }; |
77 | 77 |
78 // A class that tracks proxy preferences. It translates the configuration | 78 // A class that tracks proxy preferences. It translates the configuration |
79 // to net::ProxyConfig and pushes the result over to the IO thread for | 79 // to net::ProxyConfig and pushes the result over to the IO thread for |
80 // ChromeProxyConfigService::UpdateProxyConfig to use. | 80 // ChromeProxyConfigService::UpdateProxyConfig to use. |
81 class PrefProxyConfigTrackerImpl : public content::NotificationObserver { | 81 class PrefProxyConfigTrackerImpl : public PrefObserver { |
82 public: | 82 public: |
83 explicit PrefProxyConfigTrackerImpl(PrefService* pref_service); | 83 explicit PrefProxyConfigTrackerImpl(PrefService* pref_service); |
84 virtual ~PrefProxyConfigTrackerImpl(); | 84 virtual ~PrefProxyConfigTrackerImpl(); |
85 | 85 |
86 // Sets the proxy config service to push the preference proxy to. | 86 // Sets the proxy config service to push the preference proxy to. |
87 void SetChromeProxyConfigService( | 87 void SetChromeProxyConfigService( |
88 ChromeProxyConfigService* proxy_config_service); | 88 ChromeProxyConfigService* proxy_config_service); |
89 | 89 |
90 // Notifies the tracker that the pref service passed upon construction is | 90 // Notifies the tracker that the pref service passed upon construction is |
91 // about to go away. This must be called from the UI thread. | 91 // about to go away. This must be called from the UI thread. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 // Status is indicated in the return value. | 125 // Status is indicated in the return value. |
126 // Writes the configuration to |config| unless the return value is | 126 // Writes the configuration to |config| unless the return value is |
127 // CONFIG_UNSET, in which case |config| and |config_source| are not touched. | 127 // CONFIG_UNSET, in which case |config| and |config_source| are not touched. |
128 ProxyPrefs::ConfigState GetProxyConfig(net::ProxyConfig* config); | 128 ProxyPrefs::ConfigState GetProxyConfig(net::ProxyConfig* config); |
129 | 129 |
130 // Called when there's a change in prefs proxy config. | 130 // Called when there's a change in prefs proxy config. |
131 // Subclasses can extend it for changes in other sources of proxy config. | 131 // Subclasses can extend it for changes in other sources of proxy config. |
132 virtual void OnProxyConfigChanged(ProxyPrefs::ConfigState config_state, | 132 virtual void OnProxyConfigChanged(ProxyPrefs::ConfigState config_state, |
133 const net::ProxyConfig& config); | 133 const net::ProxyConfig& config); |
134 | 134 |
135 // content::NotificationObserver implementation: | 135 // PrefObserver implementation: |
136 virtual void Observe(int type, | 136 virtual void OnPreferenceChanged(PrefServiceBase* service, |
137 const content::NotificationSource& source, | 137 const std::string& pref_name) OVERRIDE; |
138 const content::NotificationDetails& details) OVERRIDE; | |
139 | 138 |
140 | 139 |
141 const PrefService* prefs() const { return pref_service_; } | 140 const PrefService* prefs() const { return pref_service_; } |
142 bool update_pending() const { return update_pending_; } | 141 bool update_pending() const { return update_pending_; } |
143 | 142 |
144 private: | 143 private: |
145 // Creates a proxy configuration from proxy-related preferences. Configuration | 144 // Creates a proxy configuration from proxy-related preferences. Configuration |
146 // is stored in |config|, return value indicates whether the configuration is | 145 // is stored in |config|, return value indicates whether the configuration is |
147 // valid. | 146 // valid. |
148 ProxyPrefs::ConfigState ReadPrefConfig(net::ProxyConfig* config); | 147 ProxyPrefs::ConfigState ReadPrefConfig(net::ProxyConfig* config); |
149 | 148 |
150 // Tracks configuration state. |pref_config_| is valid only if |config_state_| | 149 // Tracks configuration state. |pref_config_| is valid only if |config_state_| |
151 // is not CONFIG_UNSET. | 150 // is not CONFIG_UNSET. |
152 ProxyPrefs::ConfigState config_state_; | 151 ProxyPrefs::ConfigState config_state_; |
153 | 152 |
154 // Configuration as defined by prefs. | 153 // Configuration as defined by prefs. |
155 net::ProxyConfig pref_config_; | 154 net::ProxyConfig pref_config_; |
156 | 155 |
157 PrefService* pref_service_; | 156 PrefService* pref_service_; |
158 ChromeProxyConfigService* chrome_proxy_config_service_; // Weak ptr. | 157 ChromeProxyConfigService* chrome_proxy_config_service_; // Weak ptr. |
159 bool update_pending_; // True if config has not been pushed to network stack. | 158 bool update_pending_; // True if config has not been pushed to network stack. |
160 PrefChangeRegistrar proxy_prefs_; | 159 PrefChangeRegistrar proxy_prefs_; |
161 | 160 |
162 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigTrackerImpl); | 161 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigTrackerImpl); |
163 }; | 162 }; |
164 | 163 |
165 #endif // CHROME_BROWSER_NET_PREF_PROXY_CONFIG_TRACKER_IMPL_H_ | 164 #endif // CHROME_BROWSER_NET_PREF_PROXY_CONFIG_TRACKER_IMPL_H_ |
OLD | NEW |