Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/prefs/pref_registry_simple.h" | |
| 11 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 12 #include "base/values.h" | 11 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chromeos/login/user_manager.h" | 13 #include "chrome/browser/chromeos/login/user_manager.h" |
| 15 #include "chrome/browser/chromeos/net/proxy_config_handler.h" | 14 #include "chrome/browser/chromeos/net/proxy_config_handler.h" |
| 16 #include "chrome/browser/policy/browser_policy_connector.h" | 15 #include "chrome/browser/policy/browser_policy_connector.h" |
| 17 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" | 16 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
| 18 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 17 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
| 19 #include "chrome/browser/prefs/proxy_prefs.h" | 18 #include "chrome/browser/prefs/proxy_prefs.h" |
| 20 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 21 #include "chromeos/network/network_profile.h" | 20 #include "chromeos/network/network_profile.h" |
| 22 #include "chromeos/network/network_profile_handler.h" | 21 #include "chromeos/network/network_profile_handler.h" |
| 23 #include "chromeos/network/network_state.h" | 22 #include "chromeos/network/network_state.h" |
| 24 #include "chromeos/network/network_state_handler.h" | 23 #include "chromeos/network/network_state_handler.h" |
| 25 #include "chromeos/network/onc/onc_utils.h" | 24 #include "chromeos/network/onc/onc_utils.h" |
| 26 #include "components/user_prefs/pref_registry_syncable.h" | |
| 27 | 25 |
| 28 namespace chromeos { | 26 namespace chromeos { |
| 29 | 27 |
| 30 namespace { | 28 namespace { |
| 31 | 29 |
| 32 // Writes the proxy config of |network| to |proxy_config|. Returns false if no | 30 // Writes the proxy config of |network| to |proxy_config|. Returns false if no |
| 33 // proxy was configured for this network. | 31 // proxy was configured for this network. |
| 34 bool GetProxyConfig(const NetworkState& network, | 32 bool GetProxyConfig(const NetworkState& network, |
| 35 net::ProxyConfig* proxy_config) { | 33 net::ProxyConfig* proxy_config) { |
| 36 scoped_ptr<ProxyConfigDictionary> proxy_dict = | 34 scoped_ptr<ProxyConfigDictionary> proxy_dict = |
| 37 proxy_config::GetProxyConfigForNetwork(network); | 35 proxy_config::GetProxyConfigForNetwork(network); |
| 38 if (!proxy_dict) | 36 if (!proxy_dict) |
| 39 return false; | 37 return false; |
| 40 return PrefProxyConfigTrackerImpl::PrefConfigToNetConfig(*proxy_dict, | 38 return PrefProxyConfigTrackerImpl::PrefConfigToNetConfig(*proxy_dict, |
| 41 proxy_config); | 39 proxy_config); |
| 42 } | 40 } |
| 43 | 41 |
| 44 } // namespace | 42 } // namespace |
| 45 | 43 |
| 46 ProxyConfigServiceImpl::ProxyConfigServiceImpl(PrefService* pref_service) | 44 ProxyConfigServiceImpl::ProxyConfigServiceImpl(bool signin_profile, |
| 47 : PrefProxyConfigTrackerImpl(pref_service), | 45 PrefService* profile_prefs, |
| 46 PrefService* local_state_prefs) | |
| 47 : PrefProxyConfigTrackerImpl(profile_prefs ? profile_prefs | |
| 48 : local_state_prefs), | |
| 48 active_config_state_(ProxyPrefs::CONFIG_UNSET), | 49 active_config_state_(ProxyPrefs::CONFIG_UNSET), |
| 50 profile_prefs_(profile_prefs), | |
| 51 signin_profile_(signin_profile), | |
| 49 pointer_factory_(this) { | 52 pointer_factory_(this) { |
| 50 | |
| 51 // Register for notifications of UseSharedProxies user preference. | 53 // Register for notifications of UseSharedProxies user preference. |
| 52 if (pref_service->FindPreference(prefs::kUseSharedProxies)) { | 54 if (profile_prefs && !signin_profile) { |
| 55 DCHECK(profile_prefs->FindPreference(prefs::kUseSharedProxies)); | |
| 53 use_shared_proxies_.Init( | 56 use_shared_proxies_.Init( |
| 54 prefs::kUseSharedProxies, pref_service, | 57 prefs::kUseSharedProxies, |
| 58 profile_prefs, | |
| 55 base::Bind(&ProxyConfigServiceImpl::OnUseSharedProxiesChanged, | 59 base::Bind(&ProxyConfigServiceImpl::OnUseSharedProxiesChanged, |
| 56 base::Unretained(this))); | 60 base::Unretained(this))); |
| 57 } | 61 } |
| 58 | 62 |
| 59 // Register for changes to the default network. | 63 // Register for changes to the default network. |
| 60 NetworkStateHandler* state_handler = | 64 NetworkStateHandler* state_handler = |
| 61 NetworkHandler::Get()->network_state_handler(); | 65 NetworkHandler::Get()->network_state_handler(); |
| 62 state_handler->AddObserver(this, FROM_HERE); | 66 state_handler->AddObserver(this, FROM_HERE); |
| 63 DefaultNetworkChanged(state_handler->DefaultNetwork()); | 67 DefaultNetworkChanged(state_handler->DefaultNetwork()); |
| 64 } | 68 } |
| 65 | 69 |
| 66 ProxyConfigServiceImpl::~ProxyConfigServiceImpl() { | 70 ProxyConfigServiceImpl::~ProxyConfigServiceImpl() { |
| 67 if (NetworkHandler::IsInitialized()) { | 71 if (NetworkHandler::IsInitialized()) { |
| 68 NetworkHandler::Get()->network_state_handler()->RemoveObserver( | 72 NetworkHandler::Get()->network_state_handler()->RemoveObserver( |
| 69 this, FROM_HERE); | 73 this, FROM_HERE); |
| 70 } | 74 } |
| 71 } | 75 } |
| 72 | 76 |
| 73 void ProxyConfigServiceImpl::OnProxyConfigChanged( | 77 void ProxyConfigServiceImpl::OnProxyConfigChanged( |
| 74 ProxyPrefs::ConfigState config_state, | 78 ProxyPrefs::ConfigState config_state, |
| 75 const net::ProxyConfig& config) { | 79 const net::ProxyConfig& config) { |
| 76 VLOG(1) << "Got prefs change: " | 80 VLOG(1) << "Got prefs change: " |
| 77 << ProxyPrefs::ConfigStateToDebugString(config_state) | 81 << ProxyPrefs::ConfigStateToDebugString(config_state) |
| 78 << ", mode=" << config.proxy_rules().type; | 82 << ", mode=" << config.proxy_rules().type; |
| 79 DetermineEffectiveConfigFromDefaultNetwork(); | 83 DetermineEffectiveConfigFromDefaultNetwork(); |
| 80 } | 84 } |
| 81 | 85 |
| 82 // static | |
| 83 void ProxyConfigServiceImpl::RegisterPrefs(PrefRegistrySimple* registry) { | |
| 84 // Use shared proxies default to off. GetUseSharedProxies will return the | |
| 85 // correct value based on pre-login and login. | |
| 86 registry->RegisterBooleanPref(prefs::kUseSharedProxies, true); | |
| 87 } | |
| 88 | |
| 89 // static | |
| 90 void ProxyConfigServiceImpl::RegisterProfilePrefs( | |
| 91 user_prefs::PrefRegistrySyncable* registry) { | |
| 92 registry->RegisterBooleanPref( | |
| 93 prefs::kUseSharedProxies, | |
| 94 true, | |
| 95 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 96 } | |
| 97 | |
| 98 void ProxyConfigServiceImpl::OnUseSharedProxiesChanged() { | 86 void ProxyConfigServiceImpl::OnUseSharedProxiesChanged() { |
| 99 VLOG(1) << "New use-shared-proxies = " << GetUseSharedProxies(prefs()); | 87 VLOG(1) << "use-shared-proxies pref changed."; |
| 100 DetermineEffectiveConfigFromDefaultNetwork(); | 88 DetermineEffectiveConfigFromDefaultNetwork(); |
| 101 } | 89 } |
| 102 | 90 |
| 103 void ProxyConfigServiceImpl::DefaultNetworkChanged( | 91 void ProxyConfigServiceImpl::DefaultNetworkChanged( |
| 104 const NetworkState* new_network) { | 92 const NetworkState* new_network) { |
| 105 std::string new_network_path; | 93 std::string new_network_path; |
| 106 if (new_network) | 94 if (new_network) |
| 107 new_network_path = new_network->path(); | 95 new_network_path = new_network->path(); |
| 108 | 96 |
| 109 VLOG(1) << "DefaultNetworkChanged to '" << new_network_path << "'."; | 97 VLOG(1) << "DefaultNetworkChanged to '" << new_network_path << "'."; |
| 110 VLOG_IF(1, new_network) << "New network: name=" << new_network->name() | 98 VLOG_IF(1, new_network) << "New network: name=" << new_network->name() |
| 111 << ", proxy=" << new_network->proxy_config() | 99 << ", proxy=" << new_network->proxy_config() |
| 112 << ", profile=" << new_network->profile_path(); | 100 << ", profile=" << new_network->profile_path(); |
| 113 | 101 |
| 114 // Even if the default network is the same, its proxy config (e.g. if private | 102 // Even if the default network is the same, its proxy config (e.g. if private |
| 115 // version of network replaces the shared version after login), or | 103 // version of network replaces the shared version after login), or |
| 116 // use-shared-proxies setting (e.g. after login) may have changed, so | 104 // use-shared-proxies setting (e.g. after login) may have changed, so |
| 117 // re-determine effective proxy config, and activate if different. | 105 // re-determine effective proxy config, and activate if different. |
| 118 DetermineEffectiveConfigFromDefaultNetwork(); | 106 DetermineEffectiveConfigFromDefaultNetwork(); |
| 119 } | 107 } |
| 120 | 108 |
| 121 // static | 109 // static |
| 122 bool ProxyConfigServiceImpl::GetUseSharedProxies( | 110 bool ProxyConfigServiceImpl::IgnoreProxy(bool signin_profile, |
| 123 const PrefService* pref_service) { | 111 const PrefService* profile_prefs, |
| 124 const PrefService::Preference* use_shared_proxies_pref = | |
| 125 pref_service->FindPreference(prefs::kUseSharedProxies); | |
| 126 if (!use_shared_proxies_pref || !use_shared_proxies_pref->GetValue()) { | |
| 127 if (UserManager::Get()->IsUserLoggedIn()) { | |
| 128 VLOG(1) << "use-shared-proxies not set, defaulting to false/IgnoreProxy."; | |
| 129 return false; | |
| 130 } else { | |
| 131 // Make sure that proxies are always enabled at sign in screen. | |
| 132 VLOG(1) << "Use proxy on login screen."; | |
| 133 return true; | |
| 134 } | |
| 135 } | |
| 136 bool use_shared_proxies = false; | |
| 137 use_shared_proxies_pref->GetValue()->GetAsBoolean(&use_shared_proxies); | |
| 138 return use_shared_proxies; | |
| 139 } | |
| 140 | |
| 141 // static | |
| 142 bool ProxyConfigServiceImpl::IgnoreProxy(const PrefService* pref_service, | |
| 143 const std::string network_profile_path, | 112 const std::string network_profile_path, |
| 144 onc::ONCSource onc_source) { | 113 onc::ONCSource onc_source) { |
| 114 if (!profile_prefs) { | |
| 115 // If the profile preference are not available, this must be the object | |
| 116 // associated to local state used for system requests. Make sure that | |
| 117 // proxies are enabled. | |
| 118 VLOG(1) << "Use proxy for system requests."; | |
| 119 return false; | |
| 120 } | |
| 121 if (signin_profile) { | |
| 122 VLOG(1) << "Use proxy for sign-in screen"; | |
| 123 return false; | |
| 124 } | |
| 125 | |
| 145 const NetworkProfile* profile = | 126 const NetworkProfile* profile = |
| 146 NetworkHandler::Get()->network_profile_handler()-> | 127 NetworkHandler::Get()->network_profile_handler()-> |
| 147 GetProfileForPath(network_profile_path); | 128 GetProfileForPath(network_profile_path); |
| 148 if (!profile) { | 129 if (!profile) { |
| 149 LOG(WARNING) << "Unknown profile_path " << network_profile_path; | 130 LOG(WARNING) << "Unknown profile_path '" << network_profile_path |
| 131 << "'. Ignoring proxy."; | |
| 150 return true; | 132 return true; |
| 151 } | 133 } |
| 152 if (profile->type() == NetworkProfile::TYPE_USER) { | 134 if (profile->type() == NetworkProfile::TYPE_USER) { |
| 153 VLOG(1) << "Respect proxy of not-shared networks."; | 135 VLOG(1) << "Respect proxy of not-shared networks."; |
| 154 return false; | 136 return false; |
| 155 } | 137 } |
| 156 | 138 if (onc_source == onc::ONC_SOURCE_DEVICE_POLICY) { |
| 157 if (onc_source == onc::ONC_SOURCE_DEVICE_POLICY && | |
| 158 UserManager::Get()->IsUserLoggedIn()) { | |
| 159 policy::BrowserPolicyConnector* connector = | 139 policy::BrowserPolicyConnector* connector = |
| 160 g_browser_process->browser_policy_connector(); | 140 g_browser_process->browser_policy_connector(); |
| 161 const User* logged_in_user = UserManager::Get()->GetLoggedInUser(); | 141 const User* logged_in_user = UserManager::Get()->GetLoggedInUser(); |
| 162 if (connector->GetUserAffiliation(logged_in_user->email()) == | 142 if (connector->GetUserAffiliation(logged_in_user->email()) == |
| 163 policy::USER_AFFILIATION_MANAGED) { | 143 policy::USER_AFFILIATION_MANAGED) { |
| 164 VLOG(1) << "Respecting proxy for network, as logged-in user belongs to " | 144 VLOG(1) << "Respecting proxy for network, as logged-in user belongs to " |
| 165 << "the domain the device is enrolled to."; | 145 << "the domain the device is enrolled to."; |
| 166 return false; | 146 return false; |
| 167 } | 147 } |
| 168 } | 148 } |
| 169 | 149 |
| 170 return !GetUseSharedProxies(pref_service); | 150 // This network is shared and not managed by the user's domain. |
| 151 const PrefService::Preference* use_shared_proxies_pref = | |
| 152 profile_prefs->FindPreference(prefs::kUseSharedProxies); | |
| 153 bool use_shared_proxies = false; | |
| 154 DCHECK(use_shared_proxies_pref && use_shared_proxies_pref->GetValue()); | |
| 155 use_shared_proxies_pref->GetValue()->GetAsBoolean(&use_shared_proxies); | |
|
battre
2013/07/11 13:31:23
bool use_shared_proxies = profile_prefs->GetBoolea
pneubeck (no reviews)
2013/07/12 09:42:30
Done.
| |
| 156 VLOG(1) << "Use proxy of shared network: " << use_shared_proxies; | |
| 157 return !use_shared_proxies; | |
| 171 } | 158 } |
| 172 | 159 |
| 173 void ProxyConfigServiceImpl::DetermineEffectiveConfigFromDefaultNetwork() { | 160 void ProxyConfigServiceImpl::DetermineEffectiveConfigFromDefaultNetwork() { |
| 174 const NetworkState* network = | 161 const NetworkState* network = |
| 175 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); | 162 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); |
| 176 | 163 |
| 177 // Get prefs proxy config if available. | 164 // Get prefs proxy config if available. |
| 178 net::ProxyConfig pref_config; | 165 net::ProxyConfig pref_config; |
| 179 ProxyPrefs::ConfigState pref_state = GetProxyConfig(&pref_config); | 166 ProxyPrefs::ConfigState pref_state = GetProxyConfig(&pref_config); |
| 180 | 167 |
| 181 // Get network proxy config if available. | 168 // Get network proxy config if available. |
| 182 net::ProxyConfig network_config; | 169 net::ProxyConfig network_config; |
| 183 net::ProxyConfigService::ConfigAvailability network_availability = | 170 net::ProxyConfigService::ConfigAvailability network_availability = |
| 184 net::ProxyConfigService::CONFIG_UNSET; | 171 net::ProxyConfigService::CONFIG_UNSET; |
| 185 bool ignore_proxy = true; | 172 bool ignore_proxy = true; |
| 186 if (network) { | 173 if (network) { |
| 187 ignore_proxy = | 174 ignore_proxy = IgnoreProxy(signin_profile_, |
| 188 IgnoreProxy(prefs(), network->profile_path(), network->onc_source()); | 175 profile_prefs_, |
| 176 network->profile_path(), | |
| 177 network->onc_source()); | |
| 189 // If network is shared but use-shared-proxies is off, use direct mode. | 178 // If network is shared but use-shared-proxies is off, use direct mode. |
| 190 if (ignore_proxy) { | 179 if (ignore_proxy) { |
| 191 VLOG(1) << "Shared network && !use-shared-proxies, use direct"; | 180 VLOG(1) << "Shared network && !use-shared-proxies, use direct"; |
| 192 network_availability = net::ProxyConfigService::CONFIG_VALID; | 181 network_availability = net::ProxyConfigService::CONFIG_VALID; |
| 193 } else if (chromeos::GetProxyConfig(*network, &network_config)) { | 182 } else if (chromeos::GetProxyConfig(*network, &network_config)) { |
| 194 // Network is private or shared with user using shared proxies. | 183 // Network is private or shared with user using shared proxies. |
| 195 VLOG(1) << this << ": using network proxy: " | 184 VLOG(1) << this << ": using network proxy: " |
| 196 << network->proxy_config(); | 185 << network->proxy_config(); |
| 197 network_availability = net::ProxyConfigService::CONFIG_VALID; | 186 network_availability = net::ProxyConfigService::CONFIG_VALID; |
| 198 } | 187 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 scoped_ptr<base::DictionaryValue> config_dict( | 222 scoped_ptr<base::DictionaryValue> config_dict( |
| 234 effective_config.ToValue()); | 223 effective_config.ToValue()); |
| 235 VLOG(1) << this << ": Proxy changed: " | 224 VLOG(1) << this << ": Proxy changed: " |
| 236 << ProxyPrefs::ConfigStateToDebugString(active_config_state_) | 225 << ProxyPrefs::ConfigStateToDebugString(active_config_state_) |
| 237 << ", " << *config_dict; | 226 << ", " << *config_dict; |
| 238 } | 227 } |
| 239 } | 228 } |
| 240 } | 229 } |
| 241 | 230 |
| 242 } // namespace chromeos | 231 } // namespace chromeos |
| OLD | NEW |