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

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/net/pref_proxy_config_service.h"
14 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" 15 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h"
16 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/prefs/proxy_config_dictionary.h" 17 #include "chrome/browser/prefs/proxy_config_dictionary.h"
16 #include "chrome/browser/prefs/proxy_prefs.h" 18 #include "chrome/browser/prefs/proxy_prefs.h"
19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/common/pref_names.h"
17 #include "content/browser/browser_thread.h" 21 #include "content/browser/browser_thread.h"
18 #include "content/common/json_value_serializer.h" 22 #include "content/common/json_value_serializer.h"
19 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
20 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
21 25
22 namespace em = enterprise_management; 26 namespace em = enterprise_management;
23 27
24 namespace chromeos { 28 namespace chromeos {
25 29
26 namespace { 30 namespace {
27 31
28 const char* SourceToString(ProxyConfigServiceImpl::ProxyConfig::Source source) { 32 const char* SourceToString(ProxyConfigServiceImpl::ProxyConfig::Source source) {
29 switch (source) { 33 switch (source) {
30 case ProxyConfigServiceImpl::ProxyConfig::SOURCE_NONE: 34 case ProxyConfigServiceImpl::ProxyConfig::SOURCE_NONE:
31 return "SOURCE_NONE"; 35 return "SOURCE_NONE";
36 case ProxyConfigServiceImpl::ProxyConfig::SOURCE_NONE_DISABLED:
37 return "SOURCE_NONE_DISABLED";
32 case ProxyConfigServiceImpl::ProxyConfig::SOURCE_POLICY: 38 case ProxyConfigServiceImpl::ProxyConfig::SOURCE_POLICY:
33 return "SOURCE_POLICY"; 39 return "SOURCE_POLICY";
34 case ProxyConfigServiceImpl::ProxyConfig::SOURCE_OWNER: 40 case ProxyConfigServiceImpl::ProxyConfig::SOURCE_EXTENSION:
35 return "SOURCE_OWNER"; 41 return "SOURCE_EXTENSION";
42 case ProxyConfigServiceImpl::ProxyConfig::SOURCE_RECOMMENDED:
43 return "SOURCE_RECOMMENDED";
44 case ProxyConfigServiceImpl::ProxyConfig::SOURCE_RECOMMENDED_DISABLED:
45 return "SOURCE_RECOMMENDED_DISABLED";
46 case ProxyConfigServiceImpl::ProxyConfig::SOURCE_NETWORK:
47 return "SOURCE_NETWORK";
48 case ProxyConfigServiceImpl::ProxyConfig::SOURCE_NETWORK_DISABLED:
49 return "SOURCE_NETWORK_DISABLED";
36 } 50 }
37 NOTREACHED() << "Unrecognized source type"; 51 NOTREACHED() << "Unrecognized source type";
38 return ""; 52 return "";
39 } 53 }
40 54
41 std::ostream& operator<<(std::ostream& out, 55 std::ostream& operator<<(std::ostream& out,
42 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) { 56 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) {
Mattias Nissler (ping if slow) 2011/10/05 10:18:36 indentation: parameters should line up (break afte
kuan 2011/10/07 00:30:41 i can't line them up, 'cos they won't fit, i belie
43 out << " " << SourceToString(proxy.source) << "\n" 57 out << (proxy.server.is_valid() ? proxy.server.ToURI() : "") << "\n";
44 << " server: " << (proxy.server.is_valid() ? proxy.server.ToURI() : "")
45 << "\n";
46 return out; 58 return out;
47 } 59 }
48 60
49 std::ostream& operator<<(std::ostream& out, 61 std::ostream& operator<<(std::ostream& out,
50 const ProxyConfigServiceImpl::ProxyConfig& config) { 62 const ProxyConfigServiceImpl::ProxyConfig& config) {
Mattias Nissler (ping if slow) 2011/10/05 10:18:36 same here.
kuan 2011/10/07 00:30:41 Done.
51 switch (config.mode) { 63 switch (config.mode) {
52 case ProxyConfigServiceImpl::ProxyConfig::MODE_DIRECT: 64 case ProxyConfigServiceImpl::ProxyConfig::MODE_DIRECT:
53 out << "Direct connection:\n " 65 out << "Direct connection:\n "
54 << SourceToString(config.automatic_proxy.source) << "\n"; 66 << SourceToString(config.source) << "\n";
55 break; 67 break;
56 case ProxyConfigServiceImpl::ProxyConfig::MODE_AUTO_DETECT: 68 case ProxyConfigServiceImpl::ProxyConfig::MODE_AUTO_DETECT:
57 out << "Auto detection:\n " 69 out << "Auto detection:\n "
58 << SourceToString(config.automatic_proxy.source) << "\n"; 70 << SourceToString(config.source) << "\n";
59 break; 71 break;
60 case ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT: 72 case ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT:
61 out << "Custom PAC script:\n " 73 out << "Custom PAC script:\n "
62 << SourceToString(config.automatic_proxy.source) 74 << SourceToString(config.source)
63 << "\n PAC: " << config.automatic_proxy.pac_url << "\n"; 75 << "\n PAC: " << config.automatic_proxy.pac_url << "\n";
64 break; 76 break;
65 case ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY: 77 case ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY:
66 out << "Single proxy:\n" << config.single_proxy; 78 out << "Single proxy:\n"
79 << SourceToString(config.source) << "\n " << config.single_proxy;
67 break; 80 break;
68 case ProxyConfigServiceImpl::ProxyConfig::MODE_PROXY_PER_SCHEME: 81 case ProxyConfigServiceImpl::ProxyConfig::MODE_PROXY_PER_SCHEME:
69 out << "HTTP proxy: " << config.http_proxy; 82 out << "Manual proxies:\n"
70 out << "HTTPS proxy: " << config.https_proxy; 83 << SourceToString(config.source) << "\n"
71 out << "FTP proxy: " << config.ftp_proxy; 84 << " HTTP: " << config.http_proxy
72 out << "SOCKS proxy: " << config.socks_proxy; 85 << " HTTPS: " << config.https_proxy
86 << " FTP: " << config.ftp_proxy
87 << " SOCKS: " << config.socks_proxy;
73 break; 88 break;
74 default: 89 default:
75 NOTREACHED() << "Unrecognized proxy config mode"; 90 NOTREACHED() << "Unrecognized proxy config mode";
76 break; 91 break;
77 } 92 }
78 if (config.mode == ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY || 93 if (config.mode == ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY ||
79 config.mode == 94 config.mode ==
80 ProxyConfigServiceImpl::ProxyConfig::MODE_PROXY_PER_SCHEME) { 95 ProxyConfigServiceImpl::ProxyConfig::MODE_PROXY_PER_SCHEME) {
81 out << "Bypass list: "; 96 out << "Bypass list: ";
82 if (config.bypass_rules.rules().empty()) { 97 if (config.bypass_rules.rules().empty()) {
83 out << "[None]"; 98 out << "[None]";
84 } else { 99 } else {
85 const net::ProxyBypassRules& bypass_rules = config.bypass_rules; 100 const net::ProxyBypassRules& bypass_rules = config.bypass_rules;
86 net::ProxyBypassRules::RuleList::const_iterator it; 101 net::ProxyBypassRules::RuleList::const_iterator it;
87 for (it = bypass_rules.rules().begin(); 102 for (it = bypass_rules.rules().begin();
88 it != bypass_rules.rules().end(); ++it) { 103 it != bypass_rules.rules().end(); ++it) {
89 out << "\n " << (*it)->ToString(); 104 out << "\n " << (*it)->ToString();
90 } 105 }
91 } 106 }
92 } 107 }
93 return out; 108 return out;
94 } 109 }
95 110
96 std::string ProxyConfigToString( 111 std::string ProxyConfigToString(
Mattias Nissler (ping if slow) 2011/10/05 10:18:36 This and the functions above appear to be dead cod
kuan 2011/10/07 00:30:41 i need it for debugging, so i make #if defined. O
97 const ProxyConfigServiceImpl::ProxyConfig& proxy_config) { 112 const ProxyConfigServiceImpl::ProxyConfig& proxy_config) {
98 std::ostringstream stream; 113 std::ostringstream stream;
99 stream << proxy_config; 114 stream << proxy_config;
100 return stream.str(); 115 return stream.str();
101 } 116 }
102 117
103 } // namespace 118 } // namespace
104 119
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 -------------- 120 //----------- ProxyConfigServiceImpl::ProxyConfig: public methods --------------
115 121
116 ProxyConfigServiceImpl::ProxyConfig::ProxyConfig() : mode(MODE_DIRECT) {} 122 ProxyConfigServiceImpl::ProxyConfig::ProxyConfig()
123 : mode(MODE_DIRECT), source(SOURCE_NONE) {}
117 124
118 ProxyConfigServiceImpl::ProxyConfig::~ProxyConfig() {} 125 ProxyConfigServiceImpl::ProxyConfig::~ProxyConfig() {}
119 126
120 void ProxyConfigServiceImpl::ProxyConfig::ToNetProxyConfig( 127 void ProxyConfigServiceImpl::ProxyConfig::ToNetProxyConfig(
121 net::ProxyConfig* net_config) { 128 net::ProxyConfig* net_config) {
122 switch (mode) { 129 switch (mode) {
123 case MODE_DIRECT: 130 case MODE_DIRECT:
124 *net_config = net::ProxyConfig::CreateDirect(); 131 *net_config = net::ProxyConfig::CreateDirect();
125 break; 132 break;
126 case MODE_AUTO_DETECT: 133 case MODE_AUTO_DETECT:
(...skipping 19 matching lines...) Expand all
146 net_config->proxy_rules().proxy_for_ftp = ftp_proxy.server; 153 net_config->proxy_rules().proxy_for_ftp = ftp_proxy.server;
147 net_config->proxy_rules().fallback_proxy = socks_proxy.server; 154 net_config->proxy_rules().fallback_proxy = socks_proxy.server;
148 net_config->proxy_rules().bypass_rules = bypass_rules; 155 net_config->proxy_rules().bypass_rules = bypass_rules;
149 break; 156 break;
150 default: 157 default:
151 NOTREACHED() << "Unrecognized proxy config mode"; 158 NOTREACHED() << "Unrecognized proxy config mode";
152 break; 159 break;
153 } 160 }
154 } 161 }
155 162
156 bool ProxyConfigServiceImpl::ProxyConfig::CanBeWrittenByUser( 163 bool ProxyConfigServiceImpl::ProxyConfig::FromNetProxyConfig(
157 bool user_is_owner, const std::string& scheme) { 164 const net::ProxyConfig& net_config) {
158 // Setting can only be written by user if user is owner and setting is not 165 const net::ProxyConfig::ProxyRules& rules = net_config.proxy_rules();
159 // from policy. 166 switch (rules.type) {
160 Setting* setting = NULL; 167 case net::ProxyConfig::ProxyRules::TYPE_NO_RULES:
161 switch (mode) { 168 if (!net_config.HasAutomaticSettings()) {
162 case MODE_DIRECT: 169 mode = ProxyConfig::MODE_DIRECT;
163 case MODE_AUTO_DETECT: 170 } else if (net_config.auto_detect()) {
164 case MODE_PAC_SCRIPT: 171 mode = ProxyConfig::MODE_AUTO_DETECT;
165 setting = &automatic_proxy; 172 } else if (net_config.has_pac_url()) {
166 break; 173 mode = ProxyConfig::MODE_PAC_SCRIPT;
167 case MODE_SINGLE_PROXY: 174 automatic_proxy.pac_url = net_config.pac_url();
168 setting = &single_proxy; 175 } else {
169 break; 176 return false;
170 case MODE_PROXY_PER_SCHEME: 177 }
171 setting = MapSchemeToProxy(scheme); 178 return true;
172 break; 179 case net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY:
180 if (!rules.single_proxy.is_valid())
181 return false;
182 mode = MODE_SINGLE_PROXY;
183 single_proxy.server = rules.single_proxy;
184 bypass_rules = rules.bypass_rules;
185 return true;
186 case net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME:
187 // Make sure we have valid server for at least one of the protocols.
188 if (!rules.proxy_for_http.is_valid() &&
189 !rules.proxy_for_https.is_valid() &&
190 !rules.proxy_for_ftp.is_valid() &&
191 !rules.fallback_proxy.is_valid()) {
192 return false;
193 }
194 mode = MODE_PROXY_PER_SCHEME;
195 if (rules.proxy_for_http.is_valid())
196 http_proxy.server = rules.proxy_for_http;
197 if (rules.proxy_for_https.is_valid())
198 https_proxy.server = rules.proxy_for_https;
199 if (rules.proxy_for_ftp.is_valid())
200 ftp_proxy.server = rules.proxy_for_ftp;
201 if (rules.fallback_proxy.is_valid())
202 socks_proxy.server = rules.fallback_proxy;
203 bypass_rules = rules.bypass_rules;
204 return true;
173 default: 205 default:
206 NOTREACHED() << "Unrecognized proxy config mode";
174 break; 207 break;
175 } 208 }
176 if (!setting) { 209 return false;
177 NOTREACHED() << "Unrecognized proxy config mode";
178 return false;
179 }
180 return setting->CanBeWrittenByUser(user_is_owner);
181 } 210 }
182 211
183 ProxyConfigServiceImpl::ProxyConfig::ManualProxy* 212 ProxyConfigServiceImpl::ProxyConfig::ManualProxy*
184 ProxyConfigServiceImpl::ProxyConfig::MapSchemeToProxy( 213 ProxyConfigServiceImpl::ProxyConfig::MapSchemeToProxy(
185 const std::string& scheme) { 214 const std::string& scheme) {
186 if (scheme == "http") 215 if (scheme == "http")
187 return &http_proxy; 216 return &http_proxy;
188 if (scheme == "https") 217 if (scheme == "https")
189 return &https_proxy; 218 return &https_proxy;
190 if (scheme == "ftp") 219 if (scheme == "ftp")
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 JSONStringValueSerializer serializer(input); 295 JSONStringValueSerializer serializer(input);
267 scoped_ptr<Value> value(serializer.Deserialize(NULL, NULL)); 296 scoped_ptr<Value> value(serializer.Deserialize(NULL, NULL));
268 if (!value.get() || value->GetType() != Value::TYPE_DICTIONARY) 297 if (!value.get() || value->GetType() != Value::TYPE_DICTIONARY)
269 return false; 298 return false;
270 DictionaryValue* proxy_dict = static_cast<DictionaryValue*>(value.get()); 299 DictionaryValue* proxy_dict = static_cast<DictionaryValue*>(value.get());
271 return FromPrefProxyConfig(proxy_dict); 300 return FromPrefProxyConfig(proxy_dict);
272 } 301 }
273 302
274 bool ProxyConfigServiceImpl::ProxyConfig::Equals( 303 bool ProxyConfigServiceImpl::ProxyConfig::Equals(
275 const ProxyConfig& other) const { 304 const ProxyConfig& other) const {
305 // Intentionally ignore source which is only used for ui purposes and has no
306 // impact on proxy backend.
276 if (mode != other.mode) 307 if (mode != other.mode)
277 return false; 308 return false;
278 switch (mode) { 309 switch (mode) {
279 case MODE_DIRECT: 310 case MODE_DIRECT:
280 case MODE_AUTO_DETECT: 311 case MODE_AUTO_DETECT:
281 return true; 312 return true;
282 case MODE_PAC_SCRIPT: 313 case MODE_PAC_SCRIPT:
283 return automatic_proxy.pac_url == other.automatic_proxy.pac_url; 314 return automatic_proxy.pac_url == other.automatic_proxy.pac_url;
284 case MODE_SINGLE_PROXY: 315 case MODE_SINGLE_PROXY:
285 return single_proxy.server == other.single_proxy.server && 316 return single_proxy.server == other.single_proxy.server &&
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 } 511 }
481 } 512 }
482 513
483 void ProxyConfigServiceImpl::UIGetProxyConfig(ProxyConfig* config) { 514 void ProxyConfigServiceImpl::UIGetProxyConfig(ProxyConfig* config) {
484 // Should be called from UI thread. 515 // Should be called from UI thread.
485 CheckCurrentlyOnUIThread(); 516 CheckCurrentlyOnUIThread();
486 // Simply returns the copy on the UI thread. 517 // Simply returns the copy on the UI thread.
487 *config = current_ui_config_; 518 *config = current_ui_config_;
488 } 519 }
489 520
490 bool ProxyConfigServiceImpl::UISetCurrentNetwork( 521 void ProxyConfigServiceImpl::UISetCurrentNetworkWithProfile(
491 const std::string& current_network) { 522 const std::string& current_network, Profile* profile) {
Mattias Nissler (ping if slow) 2011/10/05 10:18:36 nit: second parameter on next line.
kuan 2011/10/07 00:30:41 Done.
492 // Should be called from UI thread. 523 // Should be called from UI thread.
493 CheckCurrentlyOnUIThread(); 524 CheckCurrentlyOnUIThread();
494 if (current_ui_network_ == current_network)
495 return false;
496 Network* network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath( 525 Network* network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath(
497 current_network); 526 current_network);
498 if (!network) { 527 if (!network) {
528 ResetUICache();
499 LOG(ERROR) << "can't find requested network " << current_network; 529 LOG(ERROR) << "can't find requested network " << current_network;
500 return false; 530 return;
501 } 531 }
502 current_ui_network_ = current_network; 532 current_ui_network_ = current_network;
503 current_ui_config_ = ProxyConfig(); 533 DetermineUIConfig(profile, network);
504 SetCurrentNetworkName(network); 534 SetCurrentNetworkName(network);
505 if (!network->proxy_config().empty())
506 current_ui_config_.DeserializeForNetwork(network->proxy_config());
507 VLOG(1) << "current ui network: " 535 VLOG(1) << "current ui network: "
508 << (current_ui_network_name_.empty() ? 536 << (current_ui_network_name_.empty() ?
509 current_ui_network_ : current_ui_network_name_) 537 current_ui_network_ : current_ui_network_name_)
510 << ", proxy mode: " << current_ui_config_.mode; 538 << ", proxy mode: " << current_ui_config_.mode
511 return true; 539 << ", " << SourceToString(current_ui_config_.source)
540 << ", modifiable:" << current_ui_config_.IsUserModifiable();
512 } 541 }
513 542
514 bool ProxyConfigServiceImpl::UIMakeActiveNetworkCurrent() { 543 void ProxyConfigServiceImpl::UIMakeActiveNetworkCurrentWithProfile(
544 Profile* profile) {
515 // Should be called from UI thread. 545 // Should be called from UI thread.
516 CheckCurrentlyOnUIThread(); 546 CheckCurrentlyOnUIThread();
517 if (current_ui_network_ == active_network_)
518 return false;
519 Network* network = NULL; 547 Network* network = NULL;
520 if (!testing_) { 548 if (!testing_) {
521 network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath( 549 network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath(
522 active_network_); 550 active_network_);
523 if (!network) { 551 if (!network) {
552 ResetUICache();
524 LOG(ERROR) << "can't find requested network " << active_network_; 553 LOG(ERROR) << "can't find requested network " << active_network_;
525 return false; 554 return;
526 } 555 }
527 } 556 }
528 current_ui_network_ = active_network_; 557 current_ui_network_ = active_network_;
529 current_ui_config_ = active_config_; 558 DetermineUIConfig(profile, network);
530 SetCurrentNetworkName(network); 559 SetCurrentNetworkName(network);
531 VLOG(1) << "current ui network: " 560 VLOG(1) << "current ui network: "
532 << (current_ui_network_name_.empty() ? 561 << (current_ui_network_name_.empty() ?
533 current_ui_network_ : current_ui_network_name_) 562 current_ui_network_ : current_ui_network_name_)
534 << ", proxy mode: " << current_ui_config_.mode; 563 << ", proxy mode: " << current_ui_config_.mode
535 return true; 564 << ", " << SourceToString(current_ui_config_.source)
565 << ", modifiable:" << current_ui_config_.IsUserModifiable();
536 } 566 }
537 567
538 void ProxyConfigServiceImpl::UISetUseSharedProxies(bool use_shared) { 568 void ProxyConfigServiceImpl::UISetUseSharedProxies(bool use_shared) {
539 // Should be called from UI thread. 569 // Should be called from UI thread.
540 CheckCurrentlyOnUIThread(); 570 CheckCurrentlyOnUIThread();
541 571
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) { 572 if (use_shared_proxies_ == use_shared) {
550 VLOG(1) << "same use_shared_proxies = " << use_shared_proxies_; 573 VLOG(1) << "same use_shared_proxies = " << use_shared_proxies_;
551 return; 574 return;
552 } 575 }
553 use_shared_proxies_ = use_shared; 576 use_shared_proxies_ = use_shared;
554 VLOG(1) << "new use_shared_proxies = " << use_shared_proxies_; 577 VLOG(1) << "new use_shared_proxies = " << use_shared_proxies_;
555 if (active_network_.empty()) 578 if (active_network_.empty())
556 return; 579 return;
557 Network* network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath( 580 Network* network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath(
558 active_network_); 581 active_network_);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 IOSetProxyConfig(active_config_, net::ProxyConfigService::CONFIG_VALID); 728 IOSetProxyConfig(active_config_, net::ProxyConfigService::CONFIG_VALID);
706 return; 729 return;
707 } 730 }
708 if (current_ui_network_.empty()) 731 if (current_ui_network_.empty())
709 return; 732 return;
710 // Update config to flimflam. 733 // Update config to flimflam.
711 std::string value; 734 std::string value;
712 if (current_ui_config_.SerializeForNetwork(&value)) { 735 if (current_ui_config_.SerializeForNetwork(&value)) {
713 VLOG(1) << "set proxy (mode=" << current_ui_config_.mode 736 VLOG(1) << "set proxy (mode=" << current_ui_config_.mode
714 << ") for " << current_ui_network_; 737 << ") for " << current_ui_network_;
738 current_ui_config_.source = ProxyConfig::SOURCE_NETWORK;
715 SetProxyConfigForNetwork(current_ui_network_, value, false); 739 SetProxyConfigForNetwork(current_ui_network_, value, false);
716 } 740 }
717 } 741 }
718 742
719 void ProxyConfigServiceImpl::IOSetProxyConfig( 743 void ProxyConfigServiceImpl::IOSetProxyConfig(
720 const ProxyConfig& new_config, 744 const ProxyConfig& new_config,
721 net::ProxyConfigService::ConfigAvailability new_availability) { 745 net::ProxyConfigService::ConfigAvailability new_availability) {
722 if (!BrowserThread::CurrentlyOn(BrowserThread::IO) && can_post_task_) { 746 if (!BrowserThread::CurrentlyOn(BrowserThread::IO) && can_post_task_) {
723 // Posts a task to IO thread with the new config, so it can update 747 // Posts a task to IO thread with the new config, so it can update
724 // |cached_config_|. 748 // |cached_config_|.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 DetermineConfigFromNetwork(network); 838 DetermineConfigFromNetwork(network);
815 } 839 }
816 } 840 }
817 841
818 void ProxyConfigServiceImpl::DetermineConfigFromNetwork( 842 void ProxyConfigServiceImpl::DetermineConfigFromNetwork(
819 const Network* network) { 843 const Network* network) {
820 active_config_ = ProxyConfig(); // Default is DIRECT mode (i.e. no proxy). 844 active_config_ = ProxyConfig(); // Default is DIRECT mode (i.e. no proxy).
821 net::ProxyConfigService::ConfigAvailability available = 845 net::ProxyConfigService::ConfigAvailability available =
822 net::ProxyConfigService::CONFIG_UNSET; 846 net::ProxyConfigService::CONFIG_UNSET;
823 // If network is shared but user doesn't use shared proxies, use direct mode. 847 // If network is shared but user doesn't use shared proxies, use direct mode.
824 if (network->profile_type() == PROFILE_SHARED && !use_shared_proxies_) { 848 if (IgnoreProxy(network)) {
825 VLOG(1) << "shared network and !use_shared_proxies, using direct"; 849 VLOG(1) << "shared network and !use_shared_proxies, using direct";
826 available = net::ProxyConfigService::CONFIG_VALID; 850 available = net::ProxyConfigService::CONFIG_VALID;
827 } else if (!network->proxy_config().empty() && 851 } else if (!network->proxy_config().empty() &&
828 active_config_.DeserializeForNetwork(network->proxy_config())) { 852 active_config_.DeserializeForNetwork(network->proxy_config())) {
829 // Network is private or shared with user using shared proxies. 853 // Network is private or shared with user using shared proxies.
830 VLOG(1) << "using network proxy: " << network->proxy_config(); 854 VLOG(1) << "using network proxy: " << network->proxy_config();
831 available = net::ProxyConfigService::CONFIG_VALID; 855 available = net::ProxyConfigService::CONFIG_VALID;
832 } 856 }
833 IOSetProxyConfig(active_config_, available); 857 IOSetProxyConfig(active_config_, available);
834 } 858 }
835 859
860 void ProxyConfigServiceImpl::DetermineUIConfig(Profile* profile,
861 const Network* network) {
Mattias Nissler (ping if slow) 2011/10/05 10:18:36 second parameter fits on previous line.
kuan 2011/10/07 00:30:41 it doesn't fit, i align it with 1st param. On 201
862 if (!network) {
863 if (testing_)
864 current_ui_config_ = active_config_;
865 return;
866 }
867 net::ProxyConfig pref_config;
868 PrefProxyConfigTracker::ConfigState state =
869 PrefProxyConfigTracker::CONFIG_UNSET;
870 if (profile)
871 state = profile->GetProxyConfigTracker()->UIGetProxyConfig(&pref_config);
872 if (state == PrefProxyConfigTracker::CONFIG_PRESENT) { // Mandatory proxy.
873 current_ui_config_.FromNetProxyConfig(pref_config);
874 const PrefService::Preference* pref = profile->GetPrefs()->FindPreference(
875 prefs::kProxy);
876 current_ui_config_.source = pref && pref->IsManaged() ?
877 ProxyConfig::SOURCE_POLICY :
878 (pref && pref->IsExtensionControlled() ?
879 ProxyConfig::SOURCE_EXTENSION : ProxyConfig::SOURCE_NONE_DISABLED);
stevenjb 2011/10/05 00:22:57 nit: Maybe use an if / else if / else here instead
Mattias Nissler (ping if slow) 2011/10/05 10:18:36 You split the logic between PrefProxyConfigTracker
kuan 2011/10/07 00:30:41 Done.
880 } else if (!network->proxy_config().empty()) { // Network proxy.
881 current_ui_config_.DeserializeForNetwork(network->proxy_config());
882 current_ui_config_.source = IgnoreProxy(network) ?
883 ProxyConfig::SOURCE_NETWORK_DISABLED : ProxyConfig::SOURCE_NETWORK;
stevenjb 2011/10/05 00:22:57 I really think source = SOURCE_NETWORK is_disa
Mattias Nissler (ping if slow) 2011/10/05 10:18:36 +1
kuan 2011/10/07 00:30:41 Done.
kuan 2011/10/07 00:30:41 Done.
884 } else if (state == PrefProxyConfigTracker::CONFIG_FALLBACK) {
885 // Recommended proxy.
886 current_ui_config_.FromNetProxyConfig(pref_config);
887 current_ui_config_.source = IgnoreProxy(network) ?
888 ProxyConfig::SOURCE_RECOMMENDED_DISABLED :
889 ProxyConfig::SOURCE_RECOMMENDED;
890 } else { // No proxy.
891 current_ui_config_ = ProxyConfig();
892 current_ui_config_.source = IgnoreProxy(network) ?
893 ProxyConfig::SOURCE_NONE_DISABLED : ProxyConfig::SOURCE_NONE;
894 }
895 }
896
836 void ProxyConfigServiceImpl::SetCurrentNetworkName(const Network* network) { 897 void ProxyConfigServiceImpl::SetCurrentNetworkName(const Network* network) {
837 if (!network) { 898 if (!network) {
838 if (testing_) 899 if (testing_)
839 current_ui_network_name_ = "test"; 900 current_ui_network_name_ = "test";
840 return; 901 return;
841 } 902 }
842 if (network->name().empty() && network->type() == chromeos::TYPE_ETHERNET) { 903 if (network->name().empty() && network->type() == chromeos::TYPE_ETHERNET) {
843 current_ui_network_name_ = l10n_util::GetStringUTF8( 904 current_ui_network_name_ = l10n_util::GetStringUTF8(
844 IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET); 905 IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
845 } else { 906 } else {
846 current_ui_network_name_ = network->name(); 907 current_ui_network_name_ = network->name();
847 } 908 }
848 } 909 }
849 910
911 void ProxyConfigServiceImpl::ResetUICache() {
912 current_ui_network_.clear();
913 current_ui_network_name_.clear();
914 current_ui_config_ = ProxyConfig();
915 }
916
850 void ProxyConfigServiceImpl::CheckCurrentlyOnIOThread() { 917 void ProxyConfigServiceImpl::CheckCurrentlyOnIOThread() {
851 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
852 } 919 }
853 920
854 void ProxyConfigServiceImpl::CheckCurrentlyOnUIThread() { 921 void ProxyConfigServiceImpl::CheckCurrentlyOnUIThread() {
855 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 922 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
856 } 923 }
857 924
858 } // namespace chromeos 925 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698