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 } | 222 } |
222 | 223 |
223 VolumeInfo::~VolumeInfo() { | 224 VolumeInfo::~VolumeInfo() { |
224 } | 225 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 kNotRemounting); | 287 kNotRemounting); |
287 } | 288 } |
288 } | 289 } |
289 | 290 |
290 // Subscribe to DiskMountManager. | 291 // Subscribe to DiskMountManager. |
291 disk_mount_manager_->AddObserver(this); | 292 disk_mount_manager_->AddObserver(this); |
292 | 293 |
293 // Subscribe to FileSystemProviderService and register currently mounted | 294 // Subscribe to FileSystemProviderService and register currently mounted |
294 // volumes for the profile. | 295 // volumes for the profile. |
295 if (file_system_provider_service_) { | 296 if (file_system_provider_service_) { |
296 using chromeos::file_system_provider::ProvidedFileSystem; | 297 using chromeos::file_system_provider::ProvidedFileSystemInfo; |
297 file_system_provider_service_->AddObserver(this); | 298 file_system_provider_service_->AddObserver(this); |
298 | 299 |
299 std::vector<ProvidedFileSystem> provided_file_systems = | 300 std::vector<ProvidedFileSystemInfo> file_system_info_list = |
300 file_system_provider_service_->GetMountedFileSystems(); | 301 file_system_provider_service_->GetProvidedFileSystemInfoList(); |
301 for (size_t i = 0; i < provided_file_systems.size(); ++i) { | 302 for (size_t i = 0; i < file_system_info_list.size(); ++i) { |
302 VolumeInfo volume_info = | 303 VolumeInfo volume_info = |
303 CreateProvidedFileSystemVolumeInfo(provided_file_systems[i]); | 304 CreateProvidedFileSystemVolumeInfo(file_system_info_list[i]); |
304 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, kNotRemounting); | 305 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, kNotRemounting); |
305 } | 306 } |
306 } | 307 } |
307 | 308 |
308 std::vector<VolumeInfo> archives; | 309 std::vector<VolumeInfo> archives; |
309 | 310 |
310 const chromeos::disks::DiskMountManager::MountPointMap& mount_points = | 311 const chromeos::disks::DiskMountManager::MountPointMap& mount_points = |
311 disk_mount_manager_->mount_points(); | 312 disk_mount_manager_->mount_points(); |
312 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it = | 313 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it = |
313 mount_points.begin(); | 314 mount_points.begin(); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 VolumeManagerObserver, observers_, | 615 VolumeManagerObserver, observers_, |
615 OnFormatCompleted(device_path, | 616 OnFormatCompleted(device_path, |
616 error_code == chromeos::FORMAT_ERROR_NONE)); | 617 error_code == chromeos::FORMAT_ERROR_NONE)); |
617 | 618 |
618 return; | 619 return; |
619 } | 620 } |
620 NOTREACHED(); | 621 NOTREACHED(); |
621 } | 622 } |
622 | 623 |
623 void VolumeManager::OnProvidedFileSystemMount( | 624 void VolumeManager::OnProvidedFileSystemMount( |
624 const chromeos::file_system_provider::ProvidedFileSystem& file_system, | 625 const chromeos::file_system_provider::ProvidedFileSystemInfo& |
| 626 file_system_info, |
625 base::File::Error error) { | 627 base::File::Error error) { |
626 VolumeInfo volume_info = CreateProvidedFileSystemVolumeInfo(file_system); | 628 VolumeInfo volume_info = CreateProvidedFileSystemVolumeInfo(file_system_info); |
627 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, | 629 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, |
628 // since it is related to cros disks only. | 630 // since it is related to cros disks only. |
629 const chromeos::MountError mount_error = error == base::File::FILE_OK | 631 const chromeos::MountError mount_error = error == base::File::FILE_OK |
630 ? chromeos::MOUNT_ERROR_NONE | 632 ? chromeos::MOUNT_ERROR_NONE |
631 : chromeos::MOUNT_ERROR_UNKNOWN; | 633 : chromeos::MOUNT_ERROR_UNKNOWN; |
632 DoMountEvent(mount_error, volume_info, false /* remounting */); | 634 DoMountEvent(mount_error, volume_info, false /* remounting */); |
633 } | 635 } |
634 | 636 |
635 void VolumeManager::OnProvidedFileSystemUnmount( | 637 void VolumeManager::OnProvidedFileSystemUnmount( |
636 const chromeos::file_system_provider::ProvidedFileSystem& file_system, | 638 const chromeos::file_system_provider::ProvidedFileSystemInfo& |
| 639 file_system_info, |
637 base::File::Error error) { | 640 base::File::Error error) { |
638 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, | 641 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, |
639 // since it is related to cros disks only. | 642 // since it is related to cros disks only. |
640 const chromeos::MountError mount_error = error == base::File::FILE_OK | 643 const chromeos::MountError mount_error = error == base::File::FILE_OK |
641 ? chromeos::MOUNT_ERROR_NONE | 644 ? chromeos::MOUNT_ERROR_NONE |
642 : chromeos::MOUNT_ERROR_UNKNOWN; | 645 : chromeos::MOUNT_ERROR_UNKNOWN; |
643 VolumeInfo volume_info = CreateProvidedFileSystemVolumeInfo(file_system); | 646 VolumeInfo volume_info = CreateProvidedFileSystemVolumeInfo(file_system_info); |
644 DoUnmountEvent(mount_error, volume_info); | 647 DoUnmountEvent(mount_error, volume_info); |
645 } | 648 } |
646 | 649 |
647 void VolumeManager::OnExternalStorageDisabledChanged() { | 650 void VolumeManager::OnExternalStorageDisabledChanged() { |
648 // If the policy just got disabled we have to unmount every device currently | 651 // If the policy just got disabled we have to unmount every device currently |
649 // mounted. The opposite is fine - we can let the user re-plug her device to | 652 // mounted. The opposite is fine - we can let the user re-plug her device to |
650 // make it available. | 653 // make it available. |
651 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { | 654 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { |
652 // We do not iterate on mount_points directly, because mount_points can | 655 // We do not iterate on mount_points directly, because mount_points can |
653 // be changed by UnmountPath(). | 656 // be changed by UnmountPath(). |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 return; | 717 return; |
715 if (error_code == chromeos::MOUNT_ERROR_NONE) | 718 if (error_code == chromeos::MOUNT_ERROR_NONE) |
716 mounted_volumes_.erase(volume_info.volume_id); | 719 mounted_volumes_.erase(volume_info.volume_id); |
717 | 720 |
718 FOR_EACH_OBSERVER(VolumeManagerObserver, | 721 FOR_EACH_OBSERVER(VolumeManagerObserver, |
719 observers_, | 722 observers_, |
720 OnVolumeUnmounted(error_code, volume_info)); | 723 OnVolumeUnmounted(error_code, volume_info)); |
721 } | 724 } |
722 | 725 |
723 } // namespace file_manager | 726 } // namespace file_manager |
OLD | NEW |