Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(405)

Unified Diff: chrome/browser/policy/configuration_policy_handler.cc

Issue 12217068: Add policies to control Chrome OS power management (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix copy&paste mistake. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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,
« no previous file with comments | « chrome/browser/policy/configuration_policy_handler.h ('k') | chrome/browser/policy/configuration_policy_handler_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698