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

Unified Diff: base/system_monitor/system_monitor.h

Issue 10406012: Base: Add power requirements to the System monitor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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 | « no previous file | base/system_monitor/system_monitor_android.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/system_monitor/system_monitor.h
===================================================================
--- base/system_monitor/system_monitor.h (revision 137792)
+++ base/system_monitor/system_monitor.h (working copy)
@@ -6,10 +6,13 @@
#define BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_
#pragma once
+#include <map>
#include <string>
+#include <utility>
#include "base/base_export.h"
#include "base/basictypes.h"
+#include "base/threading/thread_checker.h"
#include "build/build_config.h"
// Windows HiRes timers drain the battery faster so we need to know the battery
@@ -46,6 +49,13 @@
RESUME_EVENT // The system is being resumed.
};
+ enum PowerRequirement {
+ DISPLAY_REQUIRED, // The display should not be shut down.
+ SYSTEM_REQUIRED, // The system should not be suspended.
+ CPU_REQUIRED, // The process should not be suspended.
+ TEST_REQUIRED // This is used by unit tests.
+ };
+
typedef unsigned int DeviceIdType;
// Create SystemMonitor. Only one SystemMonitor instance per application
@@ -145,6 +155,22 @@
const FilePath& path);
void ProcessMediaDeviceDetached(const DeviceIdType& id);
+ // Enters or leaves a period of time with a given |requirement|. If the
+ // operation has multiple requirements, make sure to use a unique |reason| for
+ // each one. Reusing the same |reason| is OK as far as the |requirement| is
+ // the same in every call, and each BeginPowerRequirement call is paired with
+ // a call to EndPowerRequirement. |reason| is expected to be an ASCII string.
+ // Must be called from the thread that created the SystemMonitor.
+ // Warning: Please remember that sleep deprivation is not a good thing; use
+ // with caution.
+ void BeginPowerRequirement(PowerRequirement requirement,
+ const std::string& reason);
+ void EndPowerRequirement(PowerRequirement requirement,
+ const std::string& reason);
+
+ // Returns the number of outsanding power requirement requests.
+ size_t GetPowerRequirementsCountForTest() const;
+
private:
#if defined(OS_MACOSX)
void PlatformInit();
@@ -176,6 +202,11 @@
bool battery_in_use_;
bool suspended_;
+#if defined(OS_WIN)
+ std::map<std::string, std::pair<HANDLE, int> > handles_;
+ base::ThreadChecker thread_checker_;
+#endif
+
#if defined(ENABLE_BATTERY_MONITORING)
base::OneShotTimer<SystemMonitor> delayed_battery_check_;
#endif
« no previous file with comments | « no previous file | base/system_monitor/system_monitor_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698