Chromium Code Reviews| 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/light_bar.h" | |
| 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 int kDarkSuspendDelaySeconds = 4; | |
| 20 const char kLightBarControlPath[] = | |
| 21 "/sys/devices/virtual/chromeos/cros_ec/lightbar/sequence"; | |
| 22 const char kKonamiCommand[] = "KONAMI"; | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 LightBar::LightBar() | |
| 27 : control_path_(base::FilePath(kLightBarControlPath)), | |
| 28 has_light_bar_(base::PathIsWritable(control_path_)) { | |
| 29 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | |
| 30 } | |
| 31 | |
| 32 LightBar::~LightBar() { | |
| 33 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | |
| 34 } | |
| 35 | |
| 36 void LightBar::DarkSuspendImminent() { | |
| 37 // The plan is to track the progress of push events and then re-suspend as | |
| 38 // soon as we know they have been processed. In the meanwhile, we can hack | |
| 39 // around this by just having the light bar delay for a long time so that | |
| 40 // people can at least start playing around with this feature for their apps. | |
| 41 // | |
| 42 // TODO(chirantan): Remove this once we can accurately track the progress of | |
| 43 // push events. | |
| 44 base::MessageLoop::current()->PostDelayedTask( | |
|
Daniel Erat
2014/09/15 23:24:36
move this to the end and only do it if the write w
Chirantan Ekbote
2014/09/15 23:36:17
The light bar and the delay are pretty much indepe
| |
| 45 FROM_HERE, | |
| 46 DBusThreadManager::Get() | |
| 47 ->GetPowerManagerClient() | |
| 48 ->GetSuspendReadinessCallback(), | |
| 49 base::TimeDelta::FromSeconds(kDarkSuspendDelaySeconds)); | |
| 50 | |
| 51 if (!has_light_bar_) | |
| 52 return; | |
| 53 | |
| 54 if (base::WriteFile(control_path_, kKonamiCommand, strlen(kKonamiCommand)) != | |
| 55 static_cast<int>(strlen(kKonamiCommand))) | |
| 56 PLOG(WARNING) << "Unable to flash light bar during dark resume."; | |
| 57 } | |
| 58 | |
| 59 } // namespace chromeos | |
| OLD | NEW |