| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ | 5 #ifndef BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ |
| 6 #define BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ | 6 #define BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/base_export.h" | 14 #include "base/base_export.h" |
| 14 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 15 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "base/tuple.h" |
| 16 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 17 | 19 |
| 18 // Windows HiRes timers drain the battery faster so we need to know the battery | 20 // Windows HiRes timers drain the battery faster so we need to know the battery |
| 19 // status. This isn't true for other platforms. | 21 // status. This isn't true for other platforms. |
| 20 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
| 21 #define ENABLE_BATTERY_MONITORING 1 | 23 #define ENABLE_BATTERY_MONITORING 1 |
| 22 #else | 24 #else |
| 23 #undef ENABLE_BATTERY_MONITORING | 25 #undef ENABLE_BATTERY_MONITORING |
| 24 #endif // !OS_WIN | 26 #endif // !OS_WIN |
| 25 | 27 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 50 }; | 52 }; |
| 51 | 53 |
| 52 enum PowerRequirement { | 54 enum PowerRequirement { |
| 53 DISPLAY_REQUIRED, // The display should not be shut down. | 55 DISPLAY_REQUIRED, // The display should not be shut down. |
| 54 SYSTEM_REQUIRED, // The system should not be suspended. | 56 SYSTEM_REQUIRED, // The system should not be suspended. |
| 55 CPU_REQUIRED, // The process should not be suspended. | 57 CPU_REQUIRED, // The process should not be suspended. |
| 56 TEST_REQUIRED // This is used by unit tests. | 58 TEST_REQUIRED // This is used by unit tests. |
| 57 }; | 59 }; |
| 58 | 60 |
| 59 typedef unsigned int DeviceIdType; | 61 typedef unsigned int DeviceIdType; |
| 62 // (Media device id, Media device name, Media device path) |
| 63 typedef Tuple3<DeviceIdType, std::string, FilePath> MediaDeviceInfo; |
| 60 | 64 |
| 61 // Create SystemMonitor. Only one SystemMonitor instance per application | 65 // Create SystemMonitor. Only one SystemMonitor instance per application |
| 62 // is allowed. | 66 // is allowed. |
| 63 SystemMonitor(); | 67 SystemMonitor(); |
| 64 ~SystemMonitor(); | 68 ~SystemMonitor(); |
| 65 | 69 |
| 66 // Get the application-wide SystemMonitor (if not present, returns NULL). | 70 // Get the application-wide SystemMonitor (if not present, returns NULL). |
| 67 static SystemMonitor* Get(); | 71 static SystemMonitor* Get(); |
| 68 | 72 |
| 69 #if defined(OS_MACOSX) | 73 #if defined(OS_MACOSX) |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 // Cross-platform handling of a power event. | 152 // Cross-platform handling of a power event. |
| 149 void ProcessPowerMessage(PowerEvent event_id); | 153 void ProcessPowerMessage(PowerEvent event_id); |
| 150 | 154 |
| 151 // Cross-platform handling of a device change event. | 155 // Cross-platform handling of a device change event. |
| 152 void ProcessDevicesChanged(); | 156 void ProcessDevicesChanged(); |
| 153 void ProcessMediaDeviceAttached(const DeviceIdType& id, | 157 void ProcessMediaDeviceAttached(const DeviceIdType& id, |
| 154 const std::string& name, | 158 const std::string& name, |
| 155 const FilePath& path); | 159 const FilePath& path); |
| 156 void ProcessMediaDeviceDetached(const DeviceIdType& id); | 160 void ProcessMediaDeviceDetached(const DeviceIdType& id); |
| 157 | 161 |
| 162 // Returns information for attached media devices. |
| 163 std::vector<MediaDeviceInfo>* GetAttachedMediaDevices() const; |
| 164 |
| 158 // Enters or leaves a period of time with a given |requirement|. If the | 165 // Enters or leaves a period of time with a given |requirement|. If the |
| 159 // operation has multiple requirements, make sure to use a unique |reason| for | 166 // operation has multiple requirements, make sure to use a unique |reason| for |
| 160 // each one. Reusing the same |reason| is OK as far as the |requirement| is | 167 // each one. Reusing the same |reason| is OK as far as the |requirement| is |
| 161 // the same in every call, and each BeginPowerRequirement call is paired with | 168 // the same in every call, and each BeginPowerRequirement call is paired with |
| 162 // a call to EndPowerRequirement. |reason| is expected to be an ASCII string. | 169 // a call to EndPowerRequirement. |reason| is expected to be an ASCII string. |
| 163 // Must be called from the thread that created the SystemMonitor. | 170 // Must be called from the thread that created the SystemMonitor. |
| 164 // Warning: Please remember that sleep deprivation is not a good thing; use | 171 // Warning: Please remember that sleep deprivation is not a good thing; use |
| 165 // with caution. | 172 // with caution. |
| 166 void BeginPowerRequirement(PowerRequirement requirement, | 173 void BeginPowerRequirement(PowerRequirement requirement, |
| 167 const std::string& reason); | 174 const std::string& reason); |
| 168 void EndPowerRequirement(PowerRequirement requirement, | 175 void EndPowerRequirement(PowerRequirement requirement, |
| 169 const std::string& reason); | 176 const std::string& reason); |
| 170 | 177 |
| 171 // Returns the number of outsanding power requirement requests. | 178 // Returns the number of outsanding power requirement requests. |
| 172 size_t GetPowerRequirementsCountForTest() const; | 179 size_t GetPowerRequirementsCountForTest() const; |
| 173 | 180 |
| 174 private: | 181 private: |
| 182 typedef std::map<base::SystemMonitor::DeviceIdType, |
| 183 MediaDeviceInfo> MediaDeviceMap; |
| 175 #if defined(OS_MACOSX) | 184 #if defined(OS_MACOSX) |
| 176 void PlatformInit(); | 185 void PlatformInit(); |
| 177 void PlatformDestroy(); | 186 void PlatformDestroy(); |
| 178 #endif | 187 #endif |
| 179 | 188 |
| 180 // Platform-specific method to check whether the system is currently | 189 // Platform-specific method to check whether the system is currently |
| 181 // running on battery power. Returns true if running on batteries, | 190 // running on battery power. Returns true if running on batteries, |
| 182 // false otherwise. | 191 // false otherwise. |
| 183 bool IsBatteryPower(); | 192 bool IsBatteryPower(); |
| 184 | 193 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 204 | 213 |
| 205 #if defined(OS_WIN) | 214 #if defined(OS_WIN) |
| 206 std::map<std::string, std::pair<HANDLE, int> > handles_; | 215 std::map<std::string, std::pair<HANDLE, int> > handles_; |
| 207 base::ThreadChecker thread_checker_; | 216 base::ThreadChecker thread_checker_; |
| 208 #endif | 217 #endif |
| 209 | 218 |
| 210 #if defined(ENABLE_BATTERY_MONITORING) | 219 #if defined(ENABLE_BATTERY_MONITORING) |
| 211 base::OneShotTimer<SystemMonitor> delayed_battery_check_; | 220 base::OneShotTimer<SystemMonitor> delayed_battery_check_; |
| 212 #endif | 221 #endif |
| 213 | 222 |
| 223 MediaDeviceMap media_device_map_; |
| 224 |
| 214 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); | 225 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); |
| 215 }; | 226 }; |
| 216 | 227 |
| 217 } // namespace base | 228 } // namespace base |
| 218 | 229 |
| 219 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ | 230 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ |
| OLD | NEW |