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

Side by Side Diff: chrome/browser/policy/policy_service.h

Issue 109743002: Move policy code into components/policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moar fixes Created 7 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_POLICY_POLICY_SERVICE_H_
6 #define CHROME_BROWSER_POLICY_POLICY_SERVICE_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "components/policy/core/common/policy_map.h"
14 #include "components/policy/core/common/policy_namespace.h"
15
16 namespace policy {
17
18 // The PolicyService merges policies from all available sources, taking into
19 // account their priorities. Policy clients can retrieve policy for their domain
20 // and register for notifications on policy updates.
21 //
22 // The PolicyService is available from BrowserProcess as a global singleton.
23 // There is also a PolicyService for browser-wide policies available from
24 // BrowserProcess as a global singleton.
25 class PolicyService {
26 public:
27 class Observer {
28 public:
29 // Invoked whenever policies for the given |ns| namespace are modified.
30 // This is only invoked for changes that happen after AddObserver is called.
31 // |previous| contains the values of the policies before the update,
32 // and |current| contains the current values.
33 virtual void OnPolicyUpdated(const PolicyNamespace& ns,
34 const PolicyMap& previous,
35 const PolicyMap& current) = 0;
36
37 // Invoked at most once for each |domain|, when the PolicyService becomes
38 // ready. If IsInitializationComplete() is false, then this will be invoked
39 // once all the policy providers have finished loading their policies for
40 // |domain|.
41 virtual void OnPolicyServiceInitialized(PolicyDomain domain) {}
42
43 protected:
44 virtual ~Observer() {}
45 };
46
47 virtual ~PolicyService() {}
48
49 // Observes changes to all components of the given |domain|.
50 virtual void AddObserver(PolicyDomain domain, Observer* observer) = 0;
51
52 virtual void RemoveObserver(PolicyDomain domain, Observer* observer) = 0;
53
54 virtual const PolicyMap& GetPolicies(const PolicyNamespace& ns) const = 0;
55
56 // The PolicyService loads policy from several sources, and some require
57 // asynchronous loads. IsInitializationComplete() returns true once all
58 // sources have loaded their policies for the given |domain|.
59 // It is safe to read policy from the PolicyService even if
60 // IsInitializationComplete() is false; there will be an OnPolicyUpdated()
61 // notification once new policies become available.
62 //
63 // OnPolicyServiceInitialized() is called when IsInitializationComplete()
64 // becomes true, which happens at most once for each domain.
65 // If IsInitializationComplete() is already true for |domain| when an Observer
66 // is registered, then that Observer will not receive an
67 // OnPolicyServiceInitialized() notification.
68 virtual bool IsInitializationComplete(PolicyDomain domain) const = 0;
69
70 // Asks the PolicyService to reload policy from all available policy sources.
71 // |callback| is invoked once every source has reloaded its policies, and
72 // GetPolicies() is guaranteed to return the updated values at that point.
73 virtual void RefreshPolicies(const base::Closure& callback) = 0;
74 };
75
76 // A registrar that only observes changes to particular policies within the
77 // PolicyMap for the given policy namespace.
78 class PolicyChangeRegistrar : public PolicyService::Observer {
79 public:
80 typedef base::Callback<void(const Value*, const Value*)> UpdateCallback;
81
82 // Observes updates to the given (domain, component_id) namespace in the given
83 // |policy_service|, and notifies |observer| whenever any of the registered
84 // policy keys changes. Both the |policy_service| and the |observer| must
85 // outlive |this|.
86 PolicyChangeRegistrar(PolicyService* policy_service,
87 const PolicyNamespace& ns);
88
89 virtual ~PolicyChangeRegistrar();
90
91 // Will invoke |callback| whenever |policy_name| changes its value, as long
92 // as this registrar exists.
93 // Only one callback can be registed per policy name; a second call with the
94 // same |policy_name| will overwrite the previous callback.
95 void Observe(const std::string& policy_name, const UpdateCallback& callback);
96
97 // Implementation of PolicyService::Observer:
98 virtual void OnPolicyUpdated(const PolicyNamespace& ns,
99 const PolicyMap& previous,
100 const PolicyMap& current) OVERRIDE;
101
102 private:
103 typedef std::map<std::string, UpdateCallback> CallbackMap;
104
105 PolicyService* policy_service_;
106 PolicyNamespace ns_;
107 CallbackMap callback_map_;
108
109 DISALLOW_COPY_AND_ASSIGN(PolicyChangeRegistrar);
110 };
111
112 } // namespace policy
113
114 #endif // CHROME_BROWSER_POLICY_POLICY_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_loader_win_unittest.cc ('k') | chrome/browser/policy/policy_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698