Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(823)

Side by Side Diff: chrome/browser/policy/policy_service.cc

Issue 10191005: Added PolicyChangeRegistrar, to observe specific policies at the PolicyService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 Observer* observer)
15 : policy_service_(policy_service),
16 domain_(domain),
17 component_id_(component_id),
18 observer_(observer) {}
19
20 PolicyChangeRegistrar::~PolicyChangeRegistrar() {
21 if (!observing_.empty())
22 policy_service_->RemoveObserver(domain_, component_id_, this);
23 }
24
25 void PolicyChangeRegistrar::Add(const std::string& policy_name) {
26 if (observing_.empty())
27 policy_service_->AddObserver(domain_, component_id_, this);
28 observing_.insert(policy_name);
29 }
30
31 void PolicyChangeRegistrar::Remove(const std::string& policy_name) {
32 observing_.erase(policy_name);
33 if (observing_.empty())
34 policy_service_->RemoveObserver(domain_, component_id_, this);
35 }
36
37 void PolicyChangeRegistrar::OnPolicyUpdated(PolicyDomain domain,
38 const std::string& component_id,
39 const PolicyMap& previous,
40 const PolicyMap& current) {
41 for (std::set<std::string>::iterator it = observing_.begin();
42 it != observing_.end(); ++it) {
43 const Value* prev = previous.GetValue(*it);
44 const Value* cur = current.GetValue(*it);
45 if (!base::Value::Equals(prev, cur)) {
46 observer_->OnPolicyValueUpdated(
47 domain_, component_id_, *it, prev, cur);
48 }
49 }
50 }
51
52 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698