| 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 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 } // namespace | 91 } // namespace |
| 92 | 92 |
| 93 struct ManagedNetworkConfigurationHandlerImpl::Policies { | 93 struct ManagedNetworkConfigurationHandlerImpl::Policies { |
| 94 ~Policies(); | 94 ~Policies(); |
| 95 | 95 |
| 96 GuidToPolicyMap per_network_config; | 96 GuidToPolicyMap per_network_config; |
| 97 base::DictionaryValue global_network_config; | 97 base::DictionaryValue global_network_config; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 ManagedNetworkConfigurationHandlerImpl::Policies::~Policies() { | 100 ManagedNetworkConfigurationHandlerImpl::Policies::~Policies() { |
| 101 STLDeleteValues(&per_network_config); | 101 base::STLDeleteValues(&per_network_config); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void ManagedNetworkConfigurationHandlerImpl::AddObserver( | 104 void ManagedNetworkConfigurationHandlerImpl::AddObserver( |
| 105 NetworkPolicyObserver* observer) { | 105 NetworkPolicyObserver* observer) { |
| 106 observers_.AddObserver(observer); | 106 observers_.AddObserver(observer); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void ManagedNetworkConfigurationHandlerImpl::RemoveObserver( | 109 void ManagedNetworkConfigurationHandlerImpl::RemoveObserver( |
| 110 NetworkPolicyObserver* observer) { | 110 NetworkPolicyObserver* observer) { |
| 111 observers_.RemoveObserver(observer); | 111 observers_.RemoveObserver(observer); |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 const std::string& userhash, | 408 const std::string& userhash, |
| 409 const base::ListValue& network_configs_onc, | 409 const base::ListValue& network_configs_onc, |
| 410 const base::DictionaryValue& global_network_config) { | 410 const base::DictionaryValue& global_network_config) { |
| 411 VLOG(1) << "Setting policies from " << ToDebugString(onc_source, userhash) | 411 VLOG(1) << "Setting policies from " << ToDebugString(onc_source, userhash) |
| 412 << "."; | 412 << "."; |
| 413 | 413 |
| 414 // |userhash| must be empty for device policies. | 414 // |userhash| must be empty for device policies. |
| 415 DCHECK(onc_source != ::onc::ONC_SOURCE_DEVICE_POLICY || | 415 DCHECK(onc_source != ::onc::ONC_SOURCE_DEVICE_POLICY || |
| 416 userhash.empty()); | 416 userhash.empty()); |
| 417 Policies* policies = NULL; | 417 Policies* policies = NULL; |
| 418 if (ContainsKey(policies_by_user_, userhash)) { | 418 if (base::ContainsKey(policies_by_user_, userhash)) { |
| 419 policies = policies_by_user_[userhash].get(); | 419 policies = policies_by_user_[userhash].get(); |
| 420 } else { | 420 } else { |
| 421 policies = new Policies; | 421 policies = new Policies; |
| 422 policies_by_user_[userhash] = base::WrapUnique(policies); | 422 policies_by_user_[userhash] = base::WrapUnique(policies); |
| 423 } | 423 } |
| 424 | 424 |
| 425 policies->global_network_config.MergeDictionary(&global_network_config); | 425 policies->global_network_config.MergeDictionary(&global_network_config); |
| 426 | 426 |
| 427 // Update prohibited technologies. | 427 // Update prohibited technologies. |
| 428 const base::ListValue* prohibited_list = nullptr; | 428 const base::ListValue* prohibited_list = nullptr; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 459 delete policies->per_network_config[guid]; | 459 delete policies->per_network_config[guid]; |
| 460 } | 460 } |
| 461 const base::DictionaryValue* new_entry = network->DeepCopy(); | 461 const base::DictionaryValue* new_entry = network->DeepCopy(); |
| 462 policies->per_network_config[guid] = new_entry; | 462 policies->per_network_config[guid] = new_entry; |
| 463 | 463 |
| 464 const base::DictionaryValue* old_entry = old_per_network_config[guid]; | 464 const base::DictionaryValue* old_entry = old_per_network_config[guid]; |
| 465 if (!old_entry || !old_entry->Equals(new_entry)) | 465 if (!old_entry || !old_entry->Equals(new_entry)) |
| 466 modified_policies.insert(guid); | 466 modified_policies.insert(guid); |
| 467 } | 467 } |
| 468 | 468 |
| 469 STLDeleteValues(&old_per_network_config); | 469 base::STLDeleteValues(&old_per_network_config); |
| 470 ApplyOrQueuePolicies(userhash, &modified_policies); | 470 ApplyOrQueuePolicies(userhash, &modified_policies); |
| 471 FOR_EACH_OBSERVER(NetworkPolicyObserver, observers_, | 471 FOR_EACH_OBSERVER(NetworkPolicyObserver, observers_, |
| 472 PoliciesChanged(userhash)); | 472 PoliciesChanged(userhash)); |
| 473 } | 473 } |
| 474 | 474 |
| 475 bool ManagedNetworkConfigurationHandlerImpl::IsAnyPolicyApplicationRunning() | 475 bool ManagedNetworkConfigurationHandlerImpl::IsAnyPolicyApplicationRunning() |
| 476 const { | 476 const { |
| 477 return !policy_applicators_.empty() || !queued_modified_policies_.empty(); | 477 return !policy_applicators_.empty() || !queued_modified_policies_.empty(); |
| 478 } | 478 } |
| 479 | 479 |
| 480 bool ManagedNetworkConfigurationHandlerImpl::ApplyOrQueuePolicies( | 480 bool ManagedNetworkConfigurationHandlerImpl::ApplyOrQueuePolicies( |
| 481 const std::string& userhash, | 481 const std::string& userhash, |
| 482 std::set<std::string>* modified_policies) { | 482 std::set<std::string>* modified_policies) { |
| 483 DCHECK(modified_policies); | 483 DCHECK(modified_policies); |
| 484 | 484 |
| 485 const NetworkProfile* profile = | 485 const NetworkProfile* profile = |
| 486 network_profile_handler_->GetProfileForUserhash(userhash); | 486 network_profile_handler_->GetProfileForUserhash(userhash); |
| 487 if (!profile) { | 487 if (!profile) { |
| 488 VLOG(1) << "The relevant Shill profile isn't initialized yet, postponing " | 488 VLOG(1) << "The relevant Shill profile isn't initialized yet, postponing " |
| 489 << "policy application."; | 489 << "policy application."; |
| 490 // OnProfileAdded will apply all policies for this userhash. | 490 // OnProfileAdded will apply all policies for this userhash. |
| 491 return false; | 491 return false; |
| 492 } | 492 } |
| 493 | 493 |
| 494 if (ContainsKey(policy_applicators_, userhash)) { | 494 if (base::ContainsKey(policy_applicators_, userhash)) { |
| 495 // A previous policy application is still running. Queue the modified | 495 // A previous policy application is still running. Queue the modified |
| 496 // policies. | 496 // policies. |
| 497 // Note, even if |modified_policies| is empty, this means that a policy | 497 // Note, even if |modified_policies| is empty, this means that a policy |
| 498 // application will be queued. | 498 // application will be queued. |
| 499 queued_modified_policies_[userhash].insert(modified_policies->begin(), | 499 queued_modified_policies_[userhash].insert(modified_policies->begin(), |
| 500 modified_policies->end()); | 500 modified_policies->end()); |
| 501 VLOG(1) << "Previous PolicyApplicator still running. Postponing policy " | 501 VLOG(1) << "Previous PolicyApplicator still running. Postponing policy " |
| 502 "application."; | 502 "application."; |
| 503 return false; | 503 return false; |
| 504 } | 504 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 | 595 |
| 596 void ManagedNetworkConfigurationHandlerImpl::OnPoliciesApplied( | 596 void ManagedNetworkConfigurationHandlerImpl::OnPoliciesApplied( |
| 597 const NetworkProfile& profile) { | 597 const NetworkProfile& profile) { |
| 598 const std::string& userhash = profile.userhash; | 598 const std::string& userhash = profile.userhash; |
| 599 VLOG(1) << "Policy application for user '" << userhash << "' finished."; | 599 VLOG(1) << "Policy application for user '" << userhash << "' finished."; |
| 600 | 600 |
| 601 base::ThreadTaskRunnerHandle::Get()->DeleteSoon( | 601 base::ThreadTaskRunnerHandle::Get()->DeleteSoon( |
| 602 FROM_HERE, policy_applicators_[userhash].release()); | 602 FROM_HERE, policy_applicators_[userhash].release()); |
| 603 policy_applicators_.erase(userhash); | 603 policy_applicators_.erase(userhash); |
| 604 | 604 |
| 605 if (ContainsKey(queued_modified_policies_, userhash)) { | 605 if (base::ContainsKey(queued_modified_policies_, userhash)) { |
| 606 std::set<std::string> modified_policies; | 606 std::set<std::string> modified_policies; |
| 607 queued_modified_policies_[userhash].swap(modified_policies); | 607 queued_modified_policies_[userhash].swap(modified_policies); |
| 608 // Remove |userhash| from the queue. | 608 // Remove |userhash| from the queue. |
| 609 queued_modified_policies_.erase(userhash); | 609 queued_modified_policies_.erase(userhash); |
| 610 ApplyOrQueuePolicies(userhash, &modified_policies); | 610 ApplyOrQueuePolicies(userhash, &modified_policies); |
| 611 } else { | 611 } else { |
| 612 FOR_EACH_OBSERVER( | 612 FOR_EACH_OBSERVER( |
| 613 NetworkPolicyObserver, observers_, PoliciesApplied(userhash)); | 613 NetworkPolicyObserver, observers_, PoliciesApplied(userhash)); |
| 614 } | 614 } |
| 615 } | 615 } |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 std::unique_ptr<base::DictionaryValue> network_properties, | 857 std::unique_ptr<base::DictionaryValue> network_properties, |
| 858 GetDevicePropertiesCallback send_callback, | 858 GetDevicePropertiesCallback send_callback, |
| 859 const std::string& error_name, | 859 const std::string& error_name, |
| 860 std::unique_ptr<base::DictionaryValue> error_data) { | 860 std::unique_ptr<base::DictionaryValue> error_data) { |
| 861 NET_LOG_ERROR("Error getting device properties", service_path); | 861 NET_LOG_ERROR("Error getting device properties", service_path); |
| 862 send_callback.Run(service_path, std::move(network_properties)); | 862 send_callback.Run(service_path, std::move(network_properties)); |
| 863 } | 863 } |
| 864 | 864 |
| 865 | 865 |
| 866 } // namespace chromeos | 866 } // namespace chromeos |
| OLD | NEW |