| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/policy/core/browser/configuration_policy_handler.h" | 5 #include "components/policy/core/browser/configuration_policy_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | |
| 9 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/prefs/pref_value_map.h" | 15 #include "base/prefs/pref_value_map.h" |
| 16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "components/policy/core/browser/policy_error_map.h" | 19 #include "components/policy/core/browser/policy_error_map.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 144 |
| 145 if (output) | 145 if (output) |
| 146 *output = value; | 146 *output = value; |
| 147 return true; | 147 return true; |
| 148 } | 148 } |
| 149 | 149 |
| 150 | 150 |
| 151 // StringMappingListPolicyHandler implementation ----------------------------- | 151 // StringMappingListPolicyHandler implementation ----------------------------- |
| 152 | 152 |
| 153 StringMappingListPolicyHandler::MappingEntry::MappingEntry( | 153 StringMappingListPolicyHandler::MappingEntry::MappingEntry( |
| 154 const char* policy_value, scoped_ptr<base::Value> map) | 154 const char* policy_value, |
| 155 : enum_value(policy_value), mapped_value(map.Pass()) {} | 155 scoped_ptr<base::Value> map) |
| 156 : enum_value(policy_value), mapped_value(std::move(map)) {} |
| 156 | 157 |
| 157 StringMappingListPolicyHandler::MappingEntry::~MappingEntry() {} | 158 StringMappingListPolicyHandler::MappingEntry::~MappingEntry() {} |
| 158 | 159 |
| 159 StringMappingListPolicyHandler::StringMappingListPolicyHandler( | 160 StringMappingListPolicyHandler::StringMappingListPolicyHandler( |
| 160 const char* policy_name, | 161 const char* policy_name, |
| 161 const char* pref_path, | 162 const char* pref_path, |
| 162 const GenerateMapCallback& callback) | 163 const GenerateMapCallback& callback) |
| 163 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), | 164 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), |
| 164 pref_path_(pref_path), | 165 pref_path_(pref_path), |
| 165 map_getter_(callback) {} | 166 map_getter_(callback) {} |
| 166 | 167 |
| 167 StringMappingListPolicyHandler::~StringMappingListPolicyHandler() {} | 168 StringMappingListPolicyHandler::~StringMappingListPolicyHandler() {} |
| 168 | 169 |
| 169 bool StringMappingListPolicyHandler::CheckPolicySettings( | 170 bool StringMappingListPolicyHandler::CheckPolicySettings( |
| 170 const PolicyMap& policies, | 171 const PolicyMap& policies, |
| 171 PolicyErrorMap* errors) { | 172 PolicyErrorMap* errors) { |
| 172 const base::Value* value; | 173 const base::Value* value; |
| 173 return CheckAndGetValue(policies, errors, &value) && | 174 return CheckAndGetValue(policies, errors, &value) && |
| 174 Convert(value, NULL, errors); | 175 Convert(value, NULL, errors); |
| 175 } | 176 } |
| 176 | 177 |
| 177 void StringMappingListPolicyHandler::ApplyPolicySettings( | 178 void StringMappingListPolicyHandler::ApplyPolicySettings( |
| 178 const PolicyMap& policies, | 179 const PolicyMap& policies, |
| 179 PrefValueMap* prefs) { | 180 PrefValueMap* prefs) { |
| 180 if (!pref_path_) | 181 if (!pref_path_) |
| 181 return; | 182 return; |
| 182 const base::Value* value = policies.GetValue(policy_name()); | 183 const base::Value* value = policies.GetValue(policy_name()); |
| 183 scoped_ptr<base::ListValue> list(new base::ListValue()); | 184 scoped_ptr<base::ListValue> list(new base::ListValue()); |
| 184 if (value && Convert(value, list.get(), NULL)) | 185 if (value && Convert(value, list.get(), NULL)) |
| 185 prefs->SetValue(pref_path_, list.Pass()); | 186 prefs->SetValue(pref_path_, std::move(list)); |
| 186 } | 187 } |
| 187 | 188 |
| 188 bool StringMappingListPolicyHandler::Convert(const base::Value* input, | 189 bool StringMappingListPolicyHandler::Convert(const base::Value* input, |
| 189 base::ListValue* output, | 190 base::ListValue* output, |
| 190 PolicyErrorMap* errors) { | 191 PolicyErrorMap* errors) { |
| 191 if (!input) | 192 if (!input) |
| 192 return true; | 193 return true; |
| 193 | 194 |
| 194 const base::ListValue* list_value = NULL; | 195 const base::ListValue* list_value = NULL; |
| 195 if (!input->GetAsList(&list_value)) { | 196 if (!input->GetAsList(&list_value)) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 | 235 |
| 235 scoped_ptr<base::Value> return_value; | 236 scoped_ptr<base::Value> return_value; |
| 236 for (ScopedVector<MappingEntry>::const_iterator it = map_.begin(); | 237 for (ScopedVector<MappingEntry>::const_iterator it = map_.begin(); |
| 237 it != map_.end(); ++it) { | 238 it != map_.end(); ++it) { |
| 238 const MappingEntry* mapping_entry = *it; | 239 const MappingEntry* mapping_entry = *it; |
| 239 if (mapping_entry->enum_value == entry_value) { | 240 if (mapping_entry->enum_value == entry_value) { |
| 240 return_value = make_scoped_ptr(mapping_entry->mapped_value->DeepCopy()); | 241 return_value = make_scoped_ptr(mapping_entry->mapped_value->DeepCopy()); |
| 241 break; | 242 break; |
| 242 } | 243 } |
| 243 } | 244 } |
| 244 return return_value.Pass(); | 245 return return_value; |
| 245 } | 246 } |
| 246 | 247 |
| 247 // IntRangePolicyHandler implementation ---------------------------------------- | 248 // IntRangePolicyHandler implementation ---------------------------------------- |
| 248 | 249 |
| 249 IntRangePolicyHandler::IntRangePolicyHandler(const char* policy_name, | 250 IntRangePolicyHandler::IntRangePolicyHandler(const char* policy_name, |
| 250 const char* pref_path, | 251 const char* pref_path, |
| 251 int min, | 252 int min, |
| 252 int max, | 253 int max, |
| 253 bool clamp) | 254 bool clamp) |
| 254 : IntRangePolicyHandlerBase(policy_name, min, max, clamp), | 255 : IntRangePolicyHandlerBase(policy_name, min, max, clamp), |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 | 430 |
| 430 // LegacyPoliciesDeprecatingPolicyHandler implementation ----------------------- | 431 // LegacyPoliciesDeprecatingPolicyHandler implementation ----------------------- |
| 431 | 432 |
| 432 // TODO(binjin): Add a new common base class for SchemaValidatingPolicyHandler | 433 // TODO(binjin): Add a new common base class for SchemaValidatingPolicyHandler |
| 433 // and TypeCheckingPolicyHandler representing policy handlers for a single | 434 // and TypeCheckingPolicyHandler representing policy handlers for a single |
| 434 // policy, and use it as the type of |new_policy_handler|. | 435 // policy, and use it as the type of |new_policy_handler|. |
| 435 // http://crbug.com/345299 | 436 // http://crbug.com/345299 |
| 436 LegacyPoliciesDeprecatingPolicyHandler::LegacyPoliciesDeprecatingPolicyHandler( | 437 LegacyPoliciesDeprecatingPolicyHandler::LegacyPoliciesDeprecatingPolicyHandler( |
| 437 ScopedVector<ConfigurationPolicyHandler> legacy_policy_handlers, | 438 ScopedVector<ConfigurationPolicyHandler> legacy_policy_handlers, |
| 438 scoped_ptr<SchemaValidatingPolicyHandler> new_policy_handler) | 439 scoped_ptr<SchemaValidatingPolicyHandler> new_policy_handler) |
| 439 : legacy_policy_handlers_(legacy_policy_handlers.Pass()), | 440 : legacy_policy_handlers_(std::move(legacy_policy_handlers)), |
| 440 new_policy_handler_(new_policy_handler.Pass()) { | 441 new_policy_handler_(std::move(new_policy_handler)) {} |
| 441 } | |
| 442 | 442 |
| 443 LegacyPoliciesDeprecatingPolicyHandler:: | 443 LegacyPoliciesDeprecatingPolicyHandler:: |
| 444 ~LegacyPoliciesDeprecatingPolicyHandler() { | 444 ~LegacyPoliciesDeprecatingPolicyHandler() { |
| 445 } | 445 } |
| 446 | 446 |
| 447 bool LegacyPoliciesDeprecatingPolicyHandler::CheckPolicySettings( | 447 bool LegacyPoliciesDeprecatingPolicyHandler::CheckPolicySettings( |
| 448 const PolicyMap& policies, | 448 const PolicyMap& policies, |
| 449 PolicyErrorMap* errors) { | 449 PolicyErrorMap* errors) { |
| 450 if (policies.Get(new_policy_handler_->policy_name())) { | 450 if (policies.Get(new_policy_handler_->policy_name())) { |
| 451 return new_policy_handler_->CheckPolicySettings(policies, errors); | 451 return new_policy_handler_->CheckPolicySettings(policies, errors); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 } | 484 } |
| 485 } | 485 } |
| 486 } | 486 } |
| 487 void LegacyPoliciesDeprecatingPolicyHandler::ApplyPolicySettings( | 487 void LegacyPoliciesDeprecatingPolicyHandler::ApplyPolicySettings( |
| 488 const policy::PolicyMap& /* policies */, | 488 const policy::PolicyMap& /* policies */, |
| 489 PrefValueMap* /* prefs */) { | 489 PrefValueMap* /* prefs */) { |
| 490 NOTREACHED(); | 490 NOTREACHED(); |
| 491 } | 491 } |
| 492 | 492 |
| 493 } // namespace policy | 493 } // namespace policy |
| OLD | NEW |