| 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/configuration_policy_reader.h" | 5 #include "chrome/browser/policy/configuration_policy_reader.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 113 } |
| 114 | 114 |
| 115 void ConfigurationPolicyReader::OnUpdatePolicy() { | 115 void ConfigurationPolicyReader::OnUpdatePolicy() { |
| 116 Refresh(); | 116 Refresh(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void ConfigurationPolicyReader::OnProviderGoingAway() { | 119 void ConfigurationPolicyReader::OnProviderGoingAway() { |
| 120 provider_ = NULL; | 120 provider_ = NULL; |
| 121 } | 121 } |
| 122 | 122 |
| 123 void ConfigurationPolicyReader::AddObserver(Observer* observer) { |
| 124 observers_.AddObserver(observer); |
| 125 } |
| 126 |
| 127 void ConfigurationPolicyReader::RemoveObserver(Observer* observer) { |
| 128 observers_.RemoveObserver(observer); |
| 129 } |
| 130 |
| 123 // static | 131 // static |
| 124 ConfigurationPolicyReader* | 132 ConfigurationPolicyReader* |
| 125 ConfigurationPolicyReader::CreateManagedPlatformPolicyReader() { | 133 ConfigurationPolicyReader::CreateManagedPlatformPolicyReader() { |
| 126 BrowserPolicyConnector* connector = | 134 BrowserPolicyConnector* connector = |
| 127 g_browser_process->browser_policy_connector(); | 135 g_browser_process->browser_policy_connector(); |
| 128 return new ConfigurationPolicyReader( | 136 return new ConfigurationPolicyReader( |
| 129 connector->GetManagedPlatformProvider(), PolicyStatusInfo::MANDATORY); | 137 connector->GetManagedPlatformProvider(), PolicyStatusInfo::MANDATORY); |
| 130 } | 138 } |
| 131 | 139 |
| 132 // static | 140 // static |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 } | 177 } |
| 170 | 178 |
| 171 void ConfigurationPolicyReader::Refresh() { | 179 void ConfigurationPolicyReader::Refresh() { |
| 172 if (!provider_) | 180 if (!provider_) |
| 173 return; | 181 return; |
| 174 | 182 |
| 175 // Read policy state into a new keeper and swap out old keeper. | 183 // Read policy state into a new keeper and swap out old keeper. |
| 176 scoped_ptr<ConfigurationPolicyStatusKeeper> new_keeper( | 184 scoped_ptr<ConfigurationPolicyStatusKeeper> new_keeper( |
| 177 new ConfigurationPolicyStatusKeeper(provider_, policy_level_)); | 185 new ConfigurationPolicyStatusKeeper(provider_, policy_level_)); |
| 178 policy_keeper_.reset(new_keeper.release()); | 186 policy_keeper_.reset(new_keeper.release()); |
| 187 |
| 188 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyValuesChanged()); |
| 179 } | 189 } |
| 180 | 190 |
| 181 // PolicyStatus | 191 // PolicyStatus |
| 182 PolicyStatus::PolicyStatus(ConfigurationPolicyReader* managed_platform, | 192 PolicyStatus::PolicyStatus(ConfigurationPolicyReader* managed_platform, |
| 183 ConfigurationPolicyReader* managed_cloud, | 193 ConfigurationPolicyReader* managed_cloud, |
| 184 ConfigurationPolicyReader* recommended_platform, | 194 ConfigurationPolicyReader* recommended_platform, |
| 185 ConfigurationPolicyReader* recommended_cloud) | 195 ConfigurationPolicyReader* recommended_cloud) |
| 186 : managed_platform_(managed_platform), | 196 : managed_platform_(managed_platform), |
| 187 managed_cloud_(managed_cloud), | 197 managed_cloud_(managed_cloud), |
| 188 recommended_platform_(recommended_platform), | 198 recommended_platform_(recommended_platform), |
| 189 recommended_cloud_(recommended_cloud) { | 199 recommended_cloud_(recommended_cloud) { |
| 190 } | 200 } |
| 191 | 201 |
| 192 PolicyStatus::~PolicyStatus() { | 202 PolicyStatus::~PolicyStatus() { |
| 193 } | 203 } |
| 194 | 204 |
| 195 ListValue* PolicyStatus::GetPolicyStatusList(bool* any_policies_sent) const { | 205 void PolicyStatus::AddObserver(Observer* observer) const { |
| 206 managed_platform_->AddObserver(observer); |
| 207 managed_cloud_->AddObserver(observer); |
| 208 recommended_platform_->AddObserver(observer); |
| 209 recommended_cloud_->AddObserver(observer); |
| 210 } |
| 211 |
| 212 void PolicyStatus::RemoveObserver(Observer* observer) const { |
| 213 managed_platform_->RemoveObserver(observer); |
| 214 managed_cloud_->RemoveObserver(observer); |
| 215 recommended_platform_->RemoveObserver(observer); |
| 216 recommended_cloud_->RemoveObserver(observer); |
| 217 } |
| 218 |
| 219 ListValue* PolicyStatus::GetPolicyStatusList(bool* any_policies_set) const { |
| 196 ListValue* result = new ListValue(); | 220 ListValue* result = new ListValue(); |
| 197 std::vector<DictionaryValue*> unsent_policies; | 221 std::vector<DictionaryValue*> unsent_policies; |
| 198 | 222 |
| 199 *any_policies_sent = false; | 223 *any_policies_set = false; |
| 200 const PolicyDefinitionList* supported_policies = | 224 const PolicyDefinitionList* supported_policies = |
| 201 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); | 225 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); |
| 202 const PolicyDefinitionList::Entry* policy = supported_policies->begin; | 226 const PolicyDefinitionList::Entry* policy = supported_policies->begin; |
| 203 for ( ; policy != supported_policies->end; ++policy) { | 227 for ( ; policy != supported_policies->end; ++policy) { |
| 204 if (!AddPolicyFromReaders(policy->policy_type, result)) { | 228 if (!AddPolicyFromReaders(policy->policy_type, result)) { |
| 205 PolicyStatusInfo info(ASCIIToUTF16(policy->name), | 229 PolicyStatusInfo info(ASCIIToUTF16(policy->name), |
| 206 PolicyStatusInfo::SOURCE_TYPE_UNDEFINED, | 230 PolicyStatusInfo::SOURCE_TYPE_UNDEFINED, |
| 207 PolicyStatusInfo::LEVEL_UNDEFINED, | 231 PolicyStatusInfo::LEVEL_UNDEFINED, |
| 208 Value::CreateNullValue(), | 232 Value::CreateNullValue(), |
| 209 PolicyStatusInfo::STATUS_UNDEFINED, | 233 PolicyStatusInfo::STATUS_UNDEFINED, |
| 210 string16()); | 234 string16()); |
| 211 unsent_policies.push_back(info.GetDictionaryValue()); | 235 unsent_policies.push_back(info.GetDictionaryValue()); |
| 212 } else { | 236 } else { |
| 213 *any_policies_sent = true; | 237 *any_policies_set = true; |
| 214 } | 238 } |
| 215 } | 239 } |
| 216 | 240 |
| 217 // Add policies that weren't actually sent from providers to list. | 241 // Add policies that weren't actually sent from providers to list. |
| 218 std::vector<DictionaryValue*>::const_iterator info = unsent_policies.begin(); | 242 std::vector<DictionaryValue*>::const_iterator info = unsent_policies.begin(); |
| 219 for ( ; info != unsent_policies.end(); ++info) | 243 for ( ; info != unsent_policies.end(); ++info) |
| 220 result->Append(*info); | 244 result->Append(*info); |
| 221 | 245 |
| 222 return result; | 246 return result; |
| 223 } | 247 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 list->Append(mc_policy); | 291 list->Append(mc_policy); |
| 268 if (rp_policy) | 292 if (rp_policy) |
| 269 list->Append(rp_policy); | 293 list->Append(rp_policy); |
| 270 if (rc_policy) | 294 if (rc_policy) |
| 271 list->Append(rc_policy); | 295 list->Append(rc_policy); |
| 272 | 296 |
| 273 return added_policy; | 297 return added_policy; |
| 274 } | 298 } |
| 275 | 299 |
| 276 } // namespace policy | 300 } // namespace policy |
| OLD | NEW |