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

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: Rebased. 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..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,
« 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