OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_POLICY_POLICY_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_POLICY_POLICY_SERVICE_H_ |
6 #define CHROME_BROWSER_POLICY_POLICY_SERVICE_H_ | 6 #define CHROME_BROWSER_POLICY_POLICY_SERVICE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | |
9 #include <string> | 10 #include <string> |
10 | 11 |
12 #include "base/basictypes.h" | |
11 #include "chrome/browser/policy/policy_map.h" | 13 #include "chrome/browser/policy/policy_map.h" |
12 | 14 |
13 namespace policy { | 15 namespace policy { |
14 | 16 |
15 // Policies are namespaced by a (PolicyDomain, ID) pair. The meaning of the ID | 17 // Policies are namespaced by a (PolicyDomain, ID) pair. The meaning of the ID |
16 // string depends on the domain; for example, if the PolicyDomain is | 18 // string depends on the domain; for example, if the PolicyDomain is |
17 // "extensions" then the ID identifies the extension that the policies control. | 19 // "extensions" then the ID identifies the extension that the policies control. |
18 // Currently CHROME is the only domain available, and its ID is always the empty | 20 // Currently CHROME is the only domain available, and its ID is always the empty |
19 // string. | 21 // string. |
20 enum PolicyDomain { | 22 enum PolicyDomain { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 // PolicyService even if IsInitializationComplete() is false; there will be an | 70 // PolicyService even if IsInitializationComplete() is false; there will be an |
69 // OnPolicyUpdated() notification once new policies become available. | 71 // OnPolicyUpdated() notification once new policies become available. |
70 // | 72 // |
71 // OnPolicyServiceInitialized() is called when IsInitializationComplete() | 73 // OnPolicyServiceInitialized() is called when IsInitializationComplete() |
72 // becomes true, which happens at most once. If IsInitializationComplete() is | 74 // becomes true, which happens at most once. If IsInitializationComplete() is |
73 // already true when an Observer is registered, then that Observer will not | 75 // already true when an Observer is registered, then that Observer will not |
74 // have a OnPolicyServiceInitialized() notification. | 76 // have a OnPolicyServiceInitialized() notification. |
75 virtual bool IsInitializationComplete() const = 0; | 77 virtual bool IsInitializationComplete() const = 0; |
76 }; | 78 }; |
77 | 79 |
80 // A registrar that only observes changes to particular policies within the | |
81 // PolicyMap for the given policy namespace. | |
82 class PolicyChangeRegistrar : public PolicyService::Observer { | |
83 public: | |
84 class Observer { | |
85 public: | |
86 virtual ~Observer() {} | |
87 | |
88 // Invoked whenever the given |policy_name| changes within the | |
89 // (domain, component_id) namespace. Both the previous and the current | |
90 // values are provided; either can be NULL. | |
91 virtual void OnPolicyValueUpdated(PolicyDomain domain, | |
92 const std::string& component_id, | |
93 const std::string& policy_name, | |
94 const Value* previous_value, | |
95 const Value* current_value) = 0; | |
96 }; | |
97 | |
98 // Observes updates to the given (domain, component_id) namespace in the given | |
99 // |policy_service|, and notifies |observer| whenever any of the registered | |
100 // policy keys changes. Both the |policy_service| and the |observer| must | |
101 // outlive |this|. | |
102 PolicyChangeRegistrar(PolicyService* policy_service, | |
103 PolicyDomain domain, | |
104 const std::string component_id, | |
105 Observer* observer); | |
106 | |
107 ~PolicyChangeRegistrar(); | |
108 | |
109 // Adds |policy_name| to the set of policies to observe. | |
110 void Add(const std::string& policy_name); | |
111 | |
112 // Removes |policy_name| from the set of policies to observe. The destructor | |
113 // unregisters |this| as an observer of the |policy_service_|, and it's not | |
114 // necessary to Remove() the policies that were added before deleting |this|. | |
115 void Remove(const std::string& policy_name); | |
116 | |
117 // Implementation of PolicyService::Observer: | |
118 virtual void OnPolicyUpdated(PolicyDomain domain, | |
119 const std::string& component_id, | |
120 const PolicyMap& previous, | |
121 const PolicyMap& current) OVERRIDE; | |
122 | |
123 private: | |
124 PolicyService* policy_service_; | |
125 PolicyDomain domain_; | |
126 std::string component_id_; | |
127 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
| |
128 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
| |
129 | |
130 DISALLOW_COPY_AND_ASSIGN(PolicyChangeRegistrar); | |
131 }; | |
132 | |
78 } // namespace policy | 133 } // namespace policy |
79 | 134 |
80 #endif // CHROME_BROWSER_POLICY_POLICY_SERVICE_H_ | 135 #endif // CHROME_BROWSER_POLICY_POLICY_SERVICE_H_ |
OLD | NEW |