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

Side by Side Diff: chrome/browser/chromeos/power/light_bar.cc

Issue 823703004: Tracking push events for lucid sleep (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Kill renderer if it sends a bad message id Created 5 years, 10 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
OLDNEW
(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/files/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/platform/cros_ec_lpc.0/cros-ec-dev.0/chromeos/cros_ec/"
22 "lightbar/sequence";
23 const char kKonamiCommand[] = "KONAMI";
24
25 } // namespace
26
27 LightBar::LightBar()
28 : control_path_(base::FilePath(kLightBarControlPath)),
29 has_light_bar_(base::PathIsWritable(control_path_)) {
30 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
31 }
32
33 LightBar::~LightBar() {
34 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
35 }
36
37 void LightBar::DarkSuspendImminent() {
38 // The plan is to track the progress of push events and then re-suspend as
39 // soon as we know they have been processed. In the meanwhile, we can hack
40 // around this by just having the light bar delay for a long time so that
41 // people can at least start playing around with this feature for their apps.
42 //
43 // TODO(chirantan): Remove this once we can accurately track the progress of
44 // push events.
45 base::MessageLoop::current()->PostDelayedTask(
46 FROM_HERE,
47 DBusThreadManager::Get()
48 ->GetPowerManagerClient()
49 ->GetSuspendReadinessCallback(),
50 base::TimeDelta::FromSeconds(kDarkSuspendDelaySeconds));
51
52 if (!has_light_bar_)
53 return;
54
55 if (base::WriteFile(control_path_, kKonamiCommand, strlen(kKonamiCommand)) !=
56 static_cast<int>(strlen(kKonamiCommand)))
57 PLOG(WARNING) << "Unable to flash light bar during dark resume.";
58 }
59
60 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698