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_impl.h" | 5 #include "chrome/browser/policy/cloud_policy_provider_impl.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "chrome/browser/policy/browser_policy_connector.h" |
7 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 10 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
8 | 11 |
9 namespace policy { | 12 namespace policy { |
10 | 13 |
11 CloudPolicyProviderImpl::CloudPolicyProviderImpl( | 14 CloudPolicyProviderImpl::CloudPolicyProviderImpl( |
| 15 BrowserPolicyConnector* browser_policy_connector, |
12 const PolicyDefinitionList* policy_list, | 16 const PolicyDefinitionList* policy_list, |
13 CloudPolicyCacheBase::PolicyLevel level) | 17 CloudPolicyCacheBase::PolicyLevel level) |
14 : CloudPolicyProvider(policy_list), | 18 : CloudPolicyProvider(policy_list), |
| 19 browser_policy_connector_(browser_policy_connector), |
15 level_(level), | 20 level_(level), |
16 initialization_complete_(true) {} | 21 initialization_complete_(true) {} |
17 | 22 |
18 CloudPolicyProviderImpl::~CloudPolicyProviderImpl() { | 23 CloudPolicyProviderImpl::~CloudPolicyProviderImpl() { |
19 for (ListType::iterator i = caches_.begin(); i != caches_.end(); ++i) | 24 for (ListType::iterator i = caches_.begin(); i != caches_.end(); ++i) |
20 (*i)->RemoveObserver(this); | 25 (*i)->RemoveObserver(this); |
21 } | 26 } |
22 | 27 |
23 bool CloudPolicyProviderImpl::ProvideInternal(PolicyMap* result) { | 28 bool CloudPolicyProviderImpl::ProvideInternal(PolicyMap* result) { |
24 result->CopyFrom(combined_); | 29 result->CopyFrom(combined_); |
25 return true; | 30 return true; |
26 } | 31 } |
27 | 32 |
28 bool CloudPolicyProviderImpl::IsInitializationComplete() const { | 33 bool CloudPolicyProviderImpl::IsInitializationComplete() const { |
29 return initialization_complete_; | 34 return initialization_complete_; |
30 } | 35 } |
31 | 36 |
| 37 void CloudPolicyProviderImpl::RefreshPolicies() { |
| 38 pending_update_caches_ = caches_; |
| 39 if (pending_update_caches_.empty()) |
| 40 NotifyPolicyUpdated(); |
| 41 else |
| 42 browser_policy_connector_->FetchCloudPolicy(); |
| 43 } |
| 44 |
32 void CloudPolicyProviderImpl::OnCacheUpdate(CloudPolicyCacheBase* cache) { | 45 void CloudPolicyProviderImpl::OnCacheUpdate(CloudPolicyCacheBase* cache) { |
| 46 RemoveCache(cache, &pending_update_caches_); |
33 RecombineCachesAndTriggerUpdate(); | 47 RecombineCachesAndTriggerUpdate(); |
34 } | 48 } |
35 | 49 |
36 void CloudPolicyProviderImpl::OnCacheGoingAway(CloudPolicyCacheBase* cache) { | 50 void CloudPolicyProviderImpl::OnCacheGoingAway(CloudPolicyCacheBase* cache) { |
37 cache->RemoveObserver(this); | 51 cache->RemoveObserver(this); |
38 for (ListType::iterator i = caches_.begin(); i != caches_.end(); ++i) { | 52 RemoveCache(cache, &caches_); |
39 if (*i == cache) { | 53 RemoveCache(cache, &pending_update_caches_); |
40 caches_.erase(i); | |
41 break; | |
42 } | |
43 } | |
44 | |
45 RecombineCachesAndTriggerUpdate(); | 54 RecombineCachesAndTriggerUpdate(); |
46 } | 55 } |
47 | 56 |
48 void CloudPolicyProviderImpl::AppendCache(CloudPolicyCacheBase* cache) { | 57 void CloudPolicyProviderImpl::AppendCache(CloudPolicyCacheBase* cache) { |
49 initialization_complete_ &= cache->IsReady(); | 58 initialization_complete_ &= cache->IsReady(); |
50 cache->AddObserver(this); | 59 cache->AddObserver(this); |
51 caches_.push_back(cache); | 60 caches_.push_back(cache); |
52 RecombineCachesAndTriggerUpdate(); | 61 RecombineCachesAndTriggerUpdate(); |
53 } | 62 } |
54 | 63 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 for (ListType::iterator i = caches_.begin(); i != caches_.end(); ++i) { | 114 for (ListType::iterator i = caches_.begin(); i != caches_.end(); ++i) { |
106 if (!(*i)->IsReady()) | 115 if (!(*i)->IsReady()) |
107 continue; | 116 continue; |
108 PolicyMap tmp_map; | 117 PolicyMap tmp_map; |
109 CombineTwoPolicyMaps(newly_combined, *(*i)->policy(level_), &tmp_map); | 118 CombineTwoPolicyMaps(newly_combined, *(*i)->policy(level_), &tmp_map); |
110 newly_combined.Swap(&tmp_map); | 119 newly_combined.Swap(&tmp_map); |
111 } | 120 } |
112 | 121 |
113 // Trigger a notification. | 122 // Trigger a notification. |
114 combined_.Swap(&newly_combined); | 123 combined_.Swap(&newly_combined); |
115 NotifyPolicyUpdated(); | 124 if (pending_update_caches_.empty()) |
| 125 NotifyPolicyUpdated(); |
| 126 } |
| 127 |
| 128 // static |
| 129 void CloudPolicyProviderImpl::RemoveCache(CloudPolicyCacheBase* cache, |
| 130 ListType* caches) { |
| 131 ListType::iterator it = std::find(caches->begin(), caches->end(), cache); |
| 132 if (it != caches->end()) |
| 133 caches->erase(it); |
116 } | 134 } |
117 | 135 |
118 } // namespace policy | 136 } // namespace policy |
OLD | NEW |