Chromium Code Reviews| 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_export.h" | 9 #include "base/base_export.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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() {} |
| 88 | 88 |
| 89 protected: | 89 protected: |
| 90 virtual ~PowerObserver() {} | 90 virtual ~PowerObserver() {} |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 class BASE_EXPORT DeviceChangeObserver { | |
| 94 public: | |
| 95 // Notification that the devices connected to the system have changed. | |
| 96 virtual void OnDeviceChange() {} | |
|
sky
2011/11/11 02:32:59
OnDevicesChanged?
scottmg
2011/11/11 05:06:09
Done.
| |
| 97 protected: | |
|
sky
2011/11/11 02:32:59
newline between 96 and 97
scottmg
2011/11/11 05:06:09
Done.
| |
| 98 virtual ~DeviceChangeObserver() {} | |
| 99 }; | |
| 100 | |
| 93 // Add a new observer. | 101 // Add a new observer. |
| 94 // Can be called from any thread. | 102 // Can be called from any thread. |
| 95 // Must not be called from within a notification callback. | 103 // Must not be called from within a notification callback. |
| 96 void AddObserver(PowerObserver* obs); | 104 void AddObserver(PowerObserver* obs); |
| 105 void AddObserver(DeviceChangeObserver* obs); | |
|
sky
2011/11/11 02:32:59
style guide recommends using different names for t
scottmg
2011/11/11 05:06:09
Sorry, couldn't find something that looked relevan
| |
| 97 | 106 |
| 98 // Remove an existing observer. | 107 // Remove an existing observer. |
| 99 // Can be called from any thread. | 108 // Can be called from any thread. |
| 100 // Must not be called from within a notification callback. | 109 // Must not be called from within a notification callback. |
| 101 void RemoveObserver(PowerObserver* obs); | 110 void RemoveObserver(PowerObserver* obs); |
| 111 void RemoveObserver(DeviceChangeObserver* obs); | |
| 102 | 112 |
| 103 #if defined(OS_WIN) | 113 #if defined(OS_WIN) |
| 104 // Windows-specific handling of a WM_POWERBROADCAST message. | 114 // Windows-specific handling of a WM_POWERBROADCAST message. |
| 105 // Embedders of this API should hook their top-level window | 115 // Embedders of this API should hook their top-level window |
| 106 // message loop and forward WM_POWERBROADCAST through this call. | 116 // message loop and forward WM_POWERBROADCAST through this call. |
| 107 void ProcessWmPowerBroadcastMessage(int event_id); | 117 void ProcessWmPowerBroadcastMessage(int event_id); |
| 108 #endif | 118 #endif |
| 109 | 119 |
| 110 // Cross-platform handling of a power event. | 120 // Cross-platform handling of a power event. |
| 111 void ProcessPowerMessage(PowerEvent event_id); | 121 void ProcessPowerMessage(PowerEvent event_id); |
| 112 | 122 |
| 123 // Cross-platform handling of a device change event. | |
| 124 void ProcessDeviceChange(); | |
|
sky
2011/11/11 02:32:59
ProcessDevicesChanged?
scottmg
2011/11/11 05:06:09
Done.
| |
| 125 | |
| 113 private: | 126 private: |
| 114 #if defined(OS_MACOSX) | 127 #if defined(OS_MACOSX) |
| 115 void PlatformInit(); | 128 void PlatformInit(); |
| 116 void PlatformDestroy(); | 129 void PlatformDestroy(); |
| 117 #endif | 130 #endif |
| 118 | 131 |
| 119 // Platform-specific method to check whether the system is currently | 132 // Platform-specific method to check whether the system is currently |
| 120 // running on battery power. Returns true if running on batteries, | 133 // running on battery power. Returns true if running on batteries, |
| 121 // false otherwise. | 134 // false otherwise. |
| 122 bool IsBatteryPower(); | 135 bool IsBatteryPower(); |
| 123 | 136 |
| 124 // Checks the battery status and notifies observers if the battery | 137 // Checks the battery status and notifies observers if the battery |
| 125 // status has changed. | 138 // status has changed. |
| 126 void BatteryCheck(); | 139 void BatteryCheck(); |
| 127 | 140 |
| 128 // Functions to trigger notifications. | 141 // Functions to trigger notifications. |
| 142 void NotifyDeviceChange(); | |
|
sky
2011/11/11 02:32:59
NotifyDevicesChanged
scottmg
2011/11/11 05:06:09
Done.
| |
| 129 void NotifyPowerStateChange(); | 143 void NotifyPowerStateChange(); |
| 130 void NotifySuspend(); | 144 void NotifySuspend(); |
| 131 void NotifyResume(); | 145 void NotifyResume(); |
| 132 | 146 |
| 133 scoped_refptr<ObserverListThreadSafe<PowerObserver> > observer_list_; | 147 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_; |
| 148 scoped_refptr<ObserverListThreadSafe<DeviceChangeObserver> > | |
| 149 device_change_observer_list_; | |
| 134 bool battery_in_use_; | 150 bool battery_in_use_; |
| 135 bool suspended_; | 151 bool suspended_; |
| 136 | 152 |
| 137 #if defined(ENABLE_BATTERY_MONITORING) | 153 #if defined(ENABLE_BATTERY_MONITORING) |
| 138 base::OneShotTimer<SystemMonitor> delayed_battery_check_; | 154 base::OneShotTimer<SystemMonitor> delayed_battery_check_; |
| 139 #endif | 155 #endif |
| 140 | 156 |
| 141 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); | 157 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); |
| 142 }; | 158 }; |
| 143 | 159 |
| 144 } // namespace base | 160 } // namespace base |
| 145 | 161 |
| 146 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ | 162 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ |
| OLD | NEW |