| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "base/memory/scoped_ptr.h" |
| 7 #include "chrome/browser/policy/browser_policy_connector.h" | 8 #include "chrome/browser/policy/browser_policy_connector.h" |
| 9 #include "chrome/browser/policy/policy_bundle.h" |
| 10 #include "chrome/browser/policy/policy_map.h" |
| 8 | 11 |
| 9 namespace policy { | 12 namespace policy { |
| 10 | 13 |
| 11 CloudPolicyProvider::CloudPolicyProvider( | 14 CloudPolicyProvider::CloudPolicyProvider( |
| 12 BrowserPolicyConnector* browser_policy_connector, | 15 BrowserPolicyConnector* browser_policy_connector, |
| 13 const PolicyDefinitionList* policy_list, | 16 const PolicyDefinitionList* policy_list, |
| 14 PolicyLevel level) | 17 PolicyLevel level) |
| 15 : ConfigurationPolicyProvider(policy_list), | 18 : ConfigurationPolicyProvider(policy_list), |
| 16 browser_policy_connector_(browser_policy_connector), | 19 browser_policy_connector_(browser_policy_connector), |
| 17 level_(level), | 20 level_(level), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 36 | 39 |
| 37 #if defined(OS_CHROMEOS) | 40 #if defined(OS_CHROMEOS) |
| 38 void CloudPolicyProvider::SetDevicePolicyCache(CloudPolicyCacheBase* cache) { | 41 void CloudPolicyProvider::SetDevicePolicyCache(CloudPolicyCacheBase* cache) { |
| 39 DCHECK(caches_[CACHE_DEVICE] == NULL); | 42 DCHECK(caches_[CACHE_DEVICE] == NULL); |
| 40 caches_[CACHE_DEVICE] = cache; | 43 caches_[CACHE_DEVICE] = cache; |
| 41 cache->AddObserver(this); | 44 cache->AddObserver(this); |
| 42 Merge(); | 45 Merge(); |
| 43 } | 46 } |
| 44 #endif | 47 #endif |
| 45 | 48 |
| 46 bool CloudPolicyProvider::ProvideInternal(PolicyMap* result) { | |
| 47 result->CopyFrom(combined_); | |
| 48 return true; | |
| 49 } | |
| 50 | |
| 51 bool CloudPolicyProvider::IsInitializationComplete() const { | 49 bool CloudPolicyProvider::IsInitializationComplete() const { |
| 52 return initialization_complete_; | 50 return initialization_complete_; |
| 53 } | 51 } |
| 54 | 52 |
| 55 void CloudPolicyProvider::RefreshPolicies() { | 53 void CloudPolicyProvider::RefreshPolicies() { |
| 56 for (size_t i = 0; i < CACHE_SIZE; ++i) { | 54 for (size_t i = 0; i < CACHE_SIZE; ++i) { |
| 57 if (caches_[i]) | 55 if (caches_[i]) |
| 58 pending_updates_.insert(caches_[i]); | 56 pending_updates_.insert(caches_[i]); |
| 59 } | 57 } |
| 60 if (pending_updates_.empty()) | 58 if (pending_updates_.empty()) |
| 61 NotifyPolicyUpdated(); | 59 Merge(); |
| 62 else | 60 else |
| 63 browser_policy_connector_->FetchCloudPolicy(); | 61 browser_policy_connector_->FetchCloudPolicy(); |
| 64 } | 62 } |
| 65 | 63 |
| 66 void CloudPolicyProvider::OnCacheUpdate(CloudPolicyCacheBase* cache) { | 64 void CloudPolicyProvider::OnCacheUpdate(CloudPolicyCacheBase* cache) { |
| 67 pending_updates_.erase(cache); | 65 pending_updates_.erase(cache); |
| 68 Merge(); | 66 if (pending_updates_.empty()) |
| 67 Merge(); |
| 69 } | 68 } |
| 70 | 69 |
| 71 void CloudPolicyProvider::OnCacheGoingAway(CloudPolicyCacheBase* cache) { | 70 void CloudPolicyProvider::OnCacheGoingAway(CloudPolicyCacheBase* cache) { |
| 72 for (size_t i = 0; i < CACHE_SIZE; ++i) { | 71 for (size_t i = 0; i < CACHE_SIZE; ++i) { |
| 73 if (caches_[i] == cache) { | 72 if (caches_[i] == cache) { |
| 74 caches_[i] = NULL; | 73 caches_[i] = NULL; |
| 75 cache->RemoveObserver(this); | 74 cache->RemoveObserver(this); |
| 76 pending_updates_.erase(cache); | 75 pending_updates_.erase(cache); |
| 77 Merge(); | 76 Merge(); |
| 78 return; | 77 return; |
| 79 } | 78 } |
| 80 } | 79 } |
| 81 NOTREACHED(); | 80 NOTREACHED(); |
| 82 } | 81 } |
| 83 | 82 |
| 84 void CloudPolicyProvider::Merge() { | 83 void CloudPolicyProvider::Merge() { |
| 85 // Re-check whether all caches are ready. | 84 // Re-check whether all caches are ready. |
| 86 if (!initialization_complete_) { | 85 if (!initialization_complete_) { |
| 87 initialization_complete_ = true; | 86 initialization_complete_ = true; |
| 88 for (size_t i = 0; i < CACHE_SIZE; ++i) { | 87 for (size_t i = 0; i < CACHE_SIZE; ++i) { |
| 89 if (caches_[i] == NULL || !caches_[i]->IsReady()) { | 88 if (caches_[i] == NULL || !caches_[i]->IsReady()) { |
| 90 initialization_complete_ = false; | 89 initialization_complete_ = false; |
| 91 break; | 90 break; |
| 92 } | 91 } |
| 93 } | 92 } |
| 94 } | 93 } |
| 95 | 94 |
| 96 combined_.Clear(); | 95 PolicyMap combined; |
| 97 for (size_t i = 0; i < CACHE_SIZE; ++i) { | 96 for (size_t i = 0; i < CACHE_SIZE; ++i) { |
| 98 if (caches_[i] && caches_[i]->IsReady()) | 97 if (caches_[i] && caches_[i]->IsReady()) |
| 99 combined_.MergeFrom(*caches_[i]->policy()); | 98 combined.MergeFrom(*caches_[i]->policy()); |
| 100 } | 99 } |
| 101 FixDeprecatedPolicies(&combined_); | 100 combined.FilterLevel(level_); |
| 102 combined_.FilterLevel(level_); | |
| 103 | 101 |
| 104 // Trigger a notification. | 102 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); |
| 105 if (pending_updates_.empty()) | 103 bundle->Get(POLICY_DOMAIN_CHROME, std::string()).Swap(&combined); |
| 106 NotifyPolicyUpdated(); | 104 UpdatePolicy(bundle.Pass()); |
| 107 } | 105 } |
| 108 | 106 |
| 109 } // namespace policy | 107 } // namespace policy |
| OLD | NEW |