1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/policy/battery_saver_policy_handler.h"
#include "base/numerics/safe_conversions.h"
#include "build/build_config.h"
#include "components/performance_manager/public/user_tuning/prefs.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/policy_constants.h"
#include "components/prefs/pref_value_map.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "ash/constants/ash_pref_names.h"
#endif // BUILDFLAG(IS_CHROMEOS)
namespace policy {
using performance_manager::user_tuning::prefs::BatterySaverModeState;
BatterySaverPolicyHandler::BatterySaverPolicyHandler()
: TypeCheckingPolicyHandler(key::kBatterySaverModeAvailability,
base::Value::Type::INTEGER) {}
void BatterySaverPolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) {
const base::Value* value = policies.GetValue(
key::kBatterySaverModeAvailability, base::Value::Type::INTEGER);
if (!value) {
return;
}
switch (value->GetInt()) {
case base::strict_cast<int>(BatterySaverModeState::kDisabled):
#if BUILDFLAG(IS_CHROMEOS)
prefs->SetBoolean(ash::prefs::kPowerBatterySaver, false);
#endif // BUILDFLAG(IS_CHROMEOS)
prefs->SetInteger(
performance_manager::user_tuning::prefs::kBatterySaverModeState,
base::strict_cast<int>(BatterySaverModeState::kDisabled));
break;
case base::strict_cast<int>(BatterySaverModeState::kEnabledBelowThreshold):
case base::strict_cast<int>(BatterySaverModeState::kEnabledOnBattery):
// kEnabledOnBattery as a policy value is deprecated and treated as
// kEnabledBelowThreshold to unify policy with ChromeOS Battery Saver
// which does not support it.
prefs->SetInteger(
performance_manager::user_tuning::prefs::kBatterySaverModeState,
base::strict_cast<int>(
BatterySaverModeState::kEnabledBelowThreshold));
// kEnabledBelowThreshold is the default behavior of ChromeOS Battery
// Saver, so we don't need apply any policy to
// ash::prefs::kPowerBatterySaver.
break;
}
}
} // namespace policy
|