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" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
15 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 15 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
16 #include "chrome/browser/chromeos/drive/file_errors.h" | 16 #include "chrome/browser/chromeos/drive/file_errors.h" |
17 #include "chrome/browser/chromeos/drive/file_system_interface.h" | 17 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
18 #include "chrome/browser/chromeos/drive/file_system_util.h" | 18 #include "chrome/browser/chromeos/drive/file_system_util.h" |
19 #include "chrome/browser/chromeos/file_manager/mounted_disk_monitor.h" | 19 #include "chrome/browser/chromeos/file_manager/mounted_disk_monitor.h" |
20 #include "chrome/browser/chromeos/file_manager/path_util.h" | 20 #include "chrome/browser/chromeos/file_manager/path_util.h" |
21 #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h" | 21 #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h" |
22 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" | 22 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" |
23 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" | 23 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" |
24 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 24 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
25 #include "chrome/browser/local_discovery/storage/privet_filesystem_constants.h" | 25 #include "chrome/browser/local_discovery/storage/privet_filesystem_constants.h" |
26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
28 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
29 #include "chromeos/dbus/cros_disks_client.h" | 29 #include "chromeos/dbus/cros_disks_client.h" |
30 #include "chromeos/disks/disk_mount_manager.h" | 30 #include "chromeos/disks/disk_mount_manager.h" |
31 #include "content/public/browser/browser_context.h" | 31 #include "content/public/browser/browser_context.h" |
32 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
33 #include "webkit/browser/fileapi/external_mount_points.h" | 33 #include "webkit/browser/fileapi/external_mount_points.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 volume_info.type = VOLUME_TYPE_CLOUD_DEVICE; | 196 volume_info.type = VOLUME_TYPE_CLOUD_DEVICE; |
197 volume_info.mount_path = privet_volume_info.volume_path; | 197 volume_info.mount_path = privet_volume_info.volume_path; |
198 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE; | 198 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE; |
199 volume_info.is_parent = true; | 199 volume_info.is_parent = true; |
200 volume_info.is_read_only = true; | 200 volume_info.is_read_only = true; |
201 volume_info.volume_id = GenerateVolumeId(volume_info); | 201 volume_info.volume_id = GenerateVolumeId(volume_info); |
202 return volume_info; | 202 return volume_info; |
203 } | 203 } |
204 | 204 |
205 VolumeInfo CreateProvidedFileSystemVolumeInfo( | 205 VolumeInfo CreateProvidedFileSystemVolumeInfo( |
206 const chromeos::file_system_provider::ProvidedFileSystem& file_system) { | 206 const chromeos::file_system_provider::ProvidedFileSystemInfo& |
| 207 file_system_info) { |
207 VolumeInfo volume_info; | 208 VolumeInfo volume_info; |
208 volume_info.type = VOLUME_TYPE_PROVIDED; | 209 volume_info.type = VOLUME_TYPE_PROVIDED; |
209 volume_info.mount_path = file_system.mount_path(); | 210 volume_info.mount_path = file_system_info.mount_path(); |
210 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE; | 211 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE; |
211 volume_info.is_parent = true; | 212 volume_info.is_parent = true; |
212 volume_info.is_read_only = true; | 213 volume_info.is_read_only = true; |
213 volume_info.volume_id = GenerateVolumeId(volume_info); | 214 volume_info.volume_id = GenerateVolumeId(volume_info); |
214 volume_info.file_system_id = file_system.file_system_id(); | 215 volume_info.file_system_id = file_system_info.file_system_id(); |
215 return volume_info; | 216 return volume_info; |
216 } | 217 } |
217 | 218 |
218 } // namespace | 219 } // namespace |
219 | 220 |
220 VolumeInfo::VolumeInfo() | 221 VolumeInfo::VolumeInfo() |
221 : file_system_id(0), | 222 : file_system_id(0), |
222 type(VOLUME_TYPE_GOOGLE_DRIVE), | 223 type(VOLUME_TYPE_GOOGLE_DRIVE), |
223 mount_condition(chromeos::disks::MOUNT_CONDITION_NONE), | 224 mount_condition(chromeos::disks::MOUNT_CONDITION_NONE), |
224 is_parent(false), | 225 is_parent(false), |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 kNotRemounting); | 291 kNotRemounting); |
291 } | 292 } |
292 } | 293 } |
293 | 294 |
294 // Subscribe to DiskMountManager. | 295 // Subscribe to DiskMountManager. |
295 disk_mount_manager_->AddObserver(this); | 296 disk_mount_manager_->AddObserver(this); |
296 | 297 |
297 // Subscribe to FileSystemProviderService and register currently mounted | 298 // Subscribe to FileSystemProviderService and register currently mounted |
298 // volumes for the profile. | 299 // volumes for the profile. |
299 if (file_system_provider_service_) { | 300 if (file_system_provider_service_) { |
300 using chromeos::file_system_provider::ProvidedFileSystem; | 301 using chromeos::file_system_provider::ProvidedFileSystemInfo; |
301 file_system_provider_service_->AddObserver(this); | 302 file_system_provider_service_->AddObserver(this); |
302 | 303 |
303 std::vector<ProvidedFileSystem> provided_file_systems = | 304 std::vector<ProvidedFileSystemInfo> file_system_info_list = |
304 file_system_provider_service_->GetMountedFileSystems(); | 305 file_system_provider_service_->GetProvidedFileSystemInfoList(); |
305 for (size_t i = 0; i < provided_file_systems.size(); ++i) { | 306 for (size_t i = 0; i < file_system_info_list.size(); ++i) { |
306 VolumeInfo volume_info = | 307 VolumeInfo volume_info = |
307 CreateProvidedFileSystemVolumeInfo(provided_file_systems[i]); | 308 CreateProvidedFileSystemVolumeInfo(file_system_info_list[i]); |
308 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, kNotRemounting); | 309 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, kNotRemounting); |
309 } | 310 } |
310 } | 311 } |
311 | 312 |
312 std::vector<VolumeInfo> archives; | 313 std::vector<VolumeInfo> archives; |
313 | 314 |
314 const chromeos::disks::DiskMountManager::MountPointMap& mount_points = | 315 const chromeos::disks::DiskMountManager::MountPointMap& mount_points = |
315 disk_mount_manager_->mount_points(); | 316 disk_mount_manager_->mount_points(); |
316 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it = | 317 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it = |
317 mount_points.begin(); | 318 mount_points.begin(); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 VolumeManagerObserver, observers_, | 619 VolumeManagerObserver, observers_, |
619 OnFormatCompleted(device_path, | 620 OnFormatCompleted(device_path, |
620 error_code == chromeos::FORMAT_ERROR_NONE)); | 621 error_code == chromeos::FORMAT_ERROR_NONE)); |
621 | 622 |
622 return; | 623 return; |
623 } | 624 } |
624 NOTREACHED(); | 625 NOTREACHED(); |
625 } | 626 } |
626 | 627 |
627 void VolumeManager::OnProvidedFileSystemMount( | 628 void VolumeManager::OnProvidedFileSystemMount( |
628 const chromeos::file_system_provider::ProvidedFileSystem& file_system, | 629 const chromeos::file_system_provider::ProvidedFileSystemInfo& |
| 630 file_system_info, |
629 base::File::Error error) { | 631 base::File::Error error) { |
630 VolumeInfo volume_info = CreateProvidedFileSystemVolumeInfo(file_system); | 632 VolumeInfo volume_info = CreateProvidedFileSystemVolumeInfo(file_system_info); |
631 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, | 633 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, |
632 // since it is related to cros disks only. | 634 // since it is related to cros disks only. |
633 const chromeos::MountError mount_error = error == base::File::FILE_OK | 635 const chromeos::MountError mount_error = error == base::File::FILE_OK |
634 ? chromeos::MOUNT_ERROR_NONE | 636 ? chromeos::MOUNT_ERROR_NONE |
635 : chromeos::MOUNT_ERROR_UNKNOWN; | 637 : chromeos::MOUNT_ERROR_UNKNOWN; |
636 DoMountEvent(mount_error, volume_info, false /* remounting */); | 638 DoMountEvent(mount_error, volume_info, false /* remounting */); |
637 } | 639 } |
638 | 640 |
639 void VolumeManager::OnProvidedFileSystemUnmount( | 641 void VolumeManager::OnProvidedFileSystemUnmount( |
640 const chromeos::file_system_provider::ProvidedFileSystem& file_system, | 642 const chromeos::file_system_provider::ProvidedFileSystemInfo& |
| 643 file_system_info, |
641 base::File::Error error) { | 644 base::File::Error error) { |
642 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, | 645 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, |
643 // since it is related to cros disks only. | 646 // since it is related to cros disks only. |
644 const chromeos::MountError mount_error = error == base::File::FILE_OK | 647 const chromeos::MountError mount_error = error == base::File::FILE_OK |
645 ? chromeos::MOUNT_ERROR_NONE | 648 ? chromeos::MOUNT_ERROR_NONE |
646 : chromeos::MOUNT_ERROR_UNKNOWN; | 649 : chromeos::MOUNT_ERROR_UNKNOWN; |
647 VolumeInfo volume_info = CreateProvidedFileSystemVolumeInfo(file_system); | 650 VolumeInfo volume_info = CreateProvidedFileSystemVolumeInfo(file_system_info); |
648 DoUnmountEvent(mount_error, volume_info); | 651 DoUnmountEvent(mount_error, volume_info); |
649 } | 652 } |
650 | 653 |
651 void VolumeManager::OnExternalStorageDisabledChanged() { | 654 void VolumeManager::OnExternalStorageDisabledChanged() { |
652 // If the policy just got disabled we have to unmount every device currently | 655 // If the policy just got disabled we have to unmount every device currently |
653 // mounted. The opposite is fine - we can let the user re-plug her device to | 656 // mounted. The opposite is fine - we can let the user re-plug her device to |
654 // make it available. | 657 // make it available. |
655 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { | 658 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { |
656 // We do not iterate on mount_points directly, because mount_points can | 659 // We do not iterate on mount_points directly, because mount_points can |
657 // be changed by UnmountPath(). | 660 // be changed by UnmountPath(). |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 return; | 721 return; |
719 if (error_code == chromeos::MOUNT_ERROR_NONE) | 722 if (error_code == chromeos::MOUNT_ERROR_NONE) |
720 mounted_volumes_.erase(volume_info.volume_id); | 723 mounted_volumes_.erase(volume_info.volume_id); |
721 | 724 |
722 FOR_EACH_OBSERVER(VolumeManagerObserver, | 725 FOR_EACH_OBSERVER(VolumeManagerObserver, |
723 observers_, | 726 observers_, |
724 OnVolumeUnmounted(error_code, volume_info)); | 727 OnVolumeUnmounted(error_code, volume_info)); |
725 } | 728 } |
726 | 729 |
727 } // namespace file_manager | 730 } // namespace file_manager |
OLD | NEW |