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

Side by Side Diff: powerman.cc

Issue 6712052: Allow the lid to be ignored using the use_lid pref (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/power_manager.git@master
Patch Set: Add default use_lid to config directory Created 9 years, 9 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
« no previous file with comments | « power_constants.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium OS 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 <stdlib.h> 5 #include <stdlib.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <dbus/dbus-shared.h> 7 #include <dbus/dbus-shared.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <linux/vt.h> 10 #include <linux/vt.h>
(...skipping 14 matching lines...) Expand all
25 25
26 namespace power_manager { 26 namespace power_manager {
27 27
28 static const int kCheckLidClosedSeconds = 10; 28 static const int kCheckLidClosedSeconds = 10;
29 static const unsigned int kCancelDBusLidOpenedSecs = 5; 29 static const unsigned int kCancelDBusLidOpenedSecs = 5;
30 30
31 PowerManDaemon::PowerManDaemon(PowerPrefs* prefs, 31 PowerManDaemon::PowerManDaemon(PowerPrefs* prefs,
32 MetricsLibraryInterface* metrics_lib, 32 MetricsLibraryInterface* metrics_lib,
33 const FilePath& run_dir) 33 const FilePath& run_dir)
34 : loop_(NULL), 34 : loop_(NULL),
35 use_input_for_lid_(1),
35 prefs_(prefs), 36 prefs_(prefs),
36 lidstate_(kLidOpened), 37 lidstate_(kLidOpened),
37 metrics_lib_(metrics_lib), 38 metrics_lib_(metrics_lib),
38 power_button_state_(false), 39 power_button_state_(false),
39 retry_suspend_count_(0), 40 retry_suspend_count_(0),
40 suspend_pid_(0), 41 suspend_pid_(0),
41 lid_id_(0), 42 lid_id_(0),
42 powerd_id_(0), 43 powerd_id_(0),
43 powerd_state_(kPowerManagerUnknown), 44 powerd_state_(kPowerManagerUnknown),
44 run_dir_(run_dir), 45 run_dir_(run_dir),
45 console_fd_(-1) {} 46 console_fd_(-1) {}
46 47
47 PowerManDaemon::~PowerManDaemon() { 48 PowerManDaemon::~PowerManDaemon() {
48 if (console_fd_ >= 0) { 49 if (console_fd_ >= 0) {
49 close(console_fd_); 50 close(console_fd_);
50 } 51 }
51 } 52 }
52 53
53 void PowerManDaemon::Init() { 54 void PowerManDaemon::Init() {
54 int input_lidstate = 0; 55 int input_lidstate = 0;
56 int64 use_input_for_lid;
55 CHECK(prefs_->GetInt64(kRetrySuspendMs, &retry_suspend_ms_)); 57 CHECK(prefs_->GetInt64(kRetrySuspendMs, &retry_suspend_ms_));
56 CHECK(prefs_->GetInt64(kRetrySuspendAttempts, &retry_suspend_attempts_)); 58 CHECK(prefs_->GetInt64(kRetrySuspendAttempts, &retry_suspend_attempts_));
59 CHECK(prefs_->GetInt64(kUseLid, &use_input_for_lid));
57 // Retrys will occur no more than once a minute. 60 // Retrys will occur no more than once a minute.
58 CHECK_GE(retry_suspend_ms_, 60000); 61 CHECK_GE(retry_suspend_ms_, 60000);
59 // Only 1-10 retries prior to just shutting down. 62 // Only 1-10 retries prior to just shutting down.
60 CHECK_GT(retry_suspend_attempts_, 0); 63 CHECK_GT(retry_suspend_attempts_, 0);
61 CHECK_LE(retry_suspend_attempts_, 10); 64 CHECK_LE(retry_suspend_attempts_, 10);
65 use_input_for_lid_ = 1 == use_input_for_lid;
62 loop_ = g_main_loop_new(NULL, false); 66 loop_ = g_main_loop_new(NULL, false);
63 // Acquire a handle to the console for VT switch locking ioctl. 67 // Acquire a handle to the console for VT switch locking ioctl.
64 CHECK(GetConsole()); 68 CHECK(GetConsole());
65 input_.RegisterHandler(&(PowerManDaemon::OnInputEvent), this); 69 input_.RegisterHandler(&(PowerManDaemon::OnInputEvent), this);
66 CHECK(input_.Init()) << "Cannot initialize input interface."; 70 CHECK(input_.Init()) << "Cannot initialize input interface.";
67 lid_open_file_ = FilePath(run_dir_).Append(util::kLidOpenFile); 71 lid_open_file_ = FilePath(run_dir_).Append(util::kLidOpenFile);
68 if (input_.num_lid_events() > 0) { 72 if (input_.num_lid_events() > 0) {
69 input_.QueryLidState(&input_lidstate); 73 input_.QueryLidState(&input_lidstate);
70 lidstate_ = GetLidState(input_lidstate); 74 lidstate_ = GetLidState(input_lidstate);
71 lid_ticks_ = TimeTicks::Now(); 75 lid_ticks_ = TimeTicks::Now();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 case LID: { 126 case LID: {
123 daemon->lidstate_ = daemon->GetLidState(value); 127 daemon->lidstate_ = daemon->GetLidState(value);
124 daemon->lid_id_++; 128 daemon->lid_id_++;
125 daemon->lid_ticks_ = TimeTicks::Now(); 129 daemon->lid_ticks_ = TimeTicks::Now();
126 LOG(INFO) << "PowerM Daemon - lid " 130 LOG(INFO) << "PowerM Daemon - lid "
127 << (daemon->lidstate_ == kLidClosed?"closed.":"opened.") 131 << (daemon->lidstate_ == kLidClosed?"closed.":"opened.")
128 << " powerd " 132 << " powerd "
129 << (daemon->powerd_state_ == kPowerManagerDead? 133 << (daemon->powerd_state_ == kPowerManagerDead?
130 "dead":(daemon->powerd_state_ == kPowerManagerAlive? 134 "dead":(daemon->powerd_state_ == kPowerManagerAlive?
131 "alive":"unknown")); 135 "alive":"unknown"));
136 if (!daemon->use_input_for_lid_) {
137 LOG(INFO) << "Ignoring lid.";
138 break;
139 }
132 if (daemon->lidstate_ == kLidClosed) { 140 if (daemon->lidstate_ == kLidClosed) {
133 if (daemon->powerd_state_ != kPowerManagerAlive) { 141 if (daemon->powerd_state_ != kPowerManagerAlive) {
134 // powerd is not alive so act on its behalf. 142 // powerd is not alive so act on its behalf.
135 LOG(INFO) << "Forced suspend, powerd is not alive"; 143 LOG(INFO) << "Forced suspend, powerd is not alive";
136 daemon->Suspend(); 144 daemon->Suspend();
137 } else { 145 } else {
138 util::SendSignalToPowerD(util::kLidClosed); 146 util::SendSignalToPowerD(util::kLidClosed);
139 // Check that powerd stuck around to act on this event. If not, 147 // Check that powerd stuck around to act on this event. If not,
140 // callback will assume suspend responsibilities. 148 // callback will assume suspend responsibilities.
141 g_timeout_add_seconds(kCheckLidClosedSeconds, CheckLidClosedThunk, 149 g_timeout_add_seconds(kCheckLidClosedSeconds, CheckLidClosedThunk,
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 retval = false; 373 retval = false;
366 } 374 }
367 else { 375 else {
368 LOG(INFO) << "Opened console " << file_path.value().c_str() 376 LOG(INFO) << "Opened console " << file_path.value().c_str()
369 << " with file id = " << console_fd_; 377 << " with file id = " << console_fd_;
370 } 378 }
371 return retval; 379 return retval;
372 } 380 }
373 381
374 } // namespace power_manager 382 } // namespace power_manager
OLDNEW
« no previous file with comments | « power_constants.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698