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 #include "chrome/browser/policy/cloud_policy_provider.h" | 5 #include "chrome/browser/policy/cloud_policy_provider.h" |
| 6 | 6 |
| 7 #include "chrome/browser/policy/browser_policy_connector.h" | |
| 8 | |
| 7 namespace policy { | 9 namespace policy { |
| 8 | 10 |
| 9 CloudPolicyProvider::CloudPolicyProvider( | 11 CloudPolicyProvider::CloudPolicyProvider( |
| 10 const PolicyDefinitionList* policy_list) | 12 BrowserPolicyConnector* browser_policy_connector, |
| 11 : ConfigurationPolicyProvider(policy_list) { | 13 const PolicyDefinitionList* policy_list, |
| 14 PolicyLevel level) | |
| 15 : ConfigurationPolicyProvider(policy_list), | |
| 16 browser_policy_connector_(browser_policy_connector), | |
| 17 level_(level), | |
| 18 initialization_complete_(false) { | |
| 19 for (size_t i = 0; i < CACHE_SIZE; ++i) | |
| 20 caches_[i] = NULL; | |
| 12 } | 21 } |
| 13 | 22 |
| 14 CloudPolicyProvider::~CloudPolicyProvider() { | 23 CloudPolicyProvider::~CloudPolicyProvider() { |
| 24 for (size_t i = 0; i < CACHE_SIZE; ++i) { | |
| 25 if (caches_[i]) | |
| 26 caches_[i]->RemoveObserver(this); | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 void CloudPolicyProvider::SetUserPolicyCache(CloudPolicyCacheBase* cache) { | |
|
Mattias Nissler (ping if slow)
2012/03/30 08:48:46
Any chance somebody might call SetUserPolicyCache(
Joao da Silva
2012/03/30 10:09:23
That'd be incorrect, and crash on AddObserver(). I
| |
| 31 DCHECK(caches_[CACHE_USER] == NULL); | |
| 32 caches_[CACHE_USER] = cache; | |
| 33 cache->AddObserver(this); | |
| 34 Merge(); | |
| 35 } | |
| 36 | |
| 37 #if defined(OS_CHROMEOS) | |
| 38 void CloudPolicyProvider::SetDevicePolicyCache(CloudPolicyCacheBase* cache) { | |
|
Mattias Nissler (ping if slow)
2012/03/30 08:48:46
same here
Joao da Silva
2012/03/30 10:09:23
Same here.
| |
| 39 DCHECK(caches_[CACHE_DEVICE] == NULL); | |
| 40 caches_[CACHE_DEVICE] = cache; | |
| 41 cache->AddObserver(this); | |
| 42 Merge(); | |
| 43 } | |
| 44 #endif | |
| 45 | |
| 46 bool CloudPolicyProvider::ProvideInternal(PolicyMap* result) { | |
| 47 result->CopyFrom(combined_); | |
| 48 return true; | |
| 49 } | |
| 50 | |
| 51 bool CloudPolicyProvider::IsInitializationComplete() const { | |
| 52 return initialization_complete_; | |
| 53 } | |
| 54 | |
| 55 void CloudPolicyProvider::RefreshPolicies() { | |
| 56 for (size_t i = 0; i < CACHE_SIZE; ++i) { | |
| 57 if (caches_[i]) | |
| 58 pending_updates_.insert(caches_[i]); | |
| 59 } | |
| 60 if (pending_updates_.empty()) | |
| 61 NotifyPolicyUpdated(); | |
| 62 else | |
| 63 browser_policy_connector_->FetchCloudPolicy(); | |
| 64 } | |
| 65 | |
| 66 void CloudPolicyProvider::OnCacheUpdate(CloudPolicyCacheBase* cache) { | |
| 67 pending_updates_.erase(cache); | |
| 68 Merge(); | |
| 69 } | |
| 70 | |
| 71 void CloudPolicyProvider::OnCacheGoingAway(CloudPolicyCacheBase* cache) { | |
| 72 for (size_t i = 0; i < CACHE_SIZE; ++i) { | |
| 73 if (caches_[i] == cache) { | |
| 74 caches_[i] = NULL; | |
| 75 cache->RemoveObserver(this); | |
| 76 pending_updates_.erase(cache); | |
| 77 Merge(); | |
| 78 return; | |
| 79 } | |
| 80 } | |
| 81 NOTREACHED(); | |
| 82 } | |
| 83 | |
| 84 void CloudPolicyProvider::Merge() { | |
| 85 // Re-check whether all caches are ready. | |
| 86 if (!initialization_complete_) { | |
| 87 initialization_complete_ = true; | |
| 88 for (size_t i = 0; i < CACHE_SIZE; ++i) { | |
| 89 if (caches_[i] == NULL || !caches_[i]->IsReady()) { | |
| 90 initialization_complete_ = false; | |
| 91 break; | |
| 92 } | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 combined_.Clear(); | |
| 97 for (size_t i = 0; i < CACHE_SIZE; ++i) { | |
| 98 if (caches_[i] && caches_[i]->IsReady()) | |
| 99 combined_.MergeFrom(*caches_[i]->policy()); | |
| 100 } | |
| 101 FixDeprecatedPolicies(&combined_); | |
| 102 combined_.FilterLevel(level_); | |
| 103 | |
| 104 // Trigger a notification. | |
| 105 if (pending_updates_.empty()) | |
| 106 NotifyPolicyUpdated(); | |
| 15 } | 107 } |
| 16 | 108 |
| 17 } // namespace policy | 109 } // namespace policy |
| OLD | NEW |