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

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

Issue 10829384: SystemMonitor: Pull device type into the device id (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comment Created 8 years, 4 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
« no previous file with comments | « no previous file | base/system_monitor/system_monitor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 RESUME_EVENT // The system is being resumed. 51 RESUME_EVENT // The system is being resumed.
52 }; 52 };
53 53
54 // Type of devices whose change need to be monitored, such as add/remove. 54 // Type of devices whose change need to be monitored, such as add/remove.
55 enum DeviceType { 55 enum DeviceType {
56 DEVTYPE_AUDIO_CAPTURE, // Audio capture device, e.g., microphone. 56 DEVTYPE_AUDIO_CAPTURE, // Audio capture device, e.g., microphone.
57 DEVTYPE_VIDEO_CAPTURE, // Video capture device, e.g., webcam. 57 DEVTYPE_VIDEO_CAPTURE, // Video capture device, e.g., webcam.
58 DEVTYPE_UNKNOWN, // Other devices. 58 DEVTYPE_UNKNOWN, // Other devices.
59 }; 59 };
60 60
61 // Type of location data to identify a currently attached media device.
62 enum MediaDeviceType {
63 TYPE_PATH, // FilePath::StringType, e.g. a mount point.
64 TYPE_MTP, // (W)string to locate a MTP device, e.g. its usb bus/port.
65 };
66
67 struct BASE_EXPORT MediaDeviceInfo { 61 struct BASE_EXPORT MediaDeviceInfo {
68 MediaDeviceInfo(const std::string& id, 62 MediaDeviceInfo(const std::string& id,
69 const string16& device_name, 63 const string16& device_name,
70 MediaDeviceType device_type,
71 const FilePath::StringType& device_location); 64 const FilePath::StringType& device_location);
72 65
73 // Unique media device id - persists between device attachments. 66 // Unique media device id - persists between device attachments.
74 std::string unique_id; 67 std::string unique_id;
75 68
76 // Human readable media device name. 69 // Human readable media device name.
77 string16 name; 70 string16 name;
78 71
79 // Media device type.
80 MediaDeviceType type;
81
82 // Current attached media device location. 72 // Current attached media device location.
83 FilePath::StringType location; 73 FilePath::StringType location;
84 }; 74 };
85 75
86 // Create SystemMonitor. Only one SystemMonitor instance per application 76 // Create SystemMonitor. Only one SystemMonitor instance per application
87 // is allowed. 77 // is allowed.
88 SystemMonitor(); 78 SystemMonitor();
89 ~SystemMonitor(); 79 ~SystemMonitor();
90 80
91 // Get the application-wide SystemMonitor (if not present, returns NULL). 81 // Get the application-wide SystemMonitor (if not present, returns NULL).
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 class BASE_EXPORT DevicesChangedObserver { 131 class BASE_EXPORT DevicesChangedObserver {
142 public: 132 public:
143 // Notification that the devices connected to the system have changed. 133 // Notification that the devices connected to the system have changed.
144 // This is only implemented on Windows currently. 134 // This is only implemented on Windows currently.
145 virtual void OnDevicesChanged(DeviceType device_type) {} 135 virtual void OnDevicesChanged(DeviceType device_type) {}
146 136
147 // When a media device is attached or detached, one of these two events 137 // When a media device is attached or detached, one of these two events
148 // is triggered. 138 // is triggered.
149 virtual void OnMediaDeviceAttached(const std::string& id, 139 virtual void OnMediaDeviceAttached(const std::string& id,
150 const string16& name, 140 const string16& name,
151 MediaDeviceType type,
152 const FilePath::StringType& location) {} 141 const FilePath::StringType& location) {}
153 142
154 virtual void OnMediaDeviceDetached(const std::string& id) {} 143 virtual void OnMediaDeviceDetached(const std::string& id) {}
155 144
156 protected: 145 protected:
157 virtual ~DevicesChangedObserver() {} 146 virtual ~DevicesChangedObserver() {}
158 }; 147 };
159 148
160 // Add a new observer. 149 // Add a new observer.
161 // Can be called from any thread. 150 // Can be called from any thread.
(...skipping 14 matching lines...) Expand all
176 void ProcessWmPowerBroadcastMessage(int event_id); 165 void ProcessWmPowerBroadcastMessage(int event_id);
177 #endif 166 #endif
178 167
179 // Cross-platform handling of a power event. 168 // Cross-platform handling of a power event.
180 void ProcessPowerMessage(PowerEvent event_id); 169 void ProcessPowerMessage(PowerEvent event_id);
181 170
182 // Cross-platform handling of a device change event. 171 // Cross-platform handling of a device change event.
183 void ProcessDevicesChanged(DeviceType device_type); 172 void ProcessDevicesChanged(DeviceType device_type);
184 void ProcessMediaDeviceAttached(const std::string& id, 173 void ProcessMediaDeviceAttached(const std::string& id,
185 const string16& name, 174 const string16& name,
186 MediaDeviceType type,
187 const FilePath::StringType& location); 175 const FilePath::StringType& location);
188 void ProcessMediaDeviceDetached(const std::string& id); 176 void ProcessMediaDeviceDetached(const std::string& id);
189 177
190 private: 178 private:
191 // Mapping of unique device id to device info tuple. 179 // Mapping of unique device id to device info tuple.
192 typedef std::map<std::string, MediaDeviceInfo> MediaDeviceMap; 180 typedef std::map<std::string, MediaDeviceInfo> MediaDeviceMap;
193 181
194 #if defined(OS_MACOSX) 182 #if defined(OS_MACOSX)
195 void PlatformInit(); 183 void PlatformInit();
196 void PlatformDestroy(); 184 void PlatformDestroy();
197 #endif 185 #endif
198 186
199 // Platform-specific method to check whether the system is currently 187 // Platform-specific method to check whether the system is currently
200 // running on battery power. Returns true if running on batteries, 188 // running on battery power. Returns true if running on batteries,
201 // false otherwise. 189 // false otherwise.
202 bool IsBatteryPower(); 190 bool IsBatteryPower();
203 191
204 // Checks the battery status and notifies observers if the battery 192 // Checks the battery status and notifies observers if the battery
205 // status has changed. 193 // status has changed.
206 void BatteryCheck(); 194 void BatteryCheck();
207 195
208 // Functions to trigger notifications. 196 // Functions to trigger notifications.
209 void NotifyDevicesChanged(DeviceType device_type); 197 void NotifyDevicesChanged(DeviceType device_type);
210 void NotifyMediaDeviceAttached(const std::string& id, 198 void NotifyMediaDeviceAttached(const std::string& id,
211 const string16& name, 199 const string16& name,
212 MediaDeviceType type,
213 const FilePath::StringType& data); 200 const FilePath::StringType& data);
214 void NotifyMediaDeviceDetached(const std::string& id); 201 void NotifyMediaDeviceDetached(const std::string& id);
215 void NotifyPowerStateChange(); 202 void NotifyPowerStateChange();
216 void NotifySuspend(); 203 void NotifySuspend();
217 void NotifyResume(); 204 void NotifyResume();
218 205
219 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_; 206 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_;
220 scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> > 207 scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> >
221 devices_changed_observer_list_; 208 devices_changed_observer_list_;
222 bool battery_in_use_; 209 bool battery_in_use_;
(...skipping 10 matching lines...) Expand all
233 220
234 // Map of all the attached media devices. 221 // Map of all the attached media devices.
235 MediaDeviceMap media_device_map_; 222 MediaDeviceMap media_device_map_;
236 223
237 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); 224 DISALLOW_COPY_AND_ASSIGN(SystemMonitor);
238 }; 225 };
239 226
240 } // namespace base 227 } // namespace base
241 228
242 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ 229 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_
OLDNEW
« no previous file with comments | « no previous file | base/system_monitor/system_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698