OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/chromeos/power/lightbar.h" | |
Daniel Erat
2014/09/12 19:53:03
nit: this should also be light_bar.h unless the cl
| |
6 | |
7 #include <cstring> // needed for strlen() | |
8 | |
9 #include "base/command_line.h" | |
10 #include "base/file_util.h" | |
11 #include "base/logging.h" | |
12 #include "base/message_loop/message_loop.h" | |
13 #include "chromeos/chromeos_switches.h" | |
14 #include "chromeos/dbus/dbus_thread_manager.h" | |
15 | |
16 namespace chromeos { | |
17 | |
18 namespace { | |
19 const int64_t kDarkSuspendDelaySeconds = 4; | |
Daniel Erat
2014/09/12 19:53:03
nit: int is fine if you don't specifically need 64
| |
20 const char kLightBarControlPath[] = | |
21 "/sys/devices/virtual/chromeos/cros_ec/lightbar/sequence"; | |
22 const char kKonamiCommand[] = "KONAMI"; | |
23 | |
24 } // namespace | |
25 | |
26 void LightBar::DarkSuspendImminent() { | |
Daniel Erat
2014/09/12 19:53:03
nit: move this down to match the order in the .h f
| |
27 // The plan is to track the progress of push events and then re-suspend as | |
28 // soon as we know they have been processed. In the meanwhile, we can hack | |
29 // around this by just having the light bar delay for a long time so that | |
30 // people can at least start playing around with this feature for their apps. | |
31 // | |
32 // TODO(chirantan): Remove this once we can accurately track the progress of | |
33 // push events. | |
34 base::MessageLoop::current()->PostDelayedTask( | |
35 FROM_HERE, | |
36 DBusThreadManager::Get() | |
37 ->GetPowerManagerClient() | |
38 ->GetSuspendReadinessCallback(), | |
39 base::TimeDelta::FromSeconds(kDarkSuspendDelaySeconds)); | |
40 | |
41 if (!has_lightbar_) | |
42 return; | |
43 | |
44 if (base::WriteFile(control_path_, kKonamiCommand, strlen(kKonamiCommand)) != | |
Daniel Erat
2014/09/12 19:53:03
is there a plan to make a distinction between the
Chirantan Ekbote
2014/09/15 23:20:46
Yes, Derek is working on being able to distinguish
| |
45 static_cast<int>(strlen(kKonamiCommand))) | |
46 PLOG(WARNING) << "Unable to flash light bar during dark resume."; | |
47 } | |
48 | |
49 LightBar::LightBar() | |
50 : control_path_(base::FilePath(kLightBarControlPath)), | |
51 has_lightbar_(base::PathIsWritable(control_path_)), | |
52 enabled_(CommandLine::ForCurrentProcess() | |
53 ->HasSwitch(switches::kEnableLucidSleep)) { | |
54 if (enabled_) | |
55 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | |
56 } | |
57 | |
58 LightBar::~LightBar() { | |
59 if (enabled_) | |
60 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | |
61 } | |
62 | |
63 } // namespace chromeos | |
OLD | NEW |