Chromium Code Reviews| 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 "chrome/browser/policy/configuration_policy_handler.h" | 5 #include "chrome/browser/policy/configuration_policy_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 *value = policies.GetValue(policy_name_); | 205 *value = policies.GetValue(policy_name_); |
| 206 if (*value && !(*value)->IsType(value_type_)) { | 206 if (*value && !(*value)->IsType(value_type_)) { |
| 207 errors->AddError(policy_name_, | 207 errors->AddError(policy_name_, |
| 208 IDS_POLICY_TYPE_ERROR, | 208 IDS_POLICY_TYPE_ERROR, |
| 209 ValueTypeToString(value_type_)); | 209 ValueTypeToString(value_type_)); |
| 210 return false; | 210 return false; |
| 211 } | 211 } |
| 212 return true; | 212 return true; |
| 213 } | 213 } |
| 214 | 214 |
| 215 // IntRangePolicyHandlerBase implementation ------------------------------------ | |
| 216 | |
| 217 IntRangePolicyHandlerBase::IntRangePolicyHandlerBase( | |
| 218 const char* policy_name, | |
| 219 int min, | |
| 220 int max) | |
| 221 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_INTEGER), | |
| 222 min_(min), | |
| 223 max_(max) { | |
| 224 } | |
| 225 | |
| 226 bool IntRangePolicyHandlerBase::CheckPolicySettings(const PolicyMap& policies, | |
| 227 PolicyErrorMap* errors) { | |
| 228 const base::Value* value; | |
| 229 return CheckAndGetValue(policies, errors, &value) && | |
| 230 CheckRange(value, NULL, errors); | |
| 231 } | |
| 232 | |
| 233 IntRangePolicyHandlerBase::~IntRangePolicyHandlerBase() { | |
| 234 } | |
| 235 | |
| 236 bool IntRangePolicyHandlerBase::CheckRange(const base::Value* input, | |
| 237 int* output, | |
| 238 PolicyErrorMap* errors) { | |
| 239 if (!input) | |
| 240 return true; | |
| 241 | |
| 242 int value; | |
| 243 if (!input->GetAsInteger(&value)) { | |
| 244 NOTREACHED(); | |
| 245 return false; | |
| 246 } | |
| 247 | |
| 248 if (value < min_ || value > max_) { | |
| 249 if (errors) { | |
| 250 errors->AddError(policy_name(), | |
| 251 IDS_POLICY_OUT_OF_RANGE_ERROR, | |
| 252 base::IntToString(value)); | |
| 253 } | |
| 254 return false; | |
|
Mattias Nissler (ping if slow)
2013/02/08 12:04:26
Another option could be to just clamp here and con
bartfab (slow)
2013/02/08 14:13:08
Done.
| |
| 255 } | |
| 256 | |
| 257 if (output) | |
| 258 *output = value; | |
| 259 return true; | |
| 260 } | |
| 261 | |
| 215 // StringToIntEnumListPolicyHandler implementation ----------------------------- | 262 // StringToIntEnumListPolicyHandler implementation ----------------------------- |
| 216 | 263 |
| 217 StringToIntEnumListPolicyHandler::StringToIntEnumListPolicyHandler( | 264 StringToIntEnumListPolicyHandler::StringToIntEnumListPolicyHandler( |
| 218 const char* policy_name, | 265 const char* policy_name, |
| 219 const char* pref_path, | 266 const char* pref_path, |
| 220 const MappingEntry* mapping_begin, | 267 const MappingEntry* mapping_begin, |
| 221 const MappingEntry* mapping_end) | 268 const MappingEntry* mapping_end) |
| 222 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), | 269 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), |
| 223 pref_path_(pref_path), | 270 pref_path_(pref_path), |
| 224 mapping_begin_(mapping_begin), | 271 mapping_begin_(mapping_begin), |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 errors->AddError(policy_name(), | 327 errors->AddError(policy_name(), |
| 281 entry - list_value->begin(), | 328 entry - list_value->begin(), |
| 282 IDS_POLICY_OUT_OF_RANGE_ERROR); | 329 IDS_POLICY_OUT_OF_RANGE_ERROR); |
| 283 } | 330 } |
| 284 } | 331 } |
| 285 } | 332 } |
| 286 | 333 |
| 287 return true; | 334 return true; |
| 288 } | 335 } |
| 289 | 336 |
| 337 // IntRangePolicyHandler implementation ---------------------------------------- | |
| 338 | |
| 339 IntRangePolicyHandler::IntRangePolicyHandler(const char* policy_name, | |
| 340 const char* pref_path, | |
| 341 int min, | |
| 342 int max) | |
| 343 : IntRangePolicyHandlerBase(policy_name, min, max), | |
| 344 pref_path_(pref_path) { | |
| 345 } | |
| 346 | |
| 347 void IntRangePolicyHandler::ApplyPolicySettings(const PolicyMap& policies, | |
| 348 PrefValueMap* prefs) { | |
| 349 const base::Value* value = policies.GetValue(policy_name()); | |
| 350 if (value && CheckRange(value, NULL, NULL)) | |
| 351 prefs->SetValue(pref_path_, value->DeepCopy()); | |
| 352 } | |
| 353 | |
| 354 IntRangePolicyHandler::~IntRangePolicyHandler() { | |
| 355 } | |
| 356 | |
| 357 // IntPercentageToDoublePolicyHandler implementation --------------------------- | |
| 358 | |
| 359 IntPercentageToDoublePolicyHandler::IntPercentageToDoublePolicyHandler( | |
| 360 const char* policy_name, | |
| 361 const char* pref_path, | |
| 362 int min, | |
| 363 int max) | |
| 364 : IntRangePolicyHandlerBase(policy_name, min, max), | |
| 365 pref_path_(pref_path) { | |
| 366 } | |
| 367 | |
| 368 void IntPercentageToDoublePolicyHandler::ApplyPolicySettings( | |
| 369 const PolicyMap& policies, | |
| 370 PrefValueMap* prefs) { | |
| 371 const base::Value* value = policies.GetValue(policy_name()); | |
| 372 int percentage; | |
| 373 if (value && CheckRange(value, &percentage, NULL)) { | |
| 374 prefs->SetValue(pref_path_, base::Value::CreateDoubleValue( | |
| 375 static_cast<double>(percentage) / 100.)); | |
| 376 } | |
| 377 } | |
| 378 | |
| 379 IntPercentageToDoublePolicyHandler::~IntPercentageToDoublePolicyHandler() { | |
| 380 } | |
| 381 | |
| 290 // ExtensionListPolicyHandler implementation ----------------------------------- | 382 // ExtensionListPolicyHandler implementation ----------------------------------- |
| 291 | 383 |
| 292 ExtensionListPolicyHandler::ExtensionListPolicyHandler(const char* policy_name, | 384 ExtensionListPolicyHandler::ExtensionListPolicyHandler(const char* policy_name, |
| 293 const char* pref_path, | 385 const char* pref_path, |
| 294 bool allow_wildcards) | 386 bool allow_wildcards) |
| 295 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), | 387 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), |
| 296 pref_path_(pref_path), | 388 pref_path_(pref_path), |
| 297 allow_wildcards_(allow_wildcards) {} | 389 allow_wildcards_(allow_wildcards) {} |
| 298 | 390 |
| 299 ExtensionListPolicyHandler::~ExtensionListPolicyHandler() {} | 391 ExtensionListPolicyHandler::~ExtensionListPolicyHandler() {} |
| (...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1461 errors->AddError(policy_name(), | 1553 errors->AddError(policy_name(), |
| 1462 IDS_POLICY_OUT_OF_RANGE_ERROR, | 1554 IDS_POLICY_OUT_OF_RANGE_ERROR, |
| 1463 base::IntToString(restore_value)); | 1555 base::IntToString(restore_value)); |
| 1464 } | 1556 } |
| 1465 } | 1557 } |
| 1466 } | 1558 } |
| 1467 return true; | 1559 return true; |
| 1468 } | 1560 } |
| 1469 | 1561 |
| 1470 } // namespace policy | 1562 } // namespace policy |
| OLD | NEW |