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

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

Issue 109743002: Move policy code into components/policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moar fixes Created 7 years 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
« no previous file with comments | « chrome/browser/policy/policy_service.h ('k') | chrome/browser/policy/policy_service_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 const PolicyNamespace& ns)
13 : policy_service_(policy_service),
14 ns_(ns) {}
15
16 PolicyChangeRegistrar::~PolicyChangeRegistrar() {
17 if (!callback_map_.empty())
18 policy_service_->RemoveObserver(ns_.domain, this);
19 }
20
21 void PolicyChangeRegistrar::Observe(const std::string& policy_name,
22 const UpdateCallback& callback) {
23 if (callback_map_.empty())
24 policy_service_->AddObserver(ns_.domain, this);
25 callback_map_[policy_name] = callback;
26 }
27
28 void PolicyChangeRegistrar::OnPolicyUpdated(const PolicyNamespace& ns,
29 const PolicyMap& previous,
30 const PolicyMap& current) {
31 if (ns != ns_)
32 return;
33 for (CallbackMap::iterator it = callback_map_.begin();
34 it != callback_map_.end(); ++it) {
35 const Value* prev = previous.GetValue(it->first);
36 const Value* cur = current.GetValue(it->first);
37 if (!base::Value::Equals(prev, cur))
38 it->second.Run(prev, cur);
39 }
40 }
41
42 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_service.h ('k') | chrome/browser/policy/policy_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698