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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 204 |
205 VolumeInfo CreateProvidedFileSystemVolumeInfo( | 205 VolumeInfo CreateProvidedFileSystemVolumeInfo( |
206 const chromeos::file_system_provider::ProvidedFileSystem& file_system) { | 206 const chromeos::file_system_provider::ProvidedFileSystem& file_system) { |
207 VolumeInfo volume_info; | 207 VolumeInfo volume_info; |
208 volume_info.type = VOLUME_TYPE_PROVIDED; | 208 volume_info.type = VOLUME_TYPE_PROVIDED; |
209 volume_info.mount_path = file_system.mount_path(); | 209 volume_info.mount_path = file_system.mount_path(); |
210 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE; | 210 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE; |
211 volume_info.is_parent = true; | 211 volume_info.is_parent = true; |
212 volume_info.is_read_only = true; | 212 volume_info.is_read_only = true; |
213 volume_info.volume_id = GenerateVolumeId(volume_info); | 213 volume_info.volume_id = GenerateVolumeId(volume_info); |
| 214 volume_info.file_system_id = file_system.file_system_id(); |
214 return volume_info; | 215 return volume_info; |
215 } | 216 } |
216 | 217 |
217 } // namespace | 218 } // namespace |
218 | 219 |
219 VolumeInfo::VolumeInfo() { | 220 VolumeInfo::VolumeInfo() |
220 } | 221 : file_system_id(0), |
| 222 type(VOLUME_TYPE_GOOGLE_DRIVE), |
| 223 mount_condition(chromeos::disks::MOUNT_CONDITION_NONE), |
| 224 is_parent(false), |
| 225 is_read_only(false) {} |
221 | 226 |
222 VolumeInfo::~VolumeInfo() { | 227 VolumeInfo::~VolumeInfo() { |
223 } | 228 } |
224 | 229 |
225 VolumeManager::VolumeManager( | 230 VolumeManager::VolumeManager( |
226 Profile* profile, | 231 Profile* profile, |
227 drive::DriveIntegrationService* drive_integration_service, | 232 drive::DriveIntegrationService* drive_integration_service, |
228 chromeos::PowerManagerClient* power_manager_client, | 233 chromeos::PowerManagerClient* power_manager_client, |
229 chromeos::disks::DiskMountManager* disk_mount_manager, | 234 chromeos::disks::DiskMountManager* disk_mount_manager, |
230 chromeos::file_system_provider::Service* file_system_provider_service) | 235 chromeos::file_system_provider::Service* file_system_provider_service) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 // Subscribe to DiskMountManager. | 294 // Subscribe to DiskMountManager. |
290 disk_mount_manager_->AddObserver(this); | 295 disk_mount_manager_->AddObserver(this); |
291 | 296 |
292 // Subscribe to FileSystemProviderService and register currently mounted | 297 // Subscribe to FileSystemProviderService and register currently mounted |
293 // volumes for the profile. | 298 // volumes for the profile. |
294 if (file_system_provider_service_) { | 299 if (file_system_provider_service_) { |
295 using chromeos::file_system_provider::ProvidedFileSystem; | 300 using chromeos::file_system_provider::ProvidedFileSystem; |
296 file_system_provider_service_->AddObserver(this); | 301 file_system_provider_service_->AddObserver(this); |
297 | 302 |
298 std::vector<ProvidedFileSystem> provided_file_systems = | 303 std::vector<ProvidedFileSystem> provided_file_systems = |
299 file_system_provider_service_->GetRegisteredFileSystems(); | 304 file_system_provider_service_->GetMountedFileSystems(); |
300 for (size_t i = 0; i < provided_file_systems.size(); ++i) { | 305 for (size_t i = 0; i < provided_file_systems.size(); ++i) { |
301 VolumeInfo volume_info = | 306 VolumeInfo volume_info = |
302 CreateProvidedFileSystemVolumeInfo(provided_file_systems[i]); | 307 CreateProvidedFileSystemVolumeInfo(provided_file_systems[i]); |
303 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, kNotRemounting); | 308 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, kNotRemounting); |
304 } | 309 } |
305 } | 310 } |
306 | 311 |
307 std::vector<VolumeInfo> archives; | 312 std::vector<VolumeInfo> archives; |
308 | 313 |
309 const chromeos::disks::DiskMountManager::MountPointMap& mount_points = | 314 const chromeos::disks::DiskMountManager::MountPointMap& mount_points = |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 FOR_EACH_OBSERVER( | 617 FOR_EACH_OBSERVER( |
613 VolumeManagerObserver, observers_, | 618 VolumeManagerObserver, observers_, |
614 OnFormatCompleted(device_path, | 619 OnFormatCompleted(device_path, |
615 error_code == chromeos::FORMAT_ERROR_NONE)); | 620 error_code == chromeos::FORMAT_ERROR_NONE)); |
616 | 621 |
617 return; | 622 return; |
618 } | 623 } |
619 NOTREACHED(); | 624 NOTREACHED(); |
620 } | 625 } |
621 | 626 |
622 void VolumeManager::OnProvidedFileSystemRegistered( | 627 void VolumeManager::OnProvidedFileSystemMount( |
623 const chromeos::file_system_provider::ProvidedFileSystem& file_system) { | 628 const chromeos::file_system_provider::ProvidedFileSystem& file_system, |
| 629 base::File::Error error) { |
624 VolumeInfo volume_info = CreateProvidedFileSystemVolumeInfo(file_system); | 630 VolumeInfo volume_info = CreateProvidedFileSystemVolumeInfo(file_system); |
625 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, false /* remounting */); | 631 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, |
| 632 // since it is related to cros disks only. |
| 633 const chromeos::MountError mount_error = error == base::File::FILE_OK |
| 634 ? chromeos::MOUNT_ERROR_NONE |
| 635 : chromeos::MOUNT_ERROR_UNKNOWN; |
| 636 DoMountEvent(mount_error, volume_info, false /* remounting */); |
626 } | 637 } |
627 | 638 |
628 void VolumeManager::OnProvidedFileSystemUnregistered( | 639 void VolumeManager::OnProvidedFileSystemUnmount( |
629 const chromeos::file_system_provider::ProvidedFileSystem& file_system) { | 640 const chromeos::file_system_provider::ProvidedFileSystem& file_system, |
| 641 base::File::Error error) { |
| 642 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, |
| 643 // since it is related to cros disks only. |
| 644 const chromeos::MountError mount_error = error == base::File::FILE_OK |
| 645 ? chromeos::MOUNT_ERROR_NONE |
| 646 : chromeos::MOUNT_ERROR_UNKNOWN; |
630 VolumeInfo volume_info = CreateProvidedFileSystemVolumeInfo(file_system); | 647 VolumeInfo volume_info = CreateProvidedFileSystemVolumeInfo(file_system); |
631 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, volume_info); | 648 DoUnmountEvent(mount_error, volume_info); |
632 } | 649 } |
633 | 650 |
634 void VolumeManager::OnExternalStorageDisabledChanged() { | 651 void VolumeManager::OnExternalStorageDisabledChanged() { |
635 // If the policy just got disabled we have to unmount every device currently | 652 // If the policy just got disabled we have to unmount every device currently |
636 // mounted. The opposite is fine - we can let the user re-plug her device to | 653 // mounted. The opposite is fine - we can let the user re-plug her device to |
637 // make it available. | 654 // make it available. |
638 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { | 655 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { |
639 // We do not iterate on mount_points directly, because mount_points can | 656 // We do not iterate on mount_points directly, because mount_points can |
640 // be changed by UnmountPath(). | 657 // be changed by UnmountPath(). |
641 // TODO(hidehiko): Is it necessary to unmount mounted archives, too, here? | 658 // TODO(hidehiko): Is it necessary to unmount mounted archives, too, here? |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 return; | 718 return; |
702 if (error_code == chromeos::MOUNT_ERROR_NONE) | 719 if (error_code == chromeos::MOUNT_ERROR_NONE) |
703 mounted_volumes_.erase(volume_info.volume_id); | 720 mounted_volumes_.erase(volume_info.volume_id); |
704 | 721 |
705 FOR_EACH_OBSERVER(VolumeManagerObserver, | 722 FOR_EACH_OBSERVER(VolumeManagerObserver, |
706 observers_, | 723 observers_, |
707 OnVolumeUnmounted(error_code, volume_info)); | 724 OnVolumeUnmounted(error_code, volume_info)); |
708 } | 725 } |
709 | 726 |
710 } // namespace file_manager | 727 } // namespace file_manager |
OLD | NEW |