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

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

Issue 6979011: Move user cloud policy to BrowserProcess. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_CLOUD_POLICY_CACHE_BASE_H_ 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_BASE_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_BASE_H_ 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_BASE_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/gtest_prod_util.h" 9 #include "base/gtest_prod_util.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/scoped_vector.h"
11 #include "base/observer_list.h" 12 #include "base/observer_list.h"
12 #include "base/threading/non_thread_safe.h" 13 #include "base/threading/non_thread_safe.h"
13 #include "base/time.h" 14 #include "base/time.h"
14 #include "chrome/browser/policy/cloud_policy_subsystem.h" 15 #include "chrome/browser/policy/cloud_policy_subsystem.h"
15 #include "chrome/browser/policy/configuration_policy_provider.h" 16 #include "chrome/browser/policy/configuration_policy_provider.h"
16 #include "chrome/browser/policy/policy_map.h" 17 #include "chrome/browser/policy/policy_map.h"
17 #include "chrome/browser/policy/proto/device_management_backend.pb.h" 18 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
18 19
19 namespace policy { 20 namespace policy {
20 21
21 class PolicyMap; 22 class PolicyMap;
22 class PolicyNotifier; 23 class PolicyNotifier;
24 class CloudPolicyProvider;
23 25
24 namespace em = enterprise_management; 26 namespace em = enterprise_management;
25 27
26 // Caches policy information, as set by calls to |SetPolicy()|, persists 28 // Caches policy information, as set by calls to |SetPolicy()|, persists
27 // it to disk or session_manager (depending on subclass implementation), 29 // it to disk or session_manager (depending on subclass implementation),
28 // and makes it available via policy providers. 30 // and makes it available via policy providers.
29 class CloudPolicyCacheBase : public base::NonThreadSafe { 31 class CloudPolicyCacheBase : public base::NonThreadSafe {
30 public: 32 public:
31 // Used to distinguish mandatory from recommended policies. 33 // Used to distinguish mandatory from recommended policies.
32 enum PolicyLevel { 34 enum PolicyLevel {
(...skipping 27 matching lines...) Expand all
60 // Returns the time at which the policy was last fetched. 62 // Returns the time at which the policy was last fetched.
61 base::Time last_policy_refresh_time() const { 63 base::Time last_policy_refresh_time() const {
62 return last_policy_refresh_time_; 64 return last_policy_refresh_time_;
63 } 65 }
64 66
65 // Get the version of the encryption key currently used for decoding policy. 67 // Get the version of the encryption key currently used for decoding policy.
66 // Returns true if the version is available, in which case |version| is filled 68 // Returns true if the version is available, in which case |version| is filled
67 // in. 69 // in.
68 bool GetPublicKeyVersion(int* version); 70 bool GetPublicKeyVersion(int* version);
69 71
72 void AddObserver(ConfigurationPolicyProvider::Observer* observer);
Mattias Nissler (ping if slow) 2011/05/26 10:20:20 Reusing that observer interface seems odd, since y
sfeuz 2011/05/31 07:32:31 Created a seperate interface for CloudPolicyCacheB
73 void RemoveObserver(ConfigurationPolicyProvider::Observer* observer);
74
75 PolicyMap* mandatory_policy();
76 PolicyMap* recommended_policy();
77
78 // See comment for |initialization_complete_|.
79 bool initialization_complete() {
80 return initialization_complete_;
81 }
Mattias Nissler (ping if slow) 2011/05/26 10:20:20 newline before new visibility label
sfeuz 2011/05/31 07:32:31 Done.
70 protected: 82 protected:
71 // Wraps public key version and validity. 83 // Wraps public key version and validity.
72 struct PublicKeyVersion { 84 struct PublicKeyVersion {
73 int version; 85 int version;
74 bool valid; 86 bool valid;
75 }; 87 };
76 88
77 // Decodes the given |policy| using |DecodePolicyResponse()|, applies the 89 // Decodes the given |policy| using |DecodePolicyResponse()|, applies the
78 // contents to |{mandatory,recommended}_policy_|, and notifies observers. 90 // contents to |{mandatory,recommended}_policy_|, and notifies observers.
79 // |timestamp| returns the timestamp embedded in |policy|, callers can pass 91 // |timestamp| returns the timestamp embedded in |policy|, callers can pass
(...skipping 16 matching lines...) Expand all
96 // Also performs verification, returns NULL if any check fails. 108 // Also performs verification, returns NULL if any check fails.
97 bool DecodePolicyResponse(const em::PolicyFetchResponse& policy_response, 109 bool DecodePolicyResponse(const em::PolicyFetchResponse& policy_response,
98 PolicyMap* mandatory, 110 PolicyMap* mandatory,
99 PolicyMap* recommended, 111 PolicyMap* recommended,
100 base::Time* timestamp, 112 base::Time* timestamp,
101 PublicKeyVersion* public_key_version); 113 PublicKeyVersion* public_key_version);
102 114
103 void InformNotifier(CloudPolicySubsystem::PolicySubsystemState state, 115 void InformNotifier(CloudPolicySubsystem::PolicySubsystemState state,
104 CloudPolicySubsystem::ErrorDetails error_details); 116 CloudPolicySubsystem::ErrorDetails error_details);
105 117
106 // See comment for |initialization_complete_|.
107 bool initialization_complete() {
108 return initialization_complete_;
109 }
110
111 void set_last_policy_refresh_time(base::Time timestamp) { 118 void set_last_policy_refresh_time(base::Time timestamp) {
112 last_policy_refresh_time_ = timestamp; 119 last_policy_refresh_time_ = timestamp;
113 } 120 }
114 121
115 private: 122 private:
116 class CloudPolicyProvider;
117
118 friend class DevicePolicyCacheTest; 123 friend class DevicePolicyCacheTest;
119 friend class UserPolicyCacheTest; 124 friend class UserPolicyCacheTest;
120 125
121 // Policy key-value information. 126 // Policy key-value information.
122 PolicyMap mandatory_policy_; 127 PolicyMap mandatory_policy_;
123 PolicyMap recommended_policy_; 128 PolicyMap recommended_policy_;
124 129
125 // Policy providers.
126 scoped_ptr<ConfigurationPolicyProvider> managed_policy_provider_;
127 scoped_ptr<ConfigurationPolicyProvider> recommended_policy_provider_;
128
129 PolicyNotifier* notifier_; 130 PolicyNotifier* notifier_;
130 131
131 // The time at which the policy was last refreshed. Is updated both upon 132 // The time at which the policy was last refreshed. Is updated both upon
132 // successful and unsuccessful refresh attempts. 133 // successful and unsuccessful refresh attempts.
133 base::Time last_policy_refresh_time_; 134 base::Time last_policy_refresh_time_;
134 135
135 // Whether initialization has been completed. This is the case when we have 136 // Whether initialization has been completed. This is the case when we have
136 // valid policy, learned that the device is unmanaged or ran into 137 // valid policy, learned that the device is unmanaged or ran into
137 // unrecoverable errors. 138 // unrecoverable errors.
138 bool initialization_complete_; 139 bool initialization_complete_;
139 140
140 // Whether the the server has indicated this device is unmanaged. 141 // Whether the the server has indicated this device is unmanaged.
141 bool is_unmanaged_; 142 bool is_unmanaged_;
142 143
143 // Currently used public key version, if available. 144 // Currently used public key version, if available.
144 PublicKeyVersion public_key_version_; 145 PublicKeyVersion public_key_version_;
145 146
146 // Provider observers that are registered with this cache's providers. 147 // Provider observers that are registered with this provider.
Mattias Nissler (ping if slow) 2011/05/26 10:20:20 CloudPolicyCacheBase is not a provider.
sfeuz 2011/05/31 07:32:31 Done.
147 ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_; 148 ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_;
148 149
149 DISALLOW_COPY_AND_ASSIGN(CloudPolicyCacheBase); 150 DISALLOW_COPY_AND_ASSIGN(CloudPolicyCacheBase);
150 }; 151 };
151 152
153 // A thin wrapper around CloudPolicyCacheBase. Proxies the notifications and
154 // delegates the actions to the underlying |cache_|. Also exposes the PolicyMap
155 // of |cache_|.
156 // The |cache_| is kept as a weak reference and can be exchanged at any point
157 // destroying the CloudPolicyProvider instance.
158 class CloudPolicyProvider : public ConfigurationPolicyProvider,
Mattias Nissler (ping if slow) 2011/05/26 10:20:20 Seems like this should rather go into its own file
sfeuz 2011/05/31 07:32:31 I agree, split the CloudPolicyProvider+CombiningCl
159 public ConfigurationPolicyProvider::Observer {
160 public:
161 CloudPolicyProvider(const PolicyDefinitionList* policy_list,
162 CloudPolicyCacheBase::PolicyLevel level);
163 virtual ~CloudPolicyProvider();
164
165 // ConfigurationPolicyProvider implementation.
166 virtual bool Provide(ConfigurationPolicyStoreInterface* store);
167 virtual bool IsInitializationComplete() const;
168 virtual void AddObserver(ConfigurationPolicyProvider::Observer* observer);
169 virtual void RemoveObserver(ConfigurationPolicyProvider::Observer* observer);
170
171 // ConfigurationPolicyProvier::Observer implementation.
Mattias Nissler (ping if slow) 2011/05/26 10:20:20 Provier -> Provider
sfeuz 2011/05/31 07:32:31 Done.
172 virtual void OnUpdatePolicy();
173 virtual void OnProviderGoingAway();
174
175 // Exposes |policy_map| of the underlying |cache_|.
176 PolicyMap* policy_map();
177
178 // Sets another backend.
179 void set_cache(CloudPolicyCacheBase* cache);
Mattias Nissler (ping if slow) 2011/05/26 10:20:20 newline before visibility label
sfeuz 2011/05/31 07:32:31 Done.
180 private:
181 // The underlying policy cache. Can be NULL if currently none is present.
182 CloudPolicyCacheBase* cache_;
183 // Policy level this provider will handle.
184 CloudPolicyCacheBase::PolicyLevel level_;
185
186 // Provider observers that are registered with this provider.
187 ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_;
188
189 DISALLOW_COPY_AND_ASSIGN(CloudPolicyProvider);
190 };
191
192 // Combines multiple CloudPolicyProviders and applies them in the given order.
193 class CombiningCloudPolicyProvider : public ConfigurationPolicyProvider {
Mattias Nissler (ping if slow) 2011/05/26 10:20:20 It seems like this layering is overkill. Why not j
sfeuz 2011/05/31 07:32:31 Note that CloudPolicyProvider also keeps track of
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 Why would we want to combine recommended and manag
194 public:
195 explicit CombiningCloudPolicyProvider(
196 const PolicyDefinitionList* policy_list);
197 virtual ~CombiningCloudPolicyProvider();
198
199 // ConfigurationPolicyProvier implementation.
200 // Applies policy by applying the policies of the underlying
201 // CloudPolicyProviders in |cloud_policy_providers_| in the
202 // order they appear there. Early elements in |cloud_policy_providers_| take
203 // precedence. Handles special case for Proxy policy by marking all
204 // Proxy-related policies as applied as soon as one of them is applied.
205 // Returns true if we could apply at least one policy.
206 bool Provide(ConfigurationPolicyStoreInterface* store) OVERRIDE;
Mattias Nissler (ping if slow) 2011/05/26 10:20:20 newline before comment
sfeuz 2011/05/31 07:32:31 Done.
207 // Returns true if at least one CloudPolicyProvider in
208 // |cloud_policy_providers_| is initialized.
209 bool IsInitializationComplete() const OVERRIDE;
210 void AddObserver(ConfigurationPolicyProvider::Observer* observer) OVERRIDE;
211 void RemoveObserver(ConfigurationPolicyProvider::Observer* observer) OVERRIDE;
212
213 // Callbacks for CloudPolicyProviderWithObserver.
214 void OnUpdatePolicy(CloudPolicyProvider* cloud_policy_provider);
215 void OnProviderGoingAway(CloudPolicyProvider* cloud_policy_provider);
216
217 // Adds a new CloudPolicyProvider to the end of |cloud_policy_providers_|.
218 // Does not take ownership of |cloud_policy_provider|.
219 void AddCloudPolicyProvider(CloudPolicyProvider* cloud_policy_provider);
Mattias Nissler (ping if slow) 2011/05/26 10:20:20 newline before visibility label
sfeuz 2011/05/31 07:32:31 Done.
220 private:
221 // Wrapper around a CloudPolicyProvider to include the source in the
222 // callbacks. We need that to figure out which element in
223 // |cloud_policy_providers_| to remove if a CloudPolicyProvider calls
224 // OnProviderGoingAway.
225 class CloudPolicyProviderWithObserver :
226 public ConfigurationPolicyProvider::Observer {
227 public:
228 CloudPolicyProviderWithObserver(
229 CombiningCloudPolicyProvider* combining_cloud_policy_provider,
230 CloudPolicyProvider* cloud_policy_provider) :
231 combining_cloud_policy_provider_(combining_cloud_policy_provider),
232 cloud_policy_provider_(cloud_policy_provider) {
233 DCHECK(combining_cloud_policy_provider_ && cloud_policy_provider_);
234 cloud_policy_provider_->AddObserver(this);
235 }
236 ~CloudPolicyProviderWithObserver() {
237 if (cloud_policy_provider_) {
238 cloud_policy_provider_->RemoveObserver(this);
239 cloud_policy_provider_ = NULL;
240 }
241 }
242 virtual void OnUpdatePolicy() {
243 combining_cloud_policy_provider_->OnUpdatePolicy(
244 cloud_policy_provider_);
245 }
246 virtual void OnProviderGoingAway() {
247 combining_cloud_policy_provider_->OnProviderGoingAway(
248 cloud_policy_provider_);
249 // Normally our dtor is called on removal from |cloud_policy_providers_|,
250 // but just in case we are still active remove us as Observer.
251 if (cloud_policy_provider_) {
252 cloud_policy_provider_->RemoveObserver(this);
253 cloud_policy_provider_ = NULL;
254 }
255 }
256 CloudPolicyProvider* cloud_policy_provider() const {
257 return cloud_policy_provider_;
258 }
Mattias Nissler (ping if slow) 2011/05/26 10:20:20 newline
sfeuz 2011/05/31 07:32:31 Done.
259 private:
260 CombiningCloudPolicyProvider* combining_cloud_policy_provider_;
261 CloudPolicyProvider* cloud_policy_provider_;
Mattias Nissler (ping if slow) 2011/05/26 10:20:20 DISALLOW_COPY_AND_ASSIGN
sfeuz 2011/05/31 07:32:31 Done.
262 };
263
264 // CloudPolicyProviders which are combined by this instance of
265 // CombiningCoudPolicyProvider. Order dependant.
266 typedef ScopedVector<CloudPolicyProviderWithObserver> ListType;
267 ListType cloud_policy_providers_;
268
269 // Provider observers that are registered with this provider.
270 ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_;
271
272 DISALLOW_COPY_AND_ASSIGN(CombiningCloudPolicyProvider);
273 };
274
Mattias Nissler (ping if slow) 2011/05/26 10:20:20 excess newline
sfeuz 2011/05/31 07:32:31 Done.
275
152 } // namespace policy 276 } // namespace policy
153 277
154 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_BASE_H_ 278 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698