Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 namespace { | |
|
Mattias Nissler (ping if slow)
2011/06/09 14:36:26
please move this to the top.
sfeuz
2011/06/13 06:53:53
Done.
| |
| 30 | |
| 31 bool is_proxy_policy(ConfigurationPolicyType policy) { | |
| 32 return policy == kPolicyProxyMode || | |
| 33 policy == kPolicyProxyServerMode || | |
| 34 policy == kPolicyProxyServer || | |
| 35 policy == kPolicyProxyPacUrl || | |
| 36 policy == kPolicyProxyBypassList; | |
| 37 } | |
| 38 | |
| 39 } // namespace | |
| 40 | |
| 41 void CloudPolicyProvider::CombineTwoPolicyMaps(const PolicyMap& base, | |
|
Mattias Nissler (ping if slow)
2011/06/09 14:36:26
You should order the function definitions accordin
sfeuz
2011/06/13 06:53:53
Done.
| |
| 42 const PolicyMap& overlay, | |
| 43 PolicyMap* out_map) { | |
| 44 bool added_proxy_policy = false; | |
| 45 out_map->Clear(); | |
| 46 | |
| 47 for (PolicyMap::const_iterator i = base.begin(); i != base.end(); ++i) { | |
| 48 out_map->Set(i->first, i->second->DeepCopy()); | |
| 49 added_proxy_policy = added_proxy_policy || (is_proxy_policy(i->first)); | |
|
Mattias Nissler (ping if slow)
2011/06/09 14:36:26
parentheses around is_proxy_policy are not require
sfeuz
2011/06/13 06:53:53
Done.
| |
| 50 } | |
| 51 | |
| 52 // Add every entry of |overlay| which has not been added by |base|. Only add | |
| 53 // proxy policies if none of them was added by |base|. | |
| 54 for (PolicyMap::const_iterator i = overlay.begin(); i != overlay.end(); ++i) { | |
| 55 if (is_proxy_policy(i->first)) { | |
| 56 if (!added_proxy_policy) { | |
| 57 out_map->Set(i->first, i->second->DeepCopy()); | |
| 58 } | |
| 59 } else if (!out_map->Get(i->first)) { | |
| 60 out_map->Set(i->first, i->second->DeepCopy()); | |
| 61 } | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 void CloudPolicyProvider::RecombineCachesAndMaybeTriggerUpdate() { | |
| 66 PolicyMap newly_combined; | |
| 67 for (ListType::iterator i = caches_.begin(); i != caches_.end(); ++i) { | |
| 68 if (!(*i)->initialization_complete()) | |
| 69 continue; | |
| 70 PolicyMap tmp_map; | |
| 71 CombineTwoPolicyMaps(newly_combined, *(*i)->policy(level_), &tmp_map); | |
| 72 newly_combined.Swap(&tmp_map); | |
| 73 } | |
| 74 if (newly_combined.Equals(combined)) | |
| 75 return; | |
| 76 | |
| 77 // Trigger a notification if there was a change. | |
| 78 combined.Swap(&newly_combined); | |
| 79 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, | |
| 80 observer_list_, OnUpdatePolicy()); | |
| 81 } | |
| 82 | |
| 83 bool CloudPolicyProvider::Provide(ConfigurationPolicyStoreInterface* store) { | |
| 84 ApplyPolicyMap(&combined, store); | |
| 85 return true; | |
| 86 } | |
| 87 | |
| 88 bool CloudPolicyProvider::IsInitializationComplete() const { | |
| 89 return true; | |
|
Mattias Nissler (ping if slow)
2011/06/09 14:36:26
This seems wrong. I think the old code only return
sfeuz
2011/06/13 06:53:53
Done.
| |
| 90 } | |
| 91 | |
| 92 void CloudPolicyProvider::AppendCache(CloudPolicyCacheBase* cache) { | |
| 93 cache->AddObserver(this); | |
| 94 caches_.push_back(cache); | |
| 95 RecombineCachesAndMaybeTriggerUpdate(); | |
| 96 } | |
| 97 | |
| 98 void CloudPolicyProvider::PrependCache(CloudPolicyCacheBase* cache) { | |
| 99 cache->AddObserver(this); | |
| 100 caches_.insert(caches_.begin(), cache); | |
| 101 RecombineCachesAndMaybeTriggerUpdate(); | |
| 102 } | |
| 103 | |
| 104 void CloudPolicyProvider::AddObserver( | |
| 105 ConfigurationPolicyProvider::Observer* observer) { | |
| 106 observer_list_.AddObserver(observer); | |
| 107 } | |
| 108 void CloudPolicyProvider::RemoveObserver( | |
| 109 ConfigurationPolicyProvider::Observer* observer) { | |
| 110 observer_list_.RemoveObserver(observer); | |
| 111 } | |
| 112 | |
| 113 void CloudPolicyProvider::OnCacheUpdate(CloudPolicyCacheBase* cache) { | |
| 114 RecombineCachesAndMaybeTriggerUpdate(); | |
| 115 } | |
| 116 | |
| 117 void CloudPolicyProvider::OnCacheGoingAway(CloudPolicyCacheBase* cache) { | |
| 118 cache->RemoveObserver(this); | |
| 119 for (ListType::iterator i = caches_.begin(); i != caches_.end(); ++i) { | |
| 120 if (*i == cache) { | |
| 121 caches_.erase(i); | |
| 122 break; | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 RecombineCachesAndMaybeTriggerUpdate(); | |
| 127 } | |
| 128 | |
| 129 } // namespace policy | |
| OLD | NEW |