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 COMPONENTS_POLICY_CORE_COMMON_POLICY_SERVICE_H_ | 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_POLICY_SERVICE_H_ |
6 #define COMPONENTS_POLICY_CORE_COMMON_POLICY_SERVICE_H_ | 6 #define COMPONENTS_POLICY_CORE_COMMON_POLICY_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 typedef base::Callback<void(const base::Value*, | 81 typedef base::Callback<void(const base::Value*, |
82 const base::Value*)> UpdateCallback; | 82 const base::Value*)> UpdateCallback; |
83 | 83 |
84 // Observes updates to the given (domain, component_id) namespace in the given | 84 // Observes updates to the given (domain, component_id) namespace in the given |
85 // |policy_service|, and notifies |observer| whenever any of the registered | 85 // |policy_service|, and notifies |observer| whenever any of the registered |
86 // policy keys changes. Both the |policy_service| and the |observer| must | 86 // policy keys changes. Both the |policy_service| and the |observer| must |
87 // outlive |this|. | 87 // outlive |this|. |
88 PolicyChangeRegistrar(PolicyService* policy_service, | 88 PolicyChangeRegistrar(PolicyService* policy_service, |
89 const PolicyNamespace& ns); | 89 const PolicyNamespace& ns); |
90 | 90 |
91 virtual ~PolicyChangeRegistrar(); | 91 ~PolicyChangeRegistrar() override; |
92 | 92 |
93 // Will invoke |callback| whenever |policy_name| changes its value, as long | 93 // Will invoke |callback| whenever |policy_name| changes its value, as long |
94 // as this registrar exists. | 94 // as this registrar exists. |
95 // Only one callback can be registed per policy name; a second call with the | 95 // Only one callback can be registed per policy name; a second call with the |
96 // same |policy_name| will overwrite the previous callback. | 96 // same |policy_name| will overwrite the previous callback. |
97 void Observe(const std::string& policy_name, const UpdateCallback& callback); | 97 void Observe(const std::string& policy_name, const UpdateCallback& callback); |
98 | 98 |
99 // Implementation of PolicyService::Observer: | 99 // Implementation of PolicyService::Observer: |
100 virtual void OnPolicyUpdated(const PolicyNamespace& ns, | 100 void OnPolicyUpdated(const PolicyNamespace& ns, |
101 const PolicyMap& previous, | 101 const PolicyMap& previous, |
102 const PolicyMap& current) override; | 102 const PolicyMap& current) override; |
103 | 103 |
104 private: | 104 private: |
105 typedef std::map<std::string, UpdateCallback> CallbackMap; | 105 typedef std::map<std::string, UpdateCallback> CallbackMap; |
106 | 106 |
107 PolicyService* policy_service_; | 107 PolicyService* policy_service_; |
108 PolicyNamespace ns_; | 108 PolicyNamespace ns_; |
109 CallbackMap callback_map_; | 109 CallbackMap callback_map_; |
110 | 110 |
111 DISALLOW_COPY_AND_ASSIGN(PolicyChangeRegistrar); | 111 DISALLOW_COPY_AND_ASSIGN(PolicyChangeRegistrar); |
112 }; | 112 }; |
113 | 113 |
114 } // namespace policy | 114 } // namespace policy |
115 | 115 |
116 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_SERVICE_H_ | 116 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_SERVICE_H_ |
OLD | NEW |