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..db76668d4ed198b9e86636b61efda772313ca867 100644 |
--- a/chrome/browser/policy/policy_service.h |
+++ b/chrome/browser/policy/policy_service.h |
@@ -6,8 +6,10 @@ |
#define CHROME_BROWSER_POLICY_POLICY_SERVICE_H_ |
#pragma once |
+#include <set> |
#include <string> |
+#include "base/basictypes.h" |
#include "chrome/browser/policy/policy_map.h" |
namespace policy { |
@@ -75,6 +77,59 @@ 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: |
+ class Observer { |
+ public: |
+ virtual ~Observer() {} |
+ |
+ // Invoked whenever the given |policy_name| changes within the |
+ // (domain, component_id) namespace. Both the previous and the current |
+ // values are provided; either can be NULL. |
+ virtual void OnPolicyValueUpdated(PolicyDomain domain, |
+ const std::string& component_id, |
+ const std::string& policy_name, |
+ const Value* previous_value, |
+ const Value* current_value) = 0; |
+ }; |
+ |
+ // 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, |
+ Observer* observer); |
+ |
+ ~PolicyChangeRegistrar(); |
+ |
+ // Adds |policy_name| to the set of policies to observe. |
+ void Add(const std::string& policy_name); |
+ |
+ // Removes |policy_name| from the set of policies to observe. The destructor |
+ // unregisters |this| as an observer of the |policy_service_|, and it's not |
+ // necessary to Remove() the policies that were added before deleting |this|. |
+ void Remove(const std::string& policy_name); |
+ |
+ // Implementation of PolicyService::Observer: |
+ virtual void OnPolicyUpdated(PolicyDomain domain, |
+ const std::string& component_id, |
+ const PolicyMap& previous, |
+ const PolicyMap& current) OVERRIDE; |
+ |
+ private: |
+ PolicyService* policy_service_; |
+ PolicyDomain domain_; |
+ std::string component_id_; |
+ Observer* observer_; |
Mattias Nissler (ping if slow)
2012/04/23 15:42:50
How about making this a base::Callback?
Joao da Silva
2012/04/23 16:52:28
Done. I've mapped a callback per policy name, so t
|
+ std::set<std::string> observing_; |
Mattias Nissler (ping if slow)
2012/04/23 15:42:50
Could use a better name, observed_policies_ for ex
|
+ |
+ DISALLOW_COPY_AND_ASSIGN(PolicyChangeRegistrar); |
+}; |
+ |
} // namespace policy |
#endif // CHROME_BROWSER_POLICY_POLICY_SERVICE_H_ |