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

Unified Diff: src/platform/power_manager/xidle.cc

Issue 1035001: Fix off-by-one bug for the negative transition in XIdle::AddIdleTimeout, which (Closed)
Patch Set: Update to address Dan's comments Created 10 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 side-by-side diff with in-line comments
Download patch
Index: src/platform/power_manager/xidle.cc
diff --git a/src/platform/power_manager/xidle.cc b/src/platform/power_manager/xidle.cc
index 394e26c33837565d5f0fd1307bcfe1c2ac779673..c927e533151148d5bfcd32aa19ffc2b121bd0c50 100644
--- a/src/platform/power_manager/xidle.cc
+++ b/src/platform/power_manager/xidle.cc
@@ -19,20 +19,19 @@ static inline void XSyncInt64ToValue(XSyncValue* xvalue, int64 value) {
XIdle::XIdle()
: idle_counter_(0),
- min_timeout_(kint64max) {
+ min_timeout_(kint64max),
+ display_(NULL) {
}
XIdle::~XIdle() {
ClearTimeouts();
- if (display_)
- XCloseDisplay(display_);
}
-bool XIdle::Init() {
+bool XIdle::Init(Display* display) {
int major_version, minor_version;
- display_ = XOpenDisplay(NULL);
- if (display_ &&
- XSyncQueryExtension(display_, &event_base_, &error_base_) &&
+ CHECK(display);
+ display_ = display;
+ if (XSyncQueryExtension(display_, &event_base_, &error_base_) &&
XSyncInitialize(display_, &major_version, &minor_version)) {
XSyncSystemCounter* counters;
int ncounters;
@@ -53,10 +52,12 @@ bool XIdle::Init() {
bool XIdle::AddIdleTimeout(int64 idle_timeout_ms) {
DCHECK_NE(idle_counter_, 0);
+ DCHECK_GT(idle_timeout_ms, 1);
if (idle_timeout_ms < min_timeout_) {
min_timeout_ = idle_timeout_ms;
- XSyncAlarm alarm = CreateIdleAlarm(min_timeout_, XSyncNegativeTransition);
+ XSyncAlarm alarm = CreateIdleAlarm(min_timeout_ - 1,
Daniel Erat 2010/03/16 21:40:01 it'd be good to add a comment here describing the
+ XSyncNegativeTransition);
if (!alarm)
return false;
if (!alarms_.empty()) {

Powered by Google App Engine
This is Rietveld 408576698