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/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" | |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chromeos/net/proxy_config_handler.h" | 15 #include "chrome/browser/chromeos/net/proxy_config_handler.h" |
| 15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 16 #include "chromeos/network/network_profile.h" | 17 #include "chromeos/network/network_profile.h" |
| 17 #include "chromeos/network/network_profile_handler.h" | 18 #include "chromeos/network/network_profile_handler.h" |
| 18 #include "chromeos/network/network_state.h" | 19 #include "chromeos/network/network_state.h" |
| 19 #include "chromeos/network/network_state_handler.h" | 20 #include "chromeos/network/network_state_handler.h" |
| 20 #include "chromeos/network/onc/onc_utils.h" | 21 #include "chromeos/network/onc/onc_utils.h" |
| 21 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 22 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 22 #include "components/prefs/pref_service.h" | 23 #include "components/prefs/pref_service.h" |
| 23 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" | 24 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" |
| 24 #include "components/proxy_config/proxy_config_dictionary.h" | 25 #include "components/proxy_config/proxy_config_dictionary.h" |
| 26 #include "components/proxy_config/proxy_config_pref_names.h" | |
| 25 #include "components/proxy_config/proxy_prefs.h" | 27 #include "components/proxy_config/proxy_prefs.h" |
| 26 #include "components/user_manager/user_manager.h" | 28 #include "components/user_manager/user_manager.h" |
| 27 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 28 | 30 |
| 29 namespace chromeos { | 31 namespace chromeos { |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| 32 | 34 |
| 33 // Writes the proxy config of |network| to |proxy_config|. Set |onc_source| to | 35 // Writes the proxy config of |network| to |proxy_config|. Set |onc_source| to |
| 34 // the source of this configuration. Returns false if no | 36 // the source of this configuration. Returns false if no |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 return false; | 168 return false; |
| 167 } | 169 } |
| 168 } | 170 } |
| 169 | 171 |
| 170 // This network is shared and not managed by the user's domain. | 172 // This network is shared and not managed by the user's domain. |
| 171 bool use_shared_proxies = profile_prefs->GetBoolean(prefs::kUseSharedProxies); | 173 bool use_shared_proxies = profile_prefs->GetBoolean(prefs::kUseSharedProxies); |
| 172 VLOG(1) << "Use proxy of shared network: " << use_shared_proxies; | 174 VLOG(1) << "Use proxy of shared network: " << use_shared_proxies; |
| 173 return !use_shared_proxies; | 175 return !use_shared_proxies; |
| 174 } | 176 } |
| 175 | 177 |
| 178 // static | |
| 179 std::unique_ptr<ProxyConfigDictionary> | |
| 180 ProxyConfigServiceImpl::GetDefaultProxyConfigDictionary( | |
| 181 const PrefService* profile_prefs) { | |
| 182 const chromeos::NetworkState* network = chromeos::NetworkHandler::Get() | |
| 183 ->network_state_handler() | |
| 184 ->DefaultNetwork(); | |
| 185 if (network) { | |
| 186 // Apply Pref Proxy configuration if available. | |
| 187 net::ProxyConfig pref_proxy_config; | |
| 188 ProxyPrefs::ConfigState pref_state = | |
| 189 PrefProxyConfigTrackerImpl::ReadPrefConfig(profile_prefs, | |
| 190 &pref_proxy_config); | |
| 191 if (PrefProxyConfigTrackerImpl::PrefPrecedes(pref_state)) { | |
| 192 const PrefService::Preference* const pref = | |
| 193 profile_prefs->FindPreference(::proxy_config::prefs::kProxy); | |
| 194 const base::DictionaryValue* proxy_config_value; | |
| 195 bool value_exists = | |
| 196 pref->GetValue()->GetAsDictionary(&proxy_config_value); | |
| 197 DCHECK(value_exists); | |
| 198 | |
| 199 return base::MakeUnique<ProxyConfigDictionary>(proxy_config_value); | |
| 200 } | |
|
stevenjb
2016/09/06 15:49:06
This section doesn't depend on |network|. We shoul
Polina Bondarenko
2016/09/06 19:38:46
Done.
| |
| 201 | |
| 202 // Apply network proxy configuration. | |
| 203 ::onc::ONCSource onc_source; | |
| 204 std::unique_ptr<ProxyConfigDictionary> proxy_config = | |
| 205 chromeos::proxy_config::GetProxyConfigForNetwork( | |
| 206 profile_prefs, g_browser_process->local_state(), *network, | |
| 207 &onc_source); | |
| 208 if (!chromeos::ProxyConfigServiceImpl::IgnoreProxy( | |
| 209 profile_prefs, network->profile_path(), onc_source)) | |
| 210 return proxy_config; | |
| 211 } | |
| 212 | |
| 213 return base::MakeUnique<ProxyConfigDictionary>( | |
| 214 ProxyConfigDictionary::CreateDirect()); | |
| 215 } | |
| 216 | |
| 176 void ProxyConfigServiceImpl::DetermineEffectiveConfigFromDefaultNetwork() { | 217 void ProxyConfigServiceImpl::DetermineEffectiveConfigFromDefaultNetwork() { |
| 177 if (!NetworkHandler::IsInitialized()) | 218 if (!NetworkHandler::IsInitialized()) |
| 178 return; | 219 return; |
| 179 | 220 |
| 180 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 221 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
| 181 const NetworkState* network = handler->DefaultNetwork(); | 222 const NetworkState* network = handler->DefaultNetwork(); |
| 182 | 223 |
| 183 // Get prefs proxy config if available. | 224 // Get prefs proxy config if available. |
| 184 net::ProxyConfig pref_config; | 225 net::ProxyConfig pref_config; |
| 185 ProxyPrefs::ConfigState pref_state = GetProxyConfig(&pref_config); | 226 ProxyPrefs::ConfigState pref_state = GetProxyConfig(&pref_config); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 std::unique_ptr<base::DictionaryValue> config_dict( | 284 std::unique_ptr<base::DictionaryValue> config_dict( |
| 244 effective_config.ToValue()); | 285 effective_config.ToValue()); |
| 245 VLOG(1) << this << ": Proxy changed: " | 286 VLOG(1) << this << ": Proxy changed: " |
| 246 << ProxyPrefs::ConfigStateToDebugString(active_config_state_) | 287 << ProxyPrefs::ConfigStateToDebugString(active_config_state_) |
| 247 << ", " << *config_dict; | 288 << ", " << *config_dict; |
| 248 } | 289 } |
| 249 } | 290 } |
| 250 } | 291 } |
| 251 | 292 |
| 252 } // namespace chromeos | 293 } // namespace chromeos |
| OLD | NEW |