Chromium Code Reviews| Index: chrome/browser/chromeos/file_manager/volume_manager.cc |
| diff --git a/chrome/browser/chromeos/file_manager/volume_manager.cc b/chrome/browser/chromeos/file_manager/volume_manager.cc |
| index a1945b3012424462df7d0faf87832aa0c04f983f..43f0e3b839d1fff3b1de90d3e0d523f35606f1ca 100644 |
| --- a/chrome/browser/chromeos/file_manager/volume_manager.cc |
| +++ b/chrome/browser/chromeos/file_manager/volume_manager.cc |
| @@ -310,6 +310,9 @@ void VolumeManager::Initialize() { |
| // Subscribe to DiskMountManager. |
| disk_mount_manager_->AddObserver(this); |
| + disk_mount_manager_->EnsureMountInfoRefreshed( |
| + base::Bind(&VolumeManager::OnDiskMountManagerRefreshed, |
| + weak_ptr_factory_.GetWeakPtr())); |
| // Subscribe to FileSystemProviderService and register currently mounted |
| // volumes for the profile. |
| @@ -326,54 +329,6 @@ void VolumeManager::Initialize() { |
| } |
| } |
| - std::vector<VolumeInfo> archives; |
| - |
| - const chromeos::disks::DiskMountManager::MountPointMap& mount_points = |
| - disk_mount_manager_->mount_points(); |
| - for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it = |
| - mount_points.begin(); |
| - it != mount_points.end(); |
| - ++it) { |
| - if (it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { |
| - // Archives are mounted after other type of volumes. See below. |
| - archives.push_back(CreateVolumeInfoFromMountPointInfo(it->second, NULL)); |
| - continue; |
| - } |
| - DoMountEvent( |
| - chromeos::MOUNT_ERROR_NONE, |
| - CreateVolumeInfoFromMountPointInfo( |
| - it->second, |
| - disk_mount_manager_->FindDiskBySourcePath(it->second.source_path)), |
| - kNotRemounting); |
| - } |
| - |
| - // We mount archives only if they are opened from currently mounted volumes. |
| - // To check the condition correctly in DoMountEvent, we care the order. |
| - std::vector<bool> done(archives.size(), false); |
| - for (size_t i = 0; i < archives.size(); ++i) { |
| - if (!done[i]) { |
| - std::vector<VolumeInfo> chain; |
| - done[i] = true; |
| - chain.push_back(archives[i]); |
| - |
| - // If archives[i]'s source_path is in another archive, mount it first. |
| - for (size_t parent = 0; parent < archives.size(); ++parent) { |
| - if (!done[parent] && |
| - archives[parent].mount_path.IsParent(chain.back().source_path)) { |
| - done[parent] = true; |
| - chain.push_back(archives[parent]); |
| - parent = 0; // Search archives[parent]'s parent from the beginning. |
| - } |
| - } |
| - |
| - // Mount from the tail of chain. |
| - for (size_t i = chain.size(); i > 0; --i) |
| - DoMountEvent(chromeos::MOUNT_ERROR_NONE, chain[i - 1], kNotRemounting); |
| - } |
| - } |
| - |
| - disk_mount_manager_->RequestMountInfoRefresh(); |
| - |
| // Subscribe to Profile Preference change. |
| pref_change_registrar_.Init(profile_->GetPrefs()); |
| pref_change_registrar_.Add( |
| @@ -787,6 +742,59 @@ void VolumeManager::OnRemovableStorageDetached( |
| } |
| } |
| +void VolumeManager::OnDiskMountManagerRefreshed(bool success) { |
| + if (!success) { |
| + LOG(ERROR) << "Failed to refresh disk mount manager"; |
| + return; |
| + } |
| + |
| + std::vector<VolumeInfo> archives; |
| + |
| + const chromeos::disks::DiskMountManager::MountPointMap& mount_points = |
| + disk_mount_manager_->mount_points(); |
| + for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it = |
| + mount_points.begin(); |
| + it != mount_points.end(); |
| + ++it) { |
| + if (it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { |
| + // 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.
|
| + archives.push_back(CreateVolumeInfoFromMountPointInfo(it->second, NULL)); |
| + continue; |
| + } |
| + DoMountEvent( |
| + chromeos::MOUNT_ERROR_NONE, |
| + CreateVolumeInfoFromMountPointInfo( |
| + it->second, |
| + disk_mount_manager_->FindDiskBySourcePath(it->second.source_path)), |
| + kNotRemounting); |
| + } |
| + |
| + // We mount archives only if they are opened from currently mounted volumes. |
| + // 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.
|
| + std::vector<bool> done(archives.size(), false); |
| + for (size_t i = 0; i < archives.size(); ++i) { |
| + 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.
|
| + std::vector<VolumeInfo> chain; |
| + done[i] = true; |
| + chain.push_back(archives[i]); |
| + |
| + // If archives[i]'s source_path is in another archive, mount it first. |
| + 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.
|
| + if (!done[parent] && |
| + archives[parent].mount_path.IsParent(chain.back().source_path)) { |
| + done[parent] = true; |
| + chain.push_back(archives[parent]); |
| + 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.
|
| + } |
| + } |
| + |
| + // Mount from the tail of chain. |
| + for (size_t i = chain.size(); i > 0; --i) |
| + DoMountEvent(chromeos::MOUNT_ERROR_NONE, chain[i - 1], kNotRemounting); |
| + } |
| + } |
| +} |
| + |
| void VolumeManager::OnStorageMonitorInitialized() { |
| std::vector<storage_monitor::StorageInfo> storages = |
| storage_monitor::StorageMonitor::GetInstance()->GetAllAvailableStorages(); |