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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 case PowerPolicyController::ACTION_DO_NOTHING: | 51 case PowerPolicyController::ACTION_DO_NOTHING: |
52 return power_manager::PowerManagementPolicy_Action_DO_NOTHING; | 52 return power_manager::PowerManagementPolicy_Action_DO_NOTHING; |
53 default: | 53 default: |
54 NOTREACHED() << "Unhandled action " << action; | 54 NOTREACHED() << "Unhandled action " << action; |
55 return power_manager::PowerManagementPolicy_Action_DO_NOTHING; | 55 return power_manager::PowerManagementPolicy_Action_DO_NOTHING; |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 } // namespace | 59 } // namespace |
60 | 60 |
61 const int PowerPolicyController::kScreenLockAfterOffDelayMs = 10000; | |
bartfab (slow)
2013/05/31 17:39:07
Should we make this a tunable pref? Ad if so, shou
Daniel Erat
2013/06/01 03:19:43
No, I don't think that this should be a pref.
- A
| |
62 | |
61 // -1 is interpreted as "unset" by powerd, resulting in powerd's default | 63 // -1 is interpreted as "unset" by powerd, resulting in powerd's default |
62 // delays being used instead. There are no similarly-interpreted values | 64 // delays being used instead. There are no similarly-interpreted values |
63 // for the other fields, unfortunately (but the constructor-assigned values | 65 // for the other fields, unfortunately (but the constructor-assigned values |
64 // will only reach powerd if Chrome messes up and forgets to override them | 66 // will only reach powerd if Chrome messes up and forgets to override them |
65 // with the pref-assigned values). | 67 // with the pref-assigned values). |
66 PowerPolicyController::PrefValues::PrefValues() | 68 PowerPolicyController::PrefValues::PrefValues() |
67 : ac_screen_dim_delay_ms(-1), | 69 : ac_screen_dim_delay_ms(-1), |
68 ac_screen_off_delay_ms(-1), | 70 ac_screen_off_delay_ms(-1), |
69 ac_screen_lock_delay_ms(-1), | 71 ac_screen_lock_delay_ms(-1), |
70 ac_idle_warning_delay_ms(-1), | 72 ac_idle_warning_delay_ms(-1), |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 prefs_policy_.Clear(); | 142 prefs_policy_.Clear(); |
141 | 143 |
142 power_manager::PowerManagementPolicy::Delays* delays = | 144 power_manager::PowerManagementPolicy::Delays* delays = |
143 prefs_policy_.mutable_ac_delays(); | 145 prefs_policy_.mutable_ac_delays(); |
144 delays->set_screen_dim_ms(values.ac_screen_dim_delay_ms); | 146 delays->set_screen_dim_ms(values.ac_screen_dim_delay_ms); |
145 delays->set_screen_off_ms(values.ac_screen_off_delay_ms); | 147 delays->set_screen_off_ms(values.ac_screen_off_delay_ms); |
146 delays->set_screen_lock_ms(values.ac_screen_lock_delay_ms); | 148 delays->set_screen_lock_ms(values.ac_screen_lock_delay_ms); |
147 delays->set_idle_warning_ms(values.ac_idle_warning_delay_ms); | 149 delays->set_idle_warning_ms(values.ac_idle_warning_delay_ms); |
148 delays->set_idle_ms(values.ac_idle_delay_ms); | 150 delays->set_idle_ms(values.ac_idle_delay_ms); |
149 | 151 |
150 // If screen-locking is enabled, ensure that the screen is locked when | 152 // If screen-locking is enabled, ensure that the screen is locked soon |
151 // it's turned off due to user inactivity. | 153 // after it's turned off due to user inactivity. |
154 int64 lock_ms = delays->screen_off_ms() + kScreenLockAfterOffDelayMs; | |
152 if (values.enable_screen_lock && delays->screen_off_ms() > 0 && | 155 if (values.enable_screen_lock && delays->screen_off_ms() > 0 && |
153 (delays->screen_lock_ms() <= 0 || | 156 (delays->screen_lock_ms() <= 0 || lock_ms < delays->screen_lock_ms()) && |
154 delays->screen_off_ms() < delays->screen_lock_ms())) { | 157 lock_ms < delays->idle_ms()) |
155 delays->set_screen_lock_ms(delays->screen_off_ms()); | 158 delays->set_screen_lock_ms(lock_ms); |
156 } | |
157 | 159 |
158 delays = prefs_policy_.mutable_battery_delays(); | 160 delays = prefs_policy_.mutable_battery_delays(); |
159 delays->set_screen_dim_ms(values.battery_screen_dim_delay_ms); | 161 delays->set_screen_dim_ms(values.battery_screen_dim_delay_ms); |
160 delays->set_screen_off_ms(values.battery_screen_off_delay_ms); | 162 delays->set_screen_off_ms(values.battery_screen_off_delay_ms); |
161 delays->set_screen_lock_ms(values.battery_screen_lock_delay_ms); | 163 delays->set_screen_lock_ms(values.battery_screen_lock_delay_ms); |
162 delays->set_idle_warning_ms(values.battery_idle_warning_delay_ms); | 164 delays->set_idle_warning_ms(values.battery_idle_warning_delay_ms); |
163 delays->set_idle_ms(values.battery_idle_delay_ms); | 165 delays->set_idle_ms(values.battery_idle_delay_ms); |
166 | |
167 lock_ms = delays->screen_off_ms() + kScreenLockAfterOffDelayMs; | |
164 if (values.enable_screen_lock && delays->screen_off_ms() > 0 && | 168 if (values.enable_screen_lock && delays->screen_off_ms() > 0 && |
165 (delays->screen_lock_ms() <= 0 || | 169 (delays->screen_lock_ms() <= 0 || lock_ms < delays->screen_lock_ms()) && |
166 delays->screen_off_ms() < delays->screen_lock_ms())) { | 170 lock_ms < delays->idle_ms()) |
167 delays->set_screen_lock_ms(delays->screen_off_ms()); | 171 delays->set_screen_lock_ms(lock_ms); |
168 } | |
169 | 172 |
170 prefs_policy_.set_idle_action(GetProtoAction(values.idle_action)); | 173 prefs_policy_.set_idle_action(GetProtoAction(values.idle_action)); |
171 prefs_policy_.set_lid_closed_action(GetProtoAction(values.lid_closed_action)); | 174 prefs_policy_.set_lid_closed_action(GetProtoAction(values.lid_closed_action)); |
172 prefs_policy_.set_use_audio_activity(values.use_audio_activity); | 175 prefs_policy_.set_use_audio_activity(values.use_audio_activity); |
173 prefs_policy_.set_use_video_activity(values.use_video_activity); | 176 prefs_policy_.set_use_video_activity(values.use_video_activity); |
174 prefs_policy_.set_presentation_idle_delay_factor( | 177 prefs_policy_.set_presentation_idle_delay_factor( |
175 values.presentation_idle_delay_factor); | 178 values.presentation_idle_delay_factor); |
176 prefs_policy_.set_user_activity_screen_dim_delay_factor( | 179 prefs_policy_.set_user_activity_screen_dim_delay_factor( |
177 values.user_activity_screen_dim_delay_factor); | 180 values.user_activity_screen_dim_delay_factor); |
178 | 181 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 if (!reason.empty()) | 249 if (!reason.empty()) |
247 policy.set_reason(reason); | 250 policy.set_reason(reason); |
248 client_->SetPolicy(policy); | 251 client_->SetPolicy(policy); |
249 } | 252 } |
250 | 253 |
251 void PowerPolicyController::SendEmptyPolicy() { | 254 void PowerPolicyController::SendEmptyPolicy() { |
252 client_->SetPolicy(power_manager::PowerManagementPolicy()); | 255 client_->SetPolicy(power_manager::PowerManagementPolicy()); |
253 } | 256 } |
254 | 257 |
255 } // namespace chromeos | 258 } // namespace chromeos |
OLD | NEW |