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

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

Issue 11573048: [Media Galleries] Move RemovableStorageInfo notifications to chrome namespace (part 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to head Created 7 years, 11 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 <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 RESUME_EVENT // The system is being resumed. 52 RESUME_EVENT // The system is being resumed.
53 }; 53 };
54 54
55 // Type of devices whose change need to be monitored, such as add/remove. 55 // Type of devices whose change need to be monitored, such as add/remove.
56 enum DeviceType { 56 enum DeviceType {
57 DEVTYPE_AUDIO_CAPTURE, // Audio capture device, e.g., microphone. 57 DEVTYPE_AUDIO_CAPTURE, // Audio capture device, e.g., microphone.
58 DEVTYPE_VIDEO_CAPTURE, // Video capture device, e.g., webcam. 58 DEVTYPE_VIDEO_CAPTURE, // Video capture device, e.g., webcam.
59 DEVTYPE_UNKNOWN, // Other devices. 59 DEVTYPE_UNKNOWN, // Other devices.
60 }; 60 };
61 61
62 struct BASE_EXPORT RemovableStorageInfo {
63 RemovableStorageInfo();
64 RemovableStorageInfo(const std::string& id,
65 const string16& device_name,
66 const FilePath::StringType& device_location);
67
68 // Unique device id - persists between device attachments.
69 std::string device_id;
70
71 // Human readable removable storage device name.
72 string16 name;
73
74 // Current attached removable storage device location.
75 FilePath::StringType location;
76 };
77
78 // Create SystemMonitor. Only one SystemMonitor instance per application 62 // Create SystemMonitor. Only one SystemMonitor instance per application
79 // is allowed. 63 // is allowed.
80 SystemMonitor(); 64 SystemMonitor();
81 ~SystemMonitor(); 65 ~SystemMonitor();
82 66
83 // Get the application-wide SystemMonitor (if not present, returns NULL). 67 // Get the application-wide SystemMonitor (if not present, returns NULL).
84 static SystemMonitor* Get(); 68 static SystemMonitor* Get();
85 69
86 #if defined(OS_MACOSX) 70 #if defined(OS_MACOSX)
87 // Allocate system resources needed by the SystemMonitor class. 71 // Allocate system resources needed by the SystemMonitor class.
88 // 72 //
89 // This function must be called before instantiating an instance of the class 73 // This function must be called before instantiating an instance of the class
90 // and before the Sandbox is initialized. 74 // and before the Sandbox is initialized.
91 #if !defined(OS_IOS) 75 #if !defined(OS_IOS)
92 static void AllocateSystemIOPorts(); 76 static void AllocateSystemIOPorts();
93 #else 77 #else
94 static void AllocateSystemIOPorts() {} 78 static void AllocateSystemIOPorts() {}
95 #endif // OS_IOS 79 #endif // OS_IOS
96 #endif // OS_MACOSX 80 #endif // OS_MACOSX
97 81
98 // Returns information for attached removable storage.
99 std::vector<RemovableStorageInfo> GetAttachedRemovableStorage() const;
100
101 // 82 //
102 // Power-related APIs 83 // Power-related APIs
103 // 84 //
104 85
105 // Is the computer currently on battery power. 86 // Is the computer currently on battery power.
106 // Can be called on any thread. 87 // Can be called on any thread.
107 bool BatteryPower() const { 88 bool BatteryPower() const {
108 // Using a lock here is not necessary for just a bool. 89 // Using a lock here is not necessary for just a bool.
109 return battery_in_use_; 90 return battery_in_use_;
110 } 91 }
(...skipping 18 matching lines...) Expand all
129 protected: 110 protected:
130 virtual ~PowerObserver() {} 111 virtual ~PowerObserver() {}
131 }; 112 };
132 113
133 class BASE_EXPORT DevicesChangedObserver { 114 class BASE_EXPORT DevicesChangedObserver {
134 public: 115 public:
135 // Notification that the devices connected to the system have changed. 116 // Notification that the devices connected to the system have changed.
136 // This is only implemented on Windows currently. 117 // This is only implemented on Windows currently.
137 virtual void OnDevicesChanged(DeviceType device_type) {} 118 virtual void OnDevicesChanged(DeviceType device_type) {}
138 119
139 // When a removable storage device is attached or detached, one of these
140 // two events is triggered.
141 virtual void OnRemovableStorageAttached(
142 const std::string& id,
143 const string16& name,
144 const FilePath::StringType& location) {}
145 virtual void OnRemovableStorageDetached(const std::string& id) {}
146
147 protected: 120 protected:
148 virtual ~DevicesChangedObserver() {} 121 virtual ~DevicesChangedObserver() {}
149 }; 122 };
150 123
151 // Add a new observer. 124 // Add a new observer.
152 // Can be called from any thread. 125 // Can be called from any thread.
153 // Must not be called from within a notification callback. 126 // Must not be called from within a notification callback.
154 void AddPowerObserver(PowerObserver* obs); 127 void AddPowerObserver(PowerObserver* obs);
155 void AddDevicesChangedObserver(DevicesChangedObserver* obs); 128 void AddDevicesChangedObserver(DevicesChangedObserver* obs);
156 129
(...skipping 12 matching lines...) Expand all
169 // Embedders of this API should hook their top-level window 142 // Embedders of this API should hook their top-level window
170 // message loop and forward WM_POWERBROADCAST through this call. 143 // message loop and forward WM_POWERBROADCAST through this call.
171 void ProcessWmPowerBroadcastMessage(int event_id); 144 void ProcessWmPowerBroadcastMessage(int event_id);
172 #endif 145 #endif
173 146
174 // Cross-platform handling of a power event. 147 // Cross-platform handling of a power event.
175 void ProcessPowerMessage(PowerEvent event_id); 148 void ProcessPowerMessage(PowerEvent event_id);
176 149
177 // Cross-platform handling of a device change event. 150 // Cross-platform handling of a device change event.
178 void ProcessDevicesChanged(DeviceType device_type); 151 void ProcessDevicesChanged(DeviceType device_type);
179 void ProcessRemovableStorageAttached(const std::string& id,
180 const string16& name,
181 const FilePath::StringType& location);
182 void ProcessRemovableStorageDetached(const std::string& id);
183 152
184 private: 153 private:
185 // Mapping of unique device id to device info tuple.
186 typedef std::map<std::string, RemovableStorageInfo> RemovableStorageMap;
187
188 #if defined(OS_MACOSX) 154 #if defined(OS_MACOSX)
189 void PlatformInit(); 155 void PlatformInit();
190 void PlatformDestroy(); 156 void PlatformDestroy();
191 #endif 157 #endif
192 158
193 // Platform-specific method to check whether the system is currently 159 // Platform-specific method to check whether the system is currently
194 // running on battery power. Returns true if running on batteries, 160 // running on battery power. Returns true if running on batteries,
195 // false otherwise. 161 // false otherwise.
196 bool IsBatteryPower(); 162 bool IsBatteryPower();
197 163
198 // Checks the battery status and notifies observers if the battery 164 // Checks the battery status and notifies observers if the battery
199 // status has changed. 165 // status has changed.
200 void BatteryCheck(); 166 void BatteryCheck();
201 167
202 // Functions to trigger notifications. 168 // Functions to trigger notifications.
203 void NotifyDevicesChanged(DeviceType device_type); 169 void NotifyDevicesChanged(DeviceType device_type);
204 void NotifyRemovableStorageAttached(const std::string& id,
205 const string16& name,
206 const FilePath::StringType& location);
207 void NotifyRemovableStorageDetached(const std::string& id);
208 void NotifyPowerStateChange(); 170 void NotifyPowerStateChange();
209 void NotifySuspend(); 171 void NotifySuspend();
210 void NotifyResume(); 172 void NotifyResume();
211 173
212 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_; 174 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_;
213 scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> > 175 scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> >
214 devices_changed_observer_list_; 176 devices_changed_observer_list_;
215 bool battery_in_use_; 177 bool battery_in_use_;
216 bool suspended_; 178 bool suspended_;
217 179
218 #if defined(ENABLE_BATTERY_MONITORING) 180 #if defined(ENABLE_BATTERY_MONITORING)
219 base::OneShotTimer<SystemMonitor> delayed_battery_check_; 181 base::OneShotTimer<SystemMonitor> delayed_battery_check_;
220 #endif 182 #endif
221 183
222 #if defined(OS_IOS) 184 #if defined(OS_IOS)
223 // Holds pointers to system event notification observers. 185 // Holds pointers to system event notification observers.
224 std::vector<id> notification_observers_; 186 std::vector<id> notification_observers_;
225 #endif 187 #endif
226 188
227 // For manipulating removable_storage_map_ structure.
228 mutable base::Lock removable_storage_lock_;
229 // Map of all the attached removable storage devices.
230 RemovableStorageMap removable_storage_map_;
231
232 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); 189 DISALLOW_COPY_AND_ASSIGN(SystemMonitor);
233 }; 190 };
234 191
235 } // namespace base 192 } // namespace base
236 193
237 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ 194 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698