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

Side by Side Diff: chrome/browser/chromeos/proxy_config_service_impl.cc

Issue 2445153002: Move onc and proxy pref names to components. (Closed)
Patch Set: ONC_EXPORT Created 4 years, 1 month 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
OLDNEW
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/memory/ptr_util.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chromeos/net/proxy_config_handler.h" 15 #include "chrome/browser/chromeos/net/proxy_config_handler.h"
16 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
17 #include "chromeos/network/network_profile.h" 17 #include "chromeos/network/network_profile.h"
18 #include "chromeos/network/network_profile_handler.h" 18 #include "chromeos/network/network_profile_handler.h"
19 #include "chromeos/network/network_state.h" 19 #include "chromeos/network/network_state.h"
20 #include "chromeos/network/network_state_handler.h" 20 #include "chromeos/network/network_state_handler.h"
21 #include "chromeos/network/onc/onc_utils.h" 21 #include "chromeos/network/onc/onc_utils.h"
22 #include "components/onc/onc_pref_names.h"
22 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 23 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
23 #include "components/prefs/pref_service.h" 24 #include "components/prefs/pref_service.h"
24 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" 25 #include "components/proxy_config/pref_proxy_config_tracker_impl.h"
25 #include "components/proxy_config/proxy_config_dictionary.h" 26 #include "components/proxy_config/proxy_config_dictionary.h"
26 #include "components/proxy_config/proxy_config_pref_names.h" 27 #include "components/proxy_config/proxy_config_pref_names.h"
27 #include "components/proxy_config/proxy_prefs.h" 28 #include "components/proxy_config/proxy_prefs.h"
28 #include "components/user_manager/user_manager.h" 29 #include "components/user_manager/user_manager.h"
29 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
30 31
31 namespace chromeos { 32 namespace chromeos {
(...skipping 27 matching lines...) Expand all
59 content::BrowserThread::IO)), 60 content::BrowserThread::IO)),
60 active_config_state_(ProxyPrefs::CONFIG_UNSET), 61 active_config_state_(ProxyPrefs::CONFIG_UNSET),
61 profile_prefs_(profile_prefs), 62 profile_prefs_(profile_prefs),
62 local_state_prefs_(local_state_prefs), 63 local_state_prefs_(local_state_prefs),
63 pointer_factory_(this) { 64 pointer_factory_(this) {
64 const base::Closure proxy_change_callback = base::Bind( 65 const base::Closure proxy_change_callback = base::Bind(
65 &ProxyConfigServiceImpl::OnProxyPrefChanged, base::Unretained(this)); 66 &ProxyConfigServiceImpl::OnProxyPrefChanged, base::Unretained(this));
66 67
67 if (profile_prefs) { 68 if (profile_prefs) {
68 profile_pref_registrar_.Init(profile_prefs); 69 profile_pref_registrar_.Init(profile_prefs);
69 profile_pref_registrar_.Add(prefs::kOpenNetworkConfiguration, 70 profile_pref_registrar_.Add(::onc::prefs::kOpenNetworkConfiguration,
70 proxy_change_callback); 71 proxy_change_callback);
71 profile_pref_registrar_.Add(prefs::kUseSharedProxies, 72 profile_pref_registrar_.Add(::proxy_config::prefs::kUseSharedProxies,
72 proxy_change_callback); 73 proxy_change_callback);
73 } 74 }
74 local_state_pref_registrar_.Init(local_state_prefs); 75 local_state_pref_registrar_.Init(local_state_prefs);
75 local_state_pref_registrar_.Add(prefs::kDeviceOpenNetworkConfiguration, 76 local_state_pref_registrar_.Add(::onc::prefs::kDeviceOpenNetworkConfiguration,
76 proxy_change_callback); 77 proxy_change_callback);
77 78
78 // Register for changes to the default network. 79 // Register for changes to the default network.
79 NetworkStateHandler* state_handler = 80 NetworkStateHandler* state_handler =
80 NetworkHandler::Get()->network_state_handler(); 81 NetworkHandler::Get()->network_state_handler();
81 state_handler->AddObserver(this, FROM_HERE); 82 state_handler->AddObserver(this, FROM_HERE);
82 DefaultNetworkChanged(state_handler->DefaultNetwork()); 83 DefaultNetworkChanged(state_handler->DefaultNetwork());
83 } 84 }
84 85
85 ProxyConfigServiceImpl::~ProxyConfigServiceImpl() { 86 ProxyConfigServiceImpl::~ProxyConfigServiceImpl() {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 const user_manager::User* logged_in_user = 164 const user_manager::User* logged_in_user =
164 user_manager::UserManager::Get()->GetLoggedInUser(); 165 user_manager::UserManager::Get()->GetLoggedInUser();
165 if (logged_in_user->IsAffiliated()) { 166 if (logged_in_user->IsAffiliated()) {
166 VLOG(1) << "Respecting proxy for network, as logged-in user belongs to " 167 VLOG(1) << "Respecting proxy for network, as logged-in user belongs to "
167 << "the domain the device is enrolled to."; 168 << "the domain the device is enrolled to.";
168 return false; 169 return false;
169 } 170 }
170 } 171 }
171 172
172 // This network is shared and not managed by the user's domain. 173 // This network is shared and not managed by the user's domain.
173 bool use_shared_proxies = profile_prefs->GetBoolean(prefs::kUseSharedProxies); 174 bool use_shared_proxies =
175 profile_prefs->GetBoolean(::proxy_config::prefs::kUseSharedProxies);
174 VLOG(1) << "Use proxy of shared network: " << use_shared_proxies; 176 VLOG(1) << "Use proxy of shared network: " << use_shared_proxies;
175 return !use_shared_proxies; 177 return !use_shared_proxies;
176 } 178 }
177 179
178 // static 180 // static
179 std::unique_ptr<ProxyConfigDictionary> 181 std::unique_ptr<ProxyConfigDictionary>
180 ProxyConfigServiceImpl::GetActiveProxyConfigDictionary( 182 ProxyConfigServiceImpl::GetActiveProxyConfigDictionary(
181 const PrefService* profile_prefs) { 183 const PrefService* profile_prefs,
184 const PrefService* local_state_prefs) {
182 // Apply Pref Proxy configuration if available. 185 // Apply Pref Proxy configuration if available.
183 net::ProxyConfig pref_proxy_config; 186 net::ProxyConfig pref_proxy_config;
184 ProxyPrefs::ConfigState pref_state = 187 ProxyPrefs::ConfigState pref_state =
185 PrefProxyConfigTrackerImpl::ReadPrefConfig(profile_prefs, 188 PrefProxyConfigTrackerImpl::ReadPrefConfig(profile_prefs,
186 &pref_proxy_config); 189 &pref_proxy_config);
187 if (PrefProxyConfigTrackerImpl::PrefPrecedes(pref_state)) { 190 if (PrefProxyConfigTrackerImpl::PrefPrecedes(pref_state)) {
188 const PrefService::Preference* const pref = 191 const PrefService::Preference* const pref =
189 profile_prefs->FindPreference(::proxy_config::prefs::kProxy); 192 profile_prefs->FindPreference(::proxy_config::prefs::kProxy);
190 const base::DictionaryValue* proxy_config_value; 193 const base::DictionaryValue* proxy_config_value;
191 bool value_exists = pref->GetValue()->GetAsDictionary(&proxy_config_value); 194 bool value_exists = pref->GetValue()->GetAsDictionary(&proxy_config_value);
192 DCHECK(value_exists); 195 DCHECK(value_exists);
193 196
194 return base::MakeUnique<ProxyConfigDictionary>(proxy_config_value); 197 return base::MakeUnique<ProxyConfigDictionary>(proxy_config_value);
195 } 198 }
196 199
197 const chromeos::NetworkState* network = chromeos::NetworkHandler::Get() 200 const chromeos::NetworkState* network = chromeos::NetworkHandler::Get()
198 ->network_state_handler() 201 ->network_state_handler()
199 ->DefaultNetwork(); 202 ->DefaultNetwork();
200 // No connected network. 203 // No connected network.
201 if (!network) 204 if (!network)
202 return nullptr; 205 return nullptr;
203 206
204 // Apply network proxy configuration. 207 // Apply network proxy configuration.
205 ::onc::ONCSource onc_source; 208 ::onc::ONCSource onc_source;
206 std::unique_ptr<ProxyConfigDictionary> proxy_config = 209 std::unique_ptr<ProxyConfigDictionary> proxy_config =
207 chromeos::proxy_config::GetProxyConfigForNetwork( 210 chromeos::proxy_config::GetProxyConfigForNetwork(
208 profile_prefs, g_browser_process->local_state(), *network, 211 profile_prefs, local_state_prefs, *network, &onc_source);
209 &onc_source);
210 if (!chromeos::ProxyConfigServiceImpl::IgnoreProxy( 212 if (!chromeos::ProxyConfigServiceImpl::IgnoreProxy(
211 profile_prefs, network->profile_path(), onc_source)) 213 profile_prefs, network->profile_path(), onc_source))
212 return proxy_config; 214 return proxy_config;
213 215
214 return base::MakeUnique<ProxyConfigDictionary>( 216 return base::MakeUnique<ProxyConfigDictionary>(
215 ProxyConfigDictionary::CreateDirect()); 217 ProxyConfigDictionary::CreateDirect());
216 } 218 }
217 219
218 void ProxyConfigServiceImpl::DetermineEffectiveConfigFromDefaultNetwork() { 220 void ProxyConfigServiceImpl::DetermineEffectiveConfigFromDefaultNetwork() {
219 if (!NetworkHandler::IsInitialized()) 221 if (!NetworkHandler::IsInitialized())
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 std::unique_ptr<base::DictionaryValue> config_dict( 287 std::unique_ptr<base::DictionaryValue> config_dict(
286 effective_config.ToValue()); 288 effective_config.ToValue());
287 VLOG(1) << this << ": Proxy changed: " 289 VLOG(1) << this << ": Proxy changed: "
288 << ProxyPrefs::ConfigStateToDebugString(active_config_state_) 290 << ProxyPrefs::ConfigStateToDebugString(active_config_state_)
289 << ", " << *config_dict; 291 << ", " << *config_dict;
290 } 292 }
291 } 293 }
292 } 294 }
293 295
294 } // namespace chromeos 296 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/proxy_config_service_impl.h ('k') | chrome/browser/chromeos/proxy_config_service_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698