| 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 // StorageMonitorLinux processes mount point change events, notifies listeners | 5 // StorageMonitorLinux processes mount point change events, notifies listeners |
| 6 // about the addition and deletion of media devices, and answers queries about | 6 // about the addition and deletion of media devices, and answers queries about |
| 7 // mounted devices. | 7 // mounted devices. |
| 8 // StorageMonitorLinux lives on the UI thread, and uses a MtabWatcherLinux on | 8 // StorageMonitorLinux lives on the UI thread, and uses a MtabWatcherLinux on |
| 9 // the FILE thread to get mount point change events. | 9 // the FILE thread to get mount point change events. |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "chrome/browser/storage_monitor/storage_monitor.h" | 27 #include "chrome/browser/storage_monitor/storage_monitor.h" |
| 28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 29 | 29 |
| 30 namespace chrome { | 30 namespace chrome { |
| 31 | 31 |
| 32 class MediaTransferProtocolDeviceObserverLinux; | 32 class MediaTransferProtocolDeviceObserverLinux; |
| 33 | 33 |
| 34 class StorageMonitorLinux : public StorageMonitor, | 34 class StorageMonitorLinux : public StorageMonitor, |
| 35 public MtabWatcherLinux::Delegate { | 35 public MtabWatcherLinux::Delegate { |
| 36 public: | 36 public: |
| 37 // Should only be called by browser start up code. Use GetInstance() instead. | 37 // Should only be called by browser start up code. |
| 38 explicit StorageMonitorLinux(const base::FilePath& path); | 38 // Use StorageMonitor::GetInstance() instead. |
| 39 // |mtab_file_path| is the path to a mtab file to watch for mount points. |
| 40 explicit StorageMonitorLinux(const base::FilePath& mtab_file_path); |
| 39 virtual ~StorageMonitorLinux(); | 41 virtual ~StorageMonitorLinux(); |
| 40 | 42 |
| 41 // Must be called for StorageMonitorLinux to work. | 43 // Must be called for StorageMonitorLinux to work. |
| 42 void Init(); | 44 void Init(); |
| 43 | 45 |
| 44 // Finds the device that contains |path| and populates |device_info|. | |
| 45 // Returns false if unable to find the device. | |
| 46 virtual bool GetStorageInfoForPath( | |
| 47 const base::FilePath& path, | |
| 48 StorageInfo* device_info) const OVERRIDE; | |
| 49 | |
| 50 protected: | 46 protected: |
| 51 // Gets device information given a |device_path| and |mount_point|. | 47 // Gets device information given a |device_path| and |mount_point|. |
| 52 typedef base::Callback<scoped_ptr<StorageInfo>( | 48 typedef base::Callback<scoped_ptr<StorageInfo>( |
| 53 const base::FilePath& device_path, | 49 const base::FilePath& device_path, |
| 54 const base::FilePath& mount_point)> GetDeviceInfoCallback; | 50 const base::FilePath& mount_point)> GetDeviceInfoCallback; |
| 55 | 51 |
| 56 void SetGetDeviceInfoCallbackForTest( | 52 void SetGetDeviceInfoCallbackForTest( |
| 57 const GetDeviceInfoCallback& get_device_info_callback); | 53 const GetDeviceInfoCallback& get_device_info_callback); |
| 58 | 54 |
| 55 void UseDummyMediaTransferProtocolManagerForTest(); |
| 56 |
| 59 // MtabWatcherLinux::Delegate implementation. | 57 // MtabWatcherLinux::Delegate implementation. |
| 60 virtual void UpdateMtab( | 58 virtual void UpdateMtab( |
| 61 const MtabWatcherLinux::MountPointDeviceMap& new_mtab) OVERRIDE; | 59 const MtabWatcherLinux::MountPointDeviceMap& new_mtab) OVERRIDE; |
| 62 | 60 |
| 63 private: | 61 private: |
| 64 // Structure to save mounted device information such as device path, unique | 62 // Structure to save mounted device information such as device path, unique |
| 65 // identifier, device name and partition size. | 63 // identifier, device name and partition size. |
| 66 struct MountPointInfo { | 64 struct MountPointInfo { |
| 67 base::FilePath mount_device; | 65 base::FilePath mount_device; |
| 68 StorageInfo storage_info; | 66 StorageInfo storage_info; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 82 // (mount point, priority) | 80 // (mount point, priority) |
| 83 // For devices that are mounted to multiple mount points, this helps us track | 81 // For devices that are mounted to multiple mount points, this helps us track |
| 84 // which one we've notified system monitor about. | 82 // which one we've notified system monitor about. |
| 85 typedef std::map<base::FilePath, bool> ReferencedMountPoint; | 83 typedef std::map<base::FilePath, bool> ReferencedMountPoint; |
| 86 | 84 |
| 87 // (mount device, map of known mount points) | 85 // (mount device, map of known mount points) |
| 88 // For each mount device, track the places it is mounted and which one (if | 86 // For each mount device, track the places it is mounted and which one (if |
| 89 // any) we have notified system monitor about. | 87 // any) we have notified system monitor about. |
| 90 typedef std::map<base::FilePath, ReferencedMountPoint> MountPriorityMap; | 88 typedef std::map<base::FilePath, ReferencedMountPoint> MountPriorityMap; |
| 91 | 89 |
| 90 // StorageMonitor implementation. |
| 91 virtual bool GetStorageInfoForPath(const base::FilePath& path, |
| 92 StorageInfo* device_info) const OVERRIDE; |
| 93 virtual device::MediaTransferProtocolManager* |
| 94 media_transfer_protocol_manager() OVERRIDE; |
| 95 |
| 92 // Called when the MtabWatcher has been created. | 96 // Called when the MtabWatcher has been created. |
| 93 void OnMtabWatcherCreated(MtabWatcherLinux* watcher); | 97 void OnMtabWatcherCreated(MtabWatcherLinux* watcher); |
| 94 | 98 |
| 95 bool IsDeviceAlreadyMounted(const base::FilePath& mount_device) const; | 99 bool IsDeviceAlreadyMounted(const base::FilePath& mount_device) const; |
| 96 | 100 |
| 97 // Assuming |mount_device| is already mounted, and it gets mounted again at | 101 // Assuming |mount_device| is already mounted, and it gets mounted again at |
| 98 // |mount_point|, update the mappings. | 102 // |mount_point|, update the mappings. |
| 99 void HandleDeviceMountedMultipleTimes(const base::FilePath& mount_device, | 103 void HandleDeviceMountedMultipleTimes(const base::FilePath& mount_device, |
| 100 const base::FilePath& mount_point); | 104 const base::FilePath& mount_point); |
| 101 | 105 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 114 // Keep in mind on Linux, a device can be mounted at multiple mount points, | 118 // Keep in mind on Linux, a device can be mounted at multiple mount points, |
| 115 // and multiple devices can be mounted at a mount point. | 119 // and multiple devices can be mounted at a mount point. |
| 116 MountMap mount_info_map_; | 120 MountMap mount_info_map_; |
| 117 | 121 |
| 118 // Because a device can be mounted to multiple places, we only want to | 122 // Because a device can be mounted to multiple places, we only want to |
| 119 // notify about one of them. If (and only if) that one is unmounted, we need | 123 // notify about one of them. If (and only if) that one is unmounted, we need |
| 120 // to notify about it's departure and notify about another one of it's mount | 124 // to notify about it's departure and notify about another one of it's mount |
| 121 // points. | 125 // points. |
| 122 MountPriorityMap mount_priority_map_; | 126 MountPriorityMap mount_priority_map_; |
| 123 | 127 |
| 128 // When true, the |media_transfer_protocol_manager_| created will be a dummy. |
| 129 bool use_dummy_media_transfer_protocol_manager_; |
| 130 |
| 131 scoped_ptr<device::MediaTransferProtocolManager> |
| 132 media_transfer_protocol_manager_; |
| 124 scoped_ptr<MediaTransferProtocolDeviceObserverLinux> | 133 scoped_ptr<MediaTransferProtocolDeviceObserverLinux> |
| 125 media_transfer_protocol_device_observer_; | 134 media_transfer_protocol_device_observer_; |
| 126 | 135 |
| 127 scoped_ptr<MtabWatcherLinux, MtabWatcherLinuxDeleter> mtab_watcher_; | 136 scoped_ptr<MtabWatcherLinux, MtabWatcherLinuxDeleter> mtab_watcher_; |
| 128 | 137 |
| 129 base::WeakPtrFactory<StorageMonitorLinux> weak_ptr_factory_; | 138 base::WeakPtrFactory<StorageMonitorLinux> weak_ptr_factory_; |
| 130 | 139 |
| 131 DISALLOW_COPY_AND_ASSIGN(StorageMonitorLinux); | 140 DISALLOW_COPY_AND_ASSIGN(StorageMonitorLinux); |
| 132 }; | 141 }; |
| 133 | 142 |
| 134 } // namespace chrome | 143 } // namespace chrome |
| 135 | 144 |
| 136 #endif // CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_LINUX_H_ | 145 #endif // CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_LINUX_H_ |
| OLD | NEW |