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 <string> | 10 #include <string> |
11 #include <vector> | |
10 | 12 |
11 #include "base/base_export.h" | 13 #include "base/base_export.h" |
12 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/tuple.h" | |
13 #include "build/build_config.h" | 16 #include "build/build_config.h" |
14 | 17 |
15 // Windows HiRes timers drain the battery faster so we need to know the battery | 18 // Windows HiRes timers drain the battery faster so we need to know the battery |
16 // status. This isn't true for other platforms. | 19 // status. This isn't true for other platforms. |
17 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
18 #define ENABLE_BATTERY_MONITORING 1 | 21 #define ENABLE_BATTERY_MONITORING 1 |
19 #else | 22 #else |
20 #undef ENABLE_BATTERY_MONITORING | 23 #undef ENABLE_BATTERY_MONITORING |
21 #endif // !OS_WIN | 24 #endif // !OS_WIN |
22 | 25 |
(...skipping 17 matching lines...) Expand all Loading... | |
40 class BASE_EXPORT SystemMonitor { | 43 class BASE_EXPORT SystemMonitor { |
41 public: | 44 public: |
42 // Normalized list of power events. | 45 // Normalized list of power events. |
43 enum PowerEvent { | 46 enum PowerEvent { |
44 POWER_STATE_EVENT, // The Power status of the system has changed. | 47 POWER_STATE_EVENT, // The Power status of the system has changed. |
45 SUSPEND_EVENT, // The system is being suspended. | 48 SUSPEND_EVENT, // The system is being suspended. |
46 RESUME_EVENT // The system is being resumed. | 49 RESUME_EVENT // The system is being resumed. |
47 }; | 50 }; |
48 | 51 |
49 typedef unsigned int DeviceIdType; | 52 typedef unsigned int DeviceIdType; |
53 // (Media device id, Media device name, Media device path) | |
54 typedef Tuple3<DeviceIdType, std::string, FilePath> MediaDeviceInfo; | |
50 | 55 |
51 // Create SystemMonitor. Only one SystemMonitor instance per application | 56 // Create SystemMonitor. Only one SystemMonitor instance per application |
52 // is allowed. | 57 // is allowed. |
53 SystemMonitor(); | 58 SystemMonitor(); |
54 ~SystemMonitor(); | 59 ~SystemMonitor(); |
55 | 60 |
56 // Get the application-wide SystemMonitor (if not present, returns NULL). | 61 // Get the application-wide SystemMonitor (if not present, returns NULL). |
57 static SystemMonitor* Get(); | 62 static SystemMonitor* Get(); |
58 | 63 |
59 #if defined(OS_MACOSX) | 64 #if defined(OS_MACOSX) |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 // Cross-platform handling of a power event. | 143 // Cross-platform handling of a power event. |
139 void ProcessPowerMessage(PowerEvent event_id); | 144 void ProcessPowerMessage(PowerEvent event_id); |
140 | 145 |
141 // Cross-platform handling of a device change event. | 146 // Cross-platform handling of a device change event. |
142 void ProcessDevicesChanged(); | 147 void ProcessDevicesChanged(); |
143 void ProcessMediaDeviceAttached(const DeviceIdType& id, | 148 void ProcessMediaDeviceAttached(const DeviceIdType& id, |
144 const std::string& name, | 149 const std::string& name, |
145 const FilePath& path); | 150 const FilePath& path); |
146 void ProcessMediaDeviceDetached(const DeviceIdType& id); | 151 void ProcessMediaDeviceDetached(const DeviceIdType& id); |
147 | 152 |
153 // Appends info for attached media devices to |results|. | |
willchan no longer on Chromium
2012/05/21 05:32:36
Is there a reason you don't just return std::vecto
Lei Zhang
2012/05/21 19:42:06
Done.
A lot of our code in our code base does it
willchan no longer on Chromium
2012/05/21 20:24:34
You're right that our existing code generally uses
| |
154 void GetAttachedMediaDevices(std::vector<MediaDeviceInfo>* results); | |
155 | |
148 private: | 156 private: |
157 typedef std::map<base::SystemMonitor::DeviceIdType, | |
158 MediaDeviceInfo> MediaDeviceMap; | |
149 #if defined(OS_MACOSX) | 159 #if defined(OS_MACOSX) |
150 void PlatformInit(); | 160 void PlatformInit(); |
151 void PlatformDestroy(); | 161 void PlatformDestroy(); |
152 #endif | 162 #endif |
153 | 163 |
154 // Platform-specific method to check whether the system is currently | 164 // Platform-specific method to check whether the system is currently |
155 // running on battery power. Returns true if running on batteries, | 165 // running on battery power. Returns true if running on batteries, |
156 // false otherwise. | 166 // false otherwise. |
157 bool IsBatteryPower(); | 167 bool IsBatteryPower(); |
158 | 168 |
(...skipping 14 matching lines...) Expand all Loading... | |
173 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_; | 183 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_; |
174 scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> > | 184 scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> > |
175 devices_changed_observer_list_; | 185 devices_changed_observer_list_; |
176 bool battery_in_use_; | 186 bool battery_in_use_; |
177 bool suspended_; | 187 bool suspended_; |
178 | 188 |
179 #if defined(ENABLE_BATTERY_MONITORING) | 189 #if defined(ENABLE_BATTERY_MONITORING) |
180 base::OneShotTimer<SystemMonitor> delayed_battery_check_; | 190 base::OneShotTimer<SystemMonitor> delayed_battery_check_; |
181 #endif | 191 #endif |
182 | 192 |
193 MediaDeviceMap media_device_map_; | |
194 | |
183 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); | 195 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); |
184 }; | 196 }; |
185 | 197 |
186 } // namespace base | 198 } // namespace base |
187 | 199 |
188 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ | 200 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ |
OLD | NEW |