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

Side by Side Diff: chromeos/dbus/power_policy_controller.cc

Issue 16346004: Merge 203774 "chromeos: Add delay between screen off and lock." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1500/src/
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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; // 10 sec.
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
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 void PowerPolicyController::SendCurrentPolicy() { 219 void PowerPolicyController::SendCurrentPolicy() {
217 std::string reason; 220 std::string reason;
218 221
219 power_manager::PowerManagementPolicy policy = prefs_policy_; 222 power_manager::PowerManagementPolicy policy = prefs_policy_;
220 if (prefs_were_set_) 223 if (prefs_were_set_)
221 reason = "Prefs"; 224 reason = "Prefs";
222 225
223 if (honor_screen_wake_locks_ && !screen_wake_locks_.empty()) { 226 if (honor_screen_wake_locks_ && !screen_wake_locks_.empty()) {
224 policy.mutable_ac_delays()->set_screen_dim_ms(0); 227 policy.mutable_ac_delays()->set_screen_dim_ms(0);
225 policy.mutable_ac_delays()->set_screen_off_ms(0); 228 policy.mutable_ac_delays()->set_screen_off_ms(0);
229 policy.mutable_ac_delays()->set_screen_lock_ms(0);
226 policy.mutable_battery_delays()->set_screen_dim_ms(0); 230 policy.mutable_battery_delays()->set_screen_dim_ms(0);
227 policy.mutable_battery_delays()->set_screen_off_ms(0); 231 policy.mutable_battery_delays()->set_screen_off_ms(0);
232 policy.mutable_battery_delays()->set_screen_lock_ms(0);
228 } 233 }
229 234
230 if ((!screen_wake_locks_.empty() || !system_wake_locks_.empty()) && 235 if ((!screen_wake_locks_.empty() || !system_wake_locks_.empty()) &&
231 (!policy.has_idle_action() || policy.idle_action() == 236 (!policy.has_idle_action() || policy.idle_action() ==
232 power_manager::PowerManagementPolicy_Action_SUSPEND)) { 237 power_manager::PowerManagementPolicy_Action_SUSPEND)) {
233 policy.set_idle_action( 238 policy.set_idle_action(
234 power_manager::PowerManagementPolicy_Action_DO_NOTHING); 239 power_manager::PowerManagementPolicy_Action_DO_NOTHING);
235 } 240 }
236 241
237 for (WakeLockMap::const_iterator it = screen_wake_locks_.begin(); 242 for (WakeLockMap::const_iterator it = screen_wake_locks_.begin();
238 it != screen_wake_locks_.end(); ++it) { 243 it != screen_wake_locks_.end(); ++it) {
239 reason += (reason.empty() ? "" : ", ") + it->second; 244 reason += (reason.empty() ? "" : ", ") + it->second;
240 } 245 }
241 for (WakeLockMap::const_iterator it = system_wake_locks_.begin(); 246 for (WakeLockMap::const_iterator it = system_wake_locks_.begin();
242 it != system_wake_locks_.end(); ++it) { 247 it != system_wake_locks_.end(); ++it) {
243 reason += (reason.empty() ? "" : ", ") + it->second; 248 reason += (reason.empty() ? "" : ", ") + it->second;
244 } 249 }
245 250
246 if (!reason.empty()) 251 if (!reason.empty())
247 policy.set_reason(reason); 252 policy.set_reason(reason);
248 client_->SetPolicy(policy); 253 client_->SetPolicy(policy);
249 } 254 }
250 255
251 void PowerPolicyController::SendEmptyPolicy() { 256 void PowerPolicyController::SendEmptyPolicy() {
252 client_->SetPolicy(power_manager::PowerManagementPolicy()); 257 client_->SetPolicy(power_manager::PowerManagementPolicy());
253 } 258 }
254 259
255 } // namespace chromeos 260 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/power_policy_controller.h ('k') | chromeos/dbus/power_policy_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698