Chromium Code Reviews| 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..d2e98e9127d0729259d0c9599626e22a77d979b2 100644 |
| --- a/chrome/browser/policy/configuration_policy_handler.cc |
| +++ b/chrome/browser/policy/configuration_policy_handler.cc |
| @@ -212,6 +212,53 @@ bool TypeCheckingPolicyHandler::CheckAndGetValue(const PolicyMap& policies, |
| return true; |
| } |
| +// IntRangePolicyHandlerBase implementation ------------------------------------ |
| + |
| +IntRangePolicyHandlerBase::IntRangePolicyHandlerBase( |
| + const char* policy_name, |
| + int min, |
| + int max) |
| + : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_INTEGER), |
| + min_(min), |
| + max_(max) { |
| +} |
| + |
| +bool IntRangePolicyHandlerBase::CheckPolicySettings(const PolicyMap& policies, |
| + PolicyErrorMap* errors) { |
| + const base::Value* value; |
| + return CheckAndGetValue(policies, errors, &value) && |
| + CheckRange(value, NULL, errors); |
| +} |
| + |
| +IntRangePolicyHandlerBase::~IntRangePolicyHandlerBase() { |
| +} |
| + |
| +bool IntRangePolicyHandlerBase::CheckRange(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)); |
| + } |
| + 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.
|
| + } |
| + |
| + if (output) |
| + *output = value; |
| + return true; |
| +} |
| + |
| // StringToIntEnumListPolicyHandler implementation ----------------------------- |
| StringToIntEnumListPolicyHandler::StringToIntEnumListPolicyHandler( |
| @@ -287,6 +334,51 @@ 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) |
| + : IntRangePolicyHandlerBase(policy_name, min, max), |
| + pref_path_(pref_path) { |
| +} |
| + |
| +void IntRangePolicyHandler::ApplyPolicySettings(const PolicyMap& policies, |
| + PrefValueMap* prefs) { |
| + const base::Value* value = policies.GetValue(policy_name()); |
| + if (value && CheckRange(value, NULL, NULL)) |
| + prefs->SetValue(pref_path_, value->DeepCopy()); |
| +} |
| + |
| +IntRangePolicyHandler::~IntRangePolicyHandler() { |
| +} |
| + |
| +// IntPercentageToDoublePolicyHandler implementation --------------------------- |
| + |
| +IntPercentageToDoublePolicyHandler::IntPercentageToDoublePolicyHandler( |
| + const char* policy_name, |
| + const char* pref_path, |
| + int min, |
| + int max) |
| + : IntRangePolicyHandlerBase(policy_name, min, max), |
| + pref_path_(pref_path) { |
| +} |
| + |
| +void IntPercentageToDoublePolicyHandler::ApplyPolicySettings( |
| + const PolicyMap& policies, |
| + PrefValueMap* prefs) { |
| + const base::Value* value = policies.GetValue(policy_name()); |
| + int percentage; |
| + if (value && CheckRange(value, &percentage, NULL)) { |
| + prefs->SetValue(pref_path_, base::Value::CreateDoubleValue( |
| + static_cast<double>(percentage) / 100.)); |
| + } |
| +} |
| + |
| +IntPercentageToDoublePolicyHandler::~IntPercentageToDoublePolicyHandler() { |
| +} |
| + |
| // ExtensionListPolicyHandler implementation ----------------------------------- |
| ExtensionListPolicyHandler::ExtensionListPolicyHandler(const char* policy_name, |