Chromium Code Reviews| 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 type of volumes. See below. | |
|
Ben Chan
2014/07/10 00:07:12
"other type of volumes" -> "other types of volume"
kinaba
2014/07/10 01:36:32
Done.
| |
| 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 the order. | |
|
stevenjb
2014/07/10 00:53:21
s/care/care about/
kinaba
2014/07/10 01:36:32
Done.
| |
| 774 std::vector<bool> done(archives.size(), false); | |
| 775 for (size_t i = 0; i < archives.size(); ++i) { | |
| 776 if (!done[i]) { | |
|
Ben Chan
2014/07/10 00:07:12
this helps remove one indentation level
if (done[
kinaba
2014/07/10 01:36:32
Done.
| |
| 777 std::vector<VolumeInfo> chain; | |
| 778 done[i] = true; | |
| 779 chain.push_back(archives[i]); | |
| 780 | |
| 781 // If archives[i]'s source_path is in another archive, mount it first. | |
| 782 for (size_t parent = 0; parent < archives.size(); ++parent) { | |
|
stevenjb
2014/07/10 00:53:21
Can't we start this with i+1, since done[0,i] will
kinaba
2014/07/10 01:36:32
Good point. Thanks. Done.
| |
| 783 if (!done[parent] && | |
| 784 archives[parent].mount_path.IsParent(chain.back().source_path)) { | |
| 785 done[parent] = true; | |
| 786 chain.push_back(archives[parent]); | |
| 787 parent = 0; // Search archives[parent]'s parent from the beginning. | |
|
stevenjb
2014/07/10 00:53:21
parent = i + 1;
kinaba
2014/07/10 01:36:32
Done.
| |
| 788 } | |
| 789 } | |
| 790 | |
| 791 // Mount from the tail of chain. | |
| 792 for (size_t i = chain.size(); i > 0; --i) | |
| 793 DoMountEvent(chromeos::MOUNT_ERROR_NONE, chain[i - 1], kNotRemounting); | |
| 794 } | |
| 795 } | |
| 796 } | |
| 797 | |
| 790 void VolumeManager::OnStorageMonitorInitialized() { | 798 void VolumeManager::OnStorageMonitorInitialized() { |
| 791 std::vector<storage_monitor::StorageInfo> storages = | 799 std::vector<storage_monitor::StorageInfo> storages = |
| 792 storage_monitor::StorageMonitor::GetInstance()->GetAllAvailableStorages(); | 800 storage_monitor::StorageMonitor::GetInstance()->GetAllAvailableStorages(); |
| 793 for (size_t i = 0; i < storages.size(); ++i) | 801 for (size_t i = 0; i < storages.size(); ++i) |
| 794 OnRemovableStorageAttached(storages[i]); | 802 OnRemovableStorageAttached(storages[i]); |
| 795 storage_monitor::StorageMonitor::GetInstance()->AddObserver(this); | 803 storage_monitor::StorageMonitor::GetInstance()->AddObserver(this); |
| 796 } | 804 } |
| 797 | 805 |
| 798 void VolumeManager::DoMountEvent(chromeos::MountError error_code, | 806 void VolumeManager::DoMountEvent(chromeos::MountError error_code, |
| 799 const VolumeInfo& volume_info, | 807 const VolumeInfo& volume_info, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 844 return; | 852 return; |
| 845 if (error_code == chromeos::MOUNT_ERROR_NONE) | 853 if (error_code == chromeos::MOUNT_ERROR_NONE) |
| 846 mounted_volumes_.erase(volume_info.volume_id); | 854 mounted_volumes_.erase(volume_info.volume_id); |
| 847 | 855 |
| 848 FOR_EACH_OBSERVER(VolumeManagerObserver, | 856 FOR_EACH_OBSERVER(VolumeManagerObserver, |
| 849 observers_, | 857 observers_, |
| 850 OnVolumeUnmounted(error_code, volume_info)); | 858 OnVolumeUnmounted(error_code, volume_info)); |
| 851 } | 859 } |
| 852 | 860 |
| 853 } // namespace file_manager | 861 } // namespace file_manager |
| OLD | NEW |