Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Side by Side Diff: base/system_monitor/system_monitor.h

Issue 10780023: Change base::SystemMonitor's media device functions to take a type and string16 instead of a FilePa… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix win Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 7
8 #include <map>
8 #include <string> 9 #include <string>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/base_export.h" 12 #include "base/base_export.h"
12 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/string16.h"
13 #include "base/tuple.h" 15 #include "base/tuple.h"
14 #include "build/build_config.h" 16 #include "build/build_config.h"
15 17
16 // 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
17 // status. This isn't true for other platforms. 19 // status. This isn't true for other platforms.
18 #if defined(OS_WIN) 20 #if defined(OS_WIN)
19 #define ENABLE_BATTERY_MONITORING 1 21 #define ENABLE_BATTERY_MONITORING 1
20 #else 22 #else
21 #undef ENABLE_BATTERY_MONITORING 23 #undef ENABLE_BATTERY_MONITORING
22 #endif // !OS_WIN 24 #endif // !OS_WIN
23 25
24 #include "base/observer_list_threadsafe.h" 26 #include "base/observer_list_threadsafe.h"
25 #if defined(ENABLE_BATTERY_MONITORING) 27 #if defined(ENABLE_BATTERY_MONITORING)
26 #include "base/timer.h" 28 #include "base/timer.h"
27 #endif // defined(ENABLE_BATTERY_MONITORING) 29 #endif // defined(ENABLE_BATTERY_MONITORING)
28 30
29 #if defined(OS_MACOSX) && !defined(OS_IOS) 31 #if defined(OS_MACOSX) && !defined(OS_IOS)
30 #include <IOKit/pwr_mgt/IOPMLib.h> 32 #include <IOKit/pwr_mgt/IOPMLib.h>
31 #include <IOKit/IOMessage.h> 33 #include <IOKit/IOMessage.h>
32 #endif // OS_MACOSX && !OS_IOS 34 #endif // OS_MACOSX && !OS_IOS
33 35
34 #if defined(OS_IOS) 36 #if defined(OS_IOS)
35 #include <objc/runtime.h> 37 #include <objc/runtime.h>
36 #endif // OS_IOS 38 #endif // OS_IOS
37 39
38 class FilePath;
39
40 namespace base { 40 namespace base {
41 41
42 // Class for monitoring various system-related subsystems 42 // Class for monitoring various system-related subsystems
43 // such as power management, network status, etc. 43 // such as power management, network status, etc.
44 // TODO(mbelshe): Add support beyond just power management. 44 // TODO(mbelshe): Add support beyond just power management.
45 class BASE_EXPORT SystemMonitor { 45 class BASE_EXPORT SystemMonitor {
46 public: 46 public:
47 // Normalized list of power events. 47 // Normalized list of power events.
48 enum PowerEvent { 48 enum PowerEvent {
49 POWER_STATE_EVENT, // The Power status of the system has changed. 49 POWER_STATE_EVENT, // The Power status of the system has changed.
50 SUSPEND_EVENT, // The system is being suspended. 50 SUSPEND_EVENT, // The system is being suspended.
51 RESUME_EVENT // The system is being resumed. 51 RESUME_EVENT // The system is being resumed.
52 }; 52 };
53 53
54 enum MediaDeviceType {
55 TYPE_PATH,
56 TYPE_MTP,
57 };
58
54 typedef unsigned int DeviceIdType; 59 typedef unsigned int DeviceIdType;
vandebo (ex-Chrome) 2012/07/19 19:05:20 With unique_id being a string, I think you can get
Lei Zhang 2012/07/19 23:07:25 Done.
55 // (Media device id, Media device name, Media device path) 60 // (Media device id, Media device name, Media device type, Media device data)
56 typedef Tuple3<DeviceIdType, std::string, FilePath> MediaDeviceInfo; 61 typedef Tuple4<DeviceIdType, std::string, MediaDeviceType, string16>
vandebo (ex-Chrome) 2012/07/19 19:05:20 Why a Tuple4 and not just a struct?
Lei Zhang 2012/07/19 21:17:10 Because you were ok with a Tuple3 in the previous
62 MediaDeviceInfo;
57 63
58 // Create SystemMonitor. Only one SystemMonitor instance per application 64 // Create SystemMonitor. Only one SystemMonitor instance per application
59 // is allowed. 65 // is allowed.
60 SystemMonitor(); 66 SystemMonitor();
61 ~SystemMonitor(); 67 ~SystemMonitor();
62 68
63 // Get the application-wide SystemMonitor (if not present, returns NULL). 69 // Get the application-wide SystemMonitor (if not present, returns NULL).
64 static SystemMonitor* Get(); 70 static SystemMonitor* Get();
65 71
66 #if defined(OS_MACOSX) 72 #if defined(OS_MACOSX)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 }; 114 };
109 115
110 class BASE_EXPORT DevicesChangedObserver { 116 class BASE_EXPORT DevicesChangedObserver {
111 public: 117 public:
112 // Notification that the devices connected to the system have changed. 118 // Notification that the devices connected to the system have changed.
113 // This is only implemented on Windows currently. 119 // This is only implemented on Windows currently.
114 virtual void OnDevicesChanged() {} 120 virtual void OnDevicesChanged() {}
115 121
116 // When a media device is attached or detached, one of these two events 122 // When a media device is attached or detached, one of these two events
117 // is triggered. 123 // is triggered.
118 // TODO(vandebo) Pass an appropriate device identifier or way to interact
119 // with the devices instead of FilePath.
120 virtual void OnMediaDeviceAttached(const DeviceIdType& id, 124 virtual void OnMediaDeviceAttached(const DeviceIdType& id,
121 const std::string& name, 125 const std::string& name,
122 const FilePath& path) {} 126 MediaDeviceType type,
127 const string16& data) {}
123 128
124 virtual void OnMediaDeviceDetached(const DeviceIdType& id) {} 129 virtual void OnMediaDeviceDetached(const DeviceIdType& id) {}
125 130
126 protected: 131 protected:
127 virtual ~DevicesChangedObserver() {} 132 virtual ~DevicesChangedObserver() {}
128 }; 133 };
129 134
130 // Add a new observer. 135 // Add a new observer.
131 // Can be called from any thread. 136 // Can be called from any thread.
132 // Must not be called from within a notification callback. 137 // Must not be called from within a notification callback.
(...skipping 13 matching lines...) Expand all
146 void ProcessWmPowerBroadcastMessage(int event_id); 151 void ProcessWmPowerBroadcastMessage(int event_id);
147 #endif 152 #endif
148 153
149 // Cross-platform handling of a power event. 154 // Cross-platform handling of a power event.
150 void ProcessPowerMessage(PowerEvent event_id); 155 void ProcessPowerMessage(PowerEvent event_id);
151 156
152 // Cross-platform handling of a device change event. 157 // Cross-platform handling of a device change event.
153 void ProcessDevicesChanged(); 158 void ProcessDevicesChanged();
154 void ProcessMediaDeviceAttached(const DeviceIdType& id, 159 void ProcessMediaDeviceAttached(const DeviceIdType& id,
155 const std::string& name, 160 const std::string& name,
156 const FilePath& path); 161 MediaDeviceType type,
162 const string16& data);
163 #if defined(OS_POSIX)
164 // Provided for convenience.
165 void ProcessMediaDeviceAttached(const DeviceIdType& id,
166 const std::string& name,
167 MediaDeviceType type,
168 const std::string& data);
169 #endif
157 void ProcessMediaDeviceDetached(const DeviceIdType& id); 170 void ProcessMediaDeviceDetached(const DeviceIdType& id);
158 171
159 // Returns information for attached media devices. 172 // Returns information for attached media devices.
160 std::vector<MediaDeviceInfo> GetAttachedMediaDevices() const; 173 std::vector<MediaDeviceInfo> GetAttachedMediaDevices() const;
vandebo (ex-Chrome) 2012/07/19 19:05:20 This being down here implies that it's intended no
Lei Zhang 2012/07/19 23:07:25 Done.
161 174
162 private: 175 private:
163 typedef std::map<base::SystemMonitor::DeviceIdType, 176 typedef std::map<base::SystemMonitor::DeviceIdType,
164 MediaDeviceInfo> MediaDeviceMap; 177 MediaDeviceInfo> MediaDeviceMap;
165 #if defined(OS_MACOSX) 178 #if defined(OS_MACOSX)
166 void PlatformInit(); 179 void PlatformInit();
167 void PlatformDestroy(); 180 void PlatformDestroy();
168 #endif 181 #endif
169 182
170 // Platform-specific method to check whether the system is currently 183 // Platform-specific method to check whether the system is currently
171 // running on battery power. Returns true if running on batteries, 184 // running on battery power. Returns true if running on batteries,
172 // false otherwise. 185 // false otherwise.
173 bool IsBatteryPower(); 186 bool IsBatteryPower();
174 187
175 // Checks the battery status and notifies observers if the battery 188 // Checks the battery status and notifies observers if the battery
176 // status has changed. 189 // status has changed.
177 void BatteryCheck(); 190 void BatteryCheck();
178 191
179 // Functions to trigger notifications. 192 // Functions to trigger notifications.
180 void NotifyDevicesChanged(); 193 void NotifyDevicesChanged();
181 void NotifyMediaDeviceAttached(const DeviceIdType& id, 194 void NotifyMediaDeviceAttached(const DeviceIdType& id,
182 const std::string& name, 195 const std::string& name,
183 const FilePath& path); 196 MediaDeviceType type,
197 const string16& data);
184 void NotifyMediaDeviceDetached(const DeviceIdType& id); 198 void NotifyMediaDeviceDetached(const DeviceIdType& id);
185 void NotifyPowerStateChange(); 199 void NotifyPowerStateChange();
186 void NotifySuspend(); 200 void NotifySuspend();
187 void NotifyResume(); 201 void NotifyResume();
188 202
189 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_; 203 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_;
190 scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> > 204 scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> >
191 devices_changed_observer_list_; 205 devices_changed_observer_list_;
192 bool battery_in_use_; 206 bool battery_in_use_;
193 bool suspended_; 207 bool suspended_;
194 208
195 #if defined(ENABLE_BATTERY_MONITORING) 209 #if defined(ENABLE_BATTERY_MONITORING)
196 base::OneShotTimer<SystemMonitor> delayed_battery_check_; 210 base::OneShotTimer<SystemMonitor> delayed_battery_check_;
197 #endif 211 #endif
198 212
199 #if defined(OS_IOS) 213 #if defined(OS_IOS)
200 // Holds pointers to system event notification observers. 214 // Holds pointers to system event notification observers.
201 std::vector<id> notification_observers_; 215 std::vector<id> notification_observers_;
202 #endif 216 #endif
203 217
204 MediaDeviceMap media_device_map_; 218 MediaDeviceMap media_device_map_;
205 219
206 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); 220 DISALLOW_COPY_AND_ASSIGN(SystemMonitor);
207 }; 221 };
208 222
209 } // namespace base 223 } // namespace base
210 224
211 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ 225 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_
OLDNEW
« no previous file with comments | « no previous file | base/system_monitor/system_monitor.cc » ('j') | base/system_monitor/system_monitor.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698