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 DevicesChangedObserver { |
| 94 public: |
| 95 // Notification that the devices connected to the system have changed. |
| 96 virtual void OnDevicesChanged() {} |
| 97 |
| 98 protected: |
| 99 virtual ~DevicesChangedObserver() {} |
| 100 }; |
| 101 |
93 // Add a new observer. | 102 // Add a new observer. |
94 // Can be called from any thread. | 103 // Can be called from any thread. |
95 // Must not be called from within a notification callback. | 104 // Must not be called from within a notification callback. |
96 void AddObserver(PowerObserver* obs); | 105 void AddPowerObserver(PowerObserver* obs); |
| 106 void AddDevicesChangedObserver(DevicesChangedObserver* obs); |
97 | 107 |
98 // Remove an existing observer. | 108 // Remove an existing observer. |
99 // Can be called from any thread. | 109 // Can be called from any thread. |
100 // Must not be called from within a notification callback. | 110 // Must not be called from within a notification callback. |
101 void RemoveObserver(PowerObserver* obs); | 111 void RemovePowerObserver(PowerObserver* obs); |
| 112 void RemoveDevicesChangedObserver(DevicesChangedObserver* obs); |
102 | 113 |
103 #if defined(OS_WIN) | 114 #if defined(OS_WIN) |
104 // Windows-specific handling of a WM_POWERBROADCAST message. | 115 // Windows-specific handling of a WM_POWERBROADCAST message. |
105 // Embedders of this API should hook their top-level window | 116 // Embedders of this API should hook their top-level window |
106 // message loop and forward WM_POWERBROADCAST through this call. | 117 // message loop and forward WM_POWERBROADCAST through this call. |
107 void ProcessWmPowerBroadcastMessage(int event_id); | 118 void ProcessWmPowerBroadcastMessage(int event_id); |
108 #endif | 119 #endif |
109 | 120 |
110 // Cross-platform handling of a power event. | 121 // Cross-platform handling of a power event. |
111 void ProcessPowerMessage(PowerEvent event_id); | 122 void ProcessPowerMessage(PowerEvent event_id); |
112 | 123 |
| 124 // Cross-platform handling of a device change event. |
| 125 void ProcessDevicesChanged(); |
| 126 |
113 private: | 127 private: |
114 #if defined(OS_MACOSX) | 128 #if defined(OS_MACOSX) |
115 void PlatformInit(); | 129 void PlatformInit(); |
116 void PlatformDestroy(); | 130 void PlatformDestroy(); |
117 #endif | 131 #endif |
118 | 132 |
119 // Platform-specific method to check whether the system is currently | 133 // Platform-specific method to check whether the system is currently |
120 // running on battery power. Returns true if running on batteries, | 134 // running on battery power. Returns true if running on batteries, |
121 // false otherwise. | 135 // false otherwise. |
122 bool IsBatteryPower(); | 136 bool IsBatteryPower(); |
123 | 137 |
124 // Checks the battery status and notifies observers if the battery | 138 // Checks the battery status and notifies observers if the battery |
125 // status has changed. | 139 // status has changed. |
126 void BatteryCheck(); | 140 void BatteryCheck(); |
127 | 141 |
128 // Functions to trigger notifications. | 142 // Functions to trigger notifications. |
| 143 void NotifyDevicesChanged(); |
129 void NotifyPowerStateChange(); | 144 void NotifyPowerStateChange(); |
130 void NotifySuspend(); | 145 void NotifySuspend(); |
131 void NotifyResume(); | 146 void NotifyResume(); |
132 | 147 |
133 scoped_refptr<ObserverListThreadSafe<PowerObserver> > observer_list_; | 148 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_; |
| 149 scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> > |
| 150 devices_changed_observer_list_; |
134 bool battery_in_use_; | 151 bool battery_in_use_; |
135 bool suspended_; | 152 bool suspended_; |
136 | 153 |
137 #if defined(ENABLE_BATTERY_MONITORING) | 154 #if defined(ENABLE_BATTERY_MONITORING) |
138 base::OneShotTimer<SystemMonitor> delayed_battery_check_; | 155 base::OneShotTimer<SystemMonitor> delayed_battery_check_; |
139 #endif | 156 #endif |
140 | 157 |
141 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); | 158 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); |
142 }; | 159 }; |
143 | 160 |
144 } // namespace base | 161 } // namespace base |
145 | 162 |
146 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ | 163 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ |
OLD | NEW |