+void VolumeManager::OnRemovableStorageAttached(
+ const storage_monitor::StorageInfo& info) {
+ if (!storage_monitor::StorageInfo::IsMTPDevice(info.device_id()))
+ return;
+ if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled))
+ return;
+
+ const base::FilePath path = base::FilePath::FromUTF8Unsafe(info.location());
+ const std::string fsid = GetMountPointNameForMediaStorage(info);
+ const std::string name = base::UTF16ToUTF8(info.GetDisplayName(false));
+
+ bool result =
+ fileapi::ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
+ fsid, fileapi::kFileSystemTypeDeviceMediaAsFileStorage,
+ fileapi::FileSystemMountOption(), path);
+ DCHECK(result);
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO, FROM_HERE, base::Bind(
+ &MTPDeviceMapService::RegisterMTPFileSystem,
+ base::Unretained(MTPDeviceMapService::GetInstance()),
+ info.location(), fsid));
+
+ VolumeInfo volume_info;
+ volume_info.type = VOLUME_TYPE_MTP;
+ volume_info.mount_path = path;
+ volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE;
+ volume_info.is_parent = true;
+ volume_info.is_read_only = true;
+ volume_info.volume_id = "mtp:" + name;
+ volume_info.source_path = path;
+ volume_info.device_type = chromeos::DEVICE_TYPE_MOBILE;
+ DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, false);
+}
+
+void VolumeManager::OnRemovableStorageDetached(
+ const storage_monitor::StorageInfo& info) {
+ if (!storage_monitor::StorageInfo::IsMTPDevice(info.device_id()))
+ return;
+
+ for (std::map<std::string, VolumeInfo>::iterator it =
+ mounted_volumes_.begin(); it != mounted_volumes_.end(); ++it) {
+ if (it->second.source_path.value() == info.location()) {
+ DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, VolumeInfo(it->second));
+
+ const std::string fsid = GetMountPointNameForMediaStorage(info);
+ fileapi::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(
+ fsid);
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO, FROM_HERE, base::Bind(
+ &MTPDeviceMapService::RevokeMTPFileSystem,
+ base::Unretained(MTPDeviceMapService::GetInstance()),
+ fsid));
+ return;
+ }
+ }
+}
+
+void VolumeManager::OnStorageMonitorInitialized() {
+ std::vector<storage_monitor::StorageInfo> storages =
+ storage_monitor::StorageMonitor::GetInstance()->GetAllAvailableStorages();
+ for (size_t i = 0; i < storages.size(); ++i)
+ OnRemovableStorageAttached(storages[i]);
+ storage_monitor::StorageMonitor::GetInstance()->AddObserver(this);
+}
+