Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: chrome/browser/chromeos/file_manager/volume_manager.cc

Issue 210803003: [fsp] Decouple file_service_provider::Service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 case VOLUME_TYPE_GOOGLE_DRIVE: 89 case VOLUME_TYPE_GOOGLE_DRIVE:
90 return "drive"; 90 return "drive";
91 case VOLUME_TYPE_DOWNLOADS_DIRECTORY: 91 case VOLUME_TYPE_DOWNLOADS_DIRECTORY:
92 return "downloads"; 92 return "downloads";
93 case VOLUME_TYPE_REMOVABLE_DISK_PARTITION: 93 case VOLUME_TYPE_REMOVABLE_DISK_PARTITION:
94 return "removable"; 94 return "removable";
95 case VOLUME_TYPE_MOUNTED_ARCHIVE_FILE: 95 case VOLUME_TYPE_MOUNTED_ARCHIVE_FILE:
96 return "archive"; 96 return "archive";
97 case VOLUME_TYPE_CLOUD_DEVICE: 97 case VOLUME_TYPE_CLOUD_DEVICE:
98 return "cloud_device"; 98 return "cloud_device";
99 case VOLUME_TYPE_TESTING:
100 return "testing";
101 case VOLUME_TYPE_PROVIDED: 99 case VOLUME_TYPE_PROVIDED:
102 return "provided"; 100 return "provided";
103 case VOLUME_TYPE_MTP: 101 case VOLUME_TYPE_MTP:
104 return "mtp"; 102 return "mtp";
103 case VOLUME_TYPE_TESTING:
104 return "testing";
105 } 105 }
106 NOTREACHED(); 106 NOTREACHED();
107 return ""; 107 return "";
108 } 108 }
109 109
110 // Generates a unique volume ID for the given volume info. 110 // Generates a unique volume ID for the given volume info.
111 std::string GenerateVolumeId(const VolumeInfo& volume_info) { 111 std::string GenerateVolumeId(const VolumeInfo& volume_info) {
112 // For the same volume type, base names are unique, as mount points are 112 // For the same volume type, base names are unique, as mount points are
113 // flat for the same volume type. 113 // flat for the same volume type.
114 return (VolumeTypeToString(volume_info.type) + ":" + 114 return (VolumeTypeToString(volume_info.type) + ":" +
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 volume_info.type = VOLUME_TYPE_CLOUD_DEVICE; 192 volume_info.type = VOLUME_TYPE_CLOUD_DEVICE;
193 volume_info.mount_path = privet_volume_info.volume_path; 193 volume_info.mount_path = privet_volume_info.volume_path;
194 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE; 194 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE;
195 volume_info.is_parent = true; 195 volume_info.is_parent = true;
196 volume_info.is_read_only = true; 196 volume_info.is_read_only = true;
197 volume_info.volume_id = GenerateVolumeId(volume_info); 197 volume_info.volume_id = GenerateVolumeId(volume_info);
198 return volume_info; 198 return volume_info;
199 } 199 }
200 200
201 VolumeInfo CreateProvidedFileSystemVolumeInfo( 201 VolumeInfo CreateProvidedFileSystemVolumeInfo(
202 const chromeos::file_system_provider::ProvidedFileSystem& file_system) { 202 const chromeos::file_system_provider::ProvidedFileSystemInfo&
203 file_system_info) {
203 VolumeInfo volume_info; 204 VolumeInfo volume_info;
204 volume_info.type = VOLUME_TYPE_PROVIDED; 205 volume_info.type = VOLUME_TYPE_PROVIDED;
205 volume_info.mount_path = file_system.mount_path(); 206 volume_info.mount_path = file_system_info.mount_path();
206 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE; 207 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE;
207 volume_info.is_parent = true; 208 volume_info.is_parent = true;
208 volume_info.is_read_only = true; 209 volume_info.is_read_only = true;
209 volume_info.volume_id = GenerateVolumeId(volume_info); 210 volume_info.volume_id = GenerateVolumeId(volume_info);
210 volume_info.file_system_id = file_system.file_system_id(); 211 volume_info.file_system_id = file_system_info.file_system_id();
211 return volume_info; 212 return volume_info;
212 } 213 }
213 214
214 } // namespace 215 } // namespace
215 216
216 VolumeInfo::VolumeInfo() 217 VolumeInfo::VolumeInfo()
217 : file_system_id(0), 218 : file_system_id(0),
218 type(VOLUME_TYPE_GOOGLE_DRIVE), 219 type(VOLUME_TYPE_GOOGLE_DRIVE),
219 mount_condition(chromeos::disks::MOUNT_CONDITION_NONE), 220 mount_condition(chromeos::disks::MOUNT_CONDITION_NONE),
220 is_parent(false), 221 is_parent(false),
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_manager/volume_manager.h ('k') | chrome/browser/chromeos/file_manager/volume_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698