| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/base_api.h" | 9 #include "base/base_export.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 | 12 |
| 13 // Windows HiRes timers drain the battery faster so we need to know the battery | 13 // Windows HiRes timers drain the battery faster so we need to know the battery |
| 14 // status. This isn't true for other platforms. | 14 // status. This isn't true for other platforms. |
| 15 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
| 16 #define ENABLE_BATTERY_MONITORING 1 | 16 #define ENABLE_BATTERY_MONITORING 1 |
| 17 #else | 17 #else |
| 18 #undef ENABLE_BATTERY_MONITORING | 18 #undef ENABLE_BATTERY_MONITORING |
| 19 #endif // !OS_WIN | 19 #endif // !OS_WIN |
| 20 | 20 |
| 21 #include "base/observer_list_threadsafe.h" | 21 #include "base/observer_list_threadsafe.h" |
| 22 #if defined(ENABLE_BATTERY_MONITORING) | 22 #if defined(ENABLE_BATTERY_MONITORING) |
| 23 #include "base/timer.h" | 23 #include "base/timer.h" |
| 24 #endif // defined(ENABLE_BATTERY_MONITORING) | 24 #endif // defined(ENABLE_BATTERY_MONITORING) |
| 25 | 25 |
| 26 #if defined(OS_MACOSX) | 26 #if defined(OS_MACOSX) |
| 27 #include <IOKit/pwr_mgt/IOPMLib.h> | 27 #include <IOKit/pwr_mgt/IOPMLib.h> |
| 28 #include <IOKit/IOMessage.h> | 28 #include <IOKit/IOMessage.h> |
| 29 #endif // OS_MACOSX | 29 #endif // OS_MACOSX |
| 30 | 30 |
| 31 namespace base { | 31 namespace base { |
| 32 | 32 |
| 33 // Class for monitoring various system-related subsystems | 33 // Class for monitoring various system-related subsystems |
| 34 // such as power management, network status, etc. | 34 // such as power management, network status, etc. |
| 35 // TODO(mbelshe): Add support beyond just power management. | 35 // TODO(mbelshe): Add support beyond just power management. |
| 36 class BASE_API SystemMonitor { | 36 class BASE_EXPORT SystemMonitor { |
| 37 public: | 37 public: |
| 38 // Normalized list of power events. | 38 // Normalized list of power events. |
| 39 enum PowerEvent { | 39 enum PowerEvent { |
| 40 POWER_STATE_EVENT, // The Power status of the system has changed. | 40 POWER_STATE_EVENT, // The Power status of the system has changed. |
| 41 SUSPEND_EVENT, // The system is being suspended. | 41 SUSPEND_EVENT, // The system is being suspended. |
| 42 RESUME_EVENT // The system is being resumed. | 42 RESUME_EVENT // The system is being resumed. |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 // Create SystemMonitor. Only one SystemMonitor instance per application | 45 // Create SystemMonitor. Only one SystemMonitor instance per application |
| 46 // is allowed. | 46 // is allowed. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 67 bool BatteryPower() const { | 67 bool BatteryPower() const { |
| 68 // Using a lock here is not necessary for just a bool. | 68 // Using a lock here is not necessary for just a bool. |
| 69 return battery_in_use_; | 69 return battery_in_use_; |
| 70 } | 70 } |
| 71 | 71 |
| 72 // Callbacks will be called on the thread which creates the SystemMonitor. | 72 // Callbacks will be called on the thread which creates the SystemMonitor. |
| 73 // During the callback, Add/RemoveObserver will block until the callbacks | 73 // During the callback, Add/RemoveObserver will block until the callbacks |
| 74 // are finished. Observers should implement quick callback functions; if | 74 // are finished. Observers should implement quick callback functions; if |
| 75 // lengthy operations are needed, the observer should take care to invoke | 75 // lengthy operations are needed, the observer should take care to invoke |
| 76 // the operation on an appropriate thread. | 76 // the operation on an appropriate thread. |
| 77 class BASE_API PowerObserver { | 77 class BASE_EXPORT PowerObserver { |
| 78 public: | 78 public: |
| 79 // Notification of a change in power status of the computer, such | 79 // Notification of a change in power status of the computer, such |
| 80 // as from switching between battery and A/C power. | 80 // as from switching between battery and A/C power. |
| 81 virtual void OnPowerStateChange(bool on_battery_power) {} | 81 virtual void OnPowerStateChange(bool on_battery_power) {} |
| 82 | 82 |
| 83 // Notification that the system is suspending. | 83 // Notification that the system is suspending. |
| 84 virtual void OnSuspend() {} | 84 virtual void OnSuspend() {} |
| 85 | 85 |
| 86 // Notification that the system is resuming. | 86 // Notification that the system is resuming. |
| 87 virtual void OnResume() {} | 87 virtual void OnResume() {} |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 #if defined(ENABLE_BATTERY_MONITORING) | 137 #if defined(ENABLE_BATTERY_MONITORING) |
| 138 base::OneShotTimer<SystemMonitor> delayed_battery_check_; | 138 base::OneShotTimer<SystemMonitor> delayed_battery_check_; |
| 139 #endif | 139 #endif |
| 140 | 140 |
| 141 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); | 141 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); |
| 142 }; | 142 }; |
| 143 | 143 |
| 144 } // namespace base | 144 } // namespace base |
| 145 | 145 |
| 146 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ | 146 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ |
| OLD | NEW |