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

Unified Diff: chrome/browser/power_save_blocker_common.cc

Issue 287017: Disable system suspend while downloading files on win32.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: 'Fix Created 11 years, 2 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
« no previous file with comments | « chrome/browser/power_save_blocker.h ('k') | chrome/browser/power_save_blocker_stub.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/power_save_blocker_common.cc
===================================================================
--- chrome/browser/power_save_blocker_common.cc (revision 0)
+++ chrome/browser/power_save_blocker_common.cc (revision 0)
@@ -0,0 +1,58 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/power_save_blocker.h"
+#include "chrome/browser/chrome_thread.h"
+
+// Accessed only from the UI thread.
+int PowerSaveBlocker::blocker_count_ = 0;
+
+PowerSaveBlocker::PowerSaveBlocker(bool enable) : enabled_(false) {
+ if (enable)
+ Enable();
+}
+
+PowerSaveBlocker::~PowerSaveBlocker(void) {
+ Disable();
+}
+
+void PowerSaveBlocker::Enable() {
+ if (enabled_)
+ return;
+
+ enabled_ = true;
+ PostAdjustBlockCount(1);
+}
+
+void PowerSaveBlocker::Disable() {
+ if (!enabled_)
+ return;
+
+ enabled_ = false;
+ PostAdjustBlockCount(-1);
+}
+
+
+void PowerSaveBlocker::PostAdjustBlockCount(int delta) {
+ MessageLoop *ml = ChromeThread::GetMessageLoop(ChromeThread::UI);
+
+ ml->PostTask(FROM_HERE,
+ NewRunnableFunction(&PowerSaveBlocker::AdjustBlockCount, delta));
+}
+
+// Called only from UI thread.
+void PowerSaveBlocker::AdjustBlockCount(int delta) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+
+ bool was_blocking = (blocker_count_ != 0);
+
+ blocker_count_ += delta;
+
+ bool is_blocking = (blocker_count_ != 0);
+
+ DCHECK_GE(blocker_count_, 0);
+
+ if (is_blocking != was_blocking)
+ ApplyBlock(is_blocking);
+}
Property changes on: chrome\browser\power_save_blocker_common.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « chrome/browser/power_save_blocker.h ('k') | chrome/browser/power_save_blocker_stub.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698