1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // StorageMonitorCros listens for mount point changes and notifies listeners 6 // about the addition and deletion of media devices. This class lives on the 7 // UI thread. 8 9 #ifndef COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_CHROMEOS_H_ 10 #define COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_CHROMEOS_H_ 11 12 #if !defined(OS_CHROMEOS) 13 #error "Should only be used on ChromeOS." 14 #endif 15 16 #include <map> 17 #include <string> 18 19 #include "base/basictypes.h" 20 #include "base/compiler_specific.h" 21 #include "base/memory/scoped_ptr.h" 22 #include "base/memory/weak_ptr.h" 23 #include "chromeos/disks/disk_mount_manager.h" 24 #include "components/storage_monitor/storage_monitor.h" 25 26 namespace storage_monitor { 27 28 class MediaTransferProtocolDeviceObserverLinux; 29 30 class StorageMonitorCros : public StorageMonitor, 31 public chromeos::disks::DiskMountManager::Observer { 32 public: 33 // Should only be called by browser start up code. 34 // Use StorageMonitor::GetInstance() instead. 35 StorageMonitorCros(); 36 virtual ~StorageMonitorCros(); 37 38 // Sets up disk listeners and issues notifications for any discovered 39 // mount points. Sets up MTP manager and listeners. 40 virtual void Init() OVERRIDE; 41 42 protected: 43 void SetMediaTransferProtocolManagerForTest( 44 device::MediaTransferProtocolManager* test_manager); 45 46 // chromeos::disks::DiskMountManager::Observer implementation. 47 virtual void OnDiskEvent( 48 chromeos::disks::DiskMountManager::DiskEvent event, 49 const chromeos::disks::DiskMountManager::Disk* disk) OVERRIDE; 50 virtual void OnDeviceEvent( 51 chromeos::disks::DiskMountManager::DeviceEvent event, 52 const std::string& device_path) OVERRIDE; 53 virtual void OnMountEvent( 54 chromeos::disks::DiskMountManager::MountEvent event, 55 chromeos::MountError error_code, 56 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) 57 OVERRIDE; 58 virtual void OnFormatEvent( 59 chromeos::disks::DiskMountManager::FormatEvent event, 60 chromeos::FormatError error_code, 61 const std::string& device_path) OVERRIDE; 62 63 // StorageMonitor implementation. 64 virtual bool GetStorageInfoForPath(const base::FilePath& path, 65 StorageInfo* device_info) const OVERRIDE; 66 virtual void EjectDevice( 67 const std::string& device_id, 68 base::Callback<void(EjectStatus)> callback) OVERRIDE; 69 virtual device::MediaTransferProtocolManager* 70 media_transfer_protocol_manager() OVERRIDE; 71 72 private: 73 // Mapping of mount path to removable mass storage info. 74 typedef std::map<std::string, StorageInfo> MountMap; 75 76 // Helper method that checks existing mount points to see if they are media 77 // devices. Eventually calls AddMountedPath for all mount points. 78 void CheckExistingMountPoints(); 79 80 // Adds the mount point in |mount_info| to |mount_map_| and send a media 81 // device attach notification. |has_dcim| is true if the attached device has 82 // a DCIM folder. 83 void AddMountedPath( 84 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info, 85 bool has_dcim); 86 87 // Mapping of relevant mount points and their corresponding mount devices. 88 MountMap mount_map_; 89 90 scoped_ptr<device::MediaTransferProtocolManager> 91 media_transfer_protocol_manager_; 92 scoped_ptr<MediaTransferProtocolDeviceObserverLinux> 93 media_transfer_protocol_device_observer_; 94 95 base::WeakPtrFactory<StorageMonitorCros> weak_ptr_factory_; 96 97 DISALLOW_COPY_AND_ASSIGN(StorageMonitorCros); 98 }; 99 100 } // namespace storage_monitor 101 102 #endif // COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_CHROMEOS_H_ 103