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

Side by Side Diff: chrome/browser/chromeos/net/onc_utils.cc

Issue 289383004: Merge FavoriteState into NetworkState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 6 months 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 | Annotate | Revision Log
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/net/onc_utils.h" 5 #include "chrome/browser/chromeos/net/onc_utils.h"
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/chromeos/login/users/user.h" 12 #include "chrome/browser/chromeos/login/users/user.h"
13 #include "chrome/browser/chromeos/login/users/user_manager.h" 13 #include "chrome/browser/chromeos/login/users/user_manager.h"
14 #include "chrome/browser/chromeos/ui_proxy_config.h" 14 #include "chrome/browser/chromeos/ui_proxy_config.h"
15 #include "chrome/browser/prefs/proxy_config_dictionary.h" 15 #include "chrome/browser/prefs/proxy_config_dictionary.h"
16 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
17 #include "chromeos/network/favorite_state.h"
18 #include "chromeos/network/managed_network_configuration_handler.h" 17 #include "chromeos/network/managed_network_configuration_handler.h"
19 #include "chromeos/network/network_configuration_handler.h" 18 #include "chromeos/network/network_configuration_handler.h"
20 #include "chromeos/network/network_handler.h" 19 #include "chromeos/network/network_handler.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/network_ui_data.h" 24 #include "chromeos/network/network_ui_data.h"
26 #include "chromeos/network/onc/onc_normalizer.h" 25 #include "chromeos/network/onc/onc_normalizer.h"
27 #include "chromeos/network/onc/onc_signature.h" 26 #include "chromeos/network/onc/onc_signature.h"
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 ethernet->GetStringWithoutPathExpansion(::onc::ethernet::kAuthentication, 340 ethernet->GetStringWithoutPathExpansion(::onc::ethernet::kAuthentication,
342 &auth); 341 &auth);
343 if (auth == ::onc::ethernet::kNone) 342 if (auth == ::onc::ethernet::kNone)
344 return network; 343 return network;
345 } 344 }
346 return NULL; 345 return NULL;
347 } 346 }
348 347
349 const base::DictionaryValue* GetNetworkConfigForNetworkFromOnc( 348 const base::DictionaryValue* GetNetworkConfigForNetworkFromOnc(
350 const base::ListValue& network_configs, 349 const base::ListValue& network_configs,
351 const FavoriteState& favorite) { 350 const NetworkState& network) {
352 // In all cases except Ethernet, we use the GUID of |network|. 351 // In all cases except Ethernet, we use the GUID of |network|.
353 if (!favorite.Matches(NetworkTypePattern::Ethernet())) 352 if (!network.Matches(NetworkTypePattern::Ethernet()))
354 return GetNetworkConfigByGUID(network_configs, favorite.guid()); 353 return GetNetworkConfigByGUID(network_configs, network.guid());
355 354
356 // Ethernet is always shared and thus cannot store a GUID per user. Thus we 355 // Ethernet is always shared and thus cannot store a GUID per user. Thus we
357 // search for any Ethernet policy intead of a matching GUID. 356 // search for any Ethernet policy intead of a matching GUID.
358 // EthernetEAP service contains only the EAP parameters and stores the GUID of 357 // EthernetEAP service contains only the EAP parameters and stores the GUID of
359 // the respective ONC policy. The EthernetEAP service itself is however never 358 // the respective ONC policy. The EthernetEAP service itself is however never
360 // in state "connected". An EthernetEAP policy must be applied, if an Ethernet 359 // in state "connected". An EthernetEAP policy must be applied, if an Ethernet
361 // service is connected using the EAP parameters. 360 // service is connected using the EAP parameters.
362 const FavoriteState* ethernet_eap = NULL; 361 const NetworkState* ethernet_eap = NULL;
363 if (NetworkHandler::IsInitialized()) { 362 if (NetworkHandler::IsInitialized()) {
364 ethernet_eap = 363 ethernet_eap =
365 NetworkHandler::Get()->network_state_handler()->GetEAPForEthernet( 364 NetworkHandler::Get()->network_state_handler()->GetEAPForEthernet(
366 favorite.path()); 365 network.path());
367 } 366 }
368 367
369 // The GUID associated with the EthernetEAP service refers to the ONC policy 368 // The GUID associated with the EthernetEAP service refers to the ONC policy
370 // with "Authentication: 8021X". 369 // with "Authentication: 8021X".
371 if (ethernet_eap) 370 if (ethernet_eap)
372 return GetNetworkConfigByGUID(network_configs, ethernet_eap->guid()); 371 return GetNetworkConfigByGUID(network_configs, ethernet_eap->guid());
373 372
374 // Otherwise, EAP is not used and instead the Ethernet policy with 373 // Otherwise, EAP is not used and instead the Ethernet policy with
375 // "Authentication: None" applies. 374 // "Authentication: None" applies.
376 return GetNetworkConfigForEthernetWithoutEAP(network_configs); 375 return GetNetworkConfigForEthernetWithoutEAP(network_configs);
377 } 376 }
378 377
379 const base::DictionaryValue* GetPolicyForNetworkFromPref( 378 const base::DictionaryValue* GetPolicyForNetworkFromPref(
380 const PrefService* pref_service, 379 const PrefService* pref_service,
381 const char* pref_name, 380 const char* pref_name,
382 const FavoriteState& favorite) { 381 const NetworkState& network) {
383 if (!pref_service) { 382 if (!pref_service) {
384 VLOG(2) << "No pref service"; 383 VLOG(2) << "No pref service";
385 return NULL; 384 return NULL;
386 } 385 }
387 386
388 const PrefService::Preference* preference = 387 const PrefService::Preference* preference =
389 pref_service->FindPreference(pref_name); 388 pref_service->FindPreference(pref_name);
390 if (!preference) { 389 if (!preference) {
391 VLOG(2) << "No preference " << pref_name; 390 VLOG(2) << "No preference " << pref_name;
392 // The preference may not exist in tests. 391 // The preference may not exist in tests.
(...skipping 13 matching lines...) Expand all
406 return NULL; 405 return NULL;
407 } 406 }
408 VLOG(2) << "Preference with policy found."; 407 VLOG(2) << "Preference with policy found.";
409 const base::Value* onc_policy_value = preference->GetValue(); 408 const base::Value* onc_policy_value = preference->GetValue();
410 DCHECK(onc_policy_value); 409 DCHECK(onc_policy_value);
411 410
412 const base::ListValue* onc_policy = NULL; 411 const base::ListValue* onc_policy = NULL;
413 onc_policy_value->GetAsList(&onc_policy); 412 onc_policy_value->GetAsList(&onc_policy);
414 DCHECK(onc_policy); 413 DCHECK(onc_policy);
415 414
416 return GetNetworkConfigForNetworkFromOnc(*onc_policy, favorite); 415 return GetNetworkConfigForNetworkFromOnc(*onc_policy, network);
417 } 416 }
418 417
419 } // namespace 418 } // namespace
420 419
421 const base::DictionaryValue* GetPolicyForFavoriteNetwork( 420 const base::DictionaryValue* GetPolicyForNetwork(
422 const PrefService* profile_prefs, 421 const PrefService* profile_prefs,
423 const PrefService* local_state_prefs, 422 const PrefService* local_state_prefs,
424 const FavoriteState& favorite, 423 const NetworkState& network,
425 ::onc::ONCSource* onc_source) { 424 ::onc::ONCSource* onc_source) {
426 VLOG(2) << "GetPolicyForFavoriteNetwork: " << favorite.path(); 425 VLOG(2) << "GetPolicyForNetwork: " << network.path();
427 *onc_source = ::onc::ONC_SOURCE_NONE; 426 *onc_source = ::onc::ONC_SOURCE_NONE;
428 427
429 const base::DictionaryValue* network_policy = GetPolicyForNetworkFromPref( 428 const base::DictionaryValue* network_policy = GetPolicyForNetworkFromPref(
430 profile_prefs, prefs::kOpenNetworkConfiguration, favorite); 429 profile_prefs, prefs::kOpenNetworkConfiguration, network);
431 if (network_policy) { 430 if (network_policy) {
432 VLOG(1) << "Network " << favorite.path() << " is managed by user policy."; 431 VLOG(1) << "Network " << network.path() << " is managed by user policy.";
433 *onc_source = ::onc::ONC_SOURCE_USER_POLICY; 432 *onc_source = ::onc::ONC_SOURCE_USER_POLICY;
434 return network_policy; 433 return network_policy;
435 } 434 }
436 network_policy = GetPolicyForNetworkFromPref( 435 network_policy = GetPolicyForNetworkFromPref(
437 local_state_prefs, prefs::kDeviceOpenNetworkConfiguration, favorite); 436 local_state_prefs, prefs::kDeviceOpenNetworkConfiguration, network);
438 if (network_policy) { 437 if (network_policy) {
439 VLOG(1) << "Network " << favorite.path() << " is managed by device policy."; 438 VLOG(1) << "Network " << network.path() << " is managed by device policy.";
440 *onc_source = ::onc::ONC_SOURCE_DEVICE_POLICY; 439 *onc_source = ::onc::ONC_SOURCE_DEVICE_POLICY;
441 return network_policy; 440 return network_policy;
442 } 441 }
443 VLOG(2) << "Network " << favorite.path() << " is unmanaged."; 442 VLOG(2) << "Network " << network.path() << " is unmanaged.";
444 return NULL; 443 return NULL;
445 } 444 }
446 445
447 bool HasPolicyForFavoriteNetwork(const PrefService* profile_prefs, 446 bool HasPolicyForNetwork(const PrefService* profile_prefs,
448 const PrefService* local_state_prefs, 447 const PrefService* local_state_prefs,
449 const FavoriteState& network) { 448 const NetworkState& network) {
450 ::onc::ONCSource ignored_onc_source; 449 ::onc::ONCSource ignored_onc_source;
451 const base::DictionaryValue* policy = onc::GetPolicyForFavoriteNetwork( 450 const base::DictionaryValue* policy = onc::GetPolicyForNetwork(
452 profile_prefs, local_state_prefs, network, &ignored_onc_source); 451 profile_prefs, local_state_prefs, network, &ignored_onc_source);
453 return policy != NULL; 452 return policy != NULL;
454 } 453 }
455 454
456 } // namespace onc 455 } // namespace onc
457 } // namespace chromeos 456 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/net/onc_utils.h ('k') | chrome/browser/chromeos/net/proxy_config_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698