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

Side by Side 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: Use a base::Callback instead of a one-method-observer 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <map>
9 #include <string> 10 #include <string>
10 11
12 #include "base/basictypes.h"
13 #include "base/callback.h"
11 #include "chrome/browser/policy/policy_map.h" 14 #include "chrome/browser/policy/policy_map.h"
12 15
13 namespace policy { 16 namespace policy {
14 17
15 // Policies are namespaced by a (PolicyDomain, ID) pair. The meaning of the ID 18 // 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 19 // string depends on the domain; for example, if the PolicyDomain is
17 // "extensions" then the ID identifies the extension that the policies control. 20 // "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 21 // Currently CHROME is the only domain available, and its ID is always the empty
19 // string. 22 // string.
20 enum PolicyDomain { 23 enum PolicyDomain {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // PolicyService even if IsInitializationComplete() is false; there will be an 71 // PolicyService even if IsInitializationComplete() is false; there will be an
69 // OnPolicyUpdated() notification once new policies become available. 72 // OnPolicyUpdated() notification once new policies become available.
70 // 73 //
71 // OnPolicyServiceInitialized() is called when IsInitializationComplete() 74 // OnPolicyServiceInitialized() is called when IsInitializationComplete()
72 // becomes true, which happens at most once. If IsInitializationComplete() is 75 // becomes true, which happens at most once. If IsInitializationComplete() is
73 // already true when an Observer is registered, then that Observer will not 76 // already true when an Observer is registered, then that Observer will not
74 // have a OnPolicyServiceInitialized() notification. 77 // have a OnPolicyServiceInitialized() notification.
75 virtual bool IsInitializationComplete() const = 0; 78 virtual bool IsInitializationComplete() const = 0;
76 }; 79 };
77 80
81 // A registrar that only observes changes to particular policies within the
82 // PolicyMap for the given policy namespace.
83 class PolicyChangeRegistrar : public PolicyService::Observer {
84 public:
85 typedef base::Callback<void(const Value*, const Value*)> UpdateCallback;
86
87 // Observes updates to the given (domain, component_id) namespace in the given
88 // |policy_service|, and notifies |observer| whenever any of the registered
89 // policy keys changes. Both the |policy_service| and the |observer| must
90 // outlive |this|.
91 PolicyChangeRegistrar(PolicyService* policy_service,
92 PolicyDomain domain,
93 const std::string component_id);
94
95 virtual ~PolicyChangeRegistrar();
96
97 // Will invoke |callback| whenever |policy_name| changes its value, as long
98 // as this registrar exists.
99 // Only one callback can be registed per policy name; a second call with the
100 // same |policy_name| will overwrite the previous callback.
101 void Observe(const std::string& policy_name, const UpdateCallback& callback);
102
103 // Implementation of PolicyService::Observer:
104 virtual void OnPolicyUpdated(PolicyDomain domain,
105 const std::string& component_id,
106 const PolicyMap& previous,
107 const PolicyMap& current) OVERRIDE;
108
109 private:
110 typedef std::map<std::string, UpdateCallback> CallbackMap;
111
112 PolicyService* policy_service_;
113 PolicyDomain domain_;
114 std::string component_id_;
115 CallbackMap callback_map_;
116
117 DISALLOW_COPY_AND_ASSIGN(PolicyChangeRegistrar);
118 };
119
78 } // namespace policy 120 } // namespace policy
79 121
80 #endif // CHROME_BROWSER_POLICY_POLICY_SERVICE_H_ 122 #endif // CHROME_BROWSER_POLICY_POLICY_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/policy/policy_service.cc » ('j') | chrome/browser/policy/policy_service_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698