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

Unified Diff: chrome/browser/policy/policy_service.h

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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/policy/policy_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/policy/policy_service.h
diff --git a/chrome/browser/policy/policy_service.h b/chrome/browser/policy/policy_service.h
index 5b5f3f33507a61bb6a964191b3c4571bca07e9bd..f414ba0c82caac57c71a0e03bfd2cb1c6d4348c8 100644
--- a/chrome/browser/policy/policy_service.h
+++ b/chrome/browser/policy/policy_service.h
@@ -6,8 +6,11 @@
#define CHROME_BROWSER_POLICY_POLICY_SERVICE_H_
#pragma once
+#include <map>
#include <string>
+#include "base/basictypes.h"
+#include "base/callback.h"
#include "chrome/browser/policy/policy_map.h"
namespace policy {
@@ -75,6 +78,45 @@ class PolicyService {
virtual bool IsInitializationComplete() const = 0;
};
+// A registrar that only observes changes to particular policies within the
+// PolicyMap for the given policy namespace.
+class PolicyChangeRegistrar : public PolicyService::Observer {
+ public:
+ typedef base::Callback<void(const Value*, const Value*)> UpdateCallback;
+
+ // Observes updates to the given (domain, component_id) namespace in the given
+ // |policy_service|, and notifies |observer| whenever any of the registered
+ // policy keys changes. Both the |policy_service| and the |observer| must
+ // outlive |this|.
+ PolicyChangeRegistrar(PolicyService* policy_service,
+ PolicyDomain domain,
+ const std::string component_id);
+
+ virtual ~PolicyChangeRegistrar();
+
+ // Will invoke |callback| whenever |policy_name| changes its value, as long
+ // as this registrar exists.
+ // Only one callback can be registed per policy name; a second call with the
+ // same |policy_name| will overwrite the previous callback.
+ void Observe(const std::string& policy_name, const UpdateCallback& callback);
+
+ // Implementation of PolicyService::Observer:
+ virtual void OnPolicyUpdated(PolicyDomain domain,
+ const std::string& component_id,
+ const PolicyMap& previous,
+ const PolicyMap& current) OVERRIDE;
+
+ private:
+ typedef std::map<std::string, UpdateCallback> CallbackMap;
+
+ PolicyService* policy_service_;
+ PolicyDomain domain_;
+ std::string component_id_;
+ CallbackMap callback_map_;
+
+ DISALLOW_COPY_AND_ASSIGN(PolicyChangeRegistrar);
+};
+
} // namespace policy
#endif // CHROME_BROWSER_POLICY_POLICY_SERVICE_H_
« no previous file with comments | « no previous file | chrome/browser/policy/policy_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698