Chromium Code Reviews| 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 // chromeos::RemovableDeviceNotificationsCros listens for mount point changes | 5 // chromeos::RemovableDeviceNotificationsCros listens for mount point changes |
| 6 // and notifies the SystemMonitor about the addition and deletion of media | 6 // and notifies the SystemMonitor about the addition and deletion of media |
| 7 // devices. | 7 // devices. |
| 8 | 8 |
| 9 #ifndef CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_CHROMEOS_H_ | 9 #ifndef CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_CHROMEOS_H_ |
| 10 #define CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_CHROMEOS_H_ | 10 #define CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_CHROMEOS_H_ |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
| 22 #include "base/system_monitor/system_monitor.h" | 22 #include "base/system_monitor/system_monitor.h" |
| 23 #include "chromeos/disks/disk_mount_manager.h" | 23 #include "chromeos/disks/disk_mount_manager.h" |
| 24 | 24 |
| 25 namespace chromeos { | 25 namespace chromeos { |
| 26 | 26 |
| 27 class RemovableDeviceNotificationsCros | 27 class RemovableDeviceNotificationsCros |
| 28 : public base::RefCountedThreadSafe<RemovableDeviceNotificationsCros>, | 28 : public base::RefCountedThreadSafe<RemovableDeviceNotificationsCros>, |
| 29 public disks::DiskMountManager::Observer { | 29 public disks::DiskMountManager::Observer { |
| 30 public: | 30 public: |
| 31 // Should only be called by browser start up code. Use GetInstance() instead. | |
| 31 RemovableDeviceNotificationsCros(); | 32 RemovableDeviceNotificationsCros(); |
| 32 | 33 |
| 34 static RemovableDeviceNotificationsCros* GetInstance(); | |
| 35 | |
| 33 virtual void DiskChanged(disks::DiskMountManagerEventType event, | 36 virtual void DiskChanged(disks::DiskMountManagerEventType event, |
| 34 const disks::DiskMountManager::Disk* disk) OVERRIDE; | 37 const disks::DiskMountManager::Disk* disk) OVERRIDE; |
| 35 virtual void DeviceChanged(disks::DiskMountManagerEventType event, | 38 virtual void DeviceChanged(disks::DiskMountManagerEventType event, |
| 36 const std::string& device_path) OVERRIDE; | 39 const std::string& device_path) OVERRIDE; |
| 37 virtual void MountCompleted( | 40 virtual void MountCompleted( |
| 38 disks::DiskMountManager::MountEvent event_type, | 41 disks::DiskMountManager::MountEvent event_type, |
| 39 MountError error_code, | 42 MountError error_code, |
| 40 const disks::DiskMountManager::MountPointInfo& mount_info) OVERRIDE; | 43 const disks::DiskMountManager::MountPointInfo& mount_info) OVERRIDE; |
| 41 | 44 |
| 45 // Finds the device that contains |path| and populates |device_info|. | |
| 46 // Returns false if unable to find the device. | |
| 47 bool GetDeviceInfoForPath( | |
| 48 const FilePath& path, | |
| 49 base::SystemMonitor::RemovableStorageInfo* device_info) const; | |
| 50 | |
| 42 private: | 51 private: |
| 43 friend class base::RefCountedThreadSafe<RemovableDeviceNotificationsCros>; | 52 friend class base::RefCountedThreadSafe<RemovableDeviceNotificationsCros>; |
| 44 | 53 |
| 45 // Mapping of mount points to mount device IDs. | 54 // Structure to save mounted device information such as device unique id, name |
| 46 typedef std::map<std::string, std::string> MountMap; | 55 // and device path. |
| 56 struct DeviceInfo { | |
|
Lei Zhang
2012/09/16 00:17:05
Is this already defined elsewhere?
kmadhusu
2012/09/16 22:35:42
DeviceInfo and StorageInfo structs has the same me
| |
| 57 DeviceInfo(); | |
| 58 | |
| 59 // Store the unique device identifier (e.g: "dcim:UUID:AAFF:FFAA") | |
| 60 std::string id; | |
| 61 // Store the device name (e.g: "USB Co.") | |
| 62 string16 name; | |
| 63 // Store the device mount path (e.g: "/media/removable/SD card") | |
| 64 std::string location; | |
| 65 }; | |
| 66 | |
| 67 // Mapping of mount path to device info. | |
| 68 typedef std::map<std::string, DeviceInfo> MountMap; | |
| 47 | 69 |
| 48 // Private to avoid code deleting the object. | 70 // Private to avoid code deleting the object. |
| 49 virtual ~RemovableDeviceNotificationsCros(); | 71 virtual ~RemovableDeviceNotificationsCros(); |
| 50 | 72 |
| 51 // Checks existing mount points map for media devices. For each mount point, | 73 // Checks existing mount points map for media devices. For each mount point, |
| 52 // call CheckMountedPathOnFileThread() below. | 74 // call CheckMountedPathOnFileThread() below. |
| 53 void CheckExistingMountPointsOnUIThread(); | 75 void CheckExistingMountPointsOnUIThread(); |
| 54 | 76 |
| 55 // Checks if the mount point in |mount_info| is a media device. If it is, | 77 // Checks if the mount point in |mount_info| is a media device. If it is, |
| 56 // then continue with AddMountedPathOnUIThread() below. | 78 // then continue with AddMountedPathOnUIThread() below. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 67 // Mapping of relevant mount points and their corresponding mount devices. | 89 // Mapping of relevant mount points and their corresponding mount devices. |
| 68 // Only accessed on the UI thread. | 90 // Only accessed on the UI thread. |
| 69 MountMap mount_map_; | 91 MountMap mount_map_; |
| 70 | 92 |
| 71 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsCros); | 93 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsCros); |
| 72 }; | 94 }; |
| 73 | 95 |
| 74 } // namespace chromeos | 96 } // namespace chromeos |
| 75 | 97 |
| 76 #endif // CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_CHROMEOS _H_ | 98 #endif // CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_CHROMEOS _H_ |
| OLD | NEW |