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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/policy/policy_service.cc
diff --git a/chrome/browser/policy/policy_service.cc b/chrome/browser/policy/policy_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ac262eaeb3e05210750f44c089b6a8b4ba32ee87
--- /dev/null
+++ b/chrome/browser/policy/policy_service.cc
@@ -0,0 +1,52 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/policy/policy_service.h"
+
+#include "base/values.h"
+
+namespace policy {
+
+PolicyChangeRegistrar::PolicyChangeRegistrar(PolicyService* policy_service,
+ PolicyDomain domain,
+ const std::string component_id,
+ Observer* observer)
+ : policy_service_(policy_service),
+ domain_(domain),
+ component_id_(component_id),
+ observer_(observer) {}
+
+PolicyChangeRegistrar::~PolicyChangeRegistrar() {
+ if (!observing_.empty())
+ policy_service_->RemoveObserver(domain_, component_id_, this);
+}
+
+void PolicyChangeRegistrar::Add(const std::string& policy_name) {
+ if (observing_.empty())
+ policy_service_->AddObserver(domain_, component_id_, this);
+ observing_.insert(policy_name);
+}
+
+void PolicyChangeRegistrar::Remove(const std::string& policy_name) {
+ observing_.erase(policy_name);
+ if (observing_.empty())
+ policy_service_->RemoveObserver(domain_, component_id_, this);
+}
+
+void PolicyChangeRegistrar::OnPolicyUpdated(PolicyDomain domain,
+ const std::string& component_id,
+ const PolicyMap& previous,
+ const PolicyMap& current) {
+ for (std::set<std::string>::iterator it = observing_.begin();
+ it != observing_.end(); ++it) {
+ const Value* prev = previous.GetValue(*it);
+ const Value* cur = current.GetValue(*it);
+ if (!base::Value::Equals(prev, cur)) {
+ observer_->OnPolicyValueUpdated(
+ domain_, component_id_, *it, prev, cur);
+ }
+ }
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698