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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 if (!pref_path_) | 393 if (!pref_path_) |
| 394 return; | 394 return; |
| 395 const base::Value* value = policies.GetValue(policy_name()); | 395 const base::Value* value = policies.GetValue(policy_name()); |
| 396 int percentage; | 396 int percentage; |
| 397 if (value && EnsureInRange(value, &percentage, NULL)) { | 397 if (value && EnsureInRange(value, &percentage, NULL)) { |
| 398 prefs->SetValue(pref_path_, base::Value::CreateDoubleValue( | 398 prefs->SetValue(pref_path_, base::Value::CreateDoubleValue( |
| 399 static_cast<double>(percentage) / 100.)); | 399 static_cast<double>(percentage) / 100.)); |
| 400 } | 400 } |
| 401 } | 401 } |
| 402 | 402 |
| 403 // IntSetPolicyHandler implementation ------------------------------------------ | |
| 404 | |
| 405 IntSetPolicyHandler::IntSetPolicyHandler(const char* policy_name, | |
| 406 const char* pref_path, | |
| 407 const int* allowed_set_begin, | |
| 408 const int* allowed_set_end) | |
| 409 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_INTEGER), | |
| 410 pref_path_(pref_path), | |
| 411 allowed_set_begin_(allowed_set_begin), | |
| 412 allowed_set_end_(allowed_set_end) { | |
| 413 } | |
| 414 | |
| 415 IntSetPolicyHandler::~IntSetPolicyHandler() { | |
| 416 } | |
| 417 | |
| 418 bool IntSetPolicyHandler::CheckPolicySettings(const PolicyMap& policies, | |
| 419 PolicyErrorMap* errors) { | |
| 420 const base::Value* value; | |
| 421 return CheckAndGetValue(policies, errors, &value) && | |
| 422 EnsureInAllowedSet(value, errors); | |
| 423 } | |
| 424 | |
| 425 void IntSetPolicyHandler::ApplyPolicySettings(const PolicyMap& policies, | |
| 426 PrefValueMap* prefs) { | |
|
Mattias Nissler (ping if slow)
2013/07/03 16:52:18
nit: indentation
bartfab (slow)
2013/07/03 19:11:04
Done.
| |
| 427 if (!pref_path_) | |
| 428 return; | |
| 429 const base::Value* value = policies.GetValue(policy_name()); | |
| 430 if (value && EnsureInAllowedSet(value, NULL)) | |
| 431 prefs->SetValue(pref_path_, value->DeepCopy()); | |
| 432 } | |
| 433 | |
| 434 bool IntSetPolicyHandler::EnsureInAllowedSet(const base::Value* value, | |
| 435 PolicyErrorMap* errors) { | |
| 436 if (!value) | |
| 437 return true; | |
| 438 | |
| 439 int int_value; | |
| 440 if (!value->GetAsInteger(&int_value)) { | |
| 441 NOTREACHED(); | |
| 442 return false; | |
| 443 } | |
| 444 | |
| 445 for (const int* entry = allowed_set_begin_; entry != allowed_set_end_; | |
| 446 ++entry) { | |
| 447 if (*entry == int_value) | |
| 448 return true; | |
| 449 } | |
| 450 | |
| 451 if (errors) { | |
| 452 errors->AddError(policy_name(), | |
| 453 IDS_POLICY_OUT_OF_RANGE_ERROR, | |
| 454 base::IntToString(int_value)); | |
| 455 } | |
| 456 | |
| 457 return false; | |
| 458 } | |
| 459 | |
| 403 // ExtensionListPolicyHandler implementation ----------------------------------- | 460 // ExtensionListPolicyHandler implementation ----------------------------------- |
| 404 | 461 |
| 405 ExtensionListPolicyHandler::ExtensionListPolicyHandler(const char* policy_name, | 462 ExtensionListPolicyHandler::ExtensionListPolicyHandler(const char* policy_name, |
| 406 const char* pref_path, | 463 const char* pref_path, |
| 407 bool allow_wildcards) | 464 bool allow_wildcards) |
| 408 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), | 465 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), |
| 409 pref_path_(pref_path), | 466 pref_path_(pref_path), |
| 410 allow_wildcards_(allow_wildcards) {} | 467 allow_wildcards_(allow_wildcards) {} |
| 411 | 468 |
| 412 ExtensionListPolicyHandler::~ExtensionListPolicyHandler() {} | 469 ExtensionListPolicyHandler::~ExtensionListPolicyHandler() {} |
| (...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1585 errors->AddError(policy_name(), | 1642 errors->AddError(policy_name(), |
| 1586 IDS_POLICY_OUT_OF_RANGE_ERROR, | 1643 IDS_POLICY_OUT_OF_RANGE_ERROR, |
| 1587 base::IntToString(restore_value)); | 1644 base::IntToString(restore_value)); |
| 1588 } | 1645 } |
| 1589 } | 1646 } |
| 1590 } | 1647 } |
| 1591 return true; | 1648 return true; |
| 1592 } | 1649 } |
| 1593 | 1650 |
| 1594 } // namespace policy | 1651 } // namespace policy |
| OLD | NEW |