| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
| 38 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" | 38 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" |
| 39 #include "storage/browser/fileapi/external_mount_points.h" | 39 #include "storage/browser/fileapi/external_mount_points.h" |
| 40 | 40 |
| 41 namespace file_manager { | 41 namespace file_manager { |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 const uint32_t kAccessCapabilityReadWrite = 0; | 44 const uint32_t kAccessCapabilityReadWrite = 0; |
| 45 const uint32_t kFilesystemTypeGenericHierarchical = 2; | 45 const uint32_t kFilesystemTypeGenericHierarchical = 2; |
| 46 const char kFileManagerMTPMountNamePrefix[] = "fileman-mtp-"; | 46 const char kFileManagerMTPMountNamePrefix[] = "fileman-mtp-"; |
| 47 const char kMtpVolumeIdPrefix [] = "mtp:"; | 47 const char kMtpVolumeIdPrefix[] = "mtp:"; |
| 48 const char kRootPath[] = "/"; | 48 const char kRootPath[] = "/"; |
| 49 | 49 |
| 50 // Registers |path| as the "Downloads" folder to the FileSystem API backend. | 50 // Registers |path| as the "Downloads" folder to the FileSystem API backend. |
| 51 // If another folder is already mounted. It revokes and overrides the old one. | 51 // If another folder is already mounted. It revokes and overrides the old one. |
| 52 bool RegisterDownloadsMountPoint(Profile* profile, const base::FilePath& path) { | 52 bool RegisterDownloadsMountPoint(Profile* profile, const base::FilePath& path) { |
| 53 // Although we show only profile's own "Downloads" folder in Files.app, | 53 // Although we show only profile's own "Downloads" folder in Files.app, |
| 54 // in the backend we need to mount all profile's download directory globally. | 54 // in the backend we need to mount all profile's download directory globally. |
| 55 // Otherwise, Files.app cannot support cross-profile file copies, etc. | 55 // Otherwise, Files.app cannot support cross-profile file copies, etc. |
| 56 // For this reason, we need to register to the global GetSystemInstance(). | 56 // For this reason, we need to register to the global GetSystemInstance(). |
| 57 const std::string mount_point_name = | 57 const std::string mount_point_name = |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 // format if the second argument is empty. The third argument (mount | 501 // format if the second argument is empty. The third argument (mount |
| 502 // label) is not used in a disk mount operation. | 502 // label) is not used in a disk mount operation. |
| 503 disk_mount_manager_->MountPath(disk->device_path(), std::string(), | 503 disk_mount_manager_->MountPath(disk->device_path(), std::string(), |
| 504 std::string(), | 504 std::string(), |
| 505 chromeos::MOUNT_TYPE_DEVICE, | 505 chromeos::MOUNT_TYPE_DEVICE, |
| 506 GetExternalStorageAccessMode(profile_)); | 506 GetExternalStorageAccessMode(profile_)); |
| 507 mounting = true; | 507 mounting = true; |
| 508 } | 508 } |
| 509 | 509 |
| 510 // Notify to observers. | 510 // Notify to observers. |
| 511 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, | 511 for (auto& observer : observers_) |
| 512 OnDiskAdded(*disk, mounting)); | 512 observer.OnDiskAdded(*disk, mounting); |
| 513 return; | 513 return; |
| 514 } | 514 } |
| 515 | 515 |
| 516 case chromeos::disks::DiskMountManager::DISK_REMOVED: | 516 case chromeos::disks::DiskMountManager::DISK_REMOVED: |
| 517 // If the disk is already mounted, unmount it. | 517 // If the disk is already mounted, unmount it. |
| 518 if (!disk->mount_path().empty()) { | 518 if (!disk->mount_path().empty()) { |
| 519 disk_mount_manager_->UnmountPath( | 519 disk_mount_manager_->UnmountPath( |
| 520 disk->mount_path(), | 520 disk->mount_path(), |
| 521 chromeos::UNMOUNT_OPTIONS_LAZY, | 521 chromeos::UNMOUNT_OPTIONS_LAZY, |
| 522 chromeos::disks::DiskMountManager::UnmountPathCallback()); | 522 chromeos::disks::DiskMountManager::UnmountPathCallback()); |
| 523 } | 523 } |
| 524 | 524 |
| 525 // Notify to observers. | 525 // Notify to observers. |
| 526 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, | 526 for (auto& observer : observers_) |
| 527 OnDiskRemoved(*disk)); | 527 observer.OnDiskRemoved(*disk); |
| 528 return; | 528 return; |
| 529 } | 529 } |
| 530 NOTREACHED(); | 530 NOTREACHED(); |
| 531 } | 531 } |
| 532 | 532 |
| 533 void VolumeManager::OnDeviceEvent( | 533 void VolumeManager::OnDeviceEvent( |
| 534 chromeos::disks::DiskMountManager::DeviceEvent event, | 534 chromeos::disks::DiskMountManager::DeviceEvent event, |
| 535 const std::string& device_path) { | 535 const std::string& device_path) { |
| 536 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 536 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 537 | 537 |
| 538 DVLOG(1) << "OnDeviceEvent: " << event << ", " << device_path; | 538 DVLOG(1) << "OnDeviceEvent: " << event << ", " << device_path; |
| 539 switch (event) { | 539 switch (event) { |
| 540 case chromeos::disks::DiskMountManager::DEVICE_ADDED: | 540 case chromeos::disks::DiskMountManager::DEVICE_ADDED: |
| 541 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, | 541 for (auto& observer : observers_) |
| 542 OnDeviceAdded(device_path)); | 542 observer.OnDeviceAdded(device_path); |
| 543 return; | 543 return; |
| 544 case chromeos::disks::DiskMountManager::DEVICE_REMOVED: { | 544 case chromeos::disks::DiskMountManager::DEVICE_REMOVED: { |
| 545 FOR_EACH_OBSERVER( | 545 for (auto& observer : observers_) |
| 546 VolumeManagerObserver, observers_, OnDeviceRemoved(device_path)); | 546 observer.OnDeviceRemoved(device_path); |
| 547 return; | 547 return; |
| 548 } | 548 } |
| 549 case chromeos::disks::DiskMountManager::DEVICE_SCANNED: | 549 case chromeos::disks::DiskMountManager::DEVICE_SCANNED: |
| 550 DVLOG(1) << "Ignore SCANNED event: " << device_path; | 550 DVLOG(1) << "Ignore SCANNED event: " << device_path; |
| 551 return; | 551 return; |
| 552 } | 552 } |
| 553 NOTREACHED(); | 553 NOTREACHED(); |
| 554 } | 554 } |
| 555 | 555 |
| 556 void VolumeManager::OnMountEvent( | 556 void VolumeManager::OnMountEvent( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 void VolumeManager::OnFormatEvent( | 598 void VolumeManager::OnFormatEvent( |
| 599 chromeos::disks::DiskMountManager::FormatEvent event, | 599 chromeos::disks::DiskMountManager::FormatEvent event, |
| 600 chromeos::FormatError error_code, | 600 chromeos::FormatError error_code, |
| 601 const std::string& device_path) { | 601 const std::string& device_path) { |
| 602 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 602 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 603 DVLOG(1) << "OnDeviceEvent: " << event << ", " << error_code | 603 DVLOG(1) << "OnDeviceEvent: " << event << ", " << error_code |
| 604 << ", " << device_path; | 604 << ", " << device_path; |
| 605 | 605 |
| 606 switch (event) { | 606 switch (event) { |
| 607 case chromeos::disks::DiskMountManager::FORMAT_STARTED: | 607 case chromeos::disks::DiskMountManager::FORMAT_STARTED: |
| 608 FOR_EACH_OBSERVER( | 608 for (auto& observer : observers_) { |
| 609 VolumeManagerObserver, observers_, | 609 observer.OnFormatStarted(device_path, |
| 610 OnFormatStarted(device_path, | 610 error_code == chromeos::FORMAT_ERROR_NONE); |
| 611 error_code == chromeos::FORMAT_ERROR_NONE)); | 611 } |
| 612 return; | 612 return; |
| 613 case chromeos::disks::DiskMountManager::FORMAT_COMPLETED: | 613 case chromeos::disks::DiskMountManager::FORMAT_COMPLETED: |
| 614 if (error_code == chromeos::FORMAT_ERROR_NONE) { | 614 if (error_code == chromeos::FORMAT_ERROR_NONE) { |
| 615 // If format is completed successfully, try to mount the device. | 615 // If format is completed successfully, try to mount the device. |
| 616 // MountPath auto-detects filesystem format if second argument is | 616 // MountPath auto-detects filesystem format if second argument is |
| 617 // empty. The third argument (mount label) is not used in a disk mount | 617 // empty. The third argument (mount label) is not used in a disk mount |
| 618 // operation. | 618 // operation. |
| 619 disk_mount_manager_->MountPath(device_path, std::string(), | 619 disk_mount_manager_->MountPath(device_path, std::string(), |
| 620 std::string(), | 620 std::string(), |
| 621 chromeos::MOUNT_TYPE_DEVICE, | 621 chromeos::MOUNT_TYPE_DEVICE, |
| 622 GetExternalStorageAccessMode(profile_)); | 622 GetExternalStorageAccessMode(profile_)); |
| 623 } | 623 } |
| 624 | 624 |
| 625 FOR_EACH_OBSERVER( | 625 for (auto& observer : observers_) { |
| 626 VolumeManagerObserver, observers_, | 626 observer.OnFormatCompleted(device_path, |
| 627 OnFormatCompleted(device_path, | 627 error_code == chromeos::FORMAT_ERROR_NONE); |
| 628 error_code == chromeos::FORMAT_ERROR_NONE)); | 628 } |
| 629 | 629 |
| 630 return; | 630 return; |
| 631 } | 631 } |
| 632 NOTREACHED(); | 632 NOTREACHED(); |
| 633 } | 633 } |
| 634 | 634 |
| 635 void VolumeManager::OnProvidedFileSystemMount( | 635 void VolumeManager::OnProvidedFileSystemMount( |
| 636 const chromeos::file_system_provider::ProvidedFileSystemInfo& | 636 const chromeos::file_system_provider::ProvidedFileSystemInfo& |
| 637 file_system_info, | 637 file_system_info, |
| 638 chromeos::file_system_provider::MountContext context, | 638 chromeos::file_system_provider::MountContext context, |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { | 886 profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { |
| 887 return; | 887 return; |
| 888 } | 888 } |
| 889 | 889 |
| 890 if (error_code == chromeos::MOUNT_ERROR_NONE || volume->mount_condition()) { | 890 if (error_code == chromeos::MOUNT_ERROR_NONE || volume->mount_condition()) { |
| 891 mounted_volumes_[volume->volume_id()] = volume; | 891 mounted_volumes_[volume->volume_id()] = volume; |
| 892 UMA_HISTOGRAM_ENUMERATION("FileBrowser.VolumeType", volume->type(), | 892 UMA_HISTOGRAM_ENUMERATION("FileBrowser.VolumeType", volume->type(), |
| 893 NUM_VOLUME_TYPE); | 893 NUM_VOLUME_TYPE); |
| 894 } | 894 } |
| 895 | 895 |
| 896 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, | 896 for (auto& observer : observers_) |
| 897 OnVolumeMounted(error_code, *volume)); | 897 observer.OnVolumeMounted(error_code, *volume); |
| 898 } | 898 } |
| 899 | 899 |
| 900 void VolumeManager::DoUnmountEvent(chromeos::MountError error_code, | 900 void VolumeManager::DoUnmountEvent(chromeos::MountError error_code, |
| 901 const linked_ptr<Volume>& volume) { | 901 const linked_ptr<Volume>& volume) { |
| 902 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) | 902 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) |
| 903 return; | 903 return; |
| 904 if (error_code == chromeos::MOUNT_ERROR_NONE) | 904 if (error_code == chromeos::MOUNT_ERROR_NONE) |
| 905 mounted_volumes_.erase(volume->volume_id()); | 905 mounted_volumes_.erase(volume->volume_id()); |
| 906 | 906 |
| 907 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, | 907 for (auto& observer : observers_) |
| 908 OnVolumeUnmounted(error_code, *volume.get())); | 908 observer.OnVolumeUnmounted(error_code, *volume.get()); |
| 909 } | 909 } |
| 910 | 910 |
| 911 } // namespace file_manager | 911 } // namespace file_manager |
| OLD | NEW |