summaryrefslogtreecommitdiffstats
path: root/chrome/browser/power_save_blocker.h
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/power_save_blocker.h')
-rw-r--r--chrome/browser/power_save_blocker.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/chrome/browser/power_save_blocker.h b/chrome/browser/power_save_blocker.h
new file mode 100644
index 0000000..f362915
--- /dev/null
+++ b/chrome/browser/power_save_blocker.h
@@ -0,0 +1,42 @@
+// 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.
+
+#ifndef CHROME_BROWSER_POWER_SAVE_BLOCKER_H_
+#define CHROME_BROWSER_POWER_SAVE_BLOCKER_H_
+
+#include "base/basictypes.h"
+
+// A RAII-style class to block the system from entering low-power
+// (sleep) mode.
+class PowerSaveBlocker {
+ public:
+ explicit PowerSaveBlocker(bool enabled);
+ ~PowerSaveBlocker();
+
+ bool enabled() const { return enabled_; }
+
+ // Puts the sleep mode block into effect.
+ void Enable();
+ // Disables the sleep block.
+ void Disable();
+
+ private:
+ // Platform-specific function called when enable state is changed.
+ // Guarenteed to be called only from the UI thread.
+ static void ApplyBlock(bool blocked);
+
+ // Called only from UI thread.
+ static void AdjustBlockCount(int delta);
+
+ // Invokes AdjustBlockCount on the UI thread.
+ static void PostAdjustBlockCount(int delta);
+
+ bool enabled_;
+
+ static int blocker_count_;
+
+ DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker);
+};
+
+#endif // CHROME_BROWSER_POWER_SAVE_BLOCKER_H_