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

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

Issue 18153007: Add policies to control power management on the Chrome OS login screen (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nit addressed. Created 7 years, 6 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 07120fbe374794069e40a79f1f454a18ab3b7003..cc2fa273d3b329c2e6b7aa18840b259120a3ce10 100644
--- a/chrome/browser/policy/configuration_policy_handler.cc
+++ b/chrome/browser/policy/configuration_policy_handler.cc
@@ -400,6 +400,63 @@ void IntPercentageToDoublePolicyHandler::ApplyPolicySettings(
}
}
+// IntSetPolicyHandler implementation ------------------------------------------
+
+IntSetPolicyHandler::IntSetPolicyHandler(const char* policy_name,
+ const char* pref_path,
+ const int* allowed_set_begin,
+ const int* allowed_set_end)
+ : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_INTEGER),
+ pref_path_(pref_path),
+ allowed_set_begin_(allowed_set_begin),
+ allowed_set_end_(allowed_set_end) {
+}
+
+IntSetPolicyHandler::~IntSetPolicyHandler() {
+}
+
+bool IntSetPolicyHandler::CheckPolicySettings(const PolicyMap& policies,
+ PolicyErrorMap* errors) {
+ const base::Value* value;
+ return CheckAndGetValue(policies, errors, &value) &&
+ EnsureInAllowedSet(value, errors);
+}
+
+void IntSetPolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
+ PrefValueMap* prefs) {
Mattias Nissler (ping if slow) 2013/07/03 16:52:18 nit: indentation
bartfab (slow) 2013/07/03 19:11:04 Done.
+ if (!pref_path_)
+ return;
+ const base::Value* value = policies.GetValue(policy_name());
+ if (value && EnsureInAllowedSet(value, NULL))
+ prefs->SetValue(pref_path_, value->DeepCopy());
+}
+
+bool IntSetPolicyHandler::EnsureInAllowedSet(const base::Value* value,
+ PolicyErrorMap* errors) {
+ if (!value)
+ return true;
+
+ int int_value;
+ if (!value->GetAsInteger(&int_value)) {
+ NOTREACHED();
+ return false;
+ }
+
+ for (const int* entry = allowed_set_begin_; entry != allowed_set_end_;
+ ++entry) {
+ if (*entry == int_value)
+ return true;
+ }
+
+ if (errors) {
+ errors->AddError(policy_name(),
+ IDS_POLICY_OUT_OF_RANGE_ERROR,
+ base::IntToString(int_value));
+ }
+
+ return false;
+}
+
// ExtensionListPolicyHandler implementation -----------------------------------
ExtensionListPolicyHandler::ExtensionListPolicyHandler(const char* policy_name,

Powered by Google App Engine
This is Rietveld 408576698