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/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 drive_integration_service_->AddObserver(this); | 244 drive_integration_service_->AddObserver(this); |
| 245 if (drive_integration_service_->IsMounted()) { | 245 if (drive_integration_service_->IsMounted()) { |
| 246 DoMountEvent( | 246 DoMountEvent( |
| 247 chromeos::MOUNT_ERROR_NONE, CreateDriveVolumeInfo(profile_), false); | 247 chromeos::MOUNT_ERROR_NONE, CreateDriveVolumeInfo(profile_), false); |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 | 250 |
| 251 // Subscribe to DiskMountManager. | 251 // Subscribe to DiskMountManager. |
| 252 disk_mount_manager_->AddObserver(this); | 252 disk_mount_manager_->AddObserver(this); |
| 253 | 253 |
| 254 std::vector<chromeos::disks::DiskMountManager::MountPointInfo> archives; | |
| 255 | |
| 254 const chromeos::disks::DiskMountManager::MountPointMap& mount_points = | 256 const chromeos::disks::DiskMountManager::MountPointMap& mount_points = |
| 255 disk_mount_manager_->mount_points(); | 257 disk_mount_manager_->mount_points(); |
| 256 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it = | 258 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it = |
| 257 mount_points.begin(); | 259 mount_points.begin(); |
| 258 it != mount_points.end(); | 260 it != mount_points.end(); |
| 259 ++it) { | 261 ++it) { |
| 262 if (it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { | |
| 263 // Archives are mounted after other type of volumes. See below. | |
| 264 archives.push_back(it->second); | |
| 265 continue; | |
| 266 } | |
| 260 DoMountEvent( | 267 DoMountEvent( |
| 261 chromeos::MOUNT_ERROR_NONE, | 268 chromeos::MOUNT_ERROR_NONE, |
| 262 CreateVolumeInfoFromMountPointInfo( | 269 CreateVolumeInfoFromMountPointInfo( |
| 263 it->second, | 270 it->second, |
| 264 disk_mount_manager_->FindDiskBySourcePath(it->second.source_path)), | 271 disk_mount_manager_->FindDiskBySourcePath(it->second.source_path)), |
| 265 false /* is_remounting */); | 272 false /* is_remounting */); |
| 266 } | 273 } |
| 267 | 274 |
| 275 // We mount archives only if they are opened from currently mounted volumes. | |
| 276 // To check the condition correctly in DoMountEvent, we care the order. | |
| 277 std::vector<bool> done(archives.size(), false); | |
| 278 for (size_t i = 0; i < archives.size(); ++i) { | |
| 279 if (!done[i]) { | |
| 280 std::vector<chromeos::disks::DiskMountManager::MountPointInfo> chain; | |
| 281 done[i] = true; | |
| 282 chain.push_back(archives[i]); | |
| 283 | |
| 284 // If archives[i]'s source_path is in another archive, mount it first. | |
| 285 for (size_t parent = 0; parent < archives.size(); ++parent) { | |
| 286 if (!done[parent] && | |
| 287 chain.back().source_path.find(archives[parent].mount_path) == 0) { | |
|
mtomasz
2014/02/14 05:08:47
Does the mount_path contain a trailing slash? If n
kinaba
2014/02/14 05:20:19
Thanks. Very good point. Fixed.
| |
| 288 done[parent] = true; | |
| 289 chain.push_back(archives[parent]); | |
| 290 parent = 0; // Search archives[parent]'s parent from the beginning. | |
| 291 } | |
| 292 } | |
| 293 | |
| 294 // Mount from the tail of chain. | |
| 295 for (size_t i = chain.size(); i > 0; --i) { | |
| 296 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | |
| 297 CreateVolumeInfoFromMountPointInfo(chain[i - 1], NULL), | |
| 298 false); | |
| 299 } | |
| 300 } | |
| 301 } | |
| 302 | |
| 268 disk_mount_manager_->RequestMountInfoRefresh(); | 303 disk_mount_manager_->RequestMountInfoRefresh(); |
| 269 | 304 |
| 270 // Subscribe to Profile Preference change. | 305 // Subscribe to Profile Preference change. |
| 271 pref_change_registrar_.Init(profile_->GetPrefs()); | 306 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 272 pref_change_registrar_.Add( | 307 pref_change_registrar_.Add( |
| 273 prefs::kExternalStorageDisabled, | 308 prefs::kExternalStorageDisabled, |
| 274 base::Bind(&VolumeManager::OnExternalStorageDisabledChanged, | 309 base::Bind(&VolumeManager::OnExternalStorageDisabledChanged, |
| 275 base::Unretained(this))); | 310 base::Unretained(this))); |
| 276 | 311 |
| 277 if (CommandLine::ForCurrentProcess()->HasSwitch( | 312 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 for (local_discovery::PrivetVolumeLister::VolumeList::const_iterator i = | 584 for (local_discovery::PrivetVolumeLister::VolumeList::const_iterator i = |
| 550 volumes.begin(); i != volumes.end(); i++) { | 585 volumes.begin(); i != volumes.end(); i++) { |
| 551 VolumeInfo volume_info = CreatePrivetVolumeInfo(*i); | 586 VolumeInfo volume_info = CreatePrivetVolumeInfo(*i); |
| 552 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, false); | 587 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, false); |
| 553 } | 588 } |
| 554 } | 589 } |
| 555 | 590 |
| 556 void VolumeManager::DoMountEvent(chromeos::MountError error_code, | 591 void VolumeManager::DoMountEvent(chromeos::MountError error_code, |
| 557 const VolumeInfo& volume_info, | 592 const VolumeInfo& volume_info, |
| 558 bool is_remounting) { | 593 bool is_remounting) { |
| 559 // TODO(kinaba): filter zip. | 594 // Archive files are mounted globally in system. We however don't want to show |
| 595 // archives from profile-specific folders (Drive/Downloads) of other users in | |
| 596 // multi-profile session. To this end, we filter out archives not on the | |
| 597 // volumes already mounted on this VolumeManager instance. | |
| 598 if (volume_info.type == VOLUME_TYPE_MOUNTED_ARCHIVE_FILE) { | |
| 599 // Source may be in Drive cache folder under the current profile directory. | |
| 600 bool from_current_profile = | |
| 601 profile_->GetPath().IsParent(volume_info.source_path); | |
| 602 for (std::map<std::string, VolumeInfo>::const_iterator iter = | |
| 603 mounted_volumes_.begin(); | |
| 604 !from_current_profile && iter != mounted_volumes_.end(); | |
| 605 ++iter) { | |
| 606 if (iter->second.mount_path.IsParent(volume_info.source_path)) | |
| 607 from_current_profile = true; | |
| 608 } | |
| 609 if (!from_current_profile) | |
| 610 return; | |
| 611 } | |
| 560 | 612 |
| 561 if (error_code == chromeos::MOUNT_ERROR_NONE || volume_info.mount_condition) | 613 if (error_code == chromeos::MOUNT_ERROR_NONE || volume_info.mount_condition) |
| 562 mounted_volumes_[volume_info.volume_id] = volume_info; | 614 mounted_volumes_[volume_info.volume_id] = volume_info; |
| 563 | 615 |
| 564 FOR_EACH_OBSERVER(VolumeManagerObserver, | 616 FOR_EACH_OBSERVER(VolumeManagerObserver, |
| 565 observers_, | 617 observers_, |
| 566 OnVolumeMounted(error_code, volume_info, is_remounting)); | 618 OnVolumeMounted(error_code, volume_info, is_remounting)); |
| 567 } | 619 } |
| 568 | 620 |
| 569 void VolumeManager::DoUnmountEvent(chromeos::MountError error_code, | 621 void VolumeManager::DoUnmountEvent(chromeos::MountError error_code, |
| 570 const VolumeInfo& volume_info) { | 622 const VolumeInfo& volume_info) { |
| 571 if (mounted_volumes_.find(volume_info.volume_id) == mounted_volumes_.end()) | 623 if (mounted_volumes_.find(volume_info.volume_id) == mounted_volumes_.end()) |
| 572 return; | 624 return; |
| 573 if (error_code == chromeos::MOUNT_ERROR_NONE) | 625 if (error_code == chromeos::MOUNT_ERROR_NONE) |
| 574 mounted_volumes_.erase(volume_info.volume_id); | 626 mounted_volumes_.erase(volume_info.volume_id); |
| 575 | 627 |
| 576 FOR_EACH_OBSERVER(VolumeManagerObserver, | 628 FOR_EACH_OBSERVER(VolumeManagerObserver, |
| 577 observers_, | 629 observers_, |
| 578 OnVolumeUnmounted(error_code, volume_info)); | 630 OnVolumeUnmounted(error_code, volume_info)); |
| 579 } | 631 } |
| 580 | 632 |
| 581 } // namespace file_manager | 633 } // namespace file_manager |
| OLD | NEW |