Index: chrome/browser/chromeos/proxy_config_service_impl.cc |
=================================================================== |
--- chrome/browser/chromeos/proxy_config_service_impl.cc (revision 103881) |
+++ chrome/browser/chromeos/proxy_config_service_impl.cc (working copy) |
@@ -12,8 +12,10 @@ |
#include "chrome/browser/chromeos/cros/cros_library.h" |
#include "chrome/browser/chromeos/cros_settings_names.h" |
#include "chrome/browser/policy/proto/chrome_device_policy.pb.h" |
+#include "chrome/browser/prefs/pref_service.h" |
#include "chrome/browser/prefs/proxy_config_dictionary.h" |
#include "chrome/browser/prefs/proxy_prefs.h" |
+#include "chrome/browser/profiles/profile_manager.h" |
#include "content/browser/browser_thread.h" |
#include "content/common/json_value_serializer.h" |
#include "grit/generated_resources.h" |
@@ -25,51 +27,58 @@ |
namespace { |
-const char* SourceToString(ProxyConfigServiceImpl::ProxyConfig::Source source) { |
+const char* SourceToString(PrefProxyConfigTracker::ConfigSource source) { |
switch (source) { |
- case ProxyConfigServiceImpl::ProxyConfig::SOURCE_NONE: |
- return "SOURCE_NONE"; |
- case ProxyConfigServiceImpl::ProxyConfig::SOURCE_POLICY: |
- return "SOURCE_POLICY"; |
- case ProxyConfigServiceImpl::ProxyConfig::SOURCE_OWNER: |
- return "SOURCE_OWNER"; |
+ case PrefProxyConfigTracker::CONFIG_SOURCE_UNSET: |
+ return "src: unset"; |
+ case PrefProxyConfigTracker::CONFIG_SOURCE_POLICY: |
+ return "src: policy"; |
+ case PrefProxyConfigTracker::CONFIG_SOURCE_EXTENSION: |
+ return "src: extension"; |
+ case PrefProxyConfigTracker::CONFIG_SOURCE_SYSTEM: |
+ return "src: network"; // For ChromeOS, system is network. |
+ case PrefProxyConfigTracker::CONFIG_SOURCE_FALLBACK: |
+ return "src: recommended"; // Fallback is recommended. |
} |
NOTREACHED() << "Unrecognized source type"; |
return ""; |
} |
+// Only unblock if needed for debugging. |
+#if defined(NEED_DEBUG_LOG) |
std::ostream& operator<<(std::ostream& out, |
const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) { |
- out << " " << SourceToString(proxy.source) << "\n" |
- << " server: " << (proxy.server.is_valid() ? proxy.server.ToURI() : "") |
- << "\n"; |
+ out << (proxy.server.is_valid() ? proxy.server.ToURI() : "") << "\n"; |
return out; |
} |
std::ostream& operator<<(std::ostream& out, |
- const ProxyConfigServiceImpl::ProxyConfig& config) { |
+ const ProxyConfigServiceImpl::ProxyConfig& config) { |
switch (config.mode) { |
case ProxyConfigServiceImpl::ProxyConfig::MODE_DIRECT: |
out << "Direct connection:\n " |
- << SourceToString(config.automatic_proxy.source) << "\n"; |
+ << SourceToString(config.source) << "\n"; |
break; |
case ProxyConfigServiceImpl::ProxyConfig::MODE_AUTO_DETECT: |
out << "Auto detection:\n " |
- << SourceToString(config.automatic_proxy.source) << "\n"; |
+ << SourceToString(config.source) << "\n"; |
break; |
case ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT: |
out << "Custom PAC script:\n " |
- << SourceToString(config.automatic_proxy.source) |
+ << SourceToString(config.source) |
<< "\n PAC: " << config.automatic_proxy.pac_url << "\n"; |
break; |
case ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY: |
- out << "Single proxy:\n" << config.single_proxy; |
+ out << "Single proxy:\n" |
+ << SourceToString(config.source) << "\n " << config.single_proxy; |
break; |
case ProxyConfigServiceImpl::ProxyConfig::MODE_PROXY_PER_SCHEME: |
- out << "HTTP proxy: " << config.http_proxy; |
- out << "HTTPS proxy: " << config.https_proxy; |
- out << "FTP proxy: " << config.ftp_proxy; |
- out << "SOCKS proxy: " << config.socks_proxy; |
+ out << "Manual proxies:\n" |
+ << SourceToString(config.source) << "\n" |
+ << " HTTP: " << config.http_proxy |
+ << " HTTPS: " << config.https_proxy |
+ << " FTP: " << config.ftp_proxy |
+ << " SOCKS: " << config.socks_proxy; |
break; |
default: |
NOTREACHED() << "Unrecognized proxy config mode"; |
@@ -99,21 +108,16 @@ |
stream << proxy_config; |
return stream.str(); |
} |
+#endif // defined(NEED_DEBUG_LOG) |
} // namespace |
-//---------- ProxyConfigServiceImpl::ProxyConfig::Setting methods -------------- |
- |
-bool ProxyConfigServiceImpl::ProxyConfig::Setting::CanBeWrittenByUser( |
- bool user_is_owner) { |
- // Setting can only be written by user if user is owner and setting is not |
- // from policy. |
- return user_is_owner && source != ProxyConfig::SOURCE_POLICY; |
-} |
- |
//----------- ProxyConfigServiceImpl::ProxyConfig: public methods -------------- |
-ProxyConfigServiceImpl::ProxyConfig::ProxyConfig() : mode(MODE_DIRECT) {} |
+ProxyConfigServiceImpl::ProxyConfig::ProxyConfig() |
+ : mode(MODE_DIRECT), |
+ source(PrefProxyConfigTracker::CONFIG_SOURCE_UNSET), |
+ user_modifiable(true) {} |
ProxyConfigServiceImpl::ProxyConfig::~ProxyConfig() {} |
@@ -153,31 +157,53 @@ |
} |
} |
-bool ProxyConfigServiceImpl::ProxyConfig::CanBeWrittenByUser( |
- bool user_is_owner, const std::string& scheme) { |
- // Setting can only be written by user if user is owner and setting is not |
- // from policy. |
- Setting* setting = NULL; |
- switch (mode) { |
- case MODE_DIRECT: |
- case MODE_AUTO_DETECT: |
- case MODE_PAC_SCRIPT: |
- setting = &automatic_proxy; |
- break; |
- case MODE_SINGLE_PROXY: |
- setting = &single_proxy; |
- break; |
- case MODE_PROXY_PER_SCHEME: |
- setting = MapSchemeToProxy(scheme); |
- break; |
+bool ProxyConfigServiceImpl::ProxyConfig::FromNetProxyConfig( |
+ const net::ProxyConfig& net_config) { |
+ const net::ProxyConfig::ProxyRules& rules = net_config.proxy_rules(); |
+ switch (rules.type) { |
+ case net::ProxyConfig::ProxyRules::TYPE_NO_RULES: |
+ if (!net_config.HasAutomaticSettings()) { |
+ mode = ProxyConfig::MODE_DIRECT; |
+ } else if (net_config.auto_detect()) { |
+ mode = ProxyConfig::MODE_AUTO_DETECT; |
+ } else if (net_config.has_pac_url()) { |
+ mode = ProxyConfig::MODE_PAC_SCRIPT; |
+ automatic_proxy.pac_url = net_config.pac_url(); |
+ } else { |
+ return false; |
+ } |
+ return true; |
+ case net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY: |
+ if (!rules.single_proxy.is_valid()) |
+ return false; |
+ mode = MODE_SINGLE_PROXY; |
+ single_proxy.server = rules.single_proxy; |
+ bypass_rules = rules.bypass_rules; |
+ return true; |
+ case net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME: |
+ // Make sure we have valid server for at least one of the protocols. |
+ if (!rules.proxy_for_http.is_valid() && |
+ !rules.proxy_for_https.is_valid() && |
+ !rules.proxy_for_ftp.is_valid() && |
+ !rules.fallback_proxy.is_valid()) { |
+ return false; |
+ } |
+ mode = MODE_PROXY_PER_SCHEME; |
+ if (rules.proxy_for_http.is_valid()) |
+ http_proxy.server = rules.proxy_for_http; |
+ if (rules.proxy_for_https.is_valid()) |
+ https_proxy.server = rules.proxy_for_https; |
+ if (rules.proxy_for_ftp.is_valid()) |
+ ftp_proxy.server = rules.proxy_for_ftp; |
+ if (rules.fallback_proxy.is_valid()) |
+ socks_proxy.server = rules.fallback_proxy; |
+ bypass_rules = rules.bypass_rules; |
+ return true; |
default: |
+ NOTREACHED() << "Unrecognized proxy config mode"; |
break; |
} |
- if (!setting) { |
- NOTREACHED() << "Unrecognized proxy config mode"; |
- return false; |
- } |
- return setting->CanBeWrittenByUser(user_is_owner); |
+ return false; |
} |
ProxyConfigServiceImpl::ProxyConfig::ManualProxy* |
@@ -273,6 +299,8 @@ |
bool ProxyConfigServiceImpl::ProxyConfig::Equals( |
const ProxyConfig& other) const { |
+ // 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.
|
+ // impact on proxy backend. |
if (mode != other.mode) |
return false; |
switch (mode) { |
@@ -298,10 +326,6 @@ |
return false; |
} |
-std::string ProxyConfigServiceImpl::ProxyConfig::ToString() const { |
- return ProxyConfigToString(*this); |
-} |
- |
//----------- ProxyConfigServiceImpl::ProxyConfig: private methods ------------- |
// static |
@@ -441,8 +465,9 @@ |
ProxyConfigServiceImpl::ProxyConfigServiceImpl() |
: testing_(false), |
can_post_task_(false), |
- config_availability_(net::ProxyConfigService::CONFIG_UNSET), |
- use_shared_proxies_(true) { |
+ io_config_availability_(net::ProxyConfigService::CONFIG_UNSET), |
+ use_shared_proxies_(true), |
+ current_ui_profile_(NULL) { |
// Start async fetch of proxy config from settings persisted on device. |
if (CrosLibrary::Get()->EnsureLoaded()) { |
retrieve_property_op_ = SignedSettings::CreateRetrievePropertyOp( |
@@ -465,11 +490,12 @@ |
ProxyConfigServiceImpl::ProxyConfigServiceImpl(const ProxyConfig& init_config) |
: testing_(false), |
can_post_task_(true), |
- config_availability_(net::ProxyConfigService::CONFIG_VALID), |
- use_shared_proxies_(true) { |
+ io_config_availability_(net::ProxyConfigService::CONFIG_VALID), |
+ use_shared_proxies_(true), |
+ current_ui_profile_(NULL) { |
active_config_ = init_config; |
- // Update the IO-accessible copy in |cached_config_| as well. |
- cached_config_ = active_config_; |
+ // Update the IO-accessible copy in |io_config_| as well. |
+ io_config_ = active_config_; |
} |
ProxyConfigServiceImpl::~ProxyConfigServiceImpl() { |
@@ -480,87 +506,73 @@ |
} |
} |
-void ProxyConfigServiceImpl::UIGetProxyConfig(ProxyConfig* config) { |
+void ProxyConfigServiceImpl::UISetUseSharedProxies(bool use_shared) { |
// Should be called from UI thread. |
CheckCurrentlyOnUIThread(); |
- // Simply returns the copy on the UI thread. |
- *config = current_ui_config_; |
+ |
+ if (use_shared_proxies_ == use_shared) { |
+ VLOG(1) << "same use_shared_proxies = " << use_shared_proxies_; |
+ return; |
+ } |
+ use_shared_proxies_ = use_shared; |
+ VLOG(1) << "new use_shared_proxies = " << use_shared_proxies_; |
+ // UISetUseSharedProxies is always called on login, so reset |
+ // current_ui_profile_ to trigger pick up of new default profile. |
+ // If this was called from user changing the setting, we'll set the new |
+ // profile before showing proxy config of any network via |
+ // UISetCurrentUserProfile. |
+ current_ui_profile_ = NULL; |
+ Network* network = NULL; |
+ if (!active_network_.empty()) { |
+ network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath( |
+ active_network_); |
+ if (!network) |
+ LOG(WARNING) << "can't find requested network " << active_network_; |
+ } |
+ DetermineEffectiveConfig(network, true); |
} |
-bool ProxyConfigServiceImpl::UISetCurrentNetwork( |
+void ProxyConfigServiceImpl::UISetCurrentUserProfile(Profile* profile) { |
+ current_ui_profile_ = profile; |
+} |
+ |
+void ProxyConfigServiceImpl::UISetCurrentNetwork( |
const std::string& current_network) { |
// Should be called from UI thread. |
CheckCurrentlyOnUIThread(); |
- if (current_ui_network_ == current_network) |
- return false; |
Network* network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath( |
current_network); |
if (!network) { |
+ ResetUICache(); |
LOG(ERROR) << "can't find requested network " << current_network; |
- return false; |
+ return; |
} |
current_ui_network_ = current_network; |
- current_ui_config_ = ProxyConfig(); |
- SetCurrentNetworkName(network); |
- if (!network->proxy_config().empty()) |
- current_ui_config_.DeserializeForNetwork(network->proxy_config()); |
- VLOG(1) << "current ui network: " |
- << (current_ui_network_name_.empty() ? |
- current_ui_network_ : current_ui_network_name_) |
- << ", proxy mode: " << current_ui_config_.mode; |
- return true; |
+ OnUISetCurrentNetwork(network); |
} |
-bool ProxyConfigServiceImpl::UIMakeActiveNetworkCurrent() { |
+void ProxyConfigServiceImpl::UIMakeActiveNetworkCurrent() { |
// Should be called from UI thread. |
CheckCurrentlyOnUIThread(); |
- if (current_ui_network_ == active_network_) |
- return false; |
Network* network = NULL; |
if (!testing_) { |
network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath( |
active_network_); |
if (!network) { |
+ ResetUICache(); |
LOG(ERROR) << "can't find requested network " << active_network_; |
- return false; |
+ return; |
} |
} |
current_ui_network_ = active_network_; |
- current_ui_config_ = active_config_; |
- SetCurrentNetworkName(network); |
- VLOG(1) << "current ui network: " |
- << (current_ui_network_name_.empty() ? |
- current_ui_network_ : current_ui_network_name_) |
- << ", proxy mode: " << current_ui_config_.mode; |
- return true; |
+ OnUISetCurrentNetwork(network); |
} |
-void ProxyConfigServiceImpl::UISetUseSharedProxies(bool use_shared) { |
+void ProxyConfigServiceImpl::UIGetProxyConfig(ProxyConfig* config) { |
// Should be called from UI thread. |
CheckCurrentlyOnUIThread(); |
- |
- // Reset all UI-related variables so that the next opening of proxy |
- // configuration dialog of any network will trigger javascript reloading of |
- // (possibly) new proxy settings. |
- current_ui_network_.clear(); |
- current_ui_network_name_.clear(); |
- current_ui_config_ = ProxyConfig(); |
- |
- if (use_shared_proxies_ == use_shared) { |
- VLOG(1) << "same use_shared_proxies = " << use_shared_proxies_; |
- return; |
- } |
- use_shared_proxies_ = use_shared; |
- VLOG(1) << "new use_shared_proxies = " << use_shared_proxies_; |
- if (active_network_.empty()) |
- return; |
- Network* network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath( |
- active_network_); |
- if (!network) { |
- LOG(ERROR) << "can't find requested network " << active_network_; |
- return; |
- } |
- DetermineConfigFromNetwork(network); |
+ // Simply returns the copy on the UI thread. |
+ *config = current_ui_config_; |
} |
bool ProxyConfigServiceImpl::UISetProxyConfigToDirect() { |
@@ -629,29 +641,32 @@ |
return true; |
} |
-void ProxyConfigServiceImpl::AddObserver( |
- net::ProxyConfigService::Observer* observer) { |
- // Should be called from IO thread. |
- CheckCurrentlyOnIOThread(); |
- observers_.AddObserver(observer); |
-} |
- |
-void ProxyConfigServiceImpl::RemoveObserver( |
- net::ProxyConfigService::Observer* observer) { |
- // Should be called from IO thread. |
- CheckCurrentlyOnIOThread(); |
- observers_.RemoveObserver(observer); |
-} |
- |
-net::ProxyConfigService::ConfigAvailability |
- ProxyConfigServiceImpl::IOGetProxyConfig(net::ProxyConfig* net_config) { |
- // Should be called from IO thread. |
- CheckCurrentlyOnIOThread(); |
- if (config_availability_ == net::ProxyConfigService::CONFIG_VALID) { |
- VLOG(1) << "returning proxy mode=" << cached_config_.mode; |
- cached_config_.ToNetProxyConfig(net_config); |
+void ProxyConfigServiceImpl::OnPrefProxyConfigChanged( |
+ PrefProxyConfigTracker* in_tracker) { |
+ scoped_refptr<PrefProxyConfigTracker> tracker(in_tracker); |
+ // Make sure this runs on UI thread. |
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI) && can_post_task_) { |
+ // Posts a task to UI thread to handle prefs change. |
+ 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
|
+ NewRunnableMethod(this, |
+ &ProxyConfigServiceImpl::OnPrefProxyConfigChanged, |
+ tracker))) |
+ VLOG(1) << "Couldn't post task to UI thread to handle prefs change"; |
+ return; |
} |
- return config_availability_; |
+ if (tracker != GetProxyConfigTracker()) { |
+ VLOG(1) << "ignoring prefs change from unexpected tracker"; |
+ return; |
+ } |
+ VLOG(1) << "got prefs change"; |
+ Network* network = NULL; |
+ if (!active_network_.empty()) { |
+ network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath( |
+ active_network_); |
+ if (!network) |
+ LOG(ERROR) << "can't find requested network " << active_network_; |
+ } |
+ DetermineEffectiveConfig(network, true); |
} |
void ProxyConfigServiceImpl::OnSettingsOpCompleted( |
@@ -697,6 +712,31 @@ |
OnActiveNetworkChanged(network_lib, network); |
} |
+void ProxyConfigServiceImpl::AddObserver( |
+ net::ProxyConfigService::Observer* observer) { |
+ // Should be called from IO thread. |
+ CheckCurrentlyOnIOThread(); |
+ observers_.AddObserver(observer); |
+} |
+ |
+void ProxyConfigServiceImpl::RemoveObserver( |
+ net::ProxyConfigService::Observer* observer) { |
+ // Should be called from IO thread. |
+ CheckCurrentlyOnIOThread(); |
+ observers_.RemoveObserver(observer); |
+} |
+ |
+net::ProxyConfigService::ConfigAvailability |
+ ProxyConfigServiceImpl::IOGetProxyConfig(net::ProxyConfig* net_config) { |
+ // Should be called from IO thread. |
+ CheckCurrentlyOnIOThread(); |
+ if (io_config_availability_ == net::ProxyConfigService::CONFIG_VALID) { |
+ VLOG(1) << "returning proxy mode=" << io_config_.mode; |
+ io_config_.ToNetProxyConfig(net_config); |
+ } |
+ return io_config_availability_; |
+} |
+ |
//------------------ ProxyConfigServiceImpl: private methods ------------------- |
void ProxyConfigServiceImpl::OnUISetProxyConfig() { |
@@ -712,6 +752,7 @@ |
if (current_ui_config_.SerializeForNetwork(&value)) { |
VLOG(1) << "set proxy (mode=" << current_ui_config_.mode |
<< ") for " << current_ui_network_; |
+ current_ui_config_.source = PrefProxyConfigTracker::CONFIG_SOURCE_SYSTEM; |
SetProxyConfigForNetwork(current_ui_network_, value, false); |
} |
} |
@@ -721,35 +762,35 @@ |
net::ProxyConfigService::ConfigAvailability new_availability) { |
if (!BrowserThread::CurrentlyOn(BrowserThread::IO) && can_post_task_) { |
// Posts a task to IO thread with the new config, so it can update |
- // |cached_config_|. |
- Task* task = NewRunnableMethod(this, |
- &ProxyConfigServiceImpl::IOSetProxyConfig, |
- new_config, |
- new_availability); |
- if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) |
+ // |io_config_|. |
+ if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
+ NewRunnableMethod(this, |
+ &ProxyConfigServiceImpl::IOSetProxyConfig, |
+ new_config, |
+ new_availability))) |
VLOG(1) << "Couldn't post task to IO thread to set new proxy config"; |
return; |
} |
// Now guaranteed to be on the correct thread. |
- if (config_availability_ == new_availability && |
- cached_config_.Equals(new_config)) |
+ if (io_config_availability_ == new_availability && |
+ io_config_.Equals(new_config)) |
return; |
VLOG(1) << "Proxy changed: mode=" << new_config.mode |
<< ", avail=" << new_availability; |
- cached_config_ = new_config; |
- config_availability_ = new_availability; |
+ io_config_ = new_config; |
+ io_config_availability_ = new_availability; |
// Notify observers of new proxy config. |
net::ProxyConfig net_config; |
- cached_config_.ToNetProxyConfig(&net_config); |
+ io_config_.ToNetProxyConfig(&net_config); |
if (net_config.proxy_rules().type != |
net::ProxyConfig::ProxyRules::TYPE_NO_RULES) { |
net_config.proxy_rules().bypass_rules.AddRuleToBypassLocal(); |
} |
FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_, |
- OnProxyConfigChanged(net_config, config_availability_)); |
+ OnProxyConfigChanged(net_config, io_config_availability_)); |
} |
void ProxyConfigServiceImpl::OnActiveNetworkChanged(NetworkLibrary* network_lib, |
@@ -774,8 +815,7 @@ |
if (active_network_.empty()) { |
VLOG(1) << "new active network: empty"; |
- active_config_ = ProxyConfig(); |
- IOSetProxyConfig(active_config_, net::ProxyConfigService::CONFIG_UNSET); |
+ DetermineEffectiveConfig(active_network, true); |
return; |
} |
@@ -791,8 +831,9 @@ |
if (active_network->proxy_config().empty() && !device_config_.empty()) { |
VLOG(1) << "try migrating device config to " << active_network_; |
SetProxyConfigForNetwork(active_network_, device_config_, true); |
- } else { |
- DetermineConfigFromNetwork(active_network); |
+ } else { |
+ // Otherwise, determine and activate possibly new effective proxy config. |
+ DetermineEffectiveConfig(active_network, true); |
} |
} |
@@ -811,32 +852,78 @@ |
<< (network->name().empty() ? network_path : network->name()) |
<< ", value=" << value; |
if (network_path == active_network_) |
- DetermineConfigFromNetwork(network); |
+ DetermineEffectiveConfig(network, true); |
} |
} |
-void ProxyConfigServiceImpl::DetermineConfigFromNetwork( |
- const Network* network) { |
- active_config_ = ProxyConfig(); // Default is DIRECT mode (i.e. no proxy). |
- net::ProxyConfigService::ConfigAvailability available = |
+void ProxyConfigServiceImpl::DetermineEffectiveConfig(const Network* network, |
+ bool activate) { |
+ // Get prefs proxy config. |
+ net::ProxyConfig pref_config; |
+ PrefProxyConfigTracker::ConfigSource pref_source = |
+ PrefProxyConfigTracker::CONFIG_SOURCE_UNSET; |
+ PrefProxyConfigTracker::ConfigState pref_state = |
+ GetProxyConfigTracker()->UIGetProxyConfig(&pref_config, &pref_source); |
+ |
+ // Get network proxy config if available. |
+ net::ProxyConfig network_config; |
+ net::ProxyConfigService::ConfigAvailability network_availability = |
net::ProxyConfigService::CONFIG_UNSET; |
- // If network is shared but user doesn't use shared proxies, use direct mode. |
- if (network->profile_type() == PROFILE_SHARED && !use_shared_proxies_) { |
- VLOG(1) << "shared network and !use_shared_proxies, using direct"; |
- available = net::ProxyConfigService::CONFIG_VALID; |
- } else if (!network->proxy_config().empty() && |
- active_config_.DeserializeForNetwork(network->proxy_config())) { |
- // Network is private or shared with user using shared proxies. |
- VLOG(1) << "using network proxy: " << network->proxy_config(); |
- available = net::ProxyConfigService::CONFIG_VALID; |
+ bool ignore_proxy = activate; |
+ if (network) { |
+ // If we're activating proxy, ignore proxy if necessary; |
+ // otherwise, for ui, get actual proxy to show user. |
+ ignore_proxy = activate ? IgnoreProxy(network) : false; |
+ // If network is shared but use-shared-proxies is off, use direct mode. |
+ if (ignore_proxy) { |
+ VLOG(1) << "shared network and !use_shared_proxies, using direct"; |
+ network_availability = net::ProxyConfigService::CONFIG_VALID; |
+ } else if (!network->proxy_config().empty()) { |
+ // Network is private or shared with user using shared proxies. |
+ JSONStringValueSerializer serializer(network->proxy_config()); |
+ scoped_ptr<Value> value(serializer.Deserialize(NULL, NULL)); |
+ if (value.get() && value->GetType() == Value::TYPE_DICTIONARY) { |
+ DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); |
+ ProxyConfigDictionary proxy_dict(dict); |
+ if (PrefProxyConfigTracker::PrefConfigToNetConfig(proxy_dict, |
+ &network_config)) { |
+ VLOG(1) << "using network proxy: " << network->proxy_config(); |
+ network_availability = net::ProxyConfigService::CONFIG_VALID; |
+ } |
+ } |
+ } |
} |
- IOSetProxyConfig(active_config_, available); |
+ |
+ // Determine effective proxy config, either from prefs or network. |
+ net::ProxyConfig effective_config; |
+ PrefProxyConfigTracker::ConfigSource effective_config_source; |
+ net::ProxyConfigService::ConfigAvailability effective_availability = |
+ GetEffectiveProxyConfig(pref_state, pref_config, pref_source, |
+ network_availability, network_config, |
+ ignore_proxy, |
+ &effective_config, &effective_config_source); |
+ |
+ // Store effective config into the config indicated by |activate|. |
+ ProxyConfig* config_to_set = activate ? &active_config_ : ¤t_ui_config_; |
+ *config_to_set = ProxyConfig(); // Reset to default i.e. DIRECT (no proxy). |
+ config_to_set->FromNetProxyConfig(effective_config); |
+ config_to_set->source = effective_config_source; |
+ if (pref_state == PrefProxyConfigTracker::CONFIG_PRESENT) |
+ config_to_set->user_modifiable = false; |
+ else |
+ config_to_set->user_modifiable = !network || !IgnoreProxy(network); |
+ |
+ // If necessary, cache effective config in IO thread and activate it. |
+ if (activate) |
+ IOSetProxyConfig(*config_to_set, effective_availability); |
} |
-void ProxyConfigServiceImpl::SetCurrentNetworkName(const Network* network) { |
+void ProxyConfigServiceImpl::OnUISetCurrentNetwork(const Network* network) { |
if (!network) { |
- if (testing_) |
+ if (testing_) { |
+ current_ui_config_ = active_config_; |
current_ui_network_name_ = "test"; |
+ } |
return; |
} |
if (network->name().empty() && network->type() == chromeos::TYPE_ETHERNET) { |
@@ -845,8 +932,27 @@ |
} else { |
current_ui_network_name_ = network->name(); |
} |
+ DetermineEffectiveConfig(network, false); |
+ VLOG(1) << "current ui network: " |
+ << (current_ui_network_name_.empty() ? |
+ current_ui_network_ : current_ui_network_name_) |
+ << ", proxy mode: " << current_ui_config_.mode |
+ << ", " << SourceToString(current_ui_config_.source) |
+ << ", modifiable:" << current_ui_config_.user_modifiable; |
} |
+void ProxyConfigServiceImpl::ResetUICache() { |
+ current_ui_network_.clear(); |
+ current_ui_network_name_.clear(); |
+ current_ui_config_ = ProxyConfig(); |
+} |
+ |
+PrefProxyConfigTracker* ProxyConfigServiceImpl::GetProxyConfigTracker() { |
+ Profile* profile = current_ui_profile_ ? current_ui_profile_ : |
+ ProfileManager::GetDefaultProfile(); |
+ return profile->GetProxyConfigTracker(); |
+} |
+ |
void ProxyConfigServiceImpl::CheckCurrentlyOnIOThread() { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
} |