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