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

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: Moved mock method to the test class 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 : 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
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_service.h ('k') | chrome/browser/policy/policy_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698