OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/browser/chromeos/file_manager/volume_manager.h" | 5 #include "chrome/browser/chromeos/file_manager/volume_manager.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 drive_integration_service_->AddObserver(this); | 303 drive_integration_service_->AddObserver(this); |
304 if (drive_integration_service_->IsMounted()) { | 304 if (drive_integration_service_->IsMounted()) { |
305 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | 305 DoMountEvent(chromeos::MOUNT_ERROR_NONE, |
306 CreateDriveVolumeInfo(profile_), | 306 CreateDriveVolumeInfo(profile_), |
307 kNotRemounting); | 307 kNotRemounting); |
308 } | 308 } |
309 } | 309 } |
310 | 310 |
311 // Subscribe to DiskMountManager. | 311 // Subscribe to DiskMountManager. |
312 disk_mount_manager_->AddObserver(this); | 312 disk_mount_manager_->AddObserver(this); |
| 313 disk_mount_manager_->EnsureMountInfoRefreshed( |
| 314 base::Bind(&VolumeManager::OnDiskMountManagerRefreshed, |
| 315 weak_ptr_factory_.GetWeakPtr())); |
313 | 316 |
314 // Subscribe to FileSystemProviderService and register currently mounted | 317 // Subscribe to FileSystemProviderService and register currently mounted |
315 // volumes for the profile. | 318 // volumes for the profile. |
316 if (file_system_provider_service_) { | 319 if (file_system_provider_service_) { |
317 using chromeos::file_system_provider::ProvidedFileSystemInfo; | 320 using chromeos::file_system_provider::ProvidedFileSystemInfo; |
318 file_system_provider_service_->AddObserver(this); | 321 file_system_provider_service_->AddObserver(this); |
319 | 322 |
320 std::vector<ProvidedFileSystemInfo> file_system_info_list = | 323 std::vector<ProvidedFileSystemInfo> file_system_info_list = |
321 file_system_provider_service_->GetProvidedFileSystemInfoList(); | 324 file_system_provider_service_->GetProvidedFileSystemInfoList(); |
322 for (size_t i = 0; i < file_system_info_list.size(); ++i) { | 325 for (size_t i = 0; i < file_system_info_list.size(); ++i) { |
323 VolumeInfo volume_info = | 326 VolumeInfo volume_info = |
324 CreateProvidedFileSystemVolumeInfo(file_system_info_list[i]); | 327 CreateProvidedFileSystemVolumeInfo(file_system_info_list[i]); |
325 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, kNotRemounting); | 328 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, kNotRemounting); |
326 } | 329 } |
327 } | 330 } |
328 | 331 |
329 std::vector<VolumeInfo> archives; | |
330 | |
331 const chromeos::disks::DiskMountManager::MountPointMap& mount_points = | |
332 disk_mount_manager_->mount_points(); | |
333 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it = | |
334 mount_points.begin(); | |
335 it != mount_points.end(); | |
336 ++it) { | |
337 if (it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { | |
338 // Archives are mounted after other type of volumes. See below. | |
339 archives.push_back(CreateVolumeInfoFromMountPointInfo(it->second, NULL)); | |
340 continue; | |
341 } | |
342 DoMountEvent( | |
343 chromeos::MOUNT_ERROR_NONE, | |
344 CreateVolumeInfoFromMountPointInfo( | |
345 it->second, | |
346 disk_mount_manager_->FindDiskBySourcePath(it->second.source_path)), | |
347 kNotRemounting); | |
348 } | |
349 | |
350 // We mount archives only if they are opened from currently mounted volumes. | |
351 // To check the condition correctly in DoMountEvent, we care the order. | |
352 std::vector<bool> done(archives.size(), false); | |
353 for (size_t i = 0; i < archives.size(); ++i) { | |
354 if (!done[i]) { | |
355 std::vector<VolumeInfo> chain; | |
356 done[i] = true; | |
357 chain.push_back(archives[i]); | |
358 | |
359 // If archives[i]'s source_path is in another archive, mount it first. | |
360 for (size_t parent = 0; parent < archives.size(); ++parent) { | |
361 if (!done[parent] && | |
362 archives[parent].mount_path.IsParent(chain.back().source_path)) { | |
363 done[parent] = true; | |
364 chain.push_back(archives[parent]); | |
365 parent = 0; // Search archives[parent]'s parent from the beginning. | |
366 } | |
367 } | |
368 | |
369 // Mount from the tail of chain. | |
370 for (size_t i = chain.size(); i > 0; --i) | |
371 DoMountEvent(chromeos::MOUNT_ERROR_NONE, chain[i - 1], kNotRemounting); | |
372 } | |
373 } | |
374 | |
375 disk_mount_manager_->RequestMountInfoRefresh(); | |
376 | |
377 // Subscribe to Profile Preference change. | 332 // Subscribe to Profile Preference change. |
378 pref_change_registrar_.Init(profile_->GetPrefs()); | 333 pref_change_registrar_.Init(profile_->GetPrefs()); |
379 pref_change_registrar_.Add( | 334 pref_change_registrar_.Add( |
380 prefs::kExternalStorageDisabled, | 335 prefs::kExternalStorageDisabled, |
381 base::Bind(&VolumeManager::OnExternalStorageDisabledChanged, | 336 base::Bind(&VolumeManager::OnExternalStorageDisabledChanged, |
382 weak_ptr_factory_.GetWeakPtr())); | 337 weak_ptr_factory_.GetWeakPtr())); |
383 | 338 |
384 // Subscribe to Privet volume lister. | 339 // Subscribe to Privet volume lister. |
385 if (CommandLine::ForCurrentProcess()->HasSwitch( | 340 if (CommandLine::ForCurrentProcess()->HasSwitch( |
386 switches::kEnablePrivetStorage)) { | 341 switches::kEnablePrivetStorage)) { |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 content::BrowserThread::PostTask( | 735 content::BrowserThread::PostTask( |
781 content::BrowserThread::IO, FROM_HERE, base::Bind( | 736 content::BrowserThread::IO, FROM_HERE, base::Bind( |
782 &MTPDeviceMapService::RevokeMTPFileSystem, | 737 &MTPDeviceMapService::RevokeMTPFileSystem, |
783 base::Unretained(MTPDeviceMapService::GetInstance()), | 738 base::Unretained(MTPDeviceMapService::GetInstance()), |
784 fsid)); | 739 fsid)); |
785 return; | 740 return; |
786 } | 741 } |
787 } | 742 } |
788 } | 743 } |
789 | 744 |
| 745 void VolumeManager::OnDiskMountManagerRefreshed(bool success) { |
| 746 if (!success) { |
| 747 LOG(ERROR) << "Failed to refresh disk mount manager"; |
| 748 return; |
| 749 } |
| 750 |
| 751 std::vector<VolumeInfo> archives; |
| 752 |
| 753 const chromeos::disks::DiskMountManager::MountPointMap& mount_points = |
| 754 disk_mount_manager_->mount_points(); |
| 755 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it = |
| 756 mount_points.begin(); |
| 757 it != mount_points.end(); |
| 758 ++it) { |
| 759 if (it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { |
| 760 // Archives are mounted after other types of volume. See below. |
| 761 archives.push_back(CreateVolumeInfoFromMountPointInfo(it->second, NULL)); |
| 762 continue; |
| 763 } |
| 764 DoMountEvent( |
| 765 chromeos::MOUNT_ERROR_NONE, |
| 766 CreateVolumeInfoFromMountPointInfo( |
| 767 it->second, |
| 768 disk_mount_manager_->FindDiskBySourcePath(it->second.source_path)), |
| 769 kNotRemounting); |
| 770 } |
| 771 |
| 772 // We mount archives only if they are opened from currently mounted volumes. |
| 773 // To check the condition correctly in DoMountEvent, we care about the order. |
| 774 std::vector<bool> done(archives.size(), false); |
| 775 for (size_t i = 0; i < archives.size(); ++i) { |
| 776 if (done[i]) |
| 777 continue; |
| 778 |
| 779 std::vector<VolumeInfo> chain; |
| 780 done[i] = true; |
| 781 chain.push_back(archives[i]); |
| 782 |
| 783 // If archives[i]'s source_path is in another archive, mount it first. |
| 784 for (size_t parent = i + 1; parent < archives.size(); ++parent) { |
| 785 if (!done[parent] && |
| 786 archives[parent].mount_path.IsParent(chain.back().source_path)) { |
| 787 done[parent] = true; |
| 788 chain.push_back(archives[parent]); |
| 789 parent = i + 1; // Search archives[parent]'s parent from the beginning. |
| 790 } |
| 791 } |
| 792 |
| 793 // Mount from the tail of chain. |
| 794 for (size_t i = chain.size(); i > 0; --i) |
| 795 DoMountEvent(chromeos::MOUNT_ERROR_NONE, chain[i - 1], kNotRemounting); |
| 796 } |
| 797 } |
| 798 |
790 void VolumeManager::OnStorageMonitorInitialized() { | 799 void VolumeManager::OnStorageMonitorInitialized() { |
791 std::vector<storage_monitor::StorageInfo> storages = | 800 std::vector<storage_monitor::StorageInfo> storages = |
792 storage_monitor::StorageMonitor::GetInstance()->GetAllAvailableStorages(); | 801 storage_monitor::StorageMonitor::GetInstance()->GetAllAvailableStorages(); |
793 for (size_t i = 0; i < storages.size(); ++i) | 802 for (size_t i = 0; i < storages.size(); ++i) |
794 OnRemovableStorageAttached(storages[i]); | 803 OnRemovableStorageAttached(storages[i]); |
795 storage_monitor::StorageMonitor::GetInstance()->AddObserver(this); | 804 storage_monitor::StorageMonitor::GetInstance()->AddObserver(this); |
796 } | 805 } |
797 | 806 |
798 void VolumeManager::DoMountEvent(chromeos::MountError error_code, | 807 void VolumeManager::DoMountEvent(chromeos::MountError error_code, |
799 const VolumeInfo& volume_info, | 808 const VolumeInfo& volume_info, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 return; | 853 return; |
845 if (error_code == chromeos::MOUNT_ERROR_NONE) | 854 if (error_code == chromeos::MOUNT_ERROR_NONE) |
846 mounted_volumes_.erase(volume_info.volume_id); | 855 mounted_volumes_.erase(volume_info.volume_id); |
847 | 856 |
848 FOR_EACH_OBSERVER(VolumeManagerObserver, | 857 FOR_EACH_OBSERVER(VolumeManagerObserver, |
849 observers_, | 858 observers_, |
850 OnVolumeUnmounted(error_code, volume_info)); | 859 OnVolumeUnmounted(error_code, volume_info)); |
851 } | 860 } |
852 | 861 |
853 } // namespace file_manager | 862 } // namespace file_manager |
OLD | NEW |