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_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_ |
6 #define CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_ | 6 #define CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/observer_list.h" | |
16 #include "base/values.h" | 13 #include "base/values.h" |
17 #include "chrome/browser/chromeos/cros/network_library.h" | 14 #include "chrome/browser/chromeos/cros/network_library.h" |
18 #include "chrome/browser/chromeos/login/signed_settings.h" | 15 #include "chrome/browser/chromeos/login/signed_settings.h" |
19 #include "net/proxy/proxy_config.h" | 16 #include "chrome/browser/net/pref_proxy_config_tracker.h" |
20 #include "net/proxy/proxy_config_service.h" | 17 #include "chrome/browser/prefs/pref_member.h" |
21 #include "net/proxy/proxy_server.h" | |
22 | 18 |
23 namespace chromeos { | 19 namespace chromeos { |
24 | 20 |
25 // Implementation of proxy config service for chromeos that: | 21 // Implementation of proxy config service for chromeos that: |
26 // - is RefCountedThreadSafe | 22 // - extends PrefProxyConfigTracker (and so lives and runs entirely on UI |
27 // - is wrapped by chromeos::ProxyConfigService which implements | 23 // thread) to handle proxy from prefs (via PrefProxyConfigTracker) and system |
28 // net::ProxyConfigService interface by fowarding the methods to this class | 24 // i.e. network (via flimflam notifications) |
| 25 // - exists one per profile and one per local state |
29 // - retrieves initial system proxy configuration from cros settings persisted | 26 // - retrieves initial system proxy configuration from cros settings persisted |
30 // on chromeos device from chromeos revisions before migration to flimflam, | 27 // on chromeos device from chromeos revisions before migration to flimflam, |
31 // - persists proxy setting per network in flimflim | 28 // - persists proxy setting per network in flimflim |
32 // - provides network stack with latest proxy configuration for currently | 29 // - provides network stack with latest effective proxy configuration for |
33 // active network for use on IO thread | 30 // currently active network via PrefProxyConfigTracker's mechanism of pushing |
| 31 // config to ChromeProxyConfigService |
34 // - provides UI with methods to retrieve and modify proxy configuration for | 32 // - provides UI with methods to retrieve and modify proxy configuration for |
35 // any network (either currently active or non-active) on UI thread | 33 // any remembered network (either currently active or non-active) of current |
| 34 // user profile |
36 class ProxyConfigServiceImpl | 35 class ProxyConfigServiceImpl |
37 : public base::RefCountedThreadSafe<ProxyConfigServiceImpl>, | 36 : public PrefProxyConfigTracker, |
38 public SignedSettings::Delegate<std::string>, | 37 public SignedSettings::Delegate<std::string>, |
39 public NetworkLibrary::NetworkManagerObserver, | 38 public NetworkLibrary::NetworkManagerObserver, |
40 public NetworkLibrary::NetworkObserver { | 39 public NetworkLibrary::NetworkObserver { |
41 public: | 40 public: |
42 // ProxyConfigServiceImpl is created on the UI thread in | 41 // ProxyConfigServiceImpl is created in ProxyServiceFactory:: |
43 // chrome/browser/net/proxy_service_factory.cc::CreateProxyConfigService | 42 // CreatePrefProxyConfigTracker via Profile::GetProxyConfigTracker() for |
44 // via BrowserProcess::chromeos_proxy_config_service_impl, and stored in | 43 // profile or IOThread constructor for local state and is owned by the |
45 // g_browser_process as a scoped_refptr (because it's RefCountedThreadSafe). | 44 // respective classes. |
46 // | 45 // |
47 // Past that point, it can be accessed from the IO or UI threads. | 46 // From the UI, it is accessed via Profile::GetProxyConfigTracker to allow |
| 47 // user to read or modify the proxy configuration via UIGetProxyConfig or |
| 48 // UISetProxyConfigTo* respectively. |
| 49 // The new modified proxy config, together with proxy from prefs if available, |
| 50 // are used to determine the effective proxy config, which is then pushed |
| 51 // through PrefProxyConfigTracker to ChromeProxyConfigService to the network |
| 52 // stack. |
48 // | 53 // |
49 // From the IO thread, it is accessed periodically through the wrapper class | |
50 // chromeos::ProxyConfigService via net::ProxyConfigService interface | |
51 // (GetLatestProxyConfig, AddObserver, RemoveObserver). | |
52 // | |
53 // From the UI thread, it is accessed via | |
54 // BrowserProcess::chromeos_proxy_config_service_impl to allow user to read | |
55 // or modify the proxy configuration via UIGetProxyConfig or | |
56 // UISetProxyConfigTo* respectively. | |
57 // The new modified proxy config is posted to the IO thread through | |
58 // SetNewProxyConfig(). We then notify observers on the IO thread of the | |
59 // configuration change. | |
60 | |
61 // In contrary to other platforms which simply use the systems' UI to allow | 54 // In contrary to other platforms which simply use the systems' UI to allow |
62 // users to configure proxies, we have to implement our own UI on the chromeos | 55 // users to configure proxies, we have to implement our own UI on the chromeos |
63 // device. This requires extra and specific UI requirements that | 56 // device. This requires extra and specific UI requirements that |
64 // net::ProxyConfig does not suffice. So we create an augmented analog to | 57 // net::ProxyConfig does not suffice. So we create an augmented analog to |
65 // net:ProxyConfig here to include and handle these UI requirements, e.g. | 58 // net:ProxyConfig here to include and handle these UI requirements, e.g. |
66 // - where configuration was picked up from - policy or owner | 59 // - state of configuration e.g. where it was picked up from - policy, |
| 60 // extension, etc (refer to ProxyPrefs::ConfigState) |
67 // - the read/write access of a proxy setting | 61 // - the read/write access of a proxy setting |
68 // - may add more stuff later. | 62 // - may add more stuff later. |
69 // This is then converted to the common net::ProxyConfig before being returned | 63 // This is then converted to the common net::ProxyConfig before being pushed |
70 // to ProxyService::GetLatestProxyConfig on the IO thread to be used on the | 64 // to PrefProxyConfigTracker::OnProxyConfigChanged and then to the network |
71 // network stack. | 65 // stack. |
72 struct ProxyConfig { | 66 struct ProxyConfig { |
73 // Specifies if proxy config is direct, auto-detect, using pac script, | 67 // Specifies if proxy config is direct, auto-detect, using pac script, |
74 // single-proxy, or proxy-per-scheme. | 68 // single-proxy, or proxy-per-scheme. |
75 enum Mode { | 69 enum Mode { |
76 MODE_DIRECT, | 70 MODE_DIRECT, |
77 MODE_AUTO_DETECT, | 71 MODE_AUTO_DETECT, |
78 MODE_PAC_SCRIPT, | 72 MODE_PAC_SCRIPT, |
79 MODE_SINGLE_PROXY, | 73 MODE_SINGLE_PROXY, |
80 MODE_PROXY_PER_SCHEME, | 74 MODE_PROXY_PER_SCHEME, |
81 }; | 75 }; |
82 | 76 |
83 // Specifies where proxy configuration was picked up from. | |
84 enum Source { | |
85 SOURCE_NONE, // No default configuration. | |
86 SOURCE_POLICY, // Configuration is from policy. | |
87 SOURCE_OWNER, // Configuration is from owner. | |
88 }; | |
89 | |
90 struct Setting { | |
91 Setting() : source(SOURCE_NONE) {} | |
92 bool CanBeWrittenByUser(bool user_is_owner); | |
93 | |
94 Source source; | |
95 }; | |
96 | |
97 // Proxy setting for mode = direct or auto-detect or using pac script. | 77 // Proxy setting for mode = direct or auto-detect or using pac script. |
98 struct AutomaticProxy : public Setting { | 78 struct AutomaticProxy { |
99 GURL pac_url; // Set if proxy is using pac script. | 79 GURL pac_url; // Set if proxy is using pac script. |
100 }; | 80 }; |
101 | 81 |
102 // Proxy setting for mode = single-proxy or proxy-per-scheme. | 82 // Proxy setting for mode = single-proxy or proxy-per-scheme. |
103 struct ManualProxy : public Setting { | 83 struct ManualProxy { |
104 net::ProxyServer server; | 84 net::ProxyServer server; |
105 }; | 85 }; |
106 | 86 |
107 ProxyConfig(); | 87 ProxyConfig(); |
108 ~ProxyConfig(); | 88 ~ProxyConfig(); |
109 | 89 |
110 // Converts |this| to net::ProxyConfig. | 90 // Converts net::ProxyConfig to |this|. |
111 void ToNetProxyConfig(net::ProxyConfig* net_config); | 91 bool FromNetProxyConfig(const net::ProxyConfig& net_config); |
112 | 92 |
113 // Returns true if proxy config can be written by user. | 93 // Converts |this| to Dictionary of ProxyConfigDictionary format (which |
114 // If mode is MODE_PROXY_PER_SCHEME, |scheme| is one of "http", "https", | 94 // is the same format used by prefs). |
115 // "ftp" or "socks"; otherwise, it should be empty or will be ignored. | 95 DictionaryValue* ToPrefProxyConfig(); |
116 bool CanBeWrittenByUser(bool user_is_owner, const std::string& scheme); | |
117 | 96 |
118 // Map |scheme| (one of "http", "https", "ftp" or "socks") to the correct | 97 // Map |scheme| (one of "http", "https", "ftp" or "socks") to the correct |
119 // ManualProxy. Returns NULL if scheme is invalid. | 98 // ManualProxy. Returns NULL if scheme is invalid. |
120 ManualProxy* MapSchemeToProxy(const std::string& scheme); | 99 ManualProxy* MapSchemeToProxy(const std::string& scheme); |
121 | 100 |
122 // We've migrated device settings to flimflam, so we only need to | 101 // We've migrated device settings to flimflam, so we only need to |
123 // deserialize previously persisted device settings. | 102 // deserialize previously persisted device settings. |
124 // Deserializes from signed setting on device as std::string into a | 103 // Deserializes from signed setting on device as std::string into a |
125 // protobuf and then into the config. | 104 // protobuf and then into the config. |
126 bool DeserializeForDevice(const std::string& input); | 105 bool DeserializeForDevice(const std::string& input); |
127 | 106 |
128 // Serializes config into a ProxyConfigDictionary and then std::string | 107 // Serializes config into a ProxyConfigDictionary and then std::string |
129 // persisted as string property in flimflam for a network. | 108 // persisted as string property in flimflam for a network. |
130 bool SerializeForNetwork(std::string* output); | 109 bool SerializeForNetwork(std::string* output); |
131 | 110 |
132 // Deserializes from string property in flimflam for a network into a | 111 Mode mode; |
133 // ProxyConfigDictionary and then into the config. | |
134 // Opposite of SerializeForNetwork. | |
135 bool DeserializeForNetwork(const std::string& input); | |
136 | 112 |
137 // Returns true if the given config is equivalent to this config. | 113 ProxyPrefs::ConfigState state; |
138 bool Equals(const ProxyConfig& other) const; | |
139 | 114 |
140 // Creates a textual dump of the configuration. | 115 // True if user can modify proxy settings via UI. |
141 std::string ToString() const; | 116 // If proxy is managed by policy or extension or other_precde or is for |
142 | 117 // shared network but kUseSharedProxies is turned off, it can't be modified |
143 Mode mode; | 118 // by user. |
| 119 bool user_modifiable; |
144 | 120 |
145 // Set if mode is MODE_DIRECT or MODE_AUTO_DETECT or MODE_PAC_SCRIPT. | 121 // Set if mode is MODE_DIRECT or MODE_AUTO_DETECT or MODE_PAC_SCRIPT. |
146 AutomaticProxy automatic_proxy; | 122 AutomaticProxy automatic_proxy; |
147 // Set if mode is MODE_SINGLE_PROXY. | 123 // Set if mode is MODE_SINGLE_PROXY. |
148 ManualProxy single_proxy; | 124 ManualProxy single_proxy; |
149 // Set if mode is MODE_PROXY_PER_SCHEME and has http proxy. | 125 // Set if mode is MODE_PROXY_PER_SCHEME and has http proxy. |
150 ManualProxy http_proxy; | 126 ManualProxy http_proxy; |
151 // Set if mode is MODE_PROXY_PER_SCHEME and has https proxy. | 127 // Set if mode is MODE_PROXY_PER_SCHEME and has https proxy. |
152 ManualProxy https_proxy; | 128 ManualProxy https_proxy; |
153 // Set if mode is MODE_PROXY_PER_SCHEME and has ftp proxy. | 129 // Set if mode is MODE_PROXY_PER_SCHEME and has ftp proxy. |
154 ManualProxy ftp_proxy; | 130 ManualProxy ftp_proxy; |
155 // Set if mode is MODE_PROXY_PER_SCHEME and has socks proxy. | 131 // Set if mode is MODE_PROXY_PER_SCHEME and has socks proxy. |
156 ManualProxy socks_proxy; | 132 ManualProxy socks_proxy; |
157 | 133 |
158 // Exceptions for when not to use a proxy. | 134 // Exceptions for when not to use a proxy. |
159 net::ProxyBypassRules bypass_rules; | 135 net::ProxyBypassRules bypass_rules; |
160 | 136 |
161 private: | 137 private: |
162 // Encodes the proxy server as "<url-scheme>=<proxy-scheme>://<proxy>" | 138 // Encodes the proxy server as "<url-scheme>=<proxy-scheme>://<proxy>" |
163 static void EncodeAndAppendProxyServer(const std::string& scheme, | 139 static void EncodeAndAppendProxyServer(const std::string& scheme, |
164 const net::ProxyServer& server, | 140 const net::ProxyServer& server, |
165 std::string* spec); | 141 std::string* spec); |
166 | |
167 // Converts |this| to Dictionary of ProxyConfigDictionary format (which | |
168 // is the same format used by prefs). | |
169 DictionaryValue* ToPrefProxyConfig(); | |
170 | |
171 // Converts |this| from Dictionary of ProxyConfigDictionary format. | |
172 bool FromPrefProxyConfig(const DictionaryValue* proxy_dict); | |
173 }; | 142 }; |
174 | 143 |
175 // Usual constructor. | 144 // Constructor. |
176 ProxyConfigServiceImpl(); | 145 explicit ProxyConfigServiceImpl(PrefService* pref_service); |
177 // Constructor for testing. | |
178 // |init_config| specifies the ProxyConfig to use for initialization. | |
179 explicit ProxyConfigServiceImpl(const ProxyConfig& init_config); | |
180 virtual ~ProxyConfigServiceImpl(); | 146 virtual ~ProxyConfigServiceImpl(); |
181 | 147 |
182 // Methods called on IO thread from wrapper class chromeos::ProxyConfigService | 148 // Called by UI to set service path of |network| to be displayed or edited. |
183 // as ProxyConfigService methods. | 149 // Subsequent UISet* methods will use this network, until UI calls it again |
184 void AddObserver(net::ProxyConfigService::Observer* observer); | 150 // with a different network. |
185 void RemoveObserver(net::ProxyConfigService::Observer* observer); | 151 void UISetCurrentNetwork(const std::string& current_network); |
186 // Called from GetLatestProxyConfig. | |
187 net::ProxyConfigService::ConfigAvailability IOGetProxyConfig( | |
188 net::ProxyConfig* config); | |
189 | 152 |
190 // Called from UI thread to retrieve proxy configuration in |config|. | 153 // Called from UI to make the currently active network the one to be displayed |
| 154 // or edited. Subsequent UISet* methods will use this network until UI calls |
| 155 // it again when the active network has changed. |
| 156 void UIMakeActiveNetworkCurrent(); |
| 157 |
| 158 // Called from UI to get name of the current network set via |
| 159 // UISetCurrentNetwork or UIMakeActiveNetworkCurrent. |
| 160 void UIGetCurrentNetworkName(std::string* network_name); |
| 161 |
| 162 // Called from UI to retrieve proxy configuration in |current_ui_config_|. |
191 void UIGetProxyConfig(ProxyConfig* config); | 163 void UIGetProxyConfig(ProxyConfig* config); |
192 | 164 |
193 // Called from UI thread to set service path of network to be displayed or | 165 // Called from UI to update proxy configuration for different modes. |
194 // edited. Subsequent UISet* methods will use this network, until UI calls | |
195 // it again with a different network. | |
196 bool UISetCurrentNetwork(const std::string& current_network); | |
197 | |
198 // Called from UI thread to make the currently active network the one to be | |
199 // displayed or edited. Subsequent UISet* methods will use this network. until | |
200 // UI calls it again when the active network has changed. | |
201 bool UIMakeActiveNetworkCurrent(); | |
202 | |
203 // Called from UI thread to get name of the current active network. | |
204 const std::string& current_network_name() const { | |
205 return current_ui_network_name_; | |
206 } | |
207 | |
208 // Called from UI thread to set/get user preference use_shared_proxies. | |
209 void UISetUseSharedProxies(bool use_shared); | |
210 bool use_shared_proxies() const { | |
211 return use_shared_proxies_; | |
212 } | |
213 | |
214 // Called from UI thread to update proxy configuration for different modes. | |
215 // Returns true if config is set properly and persisted to flimflam for the | 166 // Returns true if config is set properly and persisted to flimflam for the |
216 // current network (set via UISetCurrentNetwork/UIMakeActiveNetworkCurrent). | 167 // current network (set via UISetCurrentNetwork/UIMakeActiveNetworkCurrent). |
217 // If this network is also currently active, config service proceeds to start | 168 // If this network is also currently active, config service proceeds to start |
218 // activating it on network stack. | 169 // activating it on network stack. |
219 // Returns false if config is not set properly, probably because information | 170 // Returns false if config is not set properly, probably because information |
220 // is incomplete or invalid; while config service won't proceed to activate or | 171 // is incomplete or invalid; while config service won't proceed to activate or |
221 // persist this config, the information is "cached" in the service, so that | 172 // persist this config, the information is "cached" in the service, so that |
222 // the next UIGetProxyConfig call will return this latest information. | 173 // the next UIGetProxyConfig call will return this latest information. |
223 bool UISetProxyConfigToDirect(); | 174 bool UISetProxyConfigToDirect(); |
224 bool UISetProxyConfigToAutoDetect(); | 175 bool UISetProxyConfigToAutoDetect(); |
225 bool UISetProxyConfigToPACScript(const GURL& pac_url); | 176 bool UISetProxyConfigToPACScript(const GURL& pac_url); |
226 bool UISetProxyConfigToSingleProxy(const net::ProxyServer& server); | 177 bool UISetProxyConfigToSingleProxy(const net::ProxyServer& server); |
227 // |scheme| is one of "http", "https", "ftp" or "socks". | 178 // |scheme| is one of "http", "https", "ftp" or "socks". |
228 bool UISetProxyConfigToProxyPerScheme(const std::string& scheme, | 179 bool UISetProxyConfigToProxyPerScheme(const std::string& scheme, |
229 const net::ProxyServer& server); | 180 const net::ProxyServer& server); |
230 // Only valid for MODE_SINGLE_PROXY or MODE_PROXY_PER_SCHEME. | 181 // Only valid for MODE_SINGLE_PROXY or MODE_PROXY_PER_SCHEME. |
231 bool UISetProxyConfigBypassRules(const net::ProxyBypassRules& bypass_rules); | 182 bool UISetProxyConfigBypassRules(const net::ProxyBypassRules& bypass_rules); |
232 | 183 |
233 // Implementation for SignedSettings::Delegate | 184 // Implementation for SignedSettings::Delegate |
234 virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code, | 185 virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code, |
235 std::string value); | 186 std::string value) OVERRIDE; |
236 | 187 |
237 // NetworkLibrary::NetworkManagerObserver implementation. | 188 // NetworkLibrary::NetworkManagerObserver implementation. |
238 virtual void OnNetworkManagerChanged(NetworkLibrary* cros); | 189 virtual void OnNetworkManagerChanged(NetworkLibrary* cros) OVERRIDE; |
239 | 190 |
240 // NetworkLibrary::NetworkObserver implementation. | 191 // NetworkLibrary::NetworkObserver implementation. |
241 virtual void OnNetworkChanged(NetworkLibrary* cros, const Network* network); | 192 virtual void OnNetworkChanged(NetworkLibrary* cros, |
| 193 const Network* network) OVERRIDE; |
| 194 |
| 195 // PrefProxyConfigTracker implementation. |
| 196 virtual void OnProxyConfigChanged(ProxyPrefs::ConfigState config_state, |
| 197 const net::ProxyConfig& config) OVERRIDE; |
| 198 |
| 199 // Register UseShardProxies preference. |
| 200 static void RegisterPrefs(PrefService* pref_service); |
242 | 201 |
243 #if defined(UNIT_TEST) | 202 #if defined(UNIT_TEST) |
244 void SetTesting() { | 203 void SetTesting(ProxyConfig* test_config) { |
245 testing_ = true; | |
246 active_network_ = "test"; | |
247 UIMakeActiveNetworkCurrent(); | 204 UIMakeActiveNetworkCurrent(); |
| 205 if (test_config) { |
| 206 std::string value; |
| 207 test_config->SerializeForNetwork(&value); |
| 208 SetProxyConfigForNetwork(active_network_, value, false); |
| 209 } |
248 } | 210 } |
249 #endif // defined(UNIT_TEST) | 211 #endif // defined(UNIT_TEST) |
250 | 212 |
251 private: | 213 private: |
252 friend class base::RefCountedThreadSafe<ProxyConfigServiceImpl>; | 214 // content::NotificationObserver implementation. |
| 215 virtual void Observe(int type, |
| 216 const content::NotificationSource& source, |
| 217 const content::NotificationDetails& details) OVERRIDE; |
253 | 218 |
254 // Called from UI thread from the various UISetProxyConfigTo*. | 219 // Called from the various UISetProxyConfigTo*. |
255 void OnUISetProxyConfig(); | 220 void OnUISetProxyConfig(); |
256 | 221 |
257 // Posted from UI thread to IO thread to carry the new config information. | |
258 void IOSetProxyConfig( | |
259 const ProxyConfig& new_config, | |
260 net::ProxyConfigService::ConfigAvailability new_availability); | |
261 | |
262 // Called from OnNetworkManagerChanged and OnNetworkChanged for currently | 222 // Called from OnNetworkManagerChanged and OnNetworkChanged for currently |
263 // active network, to handle previously active network, new active network, | 223 // active network, to handle previously active network, new active network, |
264 // and if necessary, migrates device settings to flimflam and/or activates | 224 // and if necessary, migrates device settings to flimflam and/or activates |
265 // proxy setting of new network. | 225 // proxy setting of new network. |
266 void OnActiveNetworkChanged(NetworkLibrary* cros, | 226 void OnActiveNetworkChanged(NetworkLibrary* cros, |
267 const Network* active_network); | 227 const Network* active_network); |
268 | 228 |
269 // Sets proxy config for |network_path| into flimflam and activates setting | 229 // Sets proxy config for |network_path| into flimflam and activates setting |
270 // if the network is currently active. | 230 // if the network is currently active. If |only_set_if_empty| is true, |
| 231 // proxy will be set and saved only if network has no proxy. |
271 void SetProxyConfigForNetwork(const std::string& network_path, | 232 void SetProxyConfigForNetwork(const std::string& network_path, |
272 const std::string& value, | 233 const std::string& value, |
273 bool only_set_if_empty); | 234 bool only_set_if_empty); |
274 | 235 |
275 // Determines and activates proxy config of |network| based on if network is | 236 // Returns value of UseSharedProxies preference if it's not default, else |
276 // shared/private or user is using shared proxies, etc. | 237 // returns false if user is logged in and false otherwise. |
277 void DetermineConfigFromNetwork(const Network* network); | 238 bool GetUseSharedProxies(); |
278 | 239 |
279 // Set |current_ui_network_name_| with name of |network|. | 240 // Determines effective proxy config based on prefs from config tracker, |
280 void SetCurrentNetworkName(const Network* network); | 241 // |network| and if user is using shared proxies. |
| 242 // If |activate| is true, effective config is stored in |active_config_| and |
| 243 // activated on network stack, and hence, picked up by observers. |
| 244 // if |activate| is false, effective config is stored in |current_ui_config_| |
| 245 // but not activated on network stack, and hence, not picked up by observers. |
| 246 void DetermineEffectiveConfig(const Network* network, bool activate); |
281 | 247 |
282 // Checks that method is called on BrowserThread::IO thread. | 248 // Determines UI-related variables (|current_network_name_| and |
283 void CheckCurrentlyOnIOThread(); | 249 // |current_ui_config_|) based on |network|, called from UISetCurrentNetwork |
| 250 // and UIMakeActiveNetworkActive. |
| 251 void OnUISetCurrentNetwork(const Network* network); |
284 | 252 |
285 // Checks that method is called on BrowserThread::UI thread. | 253 // Returns true if proxy is to be ignored for network, which happens if |
286 void CheckCurrentlyOnUIThread(); | 254 // network is shared and use-shared-proxies is turned off. |
| 255 bool IgnoreProxy(const Network* network) { |
| 256 return network->profile_type() == PROFILE_SHARED && !GetUseSharedProxies(); |
| 257 } |
| 258 |
| 259 // Reset UI cache variables that keep track of UI activities. |
| 260 void ResetUICache(); |
287 | 261 |
288 // Data members. | 262 // Data members. |
289 | 263 |
290 // True if running unit_tests, which will need to specifically exclude | 264 // Service path of currently active network (determined via flimflam |
291 // flimflam logic. | 265 // notifications); if effective proxy config is from system, proxy of this |
292 bool testing_; | 266 // network will be the one taking effect. |
| 267 std::string active_network_; |
293 | 268 |
294 // True if tasks can be posted, which can only happen if constructor has | 269 // State of |active_config_|. |active_config_| is only valid if |
295 // completed (NewRunnableMethod cannot be created for a RefCountedThreadBase's | 270 // |active_config_state_| is not ProxyPrefs::CONFIG_UNSET. |
296 // method until the class's ref_count is at least one). | 271 ProxyPrefs::ConfigState active_config_state_; |
297 bool can_post_task_; | |
298 | 272 |
299 // Availability status of the configuration, initialized on UI thread, but | 273 // Active proxy configuration, which could be from prefs or network. |
300 // afterwards only accessed from IO thread. | 274 net::ProxyConfig active_config_; |
301 net::ProxyConfigService::ConfigAvailability config_availability_; | |
302 | |
303 // Service path of currently active network (determined via flimflam | |
304 // notifications) whose proxy config is taking effect. | |
305 std::string active_network_; | |
306 // Proxy configuration of |active_network_|, only accessed from UI thread. | |
307 ProxyConfig active_config_; | |
308 | 275 |
309 // Proxy config retreived from device, in format generated from | 276 // Proxy config retreived from device, in format generated from |
310 // SerializeForNetwork, that can be directly set into flimflam. | 277 // SerializeForNetwork, that can be directly set into flimflam. |
311 std::string device_config_; | 278 std::string device_config_; |
312 | 279 |
313 // Cached proxy configuration, to be converted to net::ProxyConfig and | |
314 // returned by IOGetProxyConfig. | |
315 // Initially populated from UI thread, but afterwards only accessed from IO | |
316 // thread. | |
317 ProxyConfig cached_config_; | |
318 | |
319 // Service path of network whose proxy configuration is being displayed or | 280 // Service path of network whose proxy configuration is being displayed or |
320 // edited via UI, separate from |active_network_| which may be same or | 281 // edited via UI, separate from |active_network_| which may be same or |
321 // different. | 282 // different. |
322 std::string current_ui_network_; | 283 std::string current_ui_network_; |
323 | 284 |
324 // Name of network with current_ui_network_, set in UIMakeActiveNetworkCurrent | 285 // Proxy configuration of |current_ui_network_|. |
325 // and UISetCurrentNetwork. | |
326 std::string current_ui_network_name_; | |
327 | |
328 // Proxy configuration of |current_ui_network|. | |
329 ProxyConfig current_ui_config_; | 286 ProxyConfig current_ui_config_; |
330 | 287 |
331 // True if user preference UseSharedProxies is true. | 288 // Track changes in user preference UseSharedProxies. |
332 bool use_shared_proxies_; | 289 BooleanPrefMember use_shared_proxies_; |
333 | |
334 // List of observers for changes in proxy config. | |
335 ObserverList<net::ProxyConfigService::Observer> observers_; | |
336 | 290 |
337 // Operation to retrieve proxy setting from device. | 291 // Operation to retrieve proxy setting from device. |
338 scoped_refptr<SignedSettings> retrieve_property_op_; | 292 scoped_refptr<SignedSettings> retrieve_property_op_; |
339 | 293 |
340 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceImpl); | 294 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceImpl); |
341 }; | 295 }; |
342 | 296 |
343 } // namespace chromeos | 297 } // namespace chromeos |
344 | 298 |
345 #endif // CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_ | 299 #endif // CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_ |
OLD | NEW |