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

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

Issue 6979011: Move user cloud policy to BrowserProcess. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments by mnissler. Created 9 years, 6 months 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/policy/cloud_policy_provider.h"
6
7 #include <set>
8
9 #include "base/values.h"
10 #include "chrome/browser/policy/configuration_policy_pref_store.h"
11 #include "chrome/browser/policy/policy_notifier.h"
12
13 namespace policy {
14
15 CloudPolicyProvider::CloudPolicyProvider(
16 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list,
17 CloudPolicyCacheBase::PolicyLevel level)
18 : ConfigurationPolicyProvider(policy_list),
19 level_(level) {}
20
21 CloudPolicyProvider::~CloudPolicyProvider() {
22 for (ListType::iterator i = caches_.begin(); i != caches_.end(); ++i)
23 (*i)->RemoveObserver(this);
24
25 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
26 observer_list_, OnProviderGoingAway());
27 }
28
29 bool CloudPolicyProvider::Provide(ConfigurationPolicyStoreInterface* store) {
30 ApplyPolicyMap(&combined_, store);
31 return true;
32 }
33
34 bool CloudPolicyProvider::IsInitializationComplete() const {
35 for (ListType::const_iterator i = caches_.begin(); i != caches_.end(); ++i) {
36 if ((*i)->initialization_complete()) {
37 return true;
38 }
39 }
40 return false;
41 }
42
43 void CloudPolicyProvider::AddObserver(
44 ConfigurationPolicyProvider::Observer* observer) {
45 observer_list_.AddObserver(observer);
46 }
47
48 void CloudPolicyProvider::RemoveObserver(
49 ConfigurationPolicyProvider::Observer* observer) {
50 observer_list_.RemoveObserver(observer);
51 }
52
53 void CloudPolicyProvider::OnCacheUpdate(CloudPolicyCacheBase* cache) {
54 RecombineCachesAndMaybeTriggerUpdate();
55 }
56
57 void CloudPolicyProvider::OnCacheGoingAway(CloudPolicyCacheBase* cache) {
58 cache->RemoveObserver(this);
59 for (ListType::iterator i = caches_.begin(); i != caches_.end(); ++i) {
60 if (*i == cache) {
61 caches_.erase(i);
62 break;
63 }
64 }
65
66 RecombineCachesAndMaybeTriggerUpdate();
67 }
68
69 void CloudPolicyProvider::AppendCache(CloudPolicyCacheBase* cache) {
70 cache->AddObserver(this);
71 caches_.push_back(cache);
72 RecombineCachesAndMaybeTriggerUpdate();
73 }
74
75 void CloudPolicyProvider::PrependCache(CloudPolicyCacheBase* cache) {
76 cache->AddObserver(this);
77 caches_.insert(caches_.begin(), cache);
78 RecombineCachesAndMaybeTriggerUpdate();
79 }
80
81 // static
82 ConfigurationPolicyType CloudPolicyProvider::proxy_policies[] = {
83 kPolicyProxyMode,
84 kPolicyProxyServerMode,
85 kPolicyProxyServer,
86 kPolicyProxyPacUrl,
87 kPolicyProxyBypassList };
88
89 // static
90 bool CloudPolicyProvider::is_proxy_policy(ConfigurationPolicyType policy) {
91 const unsigned int n = arraysize(proxy_policies);
92 for (unsigned int i = 0; i < n; ++i)
93 if (proxy_policies[i] == policy)
94 return true;
95 return false;
96 }
97
98 // static
99 unsigned int CloudPolicyProvider::proxy_policy_count() {
100 return arraysize(CloudPolicyProvider::proxy_policies);
101 }
102
103 void CloudPolicyProvider::CombineTwoPolicyMaps(const PolicyMap& base,
104 const PolicyMap& overlay,
105 PolicyMap* out_map) {
106 bool added_proxy_policy = false;
107 out_map->Clear();
108
109 for (PolicyMap::const_iterator i = base.begin(); i != base.end(); ++i) {
110 out_map->Set(i->first, i->second->DeepCopy());
111 added_proxy_policy = added_proxy_policy || is_proxy_policy(i->first);
112 }
113
114 // Add every entry of |overlay| which has not been added by |base|. Only add
115 // proxy policies if none of them was added by |base|.
116 for (PolicyMap::const_iterator i = overlay.begin(); i != overlay.end(); ++i) {
117 if (is_proxy_policy(i->first)) {
118 if (!added_proxy_policy) {
119 out_map->Set(i->first, i->second->DeepCopy());
120 }
121 } else if (!out_map->Get(i->first)) {
122 out_map->Set(i->first, i->second->DeepCopy());
123 }
124 }
125 }
126
127 void CloudPolicyProvider::RecombineCachesAndMaybeTriggerUpdate() {
128 PolicyMap newly_combined;
129 for (ListType::iterator i = caches_.begin(); i != caches_.end(); ++i) {
130 if (!(*i)->initialization_complete())
131 continue;
132 PolicyMap tmp_map;
133 CombineTwoPolicyMaps(newly_combined, *(*i)->policy(level_), &tmp_map);
134 newly_combined.Swap(&tmp_map);
135 }
136 if (newly_combined.Equals(combined_))
137 return;
138
139 // Trigger a notification if there was a change.
140 combined_.Swap(&newly_combined);
141 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
142 observer_list_, OnUpdatePolicy());
143 }
144
145 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_provider.h ('k') | chrome/browser/policy/cloud_policy_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698