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 CHROMEOS_DISKS_DISK_MOUNT_MANAGER_H_ | 5 #ifndef CHROMEOS_DISKS_DISK_MOUNT_MANAGER_H_ |
6 #define CHROMEOS_DISKS_DISK_MOUNT_MANAGER_H_ | 6 #define CHROMEOS_DISKS_DISK_MOUNT_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "chromeos/chromeos_export.h" | 10 #include "chromeos/chromeos_export.h" |
11 #include "chromeos/dbus/cros_disks_client.h" | 11 #include "chromeos/dbus/cros_disks_client.h" |
12 | 12 |
13 namespace chromeos { | 13 namespace chromeos { |
14 namespace disks { | 14 namespace disks { |
15 | 15 |
16 // Types of events DiskMountManager sends to its observers. | |
17 enum DiskMountManagerEventType { | |
18 MOUNT_DISK_ADDED, | |
19 MOUNT_DISK_REMOVED, | |
20 MOUNT_DISK_CHANGED, | |
21 MOUNT_DISK_MOUNTED, | |
22 MOUNT_DISK_UNMOUNTED, | |
23 MOUNT_DEVICE_ADDED, | |
24 MOUNT_DEVICE_REMOVED, | |
25 MOUNT_DEVICE_SCANNED, | |
26 MOUNT_FORMATTING_STARTED, | |
27 MOUNT_FORMATTING_FINISHED, | |
28 }; | |
29 | |
30 // Condition of mounted filesystem. | 16 // Condition of mounted filesystem. |
31 enum MountCondition { | 17 enum MountCondition { |
32 MOUNT_CONDITION_NONE, | 18 MOUNT_CONDITION_NONE, |
33 MOUNT_CONDITION_UNKNOWN_FILESYSTEM, | 19 MOUNT_CONDITION_UNKNOWN_FILESYSTEM, |
34 MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM, | 20 MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM, |
35 }; | 21 }; |
36 | 22 |
37 // This class handles the interaction with cros-disks. | 23 // This class handles the interaction with cros-disks. |
38 // Other classes can add themselves as observers. | 24 // Other classes can add themselves as observers. |
39 class CHROMEOS_EXPORT DiskMountManager { | 25 class CHROMEOS_EXPORT DiskMountManager { |
40 public: | 26 public: |
41 // Event type given to observers' MountCompleted method. | 27 // Event types passed to the observers. |
| 28 enum DiskEvent { |
| 29 DISK_ADDED, |
| 30 DISK_REMOVED, |
| 31 DISK_CHANGED, |
| 32 }; |
| 33 |
| 34 enum DeviceEvent { |
| 35 DEVICE_ADDED, |
| 36 DEVICE_REMOVED, |
| 37 DEVICE_SCANNED, |
| 38 }; |
| 39 |
42 enum MountEvent { | 40 enum MountEvent { |
43 MOUNTING, | 41 MOUNTING, |
44 UNMOUNTING, | 42 UNMOUNTING, |
45 }; | 43 }; |
46 | 44 |
| 45 enum FormatEvent { |
| 46 FORMAT_STARTED, |
| 47 FORMAT_COMPLETED |
| 48 }; |
| 49 |
47 // Used to house an instance of each found mount device. | 50 // Used to house an instance of each found mount device. |
48 class Disk { | 51 class Disk { |
49 public: | 52 public: |
50 Disk(const std::string& device_path, | 53 Disk(const std::string& device_path, |
51 const std::string& mount_path, | 54 const std::string& mount_path, |
52 const std::string& system_path, | 55 const std::string& system_path, |
53 const std::string& file_path, | 56 const std::string& file_path, |
54 const std::string& device_label, | 57 const std::string& device_label, |
55 const std::string& drive_label, | 58 const std::string& drive_label, |
56 const std::string& vendor_id, | 59 const std::string& vendor_id, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 192 |
190 // A callback function type which is called after UnmountDeviceRecursive | 193 // A callback function type which is called after UnmountDeviceRecursive |
191 // finishes. | 194 // finishes. |
192 typedef void(*UnmountDeviceRecursiveCallbackType)(void*, bool); | 195 typedef void(*UnmountDeviceRecursiveCallbackType)(void*, bool); |
193 | 196 |
194 // Implement this interface to be notified about disk/mount related events. | 197 // Implement this interface to be notified about disk/mount related events. |
195 class Observer { | 198 class Observer { |
196 public: | 199 public: |
197 virtual ~Observer() {} | 200 virtual ~Observer() {} |
198 | 201 |
199 // A function called when disk mount status is changed. | 202 // Called when disk mount status is changed. |
200 virtual void DiskChanged(DiskMountManagerEventType event, | 203 virtual void OnDiskEvent(DiskEvent event, const Disk* disk) = 0; |
201 const Disk* disk) = 0; | 204 // Called when device status is changed. |
202 // A function called when device status is changed. | 205 virtual void OnDeviceEvent(DeviceEvent event, |
203 virtual void DeviceChanged(DiskMountManagerEventType event, | |
204 const std::string& device_path) = 0; | 206 const std::string& device_path) = 0; |
205 // A function called after mount is completed. | 207 // Called after a mount point has been mounted or unmounted. |
206 virtual void MountCompleted(MountEvent event_type, | 208 virtual void OnMountEvent(MountEvent event, |
207 MountError error_code, | 209 MountError error_code, |
208 const MountPointInfo& mount_info) = 0; | 210 const MountPointInfo& mount_info) = 0; |
| 211 // Called on format process events. |
| 212 virtual void OnFormatEvent(FormatEvent event, |
| 213 FormatError error_code, |
| 214 const std::string& device_path) = 0; |
209 }; | 215 }; |
210 | 216 |
211 virtual ~DiskMountManager() {} | 217 virtual ~DiskMountManager() {} |
212 | 218 |
213 // Adds an observer. | 219 // Adds an observer. |
214 virtual void AddObserver(Observer* observer) = 0; | 220 virtual void AddObserver(Observer* observer) = 0; |
215 | 221 |
216 // Removes an observer. | 222 // Removes an observer. |
217 virtual void RemoveObserver(Observer* observer) = 0; | 223 virtual void RemoveObserver(Observer* observer) = 0; |
218 | 224 |
(...skipping 14 matching lines...) Expand all Loading... |
233 virtual void MountPath(const std::string& source_path, | 239 virtual void MountPath(const std::string& source_path, |
234 const std::string& source_format, | 240 const std::string& source_format, |
235 const std::string& mount_label, | 241 const std::string& mount_label, |
236 MountType type) = 0; | 242 MountType type) = 0; |
237 | 243 |
238 // Unmounts a mounted disk. | 244 // Unmounts a mounted disk. |
239 // |UnmountOptions| enum defined in chromeos/dbus/cros_disks_client.h. | 245 // |UnmountOptions| enum defined in chromeos/dbus/cros_disks_client.h. |
240 virtual void UnmountPath(const std::string& mount_path, | 246 virtual void UnmountPath(const std::string& mount_path, |
241 UnmountOptions options) = 0; | 247 UnmountOptions options) = 0; |
242 | 248 |
243 // Formats device given its file path. | |
244 // Example: file_path: /dev/sdb1 | |
245 virtual void FormatUnmountedDevice(const std::string& file_path) = 0; | |
246 | |
247 // Formats Device given its mount path. Unmounts the device. | 249 // Formats Device given its mount path. Unmounts the device. |
248 // Example: mount_path: /media/VOLUME_LABEL | 250 // Example: mount_path: /media/VOLUME_LABEL |
249 virtual void FormatMountedDevice(const std::string& mount_path) = 0; | 251 virtual void FormatMountedDevice(const std::string& mount_path) = 0; |
250 | 252 |
251 // Unmounts device_path and all of its known children. | 253 // Unmounts device_path and all of its known children. |
252 virtual void UnmountDeviceRecursive( | 254 virtual void UnmountDeviceRecursive( |
253 const std::string& device_path, | 255 const std::string& device_path, |
254 UnmountDeviceRecursiveCallbackType callback, | 256 UnmountDeviceRecursiveCallbackType callback, |
255 void* user_data) = 0; | 257 void* user_data) = 0; |
256 | 258 |
| 259 // Used in tests to initialize the manager's disk and mount point sets. |
| 260 // Default implementation does noting. It just fails. |
| 261 virtual bool AddDiskForTest(Disk* disk); |
| 262 virtual bool AddMountPointForTest(const MountPointInfo& mount_point); |
| 263 |
257 // Returns corresponding string to |type| like "device" or "file". | 264 // Returns corresponding string to |type| like "device" or "file". |
258 static std::string MountTypeToString(MountType type); | 265 static std::string MountTypeToString(MountType type); |
259 | 266 |
260 // The inverse function of MountTypeToString. | 267 // The inverse function of MountTypeToString. |
261 static MountType MountTypeFromString(const std::string& type_str); | 268 static MountType MountTypeFromString(const std::string& type_str); |
262 | 269 |
263 // Returns corresponding string to |type| like "unknown_filesystem". | 270 // Returns corresponding string to |type| like "unknown_filesystem". |
264 static std::string MountConditionToString(MountCondition type); | 271 static std::string MountConditionToString(MountCondition type); |
265 | 272 |
266 // Returns corresponding string to |type|, like "sd", "usb". | 273 // Returns corresponding string to |type|, like "sd", "usb". |
(...skipping 13 matching lines...) Expand all Loading... |
280 | 287 |
281 // Returns a pointer to the global DiskMountManager instance. | 288 // Returns a pointer to the global DiskMountManager instance. |
282 // Initialize() should already have been called. | 289 // Initialize() should already have been called. |
283 static DiskMountManager* GetInstance(); | 290 static DiskMountManager* GetInstance(); |
284 }; | 291 }; |
285 | 292 |
286 } // namespace disks | 293 } // namespace disks |
287 } // namespace chromeos | 294 } // namespace chromeos |
288 | 295 |
289 #endif // CHROMEOS_DISKS_DISK_MOUNT_MANAGER_H_ | 296 #endif // CHROMEOS_DISKS_DISK_MOUNT_MANAGER_H_ |
OLD | NEW |