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

Side by Side Diff: chrome/browser/policy/cloud_policy_provider_impl.cc

Issue 8586030: Added ConfigurationPolicyProvider::RefreshPolicies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed win build Created 9 years, 1 month 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 | Annotate | Revision Log
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 #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();
Mattias Nissler (ping if slow) 2011/11/18 11:00:25 I think there's still an issue here. This will not
Joao da Silva 2011/11/18 14:03:30 FetchCloudPolicy() triggers CloudPolicyController:
43 }
44
32 void CloudPolicyProviderImpl::OnCacheUpdate(CloudPolicyCacheBase* cache) { 45 void CloudPolicyProviderImpl::OnCacheUpdate(CloudPolicyCacheBase* cache) {
46 RemoveFromPending(cache);
33 RecombineCachesAndTriggerUpdate(); 47 RecombineCachesAndTriggerUpdate();
34 } 48 }
35 49
36 void CloudPolicyProviderImpl::OnCacheGoingAway(CloudPolicyCacheBase* cache) { 50 void CloudPolicyProviderImpl::OnCacheGoingAway(CloudPolicyCacheBase* cache) {
51 RemoveFromPending(cache);
37 cache->RemoveObserver(this); 52 cache->RemoveObserver(this);
38 for (ListType::iterator i = caches_.begin(); i != caches_.end(); ++i) { 53 for (ListType::iterator i = caches_.begin(); i != caches_.end(); ++i) {
Mattias Nissler (ping if slow) 2011/11/18 11:00:25 can we please use std::find + erase here? :) Also,
Joao da Silva 2011/11/18 14:03:30 Done.
39 if (*i == cache) { 54 if (*i == cache) {
40 caches_.erase(i); 55 caches_.erase(i);
41 break; 56 break;
42 } 57 }
43 } 58 }
44 59
45 RecombineCachesAndTriggerUpdate(); 60 RecombineCachesAndTriggerUpdate();
46 } 61 }
47 62
48 void CloudPolicyProviderImpl::AppendCache(CloudPolicyCacheBase* cache) { 63 void CloudPolicyProviderImpl::AppendCache(CloudPolicyCacheBase* cache) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 for (ListType::iterator i = caches_.begin(); i != caches_.end(); ++i) { 120 for (ListType::iterator i = caches_.begin(); i != caches_.end(); ++i) {
106 if (!(*i)->IsReady()) 121 if (!(*i)->IsReady())
107 continue; 122 continue;
108 PolicyMap tmp_map; 123 PolicyMap tmp_map;
109 CombineTwoPolicyMaps(newly_combined, *(*i)->policy(level_), &tmp_map); 124 CombineTwoPolicyMaps(newly_combined, *(*i)->policy(level_), &tmp_map);
110 newly_combined.Swap(&tmp_map); 125 newly_combined.Swap(&tmp_map);
111 } 126 }
112 127
113 // Trigger a notification. 128 // Trigger a notification.
114 combined_.Swap(&newly_combined); 129 combined_.Swap(&newly_combined);
115 NotifyPolicyUpdated(); 130 if (pending_update_caches_.empty())
131 NotifyPolicyUpdated();
132 }
133
134 void CloudPolicyProviderImpl::RemoveFromPending(CloudPolicyCacheBase* cache) {
135 pending_update_caches_.erase(
136 std::remove(pending_update_caches_.begin(),
137 pending_update_caches_.end(),
138 cache),
139 pending_update_caches_.end());
116 } 140 }
117 141
118 } // namespace policy 142 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698