| Index: chrome/browser/policy/configuration_policy_handler.cc
|
| diff --git a/chrome/browser/policy/configuration_policy_handler.cc b/chrome/browser/policy/configuration_policy_handler.cc
|
| index 5587cae14c2c6582bdbdd08633edf7282a5e7b15..9bbd2b212ca59cd5c597c0eaef4ceeb62b16c0f0 100644
|
| --- a/chrome/browser/policy/configuration_policy_handler.cc
|
| +++ b/chrome/browser/policy/configuration_policy_handler.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "chrome/browser/policy/configuration_policy_handler.h"
|
|
|
| +#include <algorithm>
|
| #include <string>
|
|
|
| #include "base/file_path.h"
|
| @@ -212,6 +213,59 @@ bool TypeCheckingPolicyHandler::CheckAndGetValue(const PolicyMap& policies,
|
| return true;
|
| }
|
|
|
| +// IntRangePolicyHandlerBase implementation ------------------------------------
|
| +
|
| +IntRangePolicyHandlerBase::IntRangePolicyHandlerBase(
|
| + const char* policy_name,
|
| + int min,
|
| + int max,
|
| + bool clamp)
|
| + : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_INTEGER),
|
| + min_(min),
|
| + max_(max),
|
| + clamp_(clamp) {
|
| +}
|
| +
|
| +bool IntRangePolicyHandlerBase::CheckPolicySettings(const PolicyMap& policies,
|
| + PolicyErrorMap* errors) {
|
| + const base::Value* value;
|
| + return CheckAndGetValue(policies, errors, &value) &&
|
| + EnsureInRange(value, NULL, errors);
|
| +}
|
| +
|
| +IntRangePolicyHandlerBase::~IntRangePolicyHandlerBase() {
|
| +}
|
| +
|
| +bool IntRangePolicyHandlerBase::EnsureInRange(const base::Value* input,
|
| + int* output,
|
| + PolicyErrorMap* errors) {
|
| + if (!input)
|
| + return true;
|
| +
|
| + int value;
|
| + if (!input->GetAsInteger(&value)) {
|
| + NOTREACHED();
|
| + return false;
|
| + }
|
| +
|
| + if (value < min_ || value > max_) {
|
| + if (errors) {
|
| + errors->AddError(policy_name(),
|
| + IDS_POLICY_OUT_OF_RANGE_ERROR,
|
| + base::IntToString(value));
|
| + }
|
| +
|
| + if (!clamp_)
|
| + return false;
|
| +
|
| + value = std::min(std::max(value, min_), max_);
|
| + }
|
| +
|
| + if (output)
|
| + *output = value;
|
| + return true;
|
| +}
|
| +
|
| // StringToIntEnumListPolicyHandler implementation -----------------------------
|
|
|
| StringToIntEnumListPolicyHandler::StringToIntEnumListPolicyHandler(
|
| @@ -287,6 +341,56 @@ bool StringToIntEnumListPolicyHandler::Convert(const base::Value* input,
|
| return true;
|
| }
|
|
|
| +// IntRangePolicyHandler implementation ----------------------------------------
|
| +
|
| +IntRangePolicyHandler::IntRangePolicyHandler(const char* policy_name,
|
| + const char* pref_path,
|
| + int min,
|
| + int max,
|
| + bool clamp)
|
| + : IntRangePolicyHandlerBase(policy_name, min, max, clamp),
|
| + pref_path_(pref_path) {
|
| +}
|
| +
|
| +IntRangePolicyHandler::~IntRangePolicyHandler() {
|
| +}
|
| +
|
| +void IntRangePolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
|
| + PrefValueMap* prefs) {
|
| + const base::Value* value = policies.GetValue(policy_name());
|
| + int value_in_range;
|
| + if (value && EnsureInRange(value, &value_in_range, NULL)) {
|
| + prefs->SetValue(pref_path_,
|
| + base::Value::CreateIntegerValue(value_in_range));
|
| + }
|
| +}
|
| +
|
| +// IntPercentageToDoublePolicyHandler implementation ---------------------------
|
| +
|
| +IntPercentageToDoublePolicyHandler::IntPercentageToDoublePolicyHandler(
|
| + const char* policy_name,
|
| + const char* pref_path,
|
| + int min,
|
| + int max,
|
| + bool clamp)
|
| + : IntRangePolicyHandlerBase(policy_name, min, max, clamp),
|
| + pref_path_(pref_path) {
|
| +}
|
| +
|
| +IntPercentageToDoublePolicyHandler::~IntPercentageToDoublePolicyHandler() {
|
| +}
|
| +
|
| +void IntPercentageToDoublePolicyHandler::ApplyPolicySettings(
|
| + const PolicyMap& policies,
|
| + PrefValueMap* prefs) {
|
| + const base::Value* value = policies.GetValue(policy_name());
|
| + int percentage;
|
| + if (value && EnsureInRange(value, &percentage, NULL)) {
|
| + prefs->SetValue(pref_path_, base::Value::CreateDoubleValue(
|
| + static_cast<double>(percentage) / 100.));
|
| + }
|
| +}
|
| +
|
| // ExtensionListPolicyHandler implementation -----------------------------------
|
|
|
| ExtensionListPolicyHandler::ExtensionListPolicyHandler(const char* policy_name,
|
|
|