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

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

Issue 9911029: Refactored the CloudPolicyProvider so that it becomes initialized once and stays initialized. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebased 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
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_PROVIDER_H_ 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_H_ 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <set>
10
9 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "chrome/browser/policy/cloud_policy_cache_base.h"
10 #include "chrome/browser/policy/configuration_policy_provider.h" 13 #include "chrome/browser/policy/configuration_policy_provider.h"
14 #include "chrome/browser/policy/policy_map.h"
11 15
12 namespace policy { 16 namespace policy {
13 17
14 class CloudPolicyCacheBase; 18 class BrowserPolicyConnector;
15 19
16 // A policy provider having multiple backend caches, combining their relevant 20 // A policy provider that merges the policies contained in the caches it
17 // PolicyMaps and keeping the result cached. The underlying caches are kept as 21 // observes. The caches receive their policies by fetching them from the cloud,
18 // weak references and can be added dynamically. Also the 22 // through the CloudPolicyController.
19 // |CloudPolicyProvider| instance listens to cache-notifications and removes 23 class CloudPolicyProvider : public ConfigurationPolicyProvider,
20 // the caches automatically when they go away. The order in which the caches are 24 public CloudPolicyCacheBase::Observer {
21 // stored matters! The first cache is applied as is and the following caches
22 // only contribute the not-yet applied policies. There are two functions to add
23 // a new cache:
24 // PrependCache(cache): adds |cache| to the front (i.e. most important cache).
25 // AppendCache(cache): adds |cache| to the back (i.e. least important cache).
26 class CloudPolicyProvider : public ConfigurationPolicyProvider {
27 public: 25 public:
28 explicit CloudPolicyProvider(const PolicyDefinitionList* policy_list); 26 CloudPolicyProvider(BrowserPolicyConnector* browser_policy_connector,
27 const PolicyDefinitionList* policy_list,
28 PolicyLevel level);
29 virtual ~CloudPolicyProvider(); 29 virtual ~CloudPolicyProvider();
30 30
31 // Adds a new instance of CloudPolicyCacheBase to the end of |caches_|. 31 // Sets the user policy cache. This must be invoked only once, and |cache|
32 // Does not take ownership of |cache| and listens to OnCacheGoingAway to 32 // must not be NULL.
33 // automatically remove it from |caches_|. 33 void SetUserPolicyCache(CloudPolicyCacheBase* cache);
34 virtual void AppendCache(CloudPolicyCacheBase* cache) = 0;
35 34
36 // Adds a new instance of CloudPolicyCacheBase to the beginning of |caches_|. 35 #if defined(OS_CHROMEOS)
37 // Does not take ownership of |cache| and listens to OnCacheGoingAway to 36 // Sets the device policy cache. This must be invoked only once, and |cache|
38 // automatically remove it from |caches_|. 37 // must not be NULL.
39 virtual void PrependCache(CloudPolicyCacheBase* cache) = 0; 38 void SetDevicePolicyCache(CloudPolicyCacheBase* cache);
39 #endif
40
41 // ConfigurationPolicyProvider implementation.
42 virtual bool ProvideInternal(PolicyMap* result) OVERRIDE;
43 virtual bool IsInitializationComplete() const OVERRIDE;
44 virtual void RefreshPolicies() OVERRIDE;
45
46 // CloudPolicyCacheBase::Observer implementation.
47 virtual void OnCacheUpdate(CloudPolicyCacheBase* cache) OVERRIDE;
48 virtual void OnCacheGoingAway(CloudPolicyCacheBase* cache) OVERRIDE;
40 49
41 private: 50 private:
51 // Indices of the known caches in |caches_|.
52 enum {
53 CACHE_USER,
54 #if defined(OS_CHROMEOS)
55 CACHE_DEVICE,
56 #endif
57 CACHE_SIZE,
58 };
59
60 // Merges policies from both caches, and triggers a notification if ready.
61 void Merge();
62
63 // The device and user policy caches, whose policies are provided by |this|.
64 // Both are initially NULL, and the provider only becomes initialized once
65 // all the caches are available and ready.
66 CloudPolicyCacheBase* caches_[CACHE_SIZE];
67
68 // Weak pointer to the connector. Guaranteed to outlive |this|.
69 BrowserPolicyConnector* browser_policy_connector_;
70
71 // The policy level published by this provider.
72 PolicyLevel level_;
73
74 // Whether all caches are present and fully initialized.
75 bool initialization_complete_;
76
77 // Used to determine when updates due to a RefreshPolicies() call have been
78 // completed.
79 std::set<const CloudPolicyCacheBase*> pending_updates_;
80
81 // The currently valid combination of the caches. ProvideInternal() fills
82 // |results| with a copy of |combined_|.
83 PolicyMap combined_;
84
42 DISALLOW_COPY_AND_ASSIGN(CloudPolicyProvider); 85 DISALLOW_COPY_AND_ASSIGN(CloudPolicyProvider);
43 }; 86 };
44 87
45 } // namespace policy 88 } // namespace policy
46 89
47 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_H_ 90 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/browser_policy_connector.cc ('k') | chrome/browser/policy/cloud_policy_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698