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

Side by Side Diff: chrome/browser/chromeos/dbus/power_manager_client.cc

Issue 8573025: chromeos: Move EnableScreenLock to PowerManagerClient from PowerLibrary (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/dbus/power_manager_client.h" 5 #include "chrome/browser/chromeos/dbus/power_manager_client.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/file_util.h"
11 #include "base/format_macros.h" 12 #include "base/format_macros.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/observer_list.h" 14 #include "base/observer_list.h"
14 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
15 #include "base/time.h" 16 #include "base/time.h"
16 #include "base/timer.h" 17 #include "base/timer.h"
17 #include "chrome/browser/chromeos/system/runtime_environment.h" 18 #include "chrome/browser/chromeos/system/runtime_environment.h"
18 #include "dbus/bus.h" 19 #include "dbus/bus.h"
19 #include "dbus/message.h" 20 #include "dbus/message.h"
20 #include "dbus/object_proxy.h" 21 #include "dbus/object_proxy.h"
21 #include "third_party/cros_system_api/dbus/service_constants.h" 22 #include "third_party/cros_system_api/dbus/service_constants.h"
22 23
24 namespace {
25
26 const char kLockOnIdleSuspendPath[] =
27 "/var/lib/power_manager/lock_on_idle_suspend";
28
29 } // namespace
30
23 namespace chromeos { 31 namespace chromeos {
24 32
25 PowerSupplyStatus::PowerSupplyStatus() 33 PowerSupplyStatus::PowerSupplyStatus()
26 : line_power_on(false), 34 : line_power_on(false),
27 battery_is_present(false), 35 battery_is_present(false),
28 battery_is_full(false), 36 battery_is_full(false),
29 battery_seconds_to_empty(0), 37 battery_seconds_to_empty(0),
30 battery_seconds_to_full(0), 38 battery_seconds_to_full(0),
31 battery_percentage(0) { 39 battery_percentage(0) {
32 } 40 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 OVERRIDE { 168 OVERRIDE {
161 dbus::MethodCall method_call(power_manager::kPowerManagerInterface, 169 dbus::MethodCall method_call(power_manager::kPowerManagerInterface,
162 power_manager::kGetIdleTime); 170 power_manager::kGetIdleTime);
163 power_manager_proxy_->CallMethod( 171 power_manager_proxy_->CallMethod(
164 &method_call, 172 &method_call,
165 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 173 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
166 base::Bind(&PowerManagerClientImpl::OnGetIdleTime, 174 base::Bind(&PowerManagerClientImpl::OnGetIdleTime,
167 weak_ptr_factory_.GetWeakPtr(), callback)); 175 weak_ptr_factory_.GetWeakPtr(), callback));
168 } 176 }
169 177
178 virtual void EnableScreenLock(bool enable) OVERRIDE {
179 std::string config = base::StringPrintf("%d", enable);
180 file_util::WriteFile(FilePath(kLockOnIdleSuspendPath),
181 config.c_str(),
182 config.size());
satorux1 2011/11/16 00:52:49 Let's do this somewhere else. PowerManagerClient i
satorux1 2011/11/16 00:55:52 Besides, please be sure to do this in FILE thread.
satorux1 2011/11/16 00:59:48 I changed my mind. Putting the code in chrome/brow
Simon Que 2011/11/16 01:40:02 Done.
Simon Que 2011/11/16 01:40:02 Done.
183 }
184
170 private: 185 private:
171 // Called when a dbus signal is initially connected. 186 // Called when a dbus signal is initially connected.
172 void SignalConnected(const std::string& interface_name, 187 void SignalConnected(const std::string& interface_name,
173 const std::string& signal_name, 188 const std::string& signal_name,
174 bool success) { 189 bool success) {
175 LOG_IF(WARNING, !success) << "Failed to connect to signal " 190 LOG_IF(WARNING, !success) << "Failed to connect to signal "
176 << signal_name << "."; 191 << signal_name << ".";
177 } 192 }
178 193
179 // Called when a brightness change signal is received. 194 // Called when a brightness change signal is received.
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 332
318 virtual void RequestRestart() OVERRIDE {} 333 virtual void RequestRestart() OVERRIDE {}
319 334
320 virtual void RequestShutdown() OVERRIDE {} 335 virtual void RequestShutdown() OVERRIDE {}
321 336
322 virtual void CalculateIdleTime(const CalculateIdleTimeCallback& callback) 337 virtual void CalculateIdleTime(const CalculateIdleTimeCallback& callback)
323 OVERRIDE { 338 OVERRIDE {
324 callback.Run(0); 339 callback.Run(0);
325 } 340 }
326 341
342 virtual void EnableScreenLock(bool enable) OVERRIDE {}
343
327 private: 344 private:
328 void Update() { 345 void Update() {
329 // We pause at 0 and 100% so that it's easier to check those conditions. 346 // We pause at 0 and 100% so that it's easier to check those conditions.
330 if (pause_count_ > 1) { 347 if (pause_count_ > 1) {
331 pause_count_--; 348 pause_count_--;
332 return; 349 return;
333 } 350 }
334 351
335 if (battery_percentage_ == 0 || battery_percentage_ == 100) { 352 if (battery_percentage_ == 0 || battery_percentage_ == 100) {
336 if (pause_count_) { 353 if (pause_count_) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 392
376 PowerManagerClient* PowerManagerClient::Create(dbus::Bus* bus) { 393 PowerManagerClient* PowerManagerClient::Create(dbus::Bus* bus) {
377 if (system::runtime_environment::IsRunningOnChromeOS()) { 394 if (system::runtime_environment::IsRunningOnChromeOS()) {
378 return new PowerManagerClientImpl(bus); 395 return new PowerManagerClientImpl(bus);
379 } else { 396 } else {
380 return new PowerManagerClientStubImpl(); 397 return new PowerManagerClientStubImpl();
381 } 398 }
382 } 399 }
383 400
384 } // namespace chromeos 401 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/dbus/power_manager_client.h ('k') | chrome/browser/chromeos/preferences.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698