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/policy_applicator.h" | 5 #include "chromeos/network/policy_applicator.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/stl_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "chromeos/dbus/dbus_thread_manager.h" | 14 #include "chromeos/dbus/dbus_thread_manager.h" |
15 #include "chromeos/dbus/shill_profile_client.h" | 15 #include "chromeos/dbus/shill_profile_client.h" |
16 #include "chromeos/network/network_type_pattern.h" | 16 #include "chromeos/network/network_type_pattern.h" |
17 #include "chromeos/network/network_ui_data.h" | 17 #include "chromeos/network/network_ui_data.h" |
18 #include "chromeos/network/onc/onc_signature.h" | 18 #include "chromeos/network/onc/onc_signature.h" |
19 #include "chromeos/network/onc/onc_translator.h" | 19 #include "chromeos/network/onc/onc_translator.h" |
20 #include "chromeos/network/policy_util.h" | 20 #include "chromeos/network/policy_util.h" |
21 #include "chromeos/network/shill_property_util.h" | 21 #include "chromeos/network/shill_property_util.h" |
22 #include "components/onc/onc_constants.h" | 22 #include "components/onc/onc_constants.h" |
23 #include "dbus/object_path.h" | 23 #include "dbus/object_path.h" |
24 #include "third_party/cros_system_api/dbus/service_constants.h" | 24 #include "third_party/cros_system_api/dbus/service_constants.h" |
25 | 25 |
26 namespace chromeos { | 26 namespace chromeos { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 void LogErrorMessage(const tracked_objects::Location& from_where, | 30 void LogErrorMessage(const tracked_objects::Location& from_where, |
31 const std::string& error_name, | 31 const std::string& error_name, |
32 const std::string& error_message) { | 32 const std::string& error_message) { |
33 LOG(ERROR) << from_where.ToString() << ": " << error_message; | 33 LOG(ERROR) << from_where.ToString() << ": " << error_message; |
34 } | 34 } |
35 | 35 |
36 const base::DictionaryValue* GetByGUID( | 36 const base::DictionaryValue* GetByGUID( |
37 const PolicyApplicator::GuidToPolicyMap& policies, | 37 const PolicyApplicator::GuidToPolicyMap& policies, |
38 const std::string& guid) { | 38 const std::string& guid) { |
39 PolicyApplicator::GuidToPolicyMap::const_iterator it = policies.find(guid); | 39 auto it = policies.find(guid); |
40 if (it == policies.end()) | 40 if (it == policies.end()) |
41 return NULL; | 41 return NULL; |
42 return it->second; | 42 return it->second.get(); |
43 } | 43 } |
44 | 44 |
45 } // namespace | 45 } // namespace |
46 | 46 |
47 PolicyApplicator::PolicyApplicator( | 47 PolicyApplicator::PolicyApplicator( |
48 const NetworkProfile& profile, | 48 const NetworkProfile& profile, |
49 const GuidToPolicyMap& all_policies, | 49 const GuidToPolicyMap& all_policies, |
50 const base::DictionaryValue& global_network_config, | 50 const base::DictionaryValue& global_network_config, |
51 ConfigurationHandler* handler, | 51 ConfigurationHandler* handler, |
52 std::set<std::string>* modified_policies) | 52 std::set<std::string>* modified_policies) |
53 : handler_(handler), profile_(profile), weak_ptr_factory_(this) { | 53 : handler_(handler), profile_(profile), weak_ptr_factory_(this) { |
54 global_network_config_.MergeDictionary(&global_network_config); | 54 global_network_config_.MergeDictionary(&global_network_config); |
55 remaining_policies_.swap(*modified_policies); | 55 remaining_policies_.swap(*modified_policies); |
56 for (GuidToPolicyMap::const_iterator it = all_policies.begin(); | 56 for (auto it = all_policies.begin(); it != all_policies.end(); ++it) { |
armansito
2016/10/04 20:30:26
nit: "for (const auto& it : all_policies)" should
Avi (use Gerrit)
2016/10/09 18:14:52
Done.
| |
57 it != all_policies.end(); ++it) { | 57 all_policies_.insert( |
58 all_policies_.insert(std::make_pair(it->first, it->second->DeepCopy())); | 58 std::make_pair(it->first, it->second->CreateDeepCopy())); |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 PolicyApplicator::~PolicyApplicator() { | 62 PolicyApplicator::~PolicyApplicator() { |
63 base::STLDeleteValues(&all_policies_); | |
64 VLOG(1) << "Destroying PolicyApplicator for " << profile_.userhash; | 63 VLOG(1) << "Destroying PolicyApplicator for " << profile_.userhash; |
65 } | 64 } |
66 | 65 |
67 void PolicyApplicator::Run() { | 66 void PolicyApplicator::Run() { |
68 DBusThreadManager::Get()->GetShillProfileClient()->GetProperties( | 67 DBusThreadManager::Get()->GetShillProfileClient()->GetProperties( |
69 dbus::ObjectPath(profile_.path), | 68 dbus::ObjectPath(profile_.path), |
70 base::Bind(&PolicyApplicator::GetProfilePropertiesCallback, | 69 base::Bind(&PolicyApplicator::GetProfilePropertiesCallback, |
71 weak_ptr_factory_.GetWeakPtr()), | 70 weak_ptr_factory_.GetWeakPtr()), |
72 base::Bind(&PolicyApplicator::GetProfilePropertiesError, | 71 base::Bind(&PolicyApplicator::GetProfilePropertiesError, |
73 weak_ptr_factory_.GetWeakPtr())); | 72 weak_ptr_factory_.GetWeakPtr())); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 } | 331 } |
333 remaining_policies_.clear(); | 332 remaining_policies_.clear(); |
334 } | 333 } |
335 | 334 |
336 void PolicyApplicator::NotifyConfigurationHandlerAndFinish() { | 335 void PolicyApplicator::NotifyConfigurationHandlerAndFinish() { |
337 weak_ptr_factory_.InvalidateWeakPtrs(); | 336 weak_ptr_factory_.InvalidateWeakPtrs(); |
338 handler_->OnPoliciesApplied(profile_); | 337 handler_->OnPoliciesApplied(profile_); |
339 } | 338 } |
340 | 339 |
341 } // namespace chromeos | 340 } // namespace chromeos |
OLD | NEW |