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

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

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 #include "chrome/browser/chromeos/proxy_config_service_impl.h" 5 #include "chrome/browser/chromeos/proxy_config_service_impl.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/task.h" 11 #include "base/task.h"
12 #include "chrome/browser/chromeos/cros/cros_library.h" 12 #include "chrome/browser/chromeos/cros/cros_library.h"
13 #include "chrome/browser/chromeos/cros_settings_names.h" 13 #include "chrome/browser/chromeos/cros_settings_names.h"
14 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" 14 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h"
15 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/prefs/proxy_config_dictionary.h" 16 #include "chrome/browser/prefs/proxy_config_dictionary.h"
16 #include "chrome/browser/prefs/proxy_prefs.h" 17 #include "chrome/browser/prefs/proxy_prefs.h"
18 #include "chrome/browser/profiles/profile_manager.h"
17 #include "content/browser/browser_thread.h" 19 #include "content/browser/browser_thread.h"
18 #include "content/common/json_value_serializer.h" 20 #include "content/common/json_value_serializer.h"
19 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
20 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
21 23
22 namespace em = enterprise_management; 24 namespace em = enterprise_management;
23 25
24 namespace chromeos { 26 namespace chromeos {
25 27
26 namespace { 28 namespace {
27 29
28 const char* SourceToString(ProxyConfigServiceImpl::ProxyConfig::Source source) { 30 const char* SourceToString(PrefProxyConfigTracker::ConfigSource source) {
29 switch (source) { 31 switch (source) {
30 case ProxyConfigServiceImpl::ProxyConfig::SOURCE_NONE: 32 case PrefProxyConfigTracker::CONFIG_SOURCE_UNSET:
31 return "SOURCE_NONE"; 33 return "src: unset";
32 case ProxyConfigServiceImpl::ProxyConfig::SOURCE_POLICY: 34 case PrefProxyConfigTracker::CONFIG_SOURCE_POLICY:
33 return "SOURCE_POLICY"; 35 return "src: policy";
34 case ProxyConfigServiceImpl::ProxyConfig::SOURCE_OWNER: 36 case PrefProxyConfigTracker::CONFIG_SOURCE_EXTENSION:
35 return "SOURCE_OWNER"; 37 return "src: extension";
38 case PrefProxyConfigTracker::CONFIG_SOURCE_SYSTEM:
39 return "src: network"; // For ChromeOS, system is network.
40 case PrefProxyConfigTracker::CONFIG_SOURCE_FALLBACK:
41 return "src: recommended"; // Fallback is recommended.
36 } 42 }
37 NOTREACHED() << "Unrecognized source type"; 43 NOTREACHED() << "Unrecognized source type";
38 return ""; 44 return "";
39 } 45 }
40 46
47 // Only unblock if needed for debugging.
48 #if defined(NEED_DEBUG_LOG)
41 std::ostream& operator<<(std::ostream& out, 49 std::ostream& operator<<(std::ostream& out,
42 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) { 50 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) {
43 out << " " << SourceToString(proxy.source) << "\n" 51 out << (proxy.server.is_valid() ? proxy.server.ToURI() : "") << "\n";
44 << " server: " << (proxy.server.is_valid() ? proxy.server.ToURI() : "")
45 << "\n";
46 return out; 52 return out;
47 } 53 }
48 54
49 std::ostream& operator<<(std::ostream& out, 55 std::ostream& operator<<(std::ostream& out,
50 const ProxyConfigServiceImpl::ProxyConfig& config) { 56 const ProxyConfigServiceImpl::ProxyConfig& config) {
51 switch (config.mode) { 57 switch (config.mode) {
52 case ProxyConfigServiceImpl::ProxyConfig::MODE_DIRECT: 58 case ProxyConfigServiceImpl::ProxyConfig::MODE_DIRECT:
53 out << "Direct connection:\n " 59 out << "Direct connection:\n "
54 << SourceToString(config.automatic_proxy.source) << "\n"; 60 << SourceToString(config.source) << "\n";
55 break; 61 break;
56 case ProxyConfigServiceImpl::ProxyConfig::MODE_AUTO_DETECT: 62 case ProxyConfigServiceImpl::ProxyConfig::MODE_AUTO_DETECT:
57 out << "Auto detection:\n " 63 out << "Auto detection:\n "
58 << SourceToString(config.automatic_proxy.source) << "\n"; 64 << SourceToString(config.source) << "\n";
59 break; 65 break;
60 case ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT: 66 case ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT:
61 out << "Custom PAC script:\n " 67 out << "Custom PAC script:\n "
62 << SourceToString(config.automatic_proxy.source) 68 << SourceToString(config.source)
63 << "\n PAC: " << config.automatic_proxy.pac_url << "\n"; 69 << "\n PAC: " << config.automatic_proxy.pac_url << "\n";
64 break; 70 break;
65 case ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY: 71 case ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY:
66 out << "Single proxy:\n" << config.single_proxy; 72 out << "Single proxy:\n"
73 << SourceToString(config.source) << "\n " << config.single_proxy;
67 break; 74 break;
68 case ProxyConfigServiceImpl::ProxyConfig::MODE_PROXY_PER_SCHEME: 75 case ProxyConfigServiceImpl::ProxyConfig::MODE_PROXY_PER_SCHEME:
69 out << "HTTP proxy: " << config.http_proxy; 76 out << "Manual proxies:\n"
70 out << "HTTPS proxy: " << config.https_proxy; 77 << SourceToString(config.source) << "\n"
71 out << "FTP proxy: " << config.ftp_proxy; 78 << " HTTP: " << config.http_proxy
72 out << "SOCKS proxy: " << config.socks_proxy; 79 << " HTTPS: " << config.https_proxy
80 << " FTP: " << config.ftp_proxy
81 << " SOCKS: " << config.socks_proxy;
73 break; 82 break;
74 default: 83 default:
75 NOTREACHED() << "Unrecognized proxy config mode"; 84 NOTREACHED() << "Unrecognized proxy config mode";
76 break; 85 break;
77 } 86 }
78 if (config.mode == ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY || 87 if (config.mode == ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY ||
79 config.mode == 88 config.mode ==
80 ProxyConfigServiceImpl::ProxyConfig::MODE_PROXY_PER_SCHEME) { 89 ProxyConfigServiceImpl::ProxyConfig::MODE_PROXY_PER_SCHEME) {
81 out << "Bypass list: "; 90 out << "Bypass list: ";
82 if (config.bypass_rules.rules().empty()) { 91 if (config.bypass_rules.rules().empty()) {
83 out << "[None]"; 92 out << "[None]";
84 } else { 93 } else {
85 const net::ProxyBypassRules& bypass_rules = config.bypass_rules; 94 const net::ProxyBypassRules& bypass_rules = config.bypass_rules;
86 net::ProxyBypassRules::RuleList::const_iterator it; 95 net::ProxyBypassRules::RuleList::const_iterator it;
87 for (it = bypass_rules.rules().begin(); 96 for (it = bypass_rules.rules().begin();
88 it != bypass_rules.rules().end(); ++it) { 97 it != bypass_rules.rules().end(); ++it) {
89 out << "\n " << (*it)->ToString(); 98 out << "\n " << (*it)->ToString();
90 } 99 }
91 } 100 }
92 } 101 }
93 return out; 102 return out;
94 } 103 }
95 104
96 std::string ProxyConfigToString( 105 std::string ProxyConfigToString(
97 const ProxyConfigServiceImpl::ProxyConfig& proxy_config) { 106 const ProxyConfigServiceImpl::ProxyConfig& proxy_config) {
98 std::ostringstream stream; 107 std::ostringstream stream;
99 stream << proxy_config; 108 stream << proxy_config;
100 return stream.str(); 109 return stream.str();
101 } 110 }
111 #endif // defined(NEED_DEBUG_LOG)
102 112
103 } // namespace 113 } // namespace
104 114
105 //---------- ProxyConfigServiceImpl::ProxyConfig::Setting methods --------------
106
107 bool ProxyConfigServiceImpl::ProxyConfig::Setting::CanBeWrittenByUser(
108 bool user_is_owner) {
109 // Setting can only be written by user if user is owner and setting is not
110 // from policy.
111 return user_is_owner && source != ProxyConfig::SOURCE_POLICY;
112 }
113
114 //----------- ProxyConfigServiceImpl::ProxyConfig: public methods -------------- 115 //----------- ProxyConfigServiceImpl::ProxyConfig: public methods --------------
115 116
116 ProxyConfigServiceImpl::ProxyConfig::ProxyConfig() : mode(MODE_DIRECT) {} 117 ProxyConfigServiceImpl::ProxyConfig::ProxyConfig()
118 : mode(MODE_DIRECT),
119 source(PrefProxyConfigTracker::CONFIG_SOURCE_UNSET),
120 user_modifiable(true) {}
117 121
118 ProxyConfigServiceImpl::ProxyConfig::~ProxyConfig() {} 122 ProxyConfigServiceImpl::ProxyConfig::~ProxyConfig() {}
119 123
120 void ProxyConfigServiceImpl::ProxyConfig::ToNetProxyConfig( 124 void ProxyConfigServiceImpl::ProxyConfig::ToNetProxyConfig(
121 net::ProxyConfig* net_config) { 125 net::ProxyConfig* net_config) {
122 switch (mode) { 126 switch (mode) {
123 case MODE_DIRECT: 127 case MODE_DIRECT:
124 *net_config = net::ProxyConfig::CreateDirect(); 128 *net_config = net::ProxyConfig::CreateDirect();
125 break; 129 break;
126 case MODE_AUTO_DETECT: 130 case MODE_AUTO_DETECT:
(...skipping 19 matching lines...) Expand all
146 net_config->proxy_rules().proxy_for_ftp = ftp_proxy.server; 150 net_config->proxy_rules().proxy_for_ftp = ftp_proxy.server;
147 net_config->proxy_rules().fallback_proxy = socks_proxy.server; 151 net_config->proxy_rules().fallback_proxy = socks_proxy.server;
148 net_config->proxy_rules().bypass_rules = bypass_rules; 152 net_config->proxy_rules().bypass_rules = bypass_rules;
149 break; 153 break;
150 default: 154 default:
151 NOTREACHED() << "Unrecognized proxy config mode"; 155 NOTREACHED() << "Unrecognized proxy config mode";
152 break; 156 break;
153 } 157 }
154 } 158 }
155 159
156 bool ProxyConfigServiceImpl::ProxyConfig::CanBeWrittenByUser( 160 bool ProxyConfigServiceImpl::ProxyConfig::FromNetProxyConfig(
157 bool user_is_owner, const std::string& scheme) { 161 const net::ProxyConfig& net_config) {
158 // Setting can only be written by user if user is owner and setting is not 162 const net::ProxyConfig::ProxyRules& rules = net_config.proxy_rules();
159 // from policy. 163 switch (rules.type) {
160 Setting* setting = NULL; 164 case net::ProxyConfig::ProxyRules::TYPE_NO_RULES:
161 switch (mode) { 165 if (!net_config.HasAutomaticSettings()) {
162 case MODE_DIRECT: 166 mode = ProxyConfig::MODE_DIRECT;
163 case MODE_AUTO_DETECT: 167 } else if (net_config.auto_detect()) {
164 case MODE_PAC_SCRIPT: 168 mode = ProxyConfig::MODE_AUTO_DETECT;
165 setting = &automatic_proxy; 169 } else if (net_config.has_pac_url()) {
166 break; 170 mode = ProxyConfig::MODE_PAC_SCRIPT;
167 case MODE_SINGLE_PROXY: 171 automatic_proxy.pac_url = net_config.pac_url();
168 setting = &single_proxy; 172 } else {
169 break; 173 return false;
170 case MODE_PROXY_PER_SCHEME: 174 }
171 setting = MapSchemeToProxy(scheme); 175 return true;
172 break; 176 case net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY:
177 if (!rules.single_proxy.is_valid())
178 return false;
179 mode = MODE_SINGLE_PROXY;
180 single_proxy.server = rules.single_proxy;
181 bypass_rules = rules.bypass_rules;
182 return true;
183 case net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME:
184 // Make sure we have valid server for at least one of the protocols.
185 if (!rules.proxy_for_http.is_valid() &&
186 !rules.proxy_for_https.is_valid() &&
187 !rules.proxy_for_ftp.is_valid() &&
188 !rules.fallback_proxy.is_valid()) {
189 return false;
190 }
191 mode = MODE_PROXY_PER_SCHEME;
192 if (rules.proxy_for_http.is_valid())
193 http_proxy.server = rules.proxy_for_http;
194 if (rules.proxy_for_https.is_valid())
195 https_proxy.server = rules.proxy_for_https;
196 if (rules.proxy_for_ftp.is_valid())
197 ftp_proxy.server = rules.proxy_for_ftp;
198 if (rules.fallback_proxy.is_valid())
199 socks_proxy.server = rules.fallback_proxy;
200 bypass_rules = rules.bypass_rules;
201 return true;
173 default: 202 default:
203 NOTREACHED() << "Unrecognized proxy config mode";
174 break; 204 break;
175 } 205 }
176 if (!setting) { 206 return false;
177 NOTREACHED() << "Unrecognized proxy config mode";
178 return false;
179 }
180 return setting->CanBeWrittenByUser(user_is_owner);
181 } 207 }
182 208
183 ProxyConfigServiceImpl::ProxyConfig::ManualProxy* 209 ProxyConfigServiceImpl::ProxyConfig::ManualProxy*
184 ProxyConfigServiceImpl::ProxyConfig::MapSchemeToProxy( 210 ProxyConfigServiceImpl::ProxyConfig::MapSchemeToProxy(
185 const std::string& scheme) { 211 const std::string& scheme) {
186 if (scheme == "http") 212 if (scheme == "http")
187 return &http_proxy; 213 return &http_proxy;
188 if (scheme == "https") 214 if (scheme == "https")
189 return &https_proxy; 215 return &https_proxy;
190 if (scheme == "ftp") 216 if (scheme == "ftp")
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 JSONStringValueSerializer serializer(input); 292 JSONStringValueSerializer serializer(input);
267 scoped_ptr<Value> value(serializer.Deserialize(NULL, NULL)); 293 scoped_ptr<Value> value(serializer.Deserialize(NULL, NULL));
268 if (!value.get() || value->GetType() != Value::TYPE_DICTIONARY) 294 if (!value.get() || value->GetType() != Value::TYPE_DICTIONARY)
269 return false; 295 return false;
270 DictionaryValue* proxy_dict = static_cast<DictionaryValue*>(value.get()); 296 DictionaryValue* proxy_dict = static_cast<DictionaryValue*>(value.get());
271 return FromPrefProxyConfig(proxy_dict); 297 return FromPrefProxyConfig(proxy_dict);
272 } 298 }
273 299
274 bool ProxyConfigServiceImpl::ProxyConfig::Equals( 300 bool ProxyConfigServiceImpl::ProxyConfig::Equals(
275 const ProxyConfig& other) const { 301 const ProxyConfig& other) const {
302 // Intentionally ignore source which is only used for ui purposes and has no
Mattias Nissler (ping if slow) 2011/10/07 13:32:10 s/ui/UI/
kuan 2011/10/18 16:25:35 Done.
303 // impact on proxy backend.
276 if (mode != other.mode) 304 if (mode != other.mode)
277 return false; 305 return false;
278 switch (mode) { 306 switch (mode) {
279 case MODE_DIRECT: 307 case MODE_DIRECT:
280 case MODE_AUTO_DETECT: 308 case MODE_AUTO_DETECT:
281 return true; 309 return true;
282 case MODE_PAC_SCRIPT: 310 case MODE_PAC_SCRIPT:
283 return automatic_proxy.pac_url == other.automatic_proxy.pac_url; 311 return automatic_proxy.pac_url == other.automatic_proxy.pac_url;
284 case MODE_SINGLE_PROXY: 312 case MODE_SINGLE_PROXY:
285 return single_proxy.server == other.single_proxy.server && 313 return single_proxy.server == other.single_proxy.server &&
286 bypass_rules.Equals(other.bypass_rules); 314 bypass_rules.Equals(other.bypass_rules);
287 case MODE_PROXY_PER_SCHEME: 315 case MODE_PROXY_PER_SCHEME:
288 return http_proxy.server == other.http_proxy.server && 316 return http_proxy.server == other.http_proxy.server &&
289 https_proxy.server == other.https_proxy.server && 317 https_proxy.server == other.https_proxy.server &&
290 ftp_proxy.server == other.ftp_proxy.server && 318 ftp_proxy.server == other.ftp_proxy.server &&
291 socks_proxy.server == other.socks_proxy.server && 319 socks_proxy.server == other.socks_proxy.server &&
292 bypass_rules.Equals(other.bypass_rules); 320 bypass_rules.Equals(other.bypass_rules);
293 default: { 321 default: {
294 NOTREACHED() << "Unrecognized proxy config mode"; 322 NOTREACHED() << "Unrecognized proxy config mode";
295 break; 323 break;
296 } 324 }
297 } 325 }
298 return false; 326 return false;
299 } 327 }
300 328
301 std::string ProxyConfigServiceImpl::ProxyConfig::ToString() const {
302 return ProxyConfigToString(*this);
303 }
304
305 //----------- ProxyConfigServiceImpl::ProxyConfig: private methods ------------- 329 //----------- ProxyConfigServiceImpl::ProxyConfig: private methods -------------
306 330
307 // static 331 // static
308 void ProxyConfigServiceImpl::ProxyConfig::EncodeAndAppendProxyServer( 332 void ProxyConfigServiceImpl::ProxyConfig::EncodeAndAppendProxyServer(
309 const std::string& scheme, 333 const std::string& scheme,
310 const net::ProxyServer& server, 334 const net::ProxyServer& server,
311 std::string* spec) { 335 std::string* spec) {
312 if (!server.is_valid()) 336 if (!server.is_valid())
313 return; 337 return;
314 338
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 } 458 }
435 NOTREACHED() << "Unknown proxy mode, falling back to system settings."; 459 NOTREACHED() << "Unknown proxy mode, falling back to system settings.";
436 return false; 460 return false;
437 } 461 }
438 462
439 //------------------- ProxyConfigServiceImpl: public methods ------------------- 463 //------------------- ProxyConfigServiceImpl: public methods -------------------
440 464
441 ProxyConfigServiceImpl::ProxyConfigServiceImpl() 465 ProxyConfigServiceImpl::ProxyConfigServiceImpl()
442 : testing_(false), 466 : testing_(false),
443 can_post_task_(false), 467 can_post_task_(false),
444 config_availability_(net::ProxyConfigService::CONFIG_UNSET), 468 io_config_availability_(net::ProxyConfigService::CONFIG_UNSET),
445 use_shared_proxies_(true) { 469 use_shared_proxies_(true),
470 current_ui_profile_(NULL) {
446 // Start async fetch of proxy config from settings persisted on device. 471 // Start async fetch of proxy config from settings persisted on device.
447 if (CrosLibrary::Get()->EnsureLoaded()) { 472 if (CrosLibrary::Get()->EnsureLoaded()) {
448 retrieve_property_op_ = SignedSettings::CreateRetrievePropertyOp( 473 retrieve_property_op_ = SignedSettings::CreateRetrievePropertyOp(
449 kSettingProxyEverywhere, this); 474 kSettingProxyEverywhere, this);
450 if (retrieve_property_op_) { 475 if (retrieve_property_op_) {
451 retrieve_property_op_->Execute(); 476 retrieve_property_op_->Execute();
452 VLOG(1) << "Start retrieving proxy setting from device"; 477 VLOG(1) << "Start retrieving proxy setting from device";
453 } else { 478 } else {
454 VLOG(1) << "Fail to retrieve proxy setting from device"; 479 VLOG(1) << "Fail to retrieve proxy setting from device";
455 } 480 }
456 } 481 }
457 482
458 NetworkLibrary* network_lib = CrosLibrary::Get()->GetNetworkLibrary(); 483 NetworkLibrary* network_lib = CrosLibrary::Get()->GetNetworkLibrary();
459 OnActiveNetworkChanged(network_lib, network_lib->active_network()); 484 OnActiveNetworkChanged(network_lib, network_lib->active_network());
460 network_lib->AddNetworkManagerObserver(this); 485 network_lib->AddNetworkManagerObserver(this);
461 486
462 can_post_task_ = true; 487 can_post_task_ = true;
463 } 488 }
464 489
465 ProxyConfigServiceImpl::ProxyConfigServiceImpl(const ProxyConfig& init_config) 490 ProxyConfigServiceImpl::ProxyConfigServiceImpl(const ProxyConfig& init_config)
466 : testing_(false), 491 : testing_(false),
467 can_post_task_(true), 492 can_post_task_(true),
468 config_availability_(net::ProxyConfigService::CONFIG_VALID), 493 io_config_availability_(net::ProxyConfigService::CONFIG_VALID),
469 use_shared_proxies_(true) { 494 use_shared_proxies_(true),
495 current_ui_profile_(NULL) {
470 active_config_ = init_config; 496 active_config_ = init_config;
471 // Update the IO-accessible copy in |cached_config_| as well. 497 // Update the IO-accessible copy in |io_config_| as well.
472 cached_config_ = active_config_; 498 io_config_ = active_config_;
473 } 499 }
474 500
475 ProxyConfigServiceImpl::~ProxyConfigServiceImpl() { 501 ProxyConfigServiceImpl::~ProxyConfigServiceImpl() {
476 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); 502 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary();
477 if (netlib) { 503 if (netlib) {
478 netlib->RemoveNetworkManagerObserver(this); 504 netlib->RemoveNetworkManagerObserver(this);
479 netlib->RemoveObserverForAllNetworks(this); 505 netlib->RemoveObserverForAllNetworks(this);
480 } 506 }
481 } 507 }
482 508
509 void ProxyConfigServiceImpl::UISetUseSharedProxies(bool use_shared) {
510 // Should be called from UI thread.
511 CheckCurrentlyOnUIThread();
512
513 if (use_shared_proxies_ == use_shared) {
514 VLOG(1) << "same use_shared_proxies = " << use_shared_proxies_;
515 return;
516 }
517 use_shared_proxies_ = use_shared;
518 VLOG(1) << "new use_shared_proxies = " << use_shared_proxies_;
519 // UISetUseSharedProxies is always called on login, so reset
520 // current_ui_profile_ to trigger pick up of new default profile.
521 // If this was called from user changing the setting, we'll set the new
522 // profile before showing proxy config of any network via
523 // UISetCurrentUserProfile.
524 current_ui_profile_ = NULL;
525 Network* network = NULL;
526 if (!active_network_.empty()) {
527 network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath(
528 active_network_);
529 if (!network)
530 LOG(WARNING) << "can't find requested network " << active_network_;
531 }
532 DetermineEffectiveConfig(network, true);
533 }
534
535 void ProxyConfigServiceImpl::UISetCurrentUserProfile(Profile* profile) {
536 current_ui_profile_ = profile;
537 }
538
539 void ProxyConfigServiceImpl::UISetCurrentNetwork(
540 const std::string& current_network) {
541 // Should be called from UI thread.
542 CheckCurrentlyOnUIThread();
543 Network* network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath(
544 current_network);
545 if (!network) {
546 ResetUICache();
547 LOG(ERROR) << "can't find requested network " << current_network;
548 return;
549 }
550 current_ui_network_ = current_network;
551 OnUISetCurrentNetwork(network);
552 }
553
554 void ProxyConfigServiceImpl::UIMakeActiveNetworkCurrent() {
555 // Should be called from UI thread.
556 CheckCurrentlyOnUIThread();
557 Network* network = NULL;
558 if (!testing_) {
559 network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath(
560 active_network_);
561 if (!network) {
562 ResetUICache();
563 LOG(ERROR) << "can't find requested network " << active_network_;
564 return;
565 }
566 }
567 current_ui_network_ = active_network_;
568 OnUISetCurrentNetwork(network);
569 }
570
483 void ProxyConfigServiceImpl::UIGetProxyConfig(ProxyConfig* config) { 571 void ProxyConfigServiceImpl::UIGetProxyConfig(ProxyConfig* config) {
484 // Should be called from UI thread. 572 // Should be called from UI thread.
485 CheckCurrentlyOnUIThread(); 573 CheckCurrentlyOnUIThread();
486 // Simply returns the copy on the UI thread. 574 // Simply returns the copy on the UI thread.
487 *config = current_ui_config_; 575 *config = current_ui_config_;
488 } 576 }
489 577
490 bool ProxyConfigServiceImpl::UISetCurrentNetwork(
491 const std::string& current_network) {
492 // Should be called from UI thread.
493 CheckCurrentlyOnUIThread();
494 if (current_ui_network_ == current_network)
495 return false;
496 Network* network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath(
497 current_network);
498 if (!network) {
499 LOG(ERROR) << "can't find requested network " << current_network;
500 return false;
501 }
502 current_ui_network_ = current_network;
503 current_ui_config_ = ProxyConfig();
504 SetCurrentNetworkName(network);
505 if (!network->proxy_config().empty())
506 current_ui_config_.DeserializeForNetwork(network->proxy_config());
507 VLOG(1) << "current ui network: "
508 << (current_ui_network_name_.empty() ?
509 current_ui_network_ : current_ui_network_name_)
510 << ", proxy mode: " << current_ui_config_.mode;
511 return true;
512 }
513
514 bool ProxyConfigServiceImpl::UIMakeActiveNetworkCurrent() {
515 // Should be called from UI thread.
516 CheckCurrentlyOnUIThread();
517 if (current_ui_network_ == active_network_)
518 return false;
519 Network* network = NULL;
520 if (!testing_) {
521 network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath(
522 active_network_);
523 if (!network) {
524 LOG(ERROR) << "can't find requested network " << active_network_;
525 return false;
526 }
527 }
528 current_ui_network_ = active_network_;
529 current_ui_config_ = active_config_;
530 SetCurrentNetworkName(network);
531 VLOG(1) << "current ui network: "
532 << (current_ui_network_name_.empty() ?
533 current_ui_network_ : current_ui_network_name_)
534 << ", proxy mode: " << current_ui_config_.mode;
535 return true;
536 }
537
538 void ProxyConfigServiceImpl::UISetUseSharedProxies(bool use_shared) {
539 // Should be called from UI thread.
540 CheckCurrentlyOnUIThread();
541
542 // Reset all UI-related variables so that the next opening of proxy
543 // configuration dialog of any network will trigger javascript reloading of
544 // (possibly) new proxy settings.
545 current_ui_network_.clear();
546 current_ui_network_name_.clear();
547 current_ui_config_ = ProxyConfig();
548
549 if (use_shared_proxies_ == use_shared) {
550 VLOG(1) << "same use_shared_proxies = " << use_shared_proxies_;
551 return;
552 }
553 use_shared_proxies_ = use_shared;
554 VLOG(1) << "new use_shared_proxies = " << use_shared_proxies_;
555 if (active_network_.empty())
556 return;
557 Network* network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath(
558 active_network_);
559 if (!network) {
560 LOG(ERROR) << "can't find requested network " << active_network_;
561 return;
562 }
563 DetermineConfigFromNetwork(network);
564 }
565
566 bool ProxyConfigServiceImpl::UISetProxyConfigToDirect() { 578 bool ProxyConfigServiceImpl::UISetProxyConfigToDirect() {
567 // Should be called from UI thread. 579 // Should be called from UI thread.
568 CheckCurrentlyOnUIThread(); 580 CheckCurrentlyOnUIThread();
569 current_ui_config_.mode = ProxyConfig::MODE_DIRECT; 581 current_ui_config_.mode = ProxyConfig::MODE_DIRECT;
570 OnUISetProxyConfig(); 582 OnUISetProxyConfig();
571 return true; 583 return true;
572 } 584 }
573 585
574 bool ProxyConfigServiceImpl::UISetProxyConfigToAutoDetect() { 586 bool ProxyConfigServiceImpl::UISetProxyConfigToAutoDetect() {
575 // Should be called from UI thread. 587 // Should be called from UI thread.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 NOTREACHED(); 634 NOTREACHED();
623 VLOG(1) << "Cannot set bypass rules for proxy mode [" 635 VLOG(1) << "Cannot set bypass rules for proxy mode ["
624 << current_ui_config_.mode << "]"; 636 << current_ui_config_.mode << "]";
625 return false; 637 return false;
626 } 638 }
627 current_ui_config_.bypass_rules = bypass_rules; 639 current_ui_config_.bypass_rules = bypass_rules;
628 OnUISetProxyConfig(); 640 OnUISetProxyConfig();
629 return true; 641 return true;
630 } 642 }
631 643
632 void ProxyConfigServiceImpl::AddObserver( 644 void ProxyConfigServiceImpl::OnPrefProxyConfigChanged(
633 net::ProxyConfigService::Observer* observer) { 645 PrefProxyConfigTracker* in_tracker) {
634 // Should be called from IO thread. 646 scoped_refptr<PrefProxyConfigTracker> tracker(in_tracker);
635 CheckCurrentlyOnIOThread(); 647 // Make sure this runs on UI thread.
636 observers_.AddObserver(observer); 648 if (!BrowserThread::CurrentlyOn(BrowserThread::UI) && can_post_task_) {
637 } 649 // Posts a task to UI thread to handle prefs change.
638 650 if (!BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
Mattias Nissler (ping if slow) 2011/10/07 13:32:10 Yikes. Another reason to pull out pref observing a
kuan 2011/10/18 16:25:35 This entire class has been redesigned and re-imple
639 void ProxyConfigServiceImpl::RemoveObserver( 651 NewRunnableMethod(this,
640 net::ProxyConfigService::Observer* observer) { 652 &ProxyConfigServiceImpl::OnPrefProxyConfigChanged,
641 // Should be called from IO thread. 653 tracker)))
642 CheckCurrentlyOnIOThread(); 654 VLOG(1) << "Couldn't post task to UI thread to handle prefs change";
643 observers_.RemoveObserver(observer); 655 return;
644 }
645
646 net::ProxyConfigService::ConfigAvailability
647 ProxyConfigServiceImpl::IOGetProxyConfig(net::ProxyConfig* net_config) {
648 // Should be called from IO thread.
649 CheckCurrentlyOnIOThread();
650 if (config_availability_ == net::ProxyConfigService::CONFIG_VALID) {
651 VLOG(1) << "returning proxy mode=" << cached_config_.mode;
652 cached_config_.ToNetProxyConfig(net_config);
653 } 656 }
654 return config_availability_; 657 if (tracker != GetProxyConfigTracker()) {
658 VLOG(1) << "ignoring prefs change from unexpected tracker";
659 return;
660 }
661 VLOG(1) << "got prefs change";
662 Network* network = NULL;
663 if (!active_network_.empty()) {
664 network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath(
665 active_network_);
666 if (!network)
667 LOG(ERROR) << "can't find requested network " << active_network_;
668 }
669 DetermineEffectiveConfig(network, true);
655 } 670 }
656 671
657 void ProxyConfigServiceImpl::OnSettingsOpCompleted( 672 void ProxyConfigServiceImpl::OnSettingsOpCompleted(
658 SignedSettings::ReturnCode code, 673 SignedSettings::ReturnCode code,
659 std::string value) { 674 std::string value) {
660 retrieve_property_op_ = NULL; 675 retrieve_property_op_ = NULL;
661 if (code != SignedSettings::SUCCESS) { 676 if (code != SignedSettings::SUCCESS) {
662 LOG(WARNING) << "Error retrieving proxy setting from device"; 677 LOG(WARNING) << "Error retrieving proxy setting from device";
663 device_config_.clear(); 678 device_config_.clear();
664 return; 679 return;
(...skipping 25 matching lines...) Expand all
690 return; 705 return;
691 VLOG(1) << "OnNetworkChanged: " 706 VLOG(1) << "OnNetworkChanged: "
692 << (network->name().empty() ? network->service_path() : 707 << (network->name().empty() ? network->service_path() :
693 network->name()) 708 network->name())
694 << ", use-shared-proxies=" << use_shared_proxies_; 709 << ", use-shared-proxies=" << use_shared_proxies_;
695 // We only care about active network. 710 // We only care about active network.
696 if (network == network_lib->active_network()) 711 if (network == network_lib->active_network())
697 OnActiveNetworkChanged(network_lib, network); 712 OnActiveNetworkChanged(network_lib, network);
698 } 713 }
699 714
715 void ProxyConfigServiceImpl::AddObserver(
716 net::ProxyConfigService::Observer* observer) {
717 // Should be called from IO thread.
718 CheckCurrentlyOnIOThread();
719 observers_.AddObserver(observer);
720 }
721
722 void ProxyConfigServiceImpl::RemoveObserver(
723 net::ProxyConfigService::Observer* observer) {
724 // Should be called from IO thread.
725 CheckCurrentlyOnIOThread();
726 observers_.RemoveObserver(observer);
727 }
728
729 net::ProxyConfigService::ConfigAvailability
730 ProxyConfigServiceImpl::IOGetProxyConfig(net::ProxyConfig* net_config) {
731 // Should be called from IO thread.
732 CheckCurrentlyOnIOThread();
733 if (io_config_availability_ == net::ProxyConfigService::CONFIG_VALID) {
734 VLOG(1) << "returning proxy mode=" << io_config_.mode;
735 io_config_.ToNetProxyConfig(net_config);
736 }
737 return io_config_availability_;
738 }
739
700 //------------------ ProxyConfigServiceImpl: private methods ------------------- 740 //------------------ ProxyConfigServiceImpl: private methods -------------------
701 741
702 void ProxyConfigServiceImpl::OnUISetProxyConfig() { 742 void ProxyConfigServiceImpl::OnUISetProxyConfig() {
703 if (testing_) { 743 if (testing_) {
704 active_config_ = current_ui_config_; 744 active_config_ = current_ui_config_;
705 IOSetProxyConfig(active_config_, net::ProxyConfigService::CONFIG_VALID); 745 IOSetProxyConfig(active_config_, net::ProxyConfigService::CONFIG_VALID);
706 return; 746 return;
707 } 747 }
708 if (current_ui_network_.empty()) 748 if (current_ui_network_.empty())
709 return; 749 return;
710 // Update config to flimflam. 750 // Update config to flimflam.
711 std::string value; 751 std::string value;
712 if (current_ui_config_.SerializeForNetwork(&value)) { 752 if (current_ui_config_.SerializeForNetwork(&value)) {
713 VLOG(1) << "set proxy (mode=" << current_ui_config_.mode 753 VLOG(1) << "set proxy (mode=" << current_ui_config_.mode
714 << ") for " << current_ui_network_; 754 << ") for " << current_ui_network_;
755 current_ui_config_.source = PrefProxyConfigTracker::CONFIG_SOURCE_SYSTEM;
715 SetProxyConfigForNetwork(current_ui_network_, value, false); 756 SetProxyConfigForNetwork(current_ui_network_, value, false);
716 } 757 }
717 } 758 }
718 759
719 void ProxyConfigServiceImpl::IOSetProxyConfig( 760 void ProxyConfigServiceImpl::IOSetProxyConfig(
720 const ProxyConfig& new_config, 761 const ProxyConfig& new_config,
721 net::ProxyConfigService::ConfigAvailability new_availability) { 762 net::ProxyConfigService::ConfigAvailability new_availability) {
722 if (!BrowserThread::CurrentlyOn(BrowserThread::IO) && can_post_task_) { 763 if (!BrowserThread::CurrentlyOn(BrowserThread::IO) && can_post_task_) {
723 // Posts a task to IO thread with the new config, so it can update 764 // Posts a task to IO thread with the new config, so it can update
724 // |cached_config_|. 765 // |io_config_|.
725 Task* task = NewRunnableMethod(this, 766 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
726 &ProxyConfigServiceImpl::IOSetProxyConfig, 767 NewRunnableMethod(this,
727 new_config, 768 &ProxyConfigServiceImpl::IOSetProxyConfig,
728 new_availability); 769 new_config,
729 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) 770 new_availability)))
730 VLOG(1) << "Couldn't post task to IO thread to set new proxy config"; 771 VLOG(1) << "Couldn't post task to IO thread to set new proxy config";
731 return; 772 return;
732 } 773 }
733 774
734 // Now guaranteed to be on the correct thread. 775 // Now guaranteed to be on the correct thread.
735 776
736 if (config_availability_ == new_availability && 777 if (io_config_availability_ == new_availability &&
737 cached_config_.Equals(new_config)) 778 io_config_.Equals(new_config))
738 return; 779 return;
739 780
740 VLOG(1) << "Proxy changed: mode=" << new_config.mode 781 VLOG(1) << "Proxy changed: mode=" << new_config.mode
741 << ", avail=" << new_availability; 782 << ", avail=" << new_availability;
742 cached_config_ = new_config; 783 io_config_ = new_config;
743 config_availability_ = new_availability; 784 io_config_availability_ = new_availability;
744 // Notify observers of new proxy config. 785 // Notify observers of new proxy config.
745 net::ProxyConfig net_config; 786 net::ProxyConfig net_config;
746 cached_config_.ToNetProxyConfig(&net_config); 787 io_config_.ToNetProxyConfig(&net_config);
747 if (net_config.proxy_rules().type != 788 if (net_config.proxy_rules().type !=
748 net::ProxyConfig::ProxyRules::TYPE_NO_RULES) { 789 net::ProxyConfig::ProxyRules::TYPE_NO_RULES) {
749 net_config.proxy_rules().bypass_rules.AddRuleToBypassLocal(); 790 net_config.proxy_rules().bypass_rules.AddRuleToBypassLocal();
750 } 791 }
751 FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_, 792 FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_,
752 OnProxyConfigChanged(net_config, config_availability_)); 793 OnProxyConfigChanged(net_config, io_config_availability_));
753 } 794 }
754 795
755 void ProxyConfigServiceImpl::OnActiveNetworkChanged(NetworkLibrary* network_lib, 796 void ProxyConfigServiceImpl::OnActiveNetworkChanged(NetworkLibrary* network_lib,
756 const Network* active_network) { 797 const Network* active_network) {
757 std::string new_network; 798 std::string new_network;
758 if (active_network) 799 if (active_network)
759 new_network = active_network->service_path(); 800 new_network = active_network->service_path();
760 801
761 if (active_network_ == new_network) { // Same active network. 802 if (active_network_ == new_network) { // Same active network.
762 VLOG(1) << "same active network: " 803 VLOG(1) << "same active network: "
763 << (new_network.empty() ? "empty" : 804 << (new_network.empty() ? "empty" :
764 (active_network->name().empty() ? 805 (active_network->name().empty() ?
765 new_network : active_network->name())); 806 new_network : active_network->name()));
766 return; 807 return;
767 } 808 }
768 809
769 // If there was a previous active network, remove it as observer. 810 // If there was a previous active network, remove it as observer.
770 if (!active_network_.empty()) 811 if (!active_network_.empty())
771 network_lib->RemoveNetworkObserver(active_network_, this); 812 network_lib->RemoveNetworkObserver(active_network_, this);
772 813
773 active_network_ = new_network; 814 active_network_ = new_network;
774 815
775 if (active_network_.empty()) { 816 if (active_network_.empty()) {
776 VLOG(1) << "new active network: empty"; 817 VLOG(1) << "new active network: empty";
777 active_config_ = ProxyConfig(); 818 DetermineEffectiveConfig(active_network, true);
778 IOSetProxyConfig(active_config_, net::ProxyConfigService::CONFIG_UNSET);
779 return; 819 return;
780 } 820 }
781 821
782 VLOG(1) << "new active network: path=" << active_network->service_path() 822 VLOG(1) << "new active network: path=" << active_network->service_path()
783 << ", name=" << active_network->name() 823 << ", name=" << active_network->name()
784 << ", profile=" << active_network->profile_path() 824 << ", profile=" << active_network->profile_path()
785 << ", proxy=" << active_network->proxy_config(); 825 << ", proxy=" << active_network->proxy_config();
786 826
787 // Register observer for new network. 827 // Register observer for new network.
788 network_lib->AddNetworkObserver(active_network_, this); 828 network_lib->AddNetworkObserver(active_network_, this);
789 829
790 // If necessary, migrate config to flimflam. 830 // If necessary, migrate config to flimflam.
791 if (active_network->proxy_config().empty() && !device_config_.empty()) { 831 if (active_network->proxy_config().empty() && !device_config_.empty()) {
792 VLOG(1) << "try migrating device config to " << active_network_; 832 VLOG(1) << "try migrating device config to " << active_network_;
793 SetProxyConfigForNetwork(active_network_, device_config_, true); 833 SetProxyConfigForNetwork(active_network_, device_config_, true);
794 } else { 834 } else {
795 DetermineConfigFromNetwork(active_network); 835 // Otherwise, determine and activate possibly new effective proxy config.
836 DetermineEffectiveConfig(active_network, true);
796 } 837 }
797 } 838 }
798 839
799 void ProxyConfigServiceImpl::SetProxyConfigForNetwork( 840 void ProxyConfigServiceImpl::SetProxyConfigForNetwork(
800 const std::string& network_path, const std::string& value, 841 const std::string& network_path, const std::string& value,
801 bool only_set_if_empty) { 842 bool only_set_if_empty) {
802 Network* network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath( 843 Network* network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath(
803 network_path); 844 network_path);
804 if (!network) { 845 if (!network) {
805 NOTREACHED() << "can't find requested network " << network_path; 846 NOTREACHED() << "can't find requested network " << network_path;
806 return; 847 return;
807 } 848 }
808 if (!only_set_if_empty || network->proxy_config().empty()) { 849 if (!only_set_if_empty || network->proxy_config().empty()) {
809 network->SetProxyConfig(value); 850 network->SetProxyConfig(value);
810 VLOG(1) << "set proxy for " 851 VLOG(1) << "set proxy for "
811 << (network->name().empty() ? network_path : network->name()) 852 << (network->name().empty() ? network_path : network->name())
812 << ", value=" << value; 853 << ", value=" << value;
813 if (network_path == active_network_) 854 if (network_path == active_network_)
814 DetermineConfigFromNetwork(network); 855 DetermineEffectiveConfig(network, true);
815 } 856 }
816 } 857 }
817 858
818 void ProxyConfigServiceImpl::DetermineConfigFromNetwork( 859 void ProxyConfigServiceImpl::DetermineEffectiveConfig(const Network* network,
819 const Network* network) { 860 bool activate) {
820 active_config_ = ProxyConfig(); // Default is DIRECT mode (i.e. no proxy). 861 // Get prefs proxy config.
821 net::ProxyConfigService::ConfigAvailability available = 862 net::ProxyConfig pref_config;
863 PrefProxyConfigTracker::ConfigSource pref_source =
864 PrefProxyConfigTracker::CONFIG_SOURCE_UNSET;
865 PrefProxyConfigTracker::ConfigState pref_state =
866 GetProxyConfigTracker()->UIGetProxyConfig(&pref_config, &pref_source);
867
868 // Get network proxy config if available.
869 net::ProxyConfig network_config;
870 net::ProxyConfigService::ConfigAvailability network_availability =
822 net::ProxyConfigService::CONFIG_UNSET; 871 net::ProxyConfigService::CONFIG_UNSET;
823 // If network is shared but user doesn't use shared proxies, use direct mode. 872 bool ignore_proxy = activate;
824 if (network->profile_type() == PROFILE_SHARED && !use_shared_proxies_) { 873 if (network) {
825 VLOG(1) << "shared network and !use_shared_proxies, using direct"; 874 // If we're activating proxy, ignore proxy if necessary;
826 available = net::ProxyConfigService::CONFIG_VALID; 875 // otherwise, for ui, get actual proxy to show user.
827 } else if (!network->proxy_config().empty() && 876 ignore_proxy = activate ? IgnoreProxy(network) : false;
828 active_config_.DeserializeForNetwork(network->proxy_config())) { 877 // If network is shared but use-shared-proxies is off, use direct mode.
829 // Network is private or shared with user using shared proxies. 878 if (ignore_proxy) {
830 VLOG(1) << "using network proxy: " << network->proxy_config(); 879 VLOG(1) << "shared network and !use_shared_proxies, using direct";
831 available = net::ProxyConfigService::CONFIG_VALID; 880 network_availability = net::ProxyConfigService::CONFIG_VALID;
881 } else if (!network->proxy_config().empty()) {
882 // Network is private or shared with user using shared proxies.
883 JSONStringValueSerializer serializer(network->proxy_config());
884 scoped_ptr<Value> value(serializer.Deserialize(NULL, NULL));
885 if (value.get() && value->GetType() == Value::TYPE_DICTIONARY) {
886 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get());
887 ProxyConfigDictionary proxy_dict(dict);
888 if (PrefProxyConfigTracker::PrefConfigToNetConfig(proxy_dict,
889 &network_config)) {
890 VLOG(1) << "using network proxy: " << network->proxy_config();
891 network_availability = net::ProxyConfigService::CONFIG_VALID;
892 }
893 }
894 }
832 } 895 }
833 IOSetProxyConfig(active_config_, available); 896
897 // Determine effective proxy config, either from prefs or network.
898 net::ProxyConfig effective_config;
899 PrefProxyConfigTracker::ConfigSource effective_config_source;
900 net::ProxyConfigService::ConfigAvailability effective_availability =
901 GetEffectiveProxyConfig(pref_state, pref_config, pref_source,
902 network_availability, network_config,
903 ignore_proxy,
904 &effective_config, &effective_config_source);
905
906 // Store effective config into the config indicated by |activate|.
907 ProxyConfig* config_to_set = activate ? &active_config_ : &current_ui_config_;
908 *config_to_set = ProxyConfig(); // Reset to default i.e. DIRECT (no proxy).
909 config_to_set->FromNetProxyConfig(effective_config);
910 config_to_set->source = effective_config_source;
911 if (pref_state == PrefProxyConfigTracker::CONFIG_PRESENT)
912 config_to_set->user_modifiable = false;
913 else
914 config_to_set->user_modifiable = !network || !IgnoreProxy(network);
915
916 // If necessary, cache effective config in IO thread and activate it.
917 if (activate)
918 IOSetProxyConfig(*config_to_set, effective_availability);
834 } 919 }
835 920
836 void ProxyConfigServiceImpl::SetCurrentNetworkName(const Network* network) { 921 void ProxyConfigServiceImpl::OnUISetCurrentNetwork(const Network* network) {
837 if (!network) { 922 if (!network) {
838 if (testing_) 923 if (testing_) {
924 current_ui_config_ = active_config_;
839 current_ui_network_name_ = "test"; 925 current_ui_network_name_ = "test";
926 }
840 return; 927 return;
841 } 928 }
842 if (network->name().empty() && network->type() == chromeos::TYPE_ETHERNET) { 929 if (network->name().empty() && network->type() == chromeos::TYPE_ETHERNET) {
843 current_ui_network_name_ = l10n_util::GetStringUTF8( 930 current_ui_network_name_ = l10n_util::GetStringUTF8(
844 IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET); 931 IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
845 } else { 932 } else {
846 current_ui_network_name_ = network->name(); 933 current_ui_network_name_ = network->name();
847 } 934 }
935 DetermineEffectiveConfig(network, false);
936 VLOG(1) << "current ui network: "
937 << (current_ui_network_name_.empty() ?
938 current_ui_network_ : current_ui_network_name_)
939 << ", proxy mode: " << current_ui_config_.mode
940 << ", " << SourceToString(current_ui_config_.source)
941 << ", modifiable:" << current_ui_config_.user_modifiable;
942 }
943
944 void ProxyConfigServiceImpl::ResetUICache() {
945 current_ui_network_.clear();
946 current_ui_network_name_.clear();
947 current_ui_config_ = ProxyConfig();
948 }
949
950 PrefProxyConfigTracker* ProxyConfigServiceImpl::GetProxyConfigTracker() {
951 Profile* profile = current_ui_profile_ ? current_ui_profile_ :
952 ProfileManager::GetDefaultProfile();
953 return profile->GetProxyConfigTracker();
848 } 954 }
849 955
850 void ProxyConfigServiceImpl::CheckCurrentlyOnIOThread() { 956 void ProxyConfigServiceImpl::CheckCurrentlyOnIOThread() {
851 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 957 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
852 } 958 }
853 959
854 void ProxyConfigServiceImpl::CheckCurrentlyOnUIThread() { 960 void ProxyConfigServiceImpl::CheckCurrentlyOnUIThread() {
855 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 961 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
856 } 962 }
857 963
858 } // namespace chromeos 964 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698