diff options
Diffstat (limited to 'base/system_monitor/system_monitor.h')
-rw-r--r-- | base/system_monitor/system_monitor.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/base/system_monitor/system_monitor.h b/base/system_monitor/system_monitor.h index 3f73b15..e0decc9 100644 --- a/base/system_monitor/system_monitor.h +++ b/base/system_monitor/system_monitor.h @@ -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 @@ class BASE_EXPORT SystemMonitor { 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 @@ class BASE_EXPORT SystemMonitor { 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 @@ class BASE_EXPORT SystemMonitor { 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 |