| 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 247 |
| 248 VolumeManager::VolumeManager( | 248 VolumeManager::VolumeManager( |
| 249 Profile* profile, | 249 Profile* profile, |
| 250 drive::DriveIntegrationService* drive_integration_service, | 250 drive::DriveIntegrationService* drive_integration_service, |
| 251 chromeos::PowerManagerClient* power_manager_client, | 251 chromeos::PowerManagerClient* power_manager_client, |
| 252 chromeos::disks::DiskMountManager* disk_mount_manager, | 252 chromeos::disks::DiskMountManager* disk_mount_manager, |
| 253 chromeos::file_system_provider::Service* file_system_provider_service) | 253 chromeos::file_system_provider::Service* file_system_provider_service) |
| 254 : profile_(profile), | 254 : profile_(profile), |
| 255 drive_integration_service_(drive_integration_service), | 255 drive_integration_service_(drive_integration_service), |
| 256 disk_mount_manager_(disk_mount_manager), | 256 disk_mount_manager_(disk_mount_manager), |
| 257 mounted_disk_monitor_( | 257 mounted_disk_monitor_(new MountedDiskMonitor(power_manager_client)), |
| 258 new MountedDiskMonitor(power_manager_client, disk_mount_manager)), | |
| 259 file_system_provider_service_(file_system_provider_service), | 258 file_system_provider_service_(file_system_provider_service), |
| 260 snapshot_manager_(new SnapshotManager(profile_)), | 259 snapshot_manager_(new SnapshotManager(profile_)), |
| 261 weak_ptr_factory_(this) { | 260 weak_ptr_factory_(this) { |
| 262 DCHECK(disk_mount_manager); | 261 DCHECK(disk_mount_manager); |
| 263 } | 262 } |
| 264 | 263 |
| 265 VolumeManager::~VolumeManager() { | 264 VolumeManager::~VolumeManager() { |
| 266 } | 265 } |
| 267 | 266 |
| 268 VolumeManager* VolumeManager::Get(content::BrowserContext* context) { | 267 VolumeManager* VolumeManager::Get(content::BrowserContext* context) { |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 | 497 |
| 499 VolumeInfo volume_info = CreateDriveVolumeInfo(profile_); | 498 VolumeInfo volume_info = CreateDriveVolumeInfo(profile_); |
| 500 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, volume_info); | 499 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, volume_info); |
| 501 } | 500 } |
| 502 | 501 |
| 503 void VolumeManager::OnDiskEvent( | 502 void VolumeManager::OnDiskEvent( |
| 504 chromeos::disks::DiskMountManager::DiskEvent event, | 503 chromeos::disks::DiskMountManager::DiskEvent event, |
| 505 const chromeos::disks::DiskMountManager::Disk* disk) { | 504 const chromeos::disks::DiskMountManager::Disk* disk) { |
| 506 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 505 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 507 | 506 |
| 507 mounted_disk_monitor_->OnDiskEvent(event, disk); |
| 508 |
| 508 // Disregard hidden devices. | 509 // Disregard hidden devices. |
| 509 if (disk->is_hidden()) | 510 if (disk->is_hidden()) |
| 510 return; | 511 return; |
| 511 | 512 |
| 512 switch (event) { | 513 switch (event) { |
| 513 case chromeos::disks::DiskMountManager::DISK_ADDED: | 514 case chromeos::disks::DiskMountManager::DISK_ADDED: |
| 514 case chromeos::disks::DiskMountManager::DISK_CHANGED: { | 515 case chromeos::disks::DiskMountManager::DISK_CHANGED: { |
| 515 if (disk->device_path().empty()) { | 516 if (disk->device_path().empty()) { |
| 516 DVLOG(1) << "Empty system path for " << disk->device_path(); | 517 DVLOG(1) << "Empty system path for " << disk->device_path(); |
| 517 return; | 518 return; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 } | 559 } |
| 559 return; | 560 return; |
| 560 } | 561 } |
| 561 NOTREACHED(); | 562 NOTREACHED(); |
| 562 } | 563 } |
| 563 | 564 |
| 564 void VolumeManager::OnDeviceEvent( | 565 void VolumeManager::OnDeviceEvent( |
| 565 chromeos::disks::DiskMountManager::DeviceEvent event, | 566 chromeos::disks::DiskMountManager::DeviceEvent event, |
| 566 const std::string& device_path) { | 567 const std::string& device_path) { |
| 567 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 568 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 569 |
| 570 mounted_disk_monitor_->OnDeviceEvent(event, device_path); |
| 571 |
| 568 DVLOG(1) << "OnDeviceEvent: " << event << ", " << device_path; | 572 DVLOG(1) << "OnDeviceEvent: " << event << ", " << device_path; |
| 569 | |
| 570 switch (event) { | 573 switch (event) { |
| 571 case chromeos::disks::DiskMountManager::DEVICE_ADDED: | 574 case chromeos::disks::DiskMountManager::DEVICE_ADDED: |
| 572 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, | 575 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, |
| 573 OnDeviceAdded(device_path)); | 576 OnDeviceAdded(device_path)); |
| 574 return; | 577 return; |
| 575 case chromeos::disks::DiskMountManager::DEVICE_REMOVED: { | 578 case chromeos::disks::DiskMountManager::DEVICE_REMOVED: { |
| 576 FOR_EACH_OBSERVER( | 579 FOR_EACH_OBSERVER( |
| 577 VolumeManagerObserver, observers_, OnDeviceRemoved(device_path)); | 580 VolumeManagerObserver, observers_, OnDeviceRemoved(device_path)); |
| 578 return; | 581 return; |
| 579 } | 582 } |
| 580 case chromeos::disks::DiskMountManager::DEVICE_SCANNED: | 583 case chromeos::disks::DiskMountManager::DEVICE_SCANNED: |
| 581 DVLOG(1) << "Ignore SCANNED event: " << device_path; | 584 DVLOG(1) << "Ignore SCANNED event: " << device_path; |
| 582 return; | 585 return; |
| 583 } | 586 } |
| 584 NOTREACHED(); | 587 NOTREACHED(); |
| 585 } | 588 } |
| 586 | 589 |
| 587 void VolumeManager::OnMountEvent( | 590 void VolumeManager::OnMountEvent( |
| 588 chromeos::disks::DiskMountManager::MountEvent event, | 591 chromeos::disks::DiskMountManager::MountEvent event, |
| 589 chromeos::MountError error_code, | 592 chromeos::MountError error_code, |
| 590 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) { | 593 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) { |
| 591 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 594 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 592 DCHECK_NE(chromeos::MOUNT_TYPE_INVALID, mount_info.mount_type); | 595 DCHECK_NE(chromeos::MOUNT_TYPE_INVALID, mount_info.mount_type); |
| 593 | 596 |
| 597 const chromeos::disks::DiskMountManager::Disk* disk = |
| 598 disk_mount_manager_->FindDiskBySourcePath(mount_info.source_path); |
| 599 mounted_disk_monitor_->OnMountEvent(event, error_code, mount_info, disk); |
| 600 |
| 594 if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { | 601 if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { |
| 595 // If the file is not mounted now, tell it to drive file system so that | 602 // If the file is not mounted now, tell it to drive file system so that |
| 596 // it can handle file caching correctly. | 603 // it can handle file caching correctly. |
| 597 // Note that drive file system knows if the file is managed by drive file | 604 // Note that drive file system knows if the file is managed by drive file |
| 598 // system or not, so here we report all paths. | 605 // system or not, so here we report all paths. |
| 599 if ((event == chromeos::disks::DiskMountManager::MOUNTING && | 606 if ((event == chromeos::disks::DiskMountManager::MOUNTING && |
| 600 error_code != chromeos::MOUNT_ERROR_NONE) || | 607 error_code != chromeos::MOUNT_ERROR_NONE) || |
| 601 (event == chromeos::disks::DiskMountManager::UNMOUNTING && | 608 (event == chromeos::disks::DiskMountManager::UNMOUNTING && |
| 602 error_code == chromeos::MOUNT_ERROR_NONE)) { | 609 error_code == chromeos::MOUNT_ERROR_NONE)) { |
| 603 drive::FileSystemInterface* file_system = | 610 drive::FileSystemInterface* file_system = |
| 604 drive::util::GetFileSystemByProfile(profile_); | 611 drive::util::GetFileSystemByProfile(profile_); |
| 605 if (file_system) { | 612 if (file_system) { |
| 606 file_system->MarkCacheFileAsUnmounted( | 613 file_system->MarkCacheFileAsUnmounted( |
| 607 base::FilePath(mount_info.source_path), | 614 base::FilePath(mount_info.source_path), |
| 608 base::Bind(&drive::util::EmptyFileOperationCallback)); | 615 base::Bind(&drive::util::EmptyFileOperationCallback)); |
| 609 } | 616 } |
| 610 } | 617 } |
| 611 } | 618 } |
| 612 | 619 |
| 613 // Notify a mounting/unmounting event to observers. | 620 // Notify a mounting/unmounting event to observers. |
| 614 const chromeos::disks::DiskMountManager::Disk* disk = | |
| 615 disk_mount_manager_->FindDiskBySourcePath(mount_info.source_path); | |
| 616 VolumeInfo volume_info = | 621 VolumeInfo volume_info = |
| 617 CreateVolumeInfoFromMountPointInfo(mount_info, disk); | 622 CreateVolumeInfoFromMountPointInfo(mount_info, disk); |
| 618 switch (event) { | 623 switch (event) { |
| 619 case chromeos::disks::DiskMountManager::MOUNTING: { | 624 case chromeos::disks::DiskMountManager::MOUNTING: { |
| 620 bool is_remounting = | 625 bool is_remounting = |
| 621 disk && mounted_disk_monitor_->DiskIsRemounting(*disk); | 626 disk && mounted_disk_monitor_->DiskIsRemounting(*disk); |
| 622 DoMountEvent(error_code, volume_info, is_remounting); | 627 DoMountEvent(error_code, volume_info, is_remounting); |
| 623 return; | 628 return; |
| 624 } | 629 } |
| 625 case chromeos::disks::DiskMountManager::UNMOUNTING: | 630 case chromeos::disks::DiskMountManager::UNMOUNTING: |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 return; | 844 return; |
| 840 if (error_code == chromeos::MOUNT_ERROR_NONE) | 845 if (error_code == chromeos::MOUNT_ERROR_NONE) |
| 841 mounted_volumes_.erase(volume_info.volume_id); | 846 mounted_volumes_.erase(volume_info.volume_id); |
| 842 | 847 |
| 843 FOR_EACH_OBSERVER(VolumeManagerObserver, | 848 FOR_EACH_OBSERVER(VolumeManagerObserver, |
| 844 observers_, | 849 observers_, |
| 845 OnVolumeUnmounted(error_code, volume_info)); | 850 OnVolumeUnmounted(error_code, volume_info)); |
| 846 } | 851 } |
| 847 | 852 |
| 848 } // namespace file_manager | 853 } // namespace file_manager |
| OLD | NEW |