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

Side by Side Diff: chrome/browser/policy/policy_service_impl.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
« no previous file with comments | « chrome/browser/policy/policy_service.cc ('k') | chrome/browser/policy/policy_service_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_IMPL_H_
6 #define CHROME_BROWSER_POLICY_POLICY_SERVICE_IMPL_H_
7
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
12
13 #include "base/basictypes.h"
14 #include "base/callback.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/observer_list.h"
17 #include "chrome/browser/policy/policy_service.h"
18 #include "components/policy/core/common/configuration_policy_provider.h"
19 #include "components/policy/core/common/policy_bundle.h"
20
21 namespace policy {
22
23 class PolicyMap;
24
25 class PolicyServiceImpl : public PolicyService,
26 public ConfigurationPolicyProvider::Observer {
27 public:
28 typedef std::vector<ConfigurationPolicyProvider*> Providers;
29 typedef base::Callback<void(PolicyBundle*)> PreprocessCallback;
30
31 // The PolicyServiceImpl will merge policies from |providers|. |providers|
32 // must be sorted in decreasing order of priority; the first provider will
33 // have the highest priority. The PolicyServiceImpl does not take ownership of
34 // the providers, and they must outlive the PolicyServiceImpl.
35 // |preprocess_callback| will be applied every PolicyBundle before merginng.
36 PolicyServiceImpl(const Providers& providers,
37 const PreprocessCallback& preprocess_callback);
38
39 virtual ~PolicyServiceImpl();
40
41 // PolicyService overrides:
42 virtual void AddObserver(PolicyDomain domain,
43 PolicyService::Observer* observer) OVERRIDE;
44 virtual void RemoveObserver(PolicyDomain domain,
45 PolicyService::Observer* observer) OVERRIDE;
46 virtual const PolicyMap& GetPolicies(
47 const PolicyNamespace& ns) const OVERRIDE;
48 virtual bool IsInitializationComplete(PolicyDomain domain) const OVERRIDE;
49 virtual void RefreshPolicies(const base::Closure& callback) OVERRIDE;
50
51 private:
52 typedef ObserverList<PolicyService::Observer, true> Observers;
53 typedef std::map<PolicyDomain, Observers*> ObserverMap;
54
55 // ConfigurationPolicyProvider::Observer overrides:
56 virtual void OnUpdatePolicy(ConfigurationPolicyProvider* provider) OVERRIDE;
57
58 // Posts a task to notify observers of |ns| that its policies have changed,
59 // passing along the |previous| and the |current| policies.
60 void NotifyNamespaceUpdated(const PolicyNamespace& ns,
61 const PolicyMap& previous,
62 const PolicyMap& current);
63
64 // Combines the policies from all the providers, and notifies the observers
65 // of namespaces whose policies have been modified.
66 void MergeAndTriggerUpdates();
67
68 // Checks if all providers are initialized, and notifies the observers
69 // if the service just became initialized.
70 void CheckInitializationComplete();
71
72 // Invokes all the refresh callbacks if there are no more refreshes pending.
73 void CheckRefreshComplete();
74
75 // The providers passed in the constructor, in order of decreasing priority.
76 Providers providers_;
77
78 // Maps each policy namespace to its current policies.
79 PolicyBundle policy_bundle_;
80
81 // Maps each policy domain to its observer list.
82 ObserverMap observers_;
83
84 // True if all the providers are initialized for the indexed policy domain.
85 bool initialization_complete_[POLICY_DOMAIN_SIZE];
86
87 // Set of providers that have a pending update that was triggered by a
88 // call to RefreshPolicies().
89 std::set<ConfigurationPolicyProvider*> refresh_pending_;
90
91 // Callback invoked to manipulate a PolicyBundle before it is merged.
92 PreprocessCallback preprocess_callback_;
93
94 // List of callbacks to invoke once all providers refresh after a
95 // RefreshPolicies() call.
96 std::vector<base::Closure> refresh_callbacks_;
97
98 // Used to create tasks to delay new policy updates while we may be already
99 // processing previous policy updates.
100 base::WeakPtrFactory<PolicyServiceImpl> update_task_ptr_factory_;
101
102 DISALLOW_COPY_AND_ASSIGN(PolicyServiceImpl);
103 };
104
105 } // namespace policy
106
107 #endif // CHROME_BROWSER_POLICY_POLICY_SERVICE_IMPL_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_service.cc ('k') | chrome/browser/policy/policy_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698