| 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/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/policy/browser_policy_connector.h" | 15 #include "chrome/browser/policy/browser_policy_connector.h" |
| 16 #include "chrome/browser/policy/configuration_policy_handler.h" |
| 16 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 17 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 18 #include "chrome/browser/policy/policy_error_map.h" |
| 17 #include "chrome/browser/policy/policy_map.h" | 19 #include "chrome/browser/policy/policy_map.h" |
| 18 #include "policy/policy_constants.h" | 20 #include "policy/policy_constants.h" |
| 19 | 21 |
| 20 namespace policy { | 22 namespace policy { |
| 21 | 23 |
| 22 // This class functions as a container for policy status information used by the | 24 // This class functions as a container for policy status information used by the |
| 23 // ConfigurationPolicyReader class. It obtains policy values from a | 25 // ConfigurationPolicyReader class. It obtains policy values from a |
| 24 // ConfigurationPolicyProvider and maps them to their status information. | 26 // ConfigurationPolicyProvider and maps them to their status information. |
| 25 class ConfigurationPolicyStatusKeeper { | 27 class ConfigurationPolicyStatusKeeper { |
| 26 public: | 28 public: |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 65 |
| 64 DictionaryValue* ConfigurationPolicyStatusKeeper::GetPolicyStatus( | 66 DictionaryValue* ConfigurationPolicyStatusKeeper::GetPolicyStatus( |
| 65 ConfigurationPolicyType policy) const { | 67 ConfigurationPolicyType policy) const { |
| 66 PolicyStatusMap::const_iterator entry = policy_map_.find(policy); | 68 PolicyStatusMap::const_iterator entry = policy_map_.find(policy); |
| 67 return entry != policy_map_.end() ? | 69 return entry != policy_map_.end() ? |
| 68 (entry->second)->GetDictionaryValue() : NULL; | 70 (entry->second)->GetDictionaryValue() : NULL; |
| 69 } | 71 } |
| 70 | 72 |
| 71 void ConfigurationPolicyStatusKeeper::GetPoliciesFromProvider( | 73 void ConfigurationPolicyStatusKeeper::GetPoliciesFromProvider( |
| 72 ConfigurationPolicyProvider* provider) { | 74 ConfigurationPolicyProvider* provider) { |
| 73 scoped_ptr<PolicyMap> policies(new PolicyMap()); | 75 PolicyMap policies; |
| 74 if (!provider->Provide(policies.get())) | 76 if (!provider->Provide(&policies)) |
| 75 LOG(WARNING) << "Failed to get policy from provider."; | 77 DLOG(WARNING) << "Failed to get policy from provider."; |
| 76 | 78 |
| 77 PolicyMap::const_iterator policy = policies->begin(); | 79 const ConfigurationPolicyHandler::HandlerList* handlers = |
| 78 for ( ; policy != policies->end(); ++policy) { | 80 g_browser_process->browser_policy_connector()-> |
| 81 GetConfigurationPolicyHandlerList(); |
| 82 |
| 83 PolicyErrorMap errors; |
| 84 ConfigurationPolicyHandler::HandlerList::const_iterator handler; |
| 85 for (handler = handlers->begin(); handler != handlers->end(); ++handler) |
| 86 (*handler)->CheckPolicySettings(&policies, &errors); |
| 87 |
| 88 PolicyMap::const_iterator policy = policies.begin(); |
| 89 for ( ; policy != policies.end(); ++policy) { |
| 79 string16 name = ASCIIToUTF16(GetPolicyName(policy->first)); | 90 string16 name = ASCIIToUTF16(GetPolicyName(policy->first)); |
| 80 | 91 string16 error_message = errors.GetErrors(policy->first); |
| 81 // TODO(simo) actually determine whether the policy is a user or a device | 92 PolicyStatusInfo::PolicyStatus status = |
| 82 // one and whether the policy could be enforced or not once this information | 93 error_message.empty() ? PolicyStatusInfo::ENFORCED |
| 83 // is available. | 94 : PolicyStatusInfo::FAILED; |
| 95 // TODO(joaodasilva): determine whether this is a user or device policy. |
| 96 // http://crbug.com/102114 |
| 84 PolicyStatusInfo* info = new PolicyStatusInfo(name, | 97 PolicyStatusInfo* info = new PolicyStatusInfo(name, |
| 85 PolicyStatusInfo::USER, | 98 PolicyStatusInfo::USER, |
| 86 policy_level_, | 99 policy_level_, |
| 87 policy->second->DeepCopy(), | 100 policy->second->DeepCopy(), |
| 88 PolicyStatusInfo::ENFORCED, | 101 status, |
| 89 string16()); | 102 error_message); |
| 90 policy_map_[policy->first] = info; | 103 policy_map_[policy->first] = info; |
| 91 } | 104 } |
| 92 } | 105 } |
| 93 | 106 |
| 94 // ConfigurationPolicyReader | 107 // ConfigurationPolicyReader |
| 95 ConfigurationPolicyReader::ConfigurationPolicyReader( | 108 ConfigurationPolicyReader::ConfigurationPolicyReader( |
| 96 ConfigurationPolicyProvider* provider, | 109 ConfigurationPolicyProvider* provider, |
| 97 PolicyStatusInfo::PolicyLevel policy_level) | 110 PolicyStatusInfo::PolicyLevel policy_level) |
| 98 : provider_(provider), | 111 : provider_(provider), |
| 99 policy_level_(policy_level) { | 112 policy_level_(policy_level) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 220 |
| 208 void PolicyStatus::RemoveObserver(Observer* observer) const { | 221 void PolicyStatus::RemoveObserver(Observer* observer) const { |
| 209 managed_platform_->RemoveObserver(observer); | 222 managed_platform_->RemoveObserver(observer); |
| 210 managed_cloud_->RemoveObserver(observer); | 223 managed_cloud_->RemoveObserver(observer); |
| 211 recommended_platform_->RemoveObserver(observer); | 224 recommended_platform_->RemoveObserver(observer); |
| 212 recommended_cloud_->RemoveObserver(observer); | 225 recommended_cloud_->RemoveObserver(observer); |
| 213 } | 226 } |
| 214 | 227 |
| 215 ListValue* PolicyStatus::GetPolicyStatusList(bool* any_policies_set) const { | 228 ListValue* PolicyStatus::GetPolicyStatusList(bool* any_policies_set) const { |
| 216 ListValue* result = new ListValue(); | 229 ListValue* result = new ListValue(); |
| 217 std::vector<DictionaryValue*> unsent_policies; | 230 std::vector<DictionaryValue*> unset_policies; |
| 218 | 231 |
| 219 *any_policies_set = false; | 232 *any_policies_set = false; |
| 220 const PolicyDefinitionList* supported_policies = | 233 const PolicyDefinitionList* supported_policies = |
| 221 GetChromePolicyDefinitionList(); | 234 GetChromePolicyDefinitionList(); |
| 222 const PolicyDefinitionList::Entry* policy = supported_policies->begin; | 235 const PolicyDefinitionList::Entry* policy = supported_policies->begin; |
| 223 for ( ; policy != supported_policies->end; ++policy) { | 236 for ( ; policy != supported_policies->end; ++policy) { |
| 224 if (!AddPolicyFromReaders(policy->policy_type, result)) { | 237 if (!AddPolicyFromReaders(policy->policy_type, result)) { |
| 225 PolicyStatusInfo info(ASCIIToUTF16(policy->name), | 238 PolicyStatusInfo info(ASCIIToUTF16(policy->name), |
| 226 PolicyStatusInfo::SOURCE_TYPE_UNDEFINED, | 239 PolicyStatusInfo::SOURCE_TYPE_UNDEFINED, |
| 227 PolicyStatusInfo::LEVEL_UNDEFINED, | 240 PolicyStatusInfo::LEVEL_UNDEFINED, |
| 228 Value::CreateNullValue(), | 241 Value::CreateNullValue(), |
| 229 PolicyStatusInfo::STATUS_UNDEFINED, | 242 PolicyStatusInfo::STATUS_UNDEFINED, |
| 230 string16()); | 243 string16()); |
| 231 unsent_policies.push_back(info.GetDictionaryValue()); | 244 unset_policies.push_back(info.GetDictionaryValue()); |
| 232 } else { | 245 } else { |
| 233 *any_policies_set = true; | 246 *any_policies_set = true; |
| 234 } | 247 } |
| 235 } | 248 } |
| 236 | 249 |
| 237 // Add policies that weren't actually sent from providers to list. | 250 // Add policies that weren't actually sent from providers to list. |
| 238 std::vector<DictionaryValue*>::const_iterator info = unsent_policies.begin(); | 251 std::vector<DictionaryValue*>::const_iterator info = unset_policies.begin(); |
| 239 for ( ; info != unsent_policies.end(); ++info) | 252 for ( ; info != unset_policies.end(); ++info) |
| 240 result->Append(*info); | 253 result->Append(*info); |
| 241 | 254 |
| 242 return result; | 255 return result; |
| 243 } | 256 } |
| 244 | 257 |
| 245 bool PolicyStatus::AddPolicyFromReaders( | 258 bool PolicyStatus::AddPolicyFromReaders( |
| 246 ConfigurationPolicyType policy, ListValue* list) const { | 259 ConfigurationPolicyType policy, ListValue* list) const { |
| 247 DictionaryValue* mp_policy = | 260 DictionaryValue* mp_policy = |
| 248 managed_platform_->GetPolicyStatus(policy); | 261 managed_platform_->GetPolicyStatus(policy); |
| 249 DictionaryValue* mc_policy = | 262 DictionaryValue* mc_policy = |
| (...skipping 11 matching lines...) Expand all Loading... |
| 261 list->Append(mc_policy); | 274 list->Append(mc_policy); |
| 262 if (rp_policy) | 275 if (rp_policy) |
| 263 list->Append(rp_policy); | 276 list->Append(rp_policy); |
| 264 if (rc_policy) | 277 if (rc_policy) |
| 265 list->Append(rc_policy); | 278 list->Append(rc_policy); |
| 266 | 279 |
| 267 return added_policy; | 280 return added_policy; |
| 268 } | 281 } |
| 269 | 282 |
| 270 } // namespace policy | 283 } // namespace policy |
| OLD | NEW |