OLD | NEW |
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/policy/policy_service.h" | 5 #include "chrome/browser/policy/policy_service.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 | 8 |
9 namespace policy { | 9 namespace policy { |
10 | 10 |
11 PolicyChangeRegistrar::PolicyChangeRegistrar(PolicyService* policy_service, | 11 PolicyChangeRegistrar::PolicyChangeRegistrar(PolicyService* policy_service, |
12 PolicyDomain domain, | 12 PolicyDomain domain, |
13 const std::string& component_id) | 13 const std::string& component_id) |
14 : policy_service_(policy_service), | 14 : policy_service_(policy_service), |
15 domain_(domain), | 15 domain_(domain), |
16 component_id_(component_id) {} | 16 component_id_(component_id) {} |
17 | 17 |
18 PolicyChangeRegistrar::~PolicyChangeRegistrar() { | 18 PolicyChangeRegistrar::~PolicyChangeRegistrar() { |
19 if (!callback_map_.empty()) | 19 if (!callback_map_.empty()) |
20 policy_service_->RemoveObserver(domain_, component_id_, this); | 20 policy_service_->RemoveObserver(domain_, this); |
21 } | 21 } |
22 | 22 |
23 void PolicyChangeRegistrar::Observe(const std::string& policy_name, | 23 void PolicyChangeRegistrar::Observe(const std::string& policy_name, |
24 const UpdateCallback& callback) { | 24 const UpdateCallback& callback) { |
25 if (callback_map_.empty()) | 25 if (callback_map_.empty()) |
26 policy_service_->AddObserver(domain_, component_id_, this); | 26 policy_service_->AddObserver(domain_, this); |
27 callback_map_[policy_name] = callback; | 27 callback_map_[policy_name] = callback; |
28 } | 28 } |
29 | 29 |
30 void PolicyChangeRegistrar::OnPolicyUpdated(PolicyDomain domain, | 30 void PolicyChangeRegistrar::OnPolicyUpdated(PolicyDomain domain, |
31 const std::string& component_id, | 31 const std::string& component_id, |
32 const PolicyMap& previous, | 32 const PolicyMap& previous, |
33 const PolicyMap& current) { | 33 const PolicyMap& current) { |
| 34 if (component_id != component_id_) |
| 35 return; |
34 for (CallbackMap::iterator it = callback_map_.begin(); | 36 for (CallbackMap::iterator it = callback_map_.begin(); |
35 it != callback_map_.end(); ++it) { | 37 it != callback_map_.end(); ++it) { |
36 const Value* prev = previous.GetValue(it->first); | 38 const Value* prev = previous.GetValue(it->first); |
37 const Value* cur = current.GetValue(it->first); | 39 const Value* cur = current.GetValue(it->first); |
38 if (!base::Value::Equals(prev, cur)) | 40 if (!base::Value::Equals(prev, cur)) |
39 it->second.Run(prev, cur); | 41 it->second.Run(prev, cur); |
40 } | 42 } |
41 } | 43 } |
42 | 44 |
43 } // namespace policy | 45 } // namespace policy |
OLD | NEW |