| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chromeos/network/managed_network_configuration_handler_impl.h" | 5 #include "chromeos/network/managed_network_configuration_handler_impl.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/guid.h" | 12 #include "base/guid.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/stl_util.h" | |
| 18 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "base/values.h" | 18 #include "base/values.h" |
| 20 #include "chromeos/dbus/shill_manager_client.h" | 19 #include "chromeos/dbus/shill_manager_client.h" |
| 21 #include "chromeos/dbus/shill_profile_client.h" | 20 #include "chromeos/dbus/shill_profile_client.h" |
| 22 #include "chromeos/dbus/shill_service_client.h" | 21 #include "chromeos/dbus/shill_service_client.h" |
| 23 #include "chromeos/network/device_state.h" | 22 #include "chromeos/network/device_state.h" |
| 24 #include "chromeos/network/network_configuration_handler.h" | 23 #include "chromeos/network/network_configuration_handler.h" |
| 25 #include "chromeos/network/network_device_handler.h" | 24 #include "chromeos/network/network_device_handler.h" |
| 26 #include "chromeos/network/network_event_log.h" | 25 #include "chromeos/network/network_event_log.h" |
| 27 #include "chromeos/network/network_policy_observer.h" | 26 #include "chromeos/network/network_policy_observer.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 void LogErrorWithDict(const tracked_objects::Location& from_where, | 74 void LogErrorWithDict(const tracked_objects::Location& from_where, |
| 76 const std::string& error_name, | 75 const std::string& error_name, |
| 77 std::unique_ptr<base::DictionaryValue> error_data) { | 76 std::unique_ptr<base::DictionaryValue> error_data) { |
| 78 device_event_log::AddEntry(from_where.file_name(), from_where.line_number(), | 77 device_event_log::AddEntry(from_where.file_name(), from_where.line_number(), |
| 79 device_event_log::LOG_TYPE_NETWORK, | 78 device_event_log::LOG_TYPE_NETWORK, |
| 80 device_event_log::LOG_LEVEL_ERROR, error_name); | 79 device_event_log::LOG_LEVEL_ERROR, error_name); |
| 81 } | 80 } |
| 82 | 81 |
| 83 const base::DictionaryValue* GetByGUID(const GuidToPolicyMap& policies, | 82 const base::DictionaryValue* GetByGUID(const GuidToPolicyMap& policies, |
| 84 const std::string& guid) { | 83 const std::string& guid) { |
| 85 GuidToPolicyMap::const_iterator it = policies.find(guid); | 84 auto it = policies.find(guid); |
| 86 if (it == policies.end()) | 85 if (it == policies.end()) |
| 87 return NULL; | 86 return NULL; |
| 88 return it->second; | 87 return it->second.get(); |
| 89 } | 88 } |
| 90 | 89 |
| 91 } // namespace | 90 } // namespace |
| 92 | 91 |
| 93 struct ManagedNetworkConfigurationHandlerImpl::Policies { | 92 struct ManagedNetworkConfigurationHandlerImpl::Policies { |
| 94 ~Policies(); | 93 ~Policies(); |
| 95 | 94 |
| 96 GuidToPolicyMap per_network_config; | 95 GuidToPolicyMap per_network_config; |
| 97 base::DictionaryValue global_network_config; | 96 base::DictionaryValue global_network_config; |
| 98 }; | 97 }; |
| 99 | 98 |
| 100 ManagedNetworkConfigurationHandlerImpl::Policies::~Policies() { | 99 ManagedNetworkConfigurationHandlerImpl::Policies::~Policies() {} |
| 101 base::STLDeleteValues(&per_network_config); | |
| 102 } | |
| 103 | 100 |
| 104 void ManagedNetworkConfigurationHandlerImpl::AddObserver( | 101 void ManagedNetworkConfigurationHandlerImpl::AddObserver( |
| 105 NetworkPolicyObserver* observer) { | 102 NetworkPolicyObserver* observer) { |
| 106 observers_.AddObserver(observer); | 103 observers_.AddObserver(observer); |
| 107 } | 104 } |
| 108 | 105 |
| 109 void ManagedNetworkConfigurationHandlerImpl::RemoveObserver( | 106 void ManagedNetworkConfigurationHandlerImpl::RemoveObserver( |
| 110 NetworkPolicyObserver* observer) { | 107 NetworkPolicyObserver* observer) { |
| 111 observers_.RemoveObserver(observer); | 108 observers_.RemoveObserver(observer); |
| 112 } | 109 } |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 } | 420 } |
| 424 | 421 |
| 425 policies->global_network_config.MergeDictionary(&global_network_config); | 422 policies->global_network_config.MergeDictionary(&global_network_config); |
| 426 | 423 |
| 427 // Update prohibited technologies. | 424 // Update prohibited technologies. |
| 428 const base::ListValue* prohibited_list = nullptr; | 425 const base::ListValue* prohibited_list = nullptr; |
| 429 if (policies->global_network_config.GetListWithoutPathExpansion( | 426 if (policies->global_network_config.GetListWithoutPathExpansion( |
| 430 ::onc::global_network_config::kDisableNetworkTypes, | 427 ::onc::global_network_config::kDisableNetworkTypes, |
| 431 &prohibited_list) && | 428 &prohibited_list) && |
| 432 prohibited_technologies_handler_) { | 429 prohibited_technologies_handler_) { |
| 433 // Prohobited technologies are only allowed in user policy. | 430 // Prohibited technologies are only allowed in user policy. |
| 434 DCHECK_EQ(::onc::ONC_SOURCE_DEVICE_POLICY, onc_source); | 431 DCHECK_EQ(::onc::ONC_SOURCE_DEVICE_POLICY, onc_source); |
| 435 | 432 |
| 436 prohibited_technologies_handler_->SetProhibitedTechnologies( | 433 prohibited_technologies_handler_->SetProhibitedTechnologies( |
| 437 prohibited_list); | 434 prohibited_list); |
| 438 } | 435 } |
| 439 | 436 |
| 440 GuidToPolicyMap old_per_network_config; | 437 GuidToPolicyMap old_per_network_config; |
| 441 policies->per_network_config.swap(old_per_network_config); | 438 policies->per_network_config.swap(old_per_network_config); |
| 442 | 439 |
| 443 // This stores all GUIDs of policies that have changed or are new. | 440 // This stores all GUIDs of policies that have changed or are new. |
| 444 std::set<std::string> modified_policies; | 441 std::set<std::string> modified_policies; |
| 445 | 442 |
| 446 for (base::ListValue::const_iterator it = network_configs_onc.begin(); | 443 for (base::ListValue::const_iterator it = network_configs_onc.begin(); |
| 447 it != network_configs_onc.end(); ++it) { | 444 it != network_configs_onc.end(); ++it) { |
| 448 const base::DictionaryValue* network = NULL; | 445 base::DictionaryValue* network = NULL; |
| 449 (*it)->GetAsDictionary(&network); | 446 (*it)->GetAsDictionary(&network); |
| 450 DCHECK(network); | 447 DCHECK(network); |
| 451 | 448 |
| 452 std::string guid; | 449 std::string guid; |
| 453 network->GetStringWithoutPathExpansion(::onc::network_config::kGUID, &guid); | 450 network->GetStringWithoutPathExpansion(::onc::network_config::kGUID, &guid); |
| 454 DCHECK(!guid.empty()); | 451 DCHECK(!guid.empty()); |
| 455 | 452 |
| 456 if (policies->per_network_config.count(guid) > 0) { | 453 if (policies->per_network_config.count(guid) > 0) { |
| 457 NET_LOG_ERROR("ONC from " + ToDebugString(onc_source, userhash) + | 454 NET_LOG_ERROR("ONC from " + ToDebugString(onc_source, userhash) + |
| 458 " contains several entries for the same GUID ", guid); | 455 " contains several entries for the same GUID ", guid); |
| 459 delete policies->per_network_config[guid]; | |
| 460 } | 456 } |
| 461 const base::DictionaryValue* new_entry = network->DeepCopy(); | 457 base::DictionaryValue* new_entry = network->DeepCopy(); |
| 462 policies->per_network_config[guid] = new_entry; | 458 policies->per_network_config[guid] = base::WrapUnique(new_entry); |
| 463 | 459 |
| 464 const base::DictionaryValue* old_entry = old_per_network_config[guid]; | 460 base::DictionaryValue* old_entry = old_per_network_config[guid].get(); |
| 465 if (!old_entry || !old_entry->Equals(new_entry)) | 461 if (!old_entry || !old_entry->Equals(new_entry)) |
| 466 modified_policies.insert(guid); | 462 modified_policies.insert(guid); |
| 467 } | 463 } |
| 468 | 464 |
| 469 base::STLDeleteValues(&old_per_network_config); | 465 old_per_network_config.clear(); |
| 470 ApplyOrQueuePolicies(userhash, &modified_policies); | 466 ApplyOrQueuePolicies(userhash, &modified_policies); |
| 471 FOR_EACH_OBSERVER(NetworkPolicyObserver, observers_, | 467 FOR_EACH_OBSERVER(NetworkPolicyObserver, observers_, |
| 472 PoliciesChanged(userhash)); | 468 PoliciesChanged(userhash)); |
| 473 } | 469 } |
| 474 | 470 |
| 475 bool ManagedNetworkConfigurationHandlerImpl::IsAnyPolicyApplicationRunning() | 471 bool ManagedNetworkConfigurationHandlerImpl::IsAnyPolicyApplicationRunning() |
| 476 const { | 472 const { |
| 477 return !policy_applicators_.empty() || !queued_modified_policies_.empty(); | 473 return !policy_applicators_.empty() || !queued_modified_policies_.empty(); |
| 478 } | 474 } |
| 479 | 475 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 | 519 |
| 524 const Policies* policies = GetPoliciesForProfile(profile); | 520 const Policies* policies = GetPoliciesForProfile(profile); |
| 525 if (!policies) { | 521 if (!policies) { |
| 526 VLOG(1) << "The relevant policy is not initialized, " | 522 VLOG(1) << "The relevant policy is not initialized, " |
| 527 << "postponing policy application."; | 523 << "postponing policy application."; |
| 528 // See SetPolicy. | 524 // See SetPolicy. |
| 529 return; | 525 return; |
| 530 } | 526 } |
| 531 | 527 |
| 532 std::set<std::string> policy_guids; | 528 std::set<std::string> policy_guids; |
| 533 for (GuidToPolicyMap::const_iterator it = | 529 for (auto it = policies->per_network_config.begin(); |
| 534 policies->per_network_config.begin(); | |
| 535 it != policies->per_network_config.end(); ++it) { | 530 it != policies->per_network_config.end(); ++it) { |
| 536 policy_guids.insert(it->first); | 531 policy_guids.insert(it->first); |
| 537 } | 532 } |
| 538 | 533 |
| 539 const bool started_policy_application = | 534 const bool started_policy_application = |
| 540 ApplyOrQueuePolicies(profile.userhash, &policy_guids); | 535 ApplyOrQueuePolicies(profile.userhash, &policy_guids); |
| 541 DCHECK(started_policy_application); | 536 DCHECK(started_policy_application); |
| 542 } | 537 } |
| 543 | 538 |
| 544 void ManagedNetworkConfigurationHandlerImpl::OnProfileRemoved( | 539 void ManagedNetworkConfigurationHandlerImpl::OnProfileRemoved( |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 std::unique_ptr<base::DictionaryValue> network_properties, | 852 std::unique_ptr<base::DictionaryValue> network_properties, |
| 858 GetDevicePropertiesCallback send_callback, | 853 GetDevicePropertiesCallback send_callback, |
| 859 const std::string& error_name, | 854 const std::string& error_name, |
| 860 std::unique_ptr<base::DictionaryValue> error_data) { | 855 std::unique_ptr<base::DictionaryValue> error_data) { |
| 861 NET_LOG_ERROR("Error getting device properties", service_path); | 856 NET_LOG_ERROR("Error getting device properties", service_path); |
| 862 send_callback.Run(service_path, std::move(network_properties)); | 857 send_callback.Run(service_path, std::move(network_properties)); |
| 863 } | 858 } |
| 864 | 859 |
| 865 | 860 |
| 866 } // namespace chromeos | 861 } // namespace chromeos |
| OLD | NEW |