Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Side by Side Diff: chrome/browser/chromeos/proxy_config_service_impl.h

Issue 8102019: redesign and reimplement proxy config service and tracker, revise proxy ui on cros (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/observer_list.h" 15 #include "base/observer_list.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/chromeos/cros/network_library.h" 17 #include "chrome/browser/chromeos/cros/network_library.h"
18 #include "chrome/browser/chromeos/login/signed_settings.h" 18 #include "chrome/browser/chromeos/login/signed_settings.h"
19 #include "net/proxy/proxy_config.h" 19 #include "net/proxy/proxy_config.h"
20 #include "net/proxy/proxy_config_service.h" 20 #include "net/proxy/proxy_config_service.h"
21 #include "net/proxy/proxy_server.h" 21 #include "net/proxy/proxy_server.h"
22 22
23 class Profile;
24
23 namespace chromeos { 25 namespace chromeos {
24 26
25 // Implementation of proxy config service for chromeos that: 27 // Implementation of proxy config service for chromeos that:
26 // - is RefCountedThreadSafe 28 // - is RefCountedThreadSafe
27 // - is wrapped by chromeos::ProxyConfigService which implements 29 // - is wrapped by chromeos::ProxyConfigService which implements
28 // net::ProxyConfigService interface by fowarding the methods to this class 30 // net::ProxyConfigService interface by fowarding the methods to this class
29 // - retrieves initial system proxy configuration from cros settings persisted 31 // - retrieves initial system proxy configuration from cros settings persisted
30 // on chromeos device from chromeos revisions before migration to flimflam, 32 // on chromeos device from chromeos revisions before migration to flimflam,
31 // - persists proxy setting per network in flimflim 33 // - persists proxy setting per network in flimflim
32 // - provides network stack with latest proxy configuration for currently 34 // - provides network stack with latest proxy configuration for currently
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // single-proxy, or proxy-per-scheme. 76 // single-proxy, or proxy-per-scheme.
75 enum Mode { 77 enum Mode {
76 MODE_DIRECT, 78 MODE_DIRECT,
77 MODE_AUTO_DETECT, 79 MODE_AUTO_DETECT,
78 MODE_PAC_SCRIPT, 80 MODE_PAC_SCRIPT,
79 MODE_SINGLE_PROXY, 81 MODE_SINGLE_PROXY,
80 MODE_PROXY_PER_SCHEME, 82 MODE_PROXY_PER_SCHEME,
81 }; 83 };
82 84
83 // Specifies where proxy configuration was picked up from. 85 // Specifies where proxy configuration was picked up from.
86 static const int kSourceDisabled = 0x1000;
87 enum SourceType {
88 SOURCE_TYPE_NONE = 1, // No configuration.
89 SOURCE_TYPE_POLICY = 2, // Configuration is from policy.
90 SOURCE_TYPE_EXTENSION = 3, // Configuration is from extension.
91 SOURCE_TYPE_RECOMMENDED = 4, // Configuration is recommended.
92 SOURCE_TYPE_NETWORK = 5, // Configuration is from network.
93 };
84 enum Source { 94 enum Source {
85 SOURCE_NONE, // No default configuration. 95 // No configuration and writeable.
86 SOURCE_POLICY, // Configuration is from policy. 96 SOURCE_NONE = SOURCE_TYPE_NONE,
87 SOURCE_OWNER, // Configuration is from owner. 97 // No configuration and disabled.
88 }; 98 SOURCE_NONE_DISABLED = SOURCE_TYPE_NONE | kSourceDisabled,
89 99 // Configuration is from policy and readonly.
90 struct Setting { 100 SOURCE_POLICY = SOURCE_TYPE_POLICY | kSourceDisabled,
91 Setting() : source(SOURCE_NONE) {} 101 // Configuration is from extension and readonly.
92 bool CanBeWrittenByUser(bool user_is_owner); 102 SOURCE_EXTENSION = SOURCE_TYPE_EXTENSION | kSourceDisabled,
93 103 // Configuration is recommended and writeable.
94 Source source; 104 SOURCE_RECOMMENDED = SOURCE_TYPE_RECOMMENDED,
105 // Configuration is recommended but disabled.
106 SOURCE_RECOMMENDED_DISABLED = SOURCE_TYPE_RECOMMENDED | kSourceDisabled,
107 // Configuration is from network and writeable.
108 SOURCE_NETWORK = SOURCE_TYPE_NETWORK,
109 // Configuration is from network but disabled.
110 SOURCE_NETWORK_DISABLED = SOURCE_TYPE_NETWORK | kSourceDisabled,
95 }; 111 };
stevenjb 2011/10/05 00:22:57 Do we need to Source and SourceType in the same va
kuan 2011/10/07 00:30:41 i use "source| and |user_modifiable|. On 2011/10/
96 112
97 // Proxy setting for mode = direct or auto-detect or using pac script. 113 // Proxy setting for mode = direct or auto-detect or using pac script.
98 struct AutomaticProxy : public Setting { 114 struct AutomaticProxy {
99 GURL pac_url; // Set if proxy is using pac script. 115 GURL pac_url; // Set if proxy is using pac script.
stevenjb 2011/10/05 00:22:57 nit: one space betwen GURL and pac
kuan 2011/10/07 00:30:41 Done.
100 }; 116 };
101 117
102 // Proxy setting for mode = single-proxy or proxy-per-scheme. 118 // Proxy setting for mode = single-proxy or proxy-per-scheme.
103 struct ManualProxy : public Setting { 119 struct ManualProxy {
104 net::ProxyServer server; 120 net::ProxyServer server;
Mattias Nissler (ping if slow) 2011/10/05 10:18:36 same here: only one space.
kuan 2011/10/07 00:30:41 Done.
105 }; 121 };
106 122
107 ProxyConfig(); 123 ProxyConfig();
108 ~ProxyConfig(); 124 ~ProxyConfig();
109 125
110 // Converts |this| to net::ProxyConfig. 126 // Converts |this| to net::ProxyConfig.
111 void ToNetProxyConfig(net::ProxyConfig* net_config); 127 void ToNetProxyConfig(net::ProxyConfig* net_config);
112 128
113 // Returns true if proxy config can be written by user. 129 // Converts net::ProxyConfig to |this|.
114 // If mode is MODE_PROXY_PER_SCHEME, |scheme| is one of "http", "https", 130 bool FromNetProxyConfig(const net::ProxyConfig& net_config);
115 // "ftp" or "socks"; otherwise, it should be empty or will be ignored. 131
116 bool CanBeWrittenByUser(bool user_is_owner, const std::string& scheme); 132 // Returns true if proxy config can be modified by user.
133 bool IsUserModifiable() const {
134 return !(static_cast<int>(source) & kSourceDisabled);
Mattias Nissler (ping if slow) 2011/10/05 10:18:36 Seems like Steven has a point in making an actual
kuan 2011/10/07 00:30:41 i removed it. On 2011/10/05 10:18:36, Mattias Nis
135 }
117 136
118 // Map |scheme| (one of "http", "https", "ftp" or "socks") to the correct 137 // Map |scheme| (one of "http", "https", "ftp" or "socks") to the correct
119 // ManualProxy. Returns NULL if scheme is invalid. 138 // ManualProxy. Returns NULL if scheme is invalid.
120 ManualProxy* MapSchemeToProxy(const std::string& scheme); 139 ManualProxy* MapSchemeToProxy(const std::string& scheme);
121 140
122 // We've migrated device settings to flimflam, so we only need to 141 // We've migrated device settings to flimflam, so we only need to
123 // deserialize previously persisted device settings. 142 // deserialize previously persisted device settings.
124 // Deserializes from signed setting on device as std::string into a 143 // Deserializes from signed setting on device as std::string into a
125 // protobuf and then into the config. 144 // protobuf and then into the config.
126 bool DeserializeForDevice(const std::string& input); 145 bool DeserializeForDevice(const std::string& input);
127 146
128 // Serializes config into a ProxyConfigDictionary and then std::string 147 // Serializes config into a ProxyConfigDictionary and then std::string
129 // persisted as string property in flimflam for a network. 148 // persisted as string property in flimflam for a network.
130 bool SerializeForNetwork(std::string* output); 149 bool SerializeForNetwork(std::string* output);
131 150
132 // Deserializes from string property in flimflam for a network into a 151 // Deserializes from string property in flimflam for a network into a
133 // ProxyConfigDictionary and then into the config. 152 // ProxyConfigDictionary and then into the config.
134 // Opposite of SerializeForNetwork. 153 // Opposite of SerializeForNetwork.
135 bool DeserializeForNetwork(const std::string& input); 154 bool DeserializeForNetwork(const std::string& input);
136 155
137 // Returns true if the given config is equivalent to this config. 156 // Returns true if the given config is equivalent to this config.
138 bool Equals(const ProxyConfig& other) const; 157 bool Equals(const ProxyConfig& other) const;
139 158
140 // Creates a textual dump of the configuration. 159 // Creates a textual dump of the configuration.
141 std::string ToString() const; 160 std::string ToString() const;
142 161
143 Mode mode; 162 Mode mode;
144 163
164 Source source;
165
145 // Set if mode is MODE_DIRECT or MODE_AUTO_DETECT or MODE_PAC_SCRIPT. 166 // Set if mode is MODE_DIRECT or MODE_AUTO_DETECT or MODE_PAC_SCRIPT.
146 AutomaticProxy automatic_proxy; 167 AutomaticProxy automatic_proxy;
147 // Set if mode is MODE_SINGLE_PROXY. 168 // Set if mode is MODE_SINGLE_PROXY.
148 ManualProxy single_proxy; 169 ManualProxy single_proxy;
149 // Set if mode is MODE_PROXY_PER_SCHEME and has http proxy. 170 // Set if mode is MODE_PROXY_PER_SCHEME and has http proxy.
150 ManualProxy http_proxy; 171 ManualProxy http_proxy;
151 // Set if mode is MODE_PROXY_PER_SCHEME and has https proxy. 172 // Set if mode is MODE_PROXY_PER_SCHEME and has https proxy.
152 ManualProxy https_proxy; 173 ManualProxy https_proxy;
153 // Set if mode is MODE_PROXY_PER_SCHEME and has ftp proxy. 174 // Set if mode is MODE_PROXY_PER_SCHEME and has ftp proxy.
154 ManualProxy ftp_proxy; 175 ManualProxy ftp_proxy;
(...skipping 29 matching lines...) Expand all
184 void AddObserver(net::ProxyConfigService::Observer* observer); 205 void AddObserver(net::ProxyConfigService::Observer* observer);
185 void RemoveObserver(net::ProxyConfigService::Observer* observer); 206 void RemoveObserver(net::ProxyConfigService::Observer* observer);
186 // Called from GetLatestProxyConfig. 207 // Called from GetLatestProxyConfig.
187 net::ProxyConfigService::ConfigAvailability IOGetProxyConfig( 208 net::ProxyConfigService::ConfigAvailability IOGetProxyConfig(
188 net::ProxyConfig* config); 209 net::ProxyConfig* config);
189 210
190 // Called from UI thread to retrieve proxy configuration in |config|. 211 // Called from UI thread to retrieve proxy configuration in |config|.
191 void UIGetProxyConfig(ProxyConfig* config); 212 void UIGetProxyConfig(ProxyConfig* config);
192 213
193 // Called from UI thread to set service path of network to be displayed or 214 // Called from UI thread to set service path of network to be displayed or
194 // edited. Subsequent UISet* methods will use this network, until UI calls 215 // edited with the current user profile. Subsequent UISet* methods will use
195 // it again with a different network. 216 // this network, until UI calls it again with a different network.
196 bool UISetCurrentNetwork(const std::string& current_network); 217 void UISetCurrentNetworkWithProfile(const std::string& current_network,
218 Profile* profile);
197 219
198 // Called from UI thread to make the currently active network the one to be 220 // 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 221 // displayed or edited, with current user profile. Subsequent UISet* methods
200 // UI calls it again when the active network has changed. 222 // will use this network until UI calls it again when the active network has
201 bool UIMakeActiveNetworkCurrent(); 223 // changed.
224 void UIMakeActiveNetworkCurrentWithProfile(Profile* profile);
202 225
203 // Called from UI thread to get name of the current active network. 226 // Called from UI thread to get name of the current active network.
204 const std::string& current_network_name() const { 227 const std::string& current_network_name() const {
205 return current_ui_network_name_; 228 return current_ui_network_name_;
206 } 229 }
207 230
208 // Called from UI thread to set/get user preference use_shared_proxies. 231 // Called from UI thread to set user preference use_shared_proxies.
209 void UISetUseSharedProxies(bool use_shared); 232 void UISetUseSharedProxies(bool use_shared);
210 bool use_shared_proxies() const {
211 return use_shared_proxies_;
212 }
213 233
214 // Called from UI thread to update proxy configuration for different modes. 234 // 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 235 // Returns true if config is set properly and persisted to flimflam for the
216 // current network (set via UISetCurrentNetwork/UIMakeActiveNetworkCurrent). 236 // current network (set via UISetCurrentNetworkWithProfile or
237 // UIMakeActiveNetworkCurrentWithPRofile).
217 // If this network is also currently active, config service proceeds to start 238 // If this network is also currently active, config service proceeds to start
218 // activating it on network stack. 239 // activating it on network stack.
219 // Returns false if config is not set properly, probably because information 240 // 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 241 // 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 242 // persist this config, the information is "cached" in the service, so that
222 // the next UIGetProxyConfig call will return this latest information. 243 // the next UIGetProxyConfig call will return this latest information.
223 bool UISetProxyConfigToDirect(); 244 bool UISetProxyConfigToDirect();
224 bool UISetProxyConfigToAutoDetect(); 245 bool UISetProxyConfigToAutoDetect();
225 bool UISetProxyConfigToPACScript(const GURL& pac_url); 246 bool UISetProxyConfigToPACScript(const GURL& pac_url);
226 bool UISetProxyConfigToSingleProxy(const net::ProxyServer& server); 247 bool UISetProxyConfigToSingleProxy(const net::ProxyServer& server);
(...skipping 10 matching lines...) Expand all
237 // NetworkLibrary::NetworkManagerObserver implementation. 258 // NetworkLibrary::NetworkManagerObserver implementation.
238 virtual void OnNetworkManagerChanged(NetworkLibrary* cros); 259 virtual void OnNetworkManagerChanged(NetworkLibrary* cros);
239 260
240 // NetworkLibrary::NetworkObserver implementation. 261 // NetworkLibrary::NetworkObserver implementation.
241 virtual void OnNetworkChanged(NetworkLibrary* cros, const Network* network); 262 virtual void OnNetworkChanged(NetworkLibrary* cros, const Network* network);
242 263
243 #if defined(UNIT_TEST) 264 #if defined(UNIT_TEST)
244 void SetTesting() { 265 void SetTesting() {
245 testing_ = true; 266 testing_ = true;
246 active_network_ = "test"; 267 active_network_ = "test";
247 UIMakeActiveNetworkCurrent(); 268 UIMakeActiveNetworkCurrentWithProfile(NULL);
248 } 269 }
249 #endif // defined(UNIT_TEST) 270 #endif // defined(UNIT_TEST)
250 271
251 private: 272 private:
252 friend class base::RefCountedThreadSafe<ProxyConfigServiceImpl>; 273 friend class base::RefCountedThreadSafe<ProxyConfigServiceImpl>;
253 274
254 // Called from UI thread from the various UISetProxyConfigTo*. 275 // Called from UI thread from the various UISetProxyConfigTo*.
255 void OnUISetProxyConfig(); 276 void OnUISetProxyConfig();
256 277
257 // Posted from UI thread to IO thread to carry the new config information. 278 // Posted from UI thread to IO thread to carry the new config information.
(...skipping 11 matching lines...) Expand all
269 // Sets proxy config for |network_path| into flimflam and activates setting 290 // Sets proxy config for |network_path| into flimflam and activates setting
270 // if the network is currently active. 291 // if the network is currently active.
271 void SetProxyConfigForNetwork(const std::string& network_path, 292 void SetProxyConfigForNetwork(const std::string& network_path,
272 const std::string& value, 293 const std::string& value,
273 bool only_set_if_empty); 294 bool only_set_if_empty);
274 295
275 // Determines and activates proxy config of |network| based on if network is 296 // Determines and activates proxy config of |network| based on if network is
276 // shared/private or user is using shared proxies, etc. 297 // shared/private or user is using shared proxies, etc.
277 void DetermineConfigFromNetwork(const Network* network); 298 void DetermineConfigFromNetwork(const Network* network);
278 299
300 // Determines proxy config for ui based on |profile| and |network|.
301 void DetermineUIConfig(Profile* profile, const Network* network);
302
279 // Set |current_ui_network_name_| with name of |network|. 303 // Set |current_ui_network_name_| with name of |network|.
280 void SetCurrentNetworkName(const Network* network); 304 void SetCurrentNetworkName(const Network* network);
281 305
306 // Returns true if proxy is to be ignored for network, which happens if
307 // network is shared and use-shared-proxies is turned off.
308 bool IgnoreProxy(const Network* network) {
309 return network->profile_type() == PROFILE_SHARED && !use_shared_proxies_;
310 }
311
312 // Reset UI cache variables that keep track of ui changes.
313 void ResetUICache();
314
282 // Checks that method is called on BrowserThread::IO thread. 315 // Checks that method is called on BrowserThread::IO thread.
283 void CheckCurrentlyOnIOThread(); 316 void CheckCurrentlyOnIOThread();
284 317
285 // Checks that method is called on BrowserThread::UI thread. 318 // Checks that method is called on BrowserThread::UI thread.
286 void CheckCurrentlyOnUIThread(); 319 void CheckCurrentlyOnUIThread();
287 320
288 // Data members. 321 // Data members.
289 322
290 // True if running unit_tests, which will need to specifically exclude 323 // True if running unit_tests, which will need to specifically exclude
291 // flimflam logic. 324 // flimflam logic.
(...skipping 17 matching lines...) Expand all
309 // Proxy config retreived from device, in format generated from 342 // Proxy config retreived from device, in format generated from
310 // SerializeForNetwork, that can be directly set into flimflam. 343 // SerializeForNetwork, that can be directly set into flimflam.
311 std::string device_config_; 344 std::string device_config_;
312 345
313 // Cached proxy configuration, to be converted to net::ProxyConfig and 346 // Cached proxy configuration, to be converted to net::ProxyConfig and
314 // returned by IOGetProxyConfig. 347 // returned by IOGetProxyConfig.
315 // Initially populated from UI thread, but afterwards only accessed from IO 348 // Initially populated from UI thread, but afterwards only accessed from IO
316 // thread. 349 // thread.
317 ProxyConfig cached_config_; 350 ProxyConfig cached_config_;
318 351
352 // True if user preference UseSharedProxies is true.
353 bool use_shared_proxies_;
354
319 // Service path of network whose proxy configuration is being displayed or 355 // Service path of network whose proxy configuration is being displayed or
320 // edited via UI, separate from |active_network_| which may be same or 356 // edited via UI, separate from |active_network_| which may be same or
321 // different. 357 // different.
322 std::string current_ui_network_; 358 std::string current_ui_network_;
323 359
324 // Name of network with current_ui_network_, set in UIMakeActiveNetworkCurrent 360 // Name of network with current_ui_network_, set in
325 // and UISetCurrentNetwork. 361 // UIMakeActiveNetworkCurrentWithProfile and UISetCurrentNetworkWithProfile.
326 std::string current_ui_network_name_; 362 std::string current_ui_network_name_;
327 363
328 // Proxy configuration of |current_ui_network|. 364 // Proxy configuration of |current_ui_network|.
329 ProxyConfig current_ui_config_; 365 ProxyConfig current_ui_config_;
330 366
331 // True if user preference UseSharedProxies is true.
332 bool use_shared_proxies_;
333
334 // List of observers for changes in proxy config. 367 // List of observers for changes in proxy config.
335 ObserverList<net::ProxyConfigService::Observer> observers_; 368 ObserverList<net::ProxyConfigService::Observer> observers_;
336 369
337 // Operation to retrieve proxy setting from device. 370 // Operation to retrieve proxy setting from device.
338 scoped_refptr<SignedSettings> retrieve_property_op_; 371 scoped_refptr<SignedSettings> retrieve_property_op_;
339 372
340 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceImpl); 373 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceImpl);
341 }; 374 };
342 375
343 } // namespace chromeos 376 } // namespace chromeos
344 377
345 #endif // CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_ 378 #endif // CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698