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 // Apply Pref Proxy configuration if available. |
| 183 net::ProxyConfig pref_proxy_config; |
| 184 ProxyPrefs::ConfigState pref_state = |
| 185 PrefProxyConfigTrackerImpl::ReadPrefConfig(profile_prefs, |
| 186 &pref_proxy_config); |
| 187 if (PrefProxyConfigTrackerImpl::PrefPrecedes(pref_state)) { |
| 188 const PrefService::Preference* const pref = |
| 189 profile_prefs->FindPreference(::proxy_config::prefs::kProxy); |
| 190 const base::DictionaryValue* proxy_config_value; |
| 191 bool value_exists = pref->GetValue()->GetAsDictionary(&proxy_config_value); |
| 192 DCHECK(value_exists); |
| 193 |
| 194 return base::MakeUnique<ProxyConfigDictionary>(proxy_config_value); |
| 195 } |
| 196 |
| 197 const chromeos::NetworkState* network = chromeos::NetworkHandler::Get() |
| 198 ->network_state_handler() |
| 199 ->DefaultNetwork(); |
| 200 // No connected network. |
| 201 if (!network) |
| 202 return nullptr; |
| 203 |
| 204 // Apply network proxy configuration. |
| 205 ::onc::ONCSource onc_source; |
| 206 std::unique_ptr<ProxyConfigDictionary> proxy_config = |
| 207 chromeos::proxy_config::GetProxyConfigForNetwork( |
| 208 profile_prefs, g_browser_process->local_state(), *network, |
| 209 &onc_source); |
| 210 if (!chromeos::ProxyConfigServiceImpl::IgnoreProxy( |
| 211 profile_prefs, network->profile_path(), onc_source)) |
| 212 return proxy_config; |
| 213 |
| 214 return base::MakeUnique<ProxyConfigDictionary>( |
| 215 ProxyConfigDictionary::CreateDirect()); |
| 216 } |
| 217 |
176 void ProxyConfigServiceImpl::DetermineEffectiveConfigFromDefaultNetwork() { | 218 void ProxyConfigServiceImpl::DetermineEffectiveConfigFromDefaultNetwork() { |
177 if (!NetworkHandler::IsInitialized()) | 219 if (!NetworkHandler::IsInitialized()) |
178 return; | 220 return; |
179 | 221 |
180 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 222 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
181 const NetworkState* network = handler->DefaultNetwork(); | 223 const NetworkState* network = handler->DefaultNetwork(); |
182 | 224 |
183 // Get prefs proxy config if available. | 225 // Get prefs proxy config if available. |
184 net::ProxyConfig pref_config; | 226 net::ProxyConfig pref_config; |
185 ProxyPrefs::ConfigState pref_state = GetProxyConfig(&pref_config); | 227 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( | 285 std::unique_ptr<base::DictionaryValue> config_dict( |
244 effective_config.ToValue()); | 286 effective_config.ToValue()); |
245 VLOG(1) << this << ": Proxy changed: " | 287 VLOG(1) << this << ": Proxy changed: " |
246 << ProxyPrefs::ConfigStateToDebugString(active_config_state_) | 288 << ProxyPrefs::ConfigStateToDebugString(active_config_state_) |
247 << ", " << *config_dict; | 289 << ", " << *config_dict; |
248 } | 290 } |
249 } | 291 } |
250 } | 292 } |
251 | 293 |
252 } // namespace chromeos | 294 } // namespace chromeos |
OLD | NEW |