Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/dbus/power_policy_controller.h" | 5 #include "chromeos/dbus/power_policy_controller.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 manager_ = NULL; | 136 manager_ = NULL; |
| 137 } | 137 } |
| 138 | 138 |
| 139 void PowerPolicyController::ApplyPrefs(const PrefValues& values) { | 139 void PowerPolicyController::ApplyPrefs(const PrefValues& values) { |
| 140 prefs_policy_.Clear(); | 140 prefs_policy_.Clear(); |
| 141 | 141 |
| 142 power_manager::PowerManagementPolicy::Delays* delays = | 142 power_manager::PowerManagementPolicy::Delays* delays = |
| 143 prefs_policy_.mutable_ac_delays(); | 143 prefs_policy_.mutable_ac_delays(); |
| 144 delays->set_screen_dim_ms(values.ac_screen_dim_delay_ms); | 144 delays->set_screen_dim_ms(values.ac_screen_dim_delay_ms); |
| 145 delays->set_screen_off_ms(values.ac_screen_off_delay_ms); | 145 delays->set_screen_off_ms(values.ac_screen_off_delay_ms); |
| 146 delays->set_screen_lock_ms(values.ac_screen_lock_delay_ms); | 146 delays->set_screen_lock_ms( |
| 147 values.enable_screen_lock ? values.ac_screen_lock_delay_ms : 0); | |
|
Mattias Nissler (ping if slow)
2013/05/31 13:22:46
This would become:
if (values.ac_screen_lock_dela
bartfab (slow)
2013/05/31 13:35:59
Actually, I think we would want to use the minimum
bartfab (slow)
2013/05/31 13:37:32
Let me try that again, hopefully without confusing
Daniel Erat
2013/05/31 13:41:58
Yes, I agree. Like Mattias suggested, I'll just re
| |
| 147 delays->set_idle_warning_ms(values.ac_idle_warning_delay_ms); | 148 delays->set_idle_warning_ms(values.ac_idle_warning_delay_ms); |
| 148 delays->set_idle_ms(values.ac_idle_delay_ms); | 149 delays->set_idle_ms(values.ac_idle_delay_ms); |
| 149 | 150 |
| 150 // If screen-locking is enabled, ensure that the screen is locked when | |
| 151 // it's turned off due to user inactivity. | |
|
Mattias Nissler (ping if slow)
2013/05/31 13:22:46
I guess we want to retain this block.
| |
| 152 if (values.enable_screen_lock && delays->screen_off_ms() > 0 && | |
| 153 (delays->screen_lock_ms() <= 0 || | |
| 154 delays->screen_off_ms() < delays->screen_lock_ms())) { | |
| 155 delays->set_screen_lock_ms(delays->screen_off_ms()); | |
| 156 } | |
| 157 | |
| 158 delays = prefs_policy_.mutable_battery_delays(); | 151 delays = prefs_policy_.mutable_battery_delays(); |
| 159 delays->set_screen_dim_ms(values.battery_screen_dim_delay_ms); | 152 delays->set_screen_dim_ms(values.battery_screen_dim_delay_ms); |
| 160 delays->set_screen_off_ms(values.battery_screen_off_delay_ms); | 153 delays->set_screen_off_ms(values.battery_screen_off_delay_ms); |
| 161 delays->set_screen_lock_ms(values.battery_screen_lock_delay_ms); | 154 delays->set_screen_lock_ms( |
| 155 values.enable_screen_lock ? values.battery_screen_lock_delay_ms : 0); | |
|
Mattias Nissler (ping if slow)
2013/05/31 13:22:46
same for battery obviously.
| |
| 162 delays->set_idle_warning_ms(values.battery_idle_warning_delay_ms); | 156 delays->set_idle_warning_ms(values.battery_idle_warning_delay_ms); |
| 163 delays->set_idle_ms(values.battery_idle_delay_ms); | 157 delays->set_idle_ms(values.battery_idle_delay_ms); |
| 164 if (values.enable_screen_lock && delays->screen_off_ms() > 0 && | |
| 165 (delays->screen_lock_ms() <= 0 || | |
| 166 delays->screen_off_ms() < delays->screen_lock_ms())) { | |
| 167 delays->set_screen_lock_ms(delays->screen_off_ms()); | |
| 168 } | |
| 169 | 158 |
| 170 prefs_policy_.set_idle_action(GetProtoAction(values.idle_action)); | 159 prefs_policy_.set_idle_action(GetProtoAction(values.idle_action)); |
| 171 prefs_policy_.set_lid_closed_action(GetProtoAction(values.lid_closed_action)); | 160 prefs_policy_.set_lid_closed_action(GetProtoAction(values.lid_closed_action)); |
| 172 prefs_policy_.set_use_audio_activity(values.use_audio_activity); | 161 prefs_policy_.set_use_audio_activity(values.use_audio_activity); |
| 173 prefs_policy_.set_use_video_activity(values.use_video_activity); | 162 prefs_policy_.set_use_video_activity(values.use_video_activity); |
| 174 prefs_policy_.set_presentation_idle_delay_factor( | 163 prefs_policy_.set_presentation_idle_delay_factor( |
| 175 values.presentation_idle_delay_factor); | 164 values.presentation_idle_delay_factor); |
| 176 prefs_policy_.set_user_activity_screen_dim_delay_factor( | 165 prefs_policy_.set_user_activity_screen_dim_delay_factor( |
| 177 values.user_activity_screen_dim_delay_factor); | 166 values.user_activity_screen_dim_delay_factor); |
| 178 | 167 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 void PowerPolicyController::SendCurrentPolicy() { | 205 void PowerPolicyController::SendCurrentPolicy() { |
| 217 std::string reason; | 206 std::string reason; |
| 218 | 207 |
| 219 power_manager::PowerManagementPolicy policy = prefs_policy_; | 208 power_manager::PowerManagementPolicy policy = prefs_policy_; |
| 220 if (prefs_were_set_) | 209 if (prefs_were_set_) |
| 221 reason = "Prefs"; | 210 reason = "Prefs"; |
| 222 | 211 |
| 223 if (honor_screen_wake_locks_ && !screen_wake_locks_.empty()) { | 212 if (honor_screen_wake_locks_ && !screen_wake_locks_.empty()) { |
| 224 policy.mutable_ac_delays()->set_screen_dim_ms(0); | 213 policy.mutable_ac_delays()->set_screen_dim_ms(0); |
| 225 policy.mutable_ac_delays()->set_screen_off_ms(0); | 214 policy.mutable_ac_delays()->set_screen_off_ms(0); |
| 215 policy.mutable_ac_delays()->set_screen_lock_ms(0); | |
| 226 policy.mutable_battery_delays()->set_screen_dim_ms(0); | 216 policy.mutable_battery_delays()->set_screen_dim_ms(0); |
| 227 policy.mutable_battery_delays()->set_screen_off_ms(0); | 217 policy.mutable_battery_delays()->set_screen_off_ms(0); |
| 218 policy.mutable_battery_delays()->set_screen_lock_ms(0); | |
| 228 } | 219 } |
| 229 | 220 |
| 230 if ((!screen_wake_locks_.empty() || !system_wake_locks_.empty()) && | 221 if ((!screen_wake_locks_.empty() || !system_wake_locks_.empty()) && |
| 231 (!policy.has_idle_action() || policy.idle_action() == | 222 (!policy.has_idle_action() || policy.idle_action() == |
| 232 power_manager::PowerManagementPolicy_Action_SUSPEND)) { | 223 power_manager::PowerManagementPolicy_Action_SUSPEND)) { |
| 233 policy.set_idle_action( | 224 policy.set_idle_action( |
| 234 power_manager::PowerManagementPolicy_Action_DO_NOTHING); | 225 power_manager::PowerManagementPolicy_Action_DO_NOTHING); |
| 235 } | 226 } |
| 236 | 227 |
| 237 for (WakeLockMap::const_iterator it = screen_wake_locks_.begin(); | 228 for (WakeLockMap::const_iterator it = screen_wake_locks_.begin(); |
| 238 it != screen_wake_locks_.end(); ++it) { | 229 it != screen_wake_locks_.end(); ++it) { |
| 239 reason += (reason.empty() ? "" : ", ") + it->second; | 230 reason += (reason.empty() ? "" : ", ") + it->second; |
| 240 } | 231 } |
| 241 for (WakeLockMap::const_iterator it = system_wake_locks_.begin(); | 232 for (WakeLockMap::const_iterator it = system_wake_locks_.begin(); |
| 242 it != system_wake_locks_.end(); ++it) { | 233 it != system_wake_locks_.end(); ++it) { |
| 243 reason += (reason.empty() ? "" : ", ") + it->second; | 234 reason += (reason.empty() ? "" : ", ") + it->second; |
| 244 } | 235 } |
| 245 | 236 |
| 246 if (!reason.empty()) | 237 if (!reason.empty()) |
| 247 policy.set_reason(reason); | 238 policy.set_reason(reason); |
| 248 client_->SetPolicy(policy); | 239 client_->SetPolicy(policy); |
| 249 } | 240 } |
| 250 | 241 |
| 251 void PowerPolicyController::SendEmptyPolicy() { | 242 void PowerPolicyController::SendEmptyPolicy() { |
| 252 client_->SetPolicy(power_manager::PowerManagementPolicy()); | 243 client_->SetPolicy(power_manager::PowerManagementPolicy()); |
| 253 } | 244 } |
| 254 | 245 |
| 255 } // namespace chromeos | 246 } // namespace chromeos |
| OLD | NEW |