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 COMPONENTS_PROXY_CONFIG_PREF_PROXY_CONFIG_TRACKER_IMPL_H_ | 5 #ifndef COMPONENTS_PROXY_CONFIG_PREF_PROXY_CONFIG_TRACKER_IMPL_H_ |
6 #define COMPONENTS_PROXY_CONFIG_PREF_PROXY_CONFIG_TRACKER_IMPL_H_ | 6 #define COMPONENTS_PROXY_CONFIG_PREF_PROXY_CONFIG_TRACKER_IMPL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
14 #include "components/prefs/pref_change_registrar.h" | 14 #include "components/prefs/pref_change_registrar.h" |
15 #include "components/proxy_config/pref_proxy_config_tracker.h" | 15 #include "components/proxy_config/pref_proxy_config_tracker.h" |
16 #include "components/proxy_config/proxy_config_dictionary.h" | 16 #include "components/proxy_config/proxy_config_dictionary.h" |
17 #include "net/proxy/proxy_config.h" | 17 #include "net/proxy/proxy_config.h" |
18 #include "net/proxy/proxy_config_service.h" | 18 #include "net/proxy/proxy_config_service.h" |
19 | 19 |
20 class PrefService; | 20 class PrefService; |
21 class PrefRegistrySimple; | 21 class PrefRegistrySimple; |
22 | 22 |
23 namespace base { | 23 namespace base { |
24 class SingleThreadTaskRunner; | 24 class SingleThreadTaskRunner; |
25 } | 25 } |
26 | 26 |
27 namespace user_prefs { | |
28 class PrefRegistrySyncable; | |
29 } | |
30 | |
31 // A net::ProxyConfigService implementation that applies preference proxy | 27 // A net::ProxyConfigService implementation that applies preference proxy |
32 // settings (pushed from PrefProxyConfigTrackerImpl) as overrides to the proxy | 28 // settings (pushed from PrefProxyConfigTrackerImpl) as overrides to the proxy |
33 // configuration determined by a baseline delegate ProxyConfigService on | 29 // configuration determined by a baseline delegate ProxyConfigService on |
34 // non-ChromeOS platforms. ChromeOS has its own implementation of overrides in | 30 // non-ChromeOS platforms. ChromeOS has its own implementation of overrides in |
35 // chromeos::ProxyConfigServiceImpl. | 31 // chromeos::ProxyConfigServiceImpl. |
36 class ProxyConfigServiceImpl : public net::ProxyConfigService, | 32 class ProxyConfigServiceImpl : public net::ProxyConfigService, |
37 public net::ProxyConfigService::Observer { | 33 public net::ProxyConfigService::Observer { |
38 public: | 34 public: |
39 ProxyConfigServiceImpl(std::unique_ptr<net::ProxyConfigService> base_service, | 35 ProxyConfigServiceImpl(std::unique_ptr<net::ProxyConfigService> base_service, |
40 ProxyPrefs::ConfigState initial_config_state, | 36 ProxyPrefs::ConfigState initial_config_state, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 net::ProxyConfig* effective_config); | 115 net::ProxyConfig* effective_config); |
120 | 116 |
121 // Converts a ProxyConfigDictionary to net::ProxyConfig representation. | 117 // Converts a ProxyConfigDictionary to net::ProxyConfig representation. |
122 // Returns true if the data from in the dictionary is valid, false otherwise. | 118 // Returns true if the data from in the dictionary is valid, false otherwise. |
123 static bool PrefConfigToNetConfig(const ProxyConfigDictionary& proxy_dict, | 119 static bool PrefConfigToNetConfig(const ProxyConfigDictionary& proxy_dict, |
124 net::ProxyConfig* config); | 120 net::ProxyConfig* config); |
125 | 121 |
126 // Registers the proxy preferences. These are actually registered | 122 // Registers the proxy preferences. These are actually registered |
127 // the same way in local state and in user prefs. | 123 // the same way in local state and in user prefs. |
128 static void RegisterPrefs(PrefRegistrySimple* registry); | 124 static void RegisterPrefs(PrefRegistrySimple* registry); |
129 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 125 static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
130 | 126 |
131 // Creates a proxy configuration from proxy-related preferences of | 127 // Creates a proxy configuration from proxy-related preferences of |
132 // |pref_service|. Configuration is stored in |config|, return value indicates | 128 // |pref_service|. Configuration is stored in |config|, return value indicates |
133 // whether the configuration is valid. | 129 // whether the configuration is valid. |
134 static ProxyPrefs::ConfigState ReadPrefConfig(const PrefService* pref_service, | 130 static ProxyPrefs::ConfigState ReadPrefConfig(const PrefService* pref_service, |
135 net::ProxyConfig* config); | 131 net::ProxyConfig* config); |
136 | 132 |
137 protected: | 133 protected: |
138 // Get the proxy configuration currently defined by preferences. | 134 // Get the proxy configuration currently defined by preferences. |
139 // Status is indicated in the return value. | 135 // Status is indicated in the return value. |
140 // Writes the configuration to |config| unless the return value is | 136 // Writes the configuration to |config| unless the return value is |
141 // CONFIG_UNSET, in which case |config| and |config_source| are not touched. | 137 // CONFIG_UNSET, in which case |config| and |config_source| are not touched. |
142 ProxyPrefs::ConfigState GetProxyConfig(net::ProxyConfig* config); | 138 ProxyPrefs::ConfigState GetProxyConfig(net::ProxyConfig* config); |
143 | 139 |
144 // Called when there's a change in prefs proxy config. | 140 // Called when there's a change in prefs proxy config. |
145 // Subclasses can extend it for changes in other sources of proxy config. | 141 // Subclasses can extend it for changes in other sources of proxy config. |
| 142 // Checks new config against old config, and if there was no change, does |
| 143 // nothing. |
146 virtual void OnProxyConfigChanged(ProxyPrefs::ConfigState config_state, | 144 virtual void OnProxyConfigChanged(ProxyPrefs::ConfigState config_state, |
147 const net::ProxyConfig& config); | 145 const net::ProxyConfig& config); |
148 | 146 |
149 void OnProxyPrefChanged(); | 147 void OnProxyPrefChanged(); |
150 | 148 |
151 const PrefService* prefs() const { return pref_service_; } | 149 const PrefService* prefs() const { return pref_service_; } |
152 | 150 |
153 private: | 151 private: |
154 // Tracks configuration state. |pref_config_| is valid only if |config_state_| | 152 // Tracks configuration state. |pref_config_| is valid only if |config_state_| |
155 // is not CONFIG_UNSET. | 153 // is not CONFIG_UNSET. |
156 ProxyPrefs::ConfigState config_state_; | 154 ProxyPrefs::ConfigState pref_config_state_; |
157 | 155 |
158 // Configuration as defined by prefs. | 156 // Configuration as defined by prefs. |
159 net::ProxyConfig pref_config_; | 157 net::ProxyConfig pref_config_; |
160 | 158 |
161 PrefService* pref_service_; | 159 PrefService* pref_service_; |
162 ProxyConfigServiceImpl* proxy_config_service_impl_; // Weak ptr. | 160 ProxyConfigServiceImpl* proxy_config_service_impl_; // Weak ptr. |
163 PrefChangeRegistrar proxy_prefs_; | 161 PrefChangeRegistrar proxy_prefs_; |
164 | 162 |
| 163 // State of |active_config_|. |active_config_| is only valid if |
| 164 // |active_config_state_| is not ProxyPrefs::CONFIG_UNSET. |
| 165 ProxyPrefs::ConfigState active_config_state_; |
| 166 |
| 167 // Active proxy configuration, last received from OnProxyConfigChanged. |
| 168 net::ProxyConfig active_config_; |
| 169 |
165 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 170 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
166 | 171 |
167 base::ThreadChecker thread_checker_; | 172 base::ThreadChecker thread_checker_; |
168 | 173 |
169 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigTrackerImpl); | 174 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigTrackerImpl); |
170 }; | 175 }; |
171 | 176 |
172 #endif // COMPONENTS_PROXY_CONFIG_PREF_PROXY_CONFIG_TRACKER_IMPL_H_ | 177 #endif // COMPONENTS_PROXY_CONFIG_PREF_PROXY_CONFIG_TRACKER_IMPL_H_ |
OLD | NEW |