Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 its policy caches. |
|
Mattias Nissler (ping if slow)
2012/03/30 08:48:46
This sentence suggests that every policy provide h
Joao da Silva
2012/03/30 10:09:23
Done.
| |
| 17 // PolicyMaps and keeping the result cached. The underlying caches are kept as | 21 // The caches receive their policies by fetching them from the cloud, through |
| 18 // weak references and can be added dynamically. Also the | 22 // 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 void SetUserPolicyCache(CloudPolicyCacheBase* cache); |
| 32 // Does not take ownership of |cache| and listens to OnCacheGoingAway to | |
| 33 // automatically remove it from |caches_|. | |
| 34 virtual void AppendCache(CloudPolicyCacheBase* cache) = 0; | |
| 35 | 32 |
| 36 // Adds a new instance of CloudPolicyCacheBase to the beginning of |caches_|. | 33 #if defined(OS_CHROMEOS) |
| 37 // Does not take ownership of |cache| and listens to OnCacheGoingAway to | 34 void SetDevicePolicyCache(CloudPolicyCacheBase* cache); |
| 38 // automatically remove it from |caches_|. | 35 #endif |
| 39 virtual void PrependCache(CloudPolicyCacheBase* cache) = 0; | 36 |
| 37 // ConfigurationPolicyProvider implementation. | |
| 38 virtual bool ProvideInternal(PolicyMap* result) OVERRIDE; | |
| 39 virtual bool IsInitializationComplete() const OVERRIDE; | |
| 40 virtual void RefreshPolicies() OVERRIDE; | |
| 41 | |
| 42 // CloudPolicyCacheBase::Observer implementation. | |
| 43 virtual void OnCacheUpdate(CloudPolicyCacheBase* cache) OVERRIDE; | |
| 44 virtual void OnCacheGoingAway(CloudPolicyCacheBase* cache) OVERRIDE; | |
| 40 | 45 |
| 41 private: | 46 private: |
| 47 // Indices of the known caches in |caches_|. | |
| 48 enum { | |
| 49 CACHE_USER, | |
| 50 #if defined(OS_CHROMEOS) | |
| 51 CACHE_DEVICE, | |
| 52 #endif | |
| 53 CACHE_SIZE, | |
| 54 }; | |
| 55 | |
| 56 // Merges policies from both caches, and triggers a notification if ready. | |
| 57 void Merge(); | |
| 58 | |
| 59 // The device and user policy caches, whose policies are provided by |this|. | |
| 60 // Both are initially NULL, and the provider only becomes initialized once | |
| 61 // all the caches are available and ready. | |
| 62 CloudPolicyCacheBase* caches_[CACHE_SIZE]; | |
| 63 | |
| 64 // Weak pointer to the connector. Guaranteed to outlive |this|. | |
| 65 BrowserPolicyConnector* browser_policy_connector_; | |
| 66 | |
| 67 // The policy level published by this provider. | |
| 68 PolicyLevel level_; | |
| 69 | |
| 70 // Whether all caches are present and fully initialized. | |
| 71 bool initialization_complete_; | |
| 72 | |
| 73 // Used to determine when updates due to a RefreshPolicies() call have been | |
| 74 // completed. | |
| 75 std::set<const CloudPolicyCacheBase*> pending_updates_; | |
| 76 | |
| 77 // The currently valid combination of the caches. ProvideInternal() fills | |
| 78 // |results| with a copy of |combined_|. | |
| 79 PolicyMap combined_; | |
| 80 | |
| 42 DISALLOW_COPY_AND_ASSIGN(CloudPolicyProvider); | 81 DISALLOW_COPY_AND_ASSIGN(CloudPolicyProvider); |
| 43 }; | 82 }; |
| 44 | 83 |
| 45 } // namespace policy | 84 } // namespace policy |
| 46 | 85 |
| 47 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_H_ | 86 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_H_ |
| OLD | NEW |