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

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

Issue 192573002: [fsp] Introduce file_system_provider::Service class for the FileSystemProvider API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up. Created 6 years, 9 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/profiles/profile_helper.h" 24 #include "chrome/browser/chromeos/profiles/profile_helper.h"
24 #include "chrome/browser/local_discovery/storage/privet_filesystem_constants.h" 25 #include "chrome/browser/local_discovery/storage/privet_filesystem_constants.h"
25 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
28 #include "chromeos/dbus/cros_disks_client.h" 29 #include "chromeos/dbus/cros_disks_client.h"
29 #include "chromeos/disks/disk_mount_manager.h" 30 #include "chromeos/disks/disk_mount_manager.h"
30 #include "content/public/browser/browser_context.h" 31 #include "content/public/browser/browser_context.h"
31 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
32 #include "webkit/browser/fileapi/external_mount_points.h" 33 #include "webkit/browser/fileapi/external_mount_points.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 case VOLUME_TYPE_DOWNLOADS_DIRECTORY: 97 case VOLUME_TYPE_DOWNLOADS_DIRECTORY:
97 return "downloads"; 98 return "downloads";
98 case VOLUME_TYPE_REMOVABLE_DISK_PARTITION: 99 case VOLUME_TYPE_REMOVABLE_DISK_PARTITION:
99 return "removable"; 100 return "removable";
100 case VOLUME_TYPE_MOUNTED_ARCHIVE_FILE: 101 case VOLUME_TYPE_MOUNTED_ARCHIVE_FILE:
101 return "archive"; 102 return "archive";
102 case VOLUME_TYPE_CLOUD_DEVICE: 103 case VOLUME_TYPE_CLOUD_DEVICE:
103 return "cloud_device"; 104 return "cloud_device";
104 case VOLUME_TYPE_TESTING: 105 case VOLUME_TYPE_TESTING:
105 return "testing"; 106 return "testing";
107 case VOLUME_TYPE_PROVIDED:
108 return "provided";
106 } 109 }
107 NOTREACHED(); 110 NOTREACHED();
108 return ""; 111 return "";
109 } 112 }
110 113
111 // Generates a unique volume ID for the given volume info. 114 // Generates a unique volume ID for the given volume info.
112 std::string GenerateVolumeId(const VolumeInfo& volume_info) { 115 std::string GenerateVolumeId(const VolumeInfo& volume_info) {
113 // For the same volume type, base names are unique, as mount points are 116 // For the same volume type, base names are unique, as mount points are
114 // flat for the same volume type. 117 // flat for the same volume type.
115 return (VolumeTypeToString(volume_info.type) + ":" + 118 return (VolumeTypeToString(volume_info.type) + ":" +
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 VolumeInfo volume_info; 193 VolumeInfo volume_info;
191 volume_info.type = VOLUME_TYPE_CLOUD_DEVICE; 194 volume_info.type = VOLUME_TYPE_CLOUD_DEVICE;
192 volume_info.mount_path = privet_volume_info.volume_path; 195 volume_info.mount_path = privet_volume_info.volume_path;
193 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE; 196 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE;
194 volume_info.is_parent = true; 197 volume_info.is_parent = true;
195 volume_info.is_read_only = true; 198 volume_info.is_read_only = true;
196 volume_info.volume_id = GenerateVolumeId(volume_info); 199 volume_info.volume_id = GenerateVolumeId(volume_info);
197 return volume_info; 200 return volume_info;
198 } 201 }
199 202
203 VolumeInfo CreateProvidedFileSystemVolumeInfo(
204 const chromeos::file_system_provider::ProvidedFileSystem& file_system) {
205 VolumeInfo volume_info;
206 volume_info.type = VOLUME_TYPE_PROVIDED;
207 volume_info.mount_path = file_system.mount_path;
208 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE;
209 volume_info.is_parent = true;
210 volume_info.is_read_only = true;
211 volume_info.volume_id = GenerateVolumeId(volume_info);
212 return volume_info;
213 }
214
200 } // namespace 215 } // namespace
201 216
202 VolumeInfo::VolumeInfo() { 217 VolumeInfo::VolumeInfo() {
203 } 218 }
204 219
205 VolumeInfo::~VolumeInfo() { 220 VolumeInfo::~VolumeInfo() {
206 } 221 }
207 222
208 VolumeManager::VolumeManager( 223 VolumeManager::VolumeManager(
209 Profile* profile, 224 Profile* profile,
210 drive::DriveIntegrationService* drive_integration_service, 225 drive::DriveIntegrationService* drive_integration_service,
211 chromeos::PowerManagerClient* power_manager_client, 226 chromeos::PowerManagerClient* power_manager_client,
212 chromeos::disks::DiskMountManager* disk_mount_manager) 227 chromeos::disks::DiskMountManager* disk_mount_manager,
228 chromeos::file_system_provider::Service* file_system_provider_service)
213 : profile_(profile), 229 : profile_(profile),
214 drive_integration_service_(drive_integration_service), 230 drive_integration_service_(drive_integration_service),
215 disk_mount_manager_(disk_mount_manager), 231 disk_mount_manager_(disk_mount_manager),
216 mounted_disk_monitor_( 232 mounted_disk_monitor_(
217 new MountedDiskMonitor(power_manager_client, disk_mount_manager)) { 233 new MountedDiskMonitor(power_manager_client, disk_mount_manager)),
234 file_system_provider_service_(file_system_provider_service) {
218 DCHECK(disk_mount_manager); 235 DCHECK(disk_mount_manager);
219 } 236 }
220 237
221 VolumeManager::~VolumeManager() { 238 VolumeManager::~VolumeManager() {
222 } 239 }
223 240
224 VolumeManager* VolumeManager::Get(content::BrowserContext* context) { 241 VolumeManager* VolumeManager::Get(content::BrowserContext* context) {
225 return VolumeManagerFactory::Get(context); 242 return VolumeManagerFactory::Get(context);
226 } 243 }
227 244
228 void VolumeManager::Initialize() { 245 void VolumeManager::Initialize() {
229 const bool kNotRemounting = false; 246 static const bool kNotRemounting = false;
230 247
231 // Path to mount user folders have changed several times. We need to migrate 248 // Path to mount user folders have changed several times. We need to migrate
232 // the old preferences on paths to the new format when needed. For the detail, 249 // the old preferences on paths to the new format when needed. For the detail,
233 // see the comments in file_manager::util::MigratePathFromOldFormat, 250 // see the comments in file_manager::util::MigratePathFromOldFormat,
234 // Note: Preferences related to downloads are handled in download_prefs.cc. 251 // Note: Preferences related to downloads are handled in download_prefs.cc.
235 // TODO(kinaba): Remove this after several rounds of releases. 252 // TODO(kinaba): Remove this after several rounds of releases.
236 const base::FilePath old_path = 253 const base::FilePath old_path =
237 profile_->GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); 254 profile_->GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory);
238 base::FilePath new_path; 255 base::FilePath new_path;
239 if (!old_path.empty() && 256 if (!old_path.empty() &&
(...skipping 23 matching lines...) Expand all
263 if (drive_integration_service_->IsMounted()) { 280 if (drive_integration_service_->IsMounted()) {
264 DoMountEvent(chromeos::MOUNT_ERROR_NONE, 281 DoMountEvent(chromeos::MOUNT_ERROR_NONE,
265 CreateDriveVolumeInfo(profile_), 282 CreateDriveVolumeInfo(profile_),
266 kNotRemounting); 283 kNotRemounting);
267 } 284 }
268 } 285 }
269 286
270 // Subscribe to DiskMountManager. 287 // Subscribe to DiskMountManager.
271 disk_mount_manager_->AddObserver(this); 288 disk_mount_manager_->AddObserver(this);
272 289
290 // Subscribe to FileSystemProviderService and register currently mounted
291 // volumes for the profile.
292 if (file_system_provider_service_) {
293 using chromeos::file_system_provider::ProvidedFileSystem;
294 file_system_provider_service_->AddObserver(this);
295
296 std::vector<ProvidedFileSystem> provided_file_systems =
297 file_system_provider_service_->GetRegisteredFileSystems();
298 for (size_t i = 0; i < provided_file_systems.size(); ++i) {
299 VolumeInfo volume_info =
300 CreateProvidedFileSystemVolumeInfo(provided_file_systems[i]);
301 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, kNotRemounting);
302 }
303 }
304
273 std::vector<VolumeInfo> archives; 305 std::vector<VolumeInfo> archives;
274 306
275 const chromeos::disks::DiskMountManager::MountPointMap& mount_points = 307 const chromeos::disks::DiskMountManager::MountPointMap& mount_points =
276 disk_mount_manager_->mount_points(); 308 disk_mount_manager_->mount_points();
277 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it = 309 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it =
278 mount_points.begin(); 310 mount_points.begin();
279 it != mount_points.end(); 311 it != mount_points.end();
280 ++it) { 312 ++it) {
281 if (it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { 313 if (it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) {
282 // Archives are mounted after other type of volumes. See below. 314 // Archives are mounted after other type of volumes. See below.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 privet_volume_lister_->Start(); 365 privet_volume_lister_->Start();
334 } 366 }
335 } 367 }
336 368
337 void VolumeManager::Shutdown() { 369 void VolumeManager::Shutdown() {
338 pref_change_registrar_.RemoveAll(); 370 pref_change_registrar_.RemoveAll();
339 disk_mount_manager_->RemoveObserver(this); 371 disk_mount_manager_->RemoveObserver(this);
340 372
341 if (drive_integration_service_) 373 if (drive_integration_service_)
342 drive_integration_service_->RemoveObserver(this); 374 drive_integration_service_->RemoveObserver(this);
375
376 if (file_system_provider_service_)
377 file_system_provider_service_->RemoveObserver(this);
343 } 378 }
344 379
345 void VolumeManager::AddObserver(VolumeManagerObserver* observer) { 380 void VolumeManager::AddObserver(VolumeManagerObserver* observer) {
346 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 381 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
347 DCHECK(observer); 382 DCHECK(observer);
348 observers_.AddObserver(observer); 383 observers_.AddObserver(observer);
349 } 384 }
350 385
351 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) { 386 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) {
352 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 387 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 FOR_EACH_OBSERVER( 612 FOR_EACH_OBSERVER(
578 VolumeManagerObserver, observers_, 613 VolumeManagerObserver, observers_,
579 OnFormatCompleted(device_path, 614 OnFormatCompleted(device_path,
580 error_code == chromeos::FORMAT_ERROR_NONE)); 615 error_code == chromeos::FORMAT_ERROR_NONE));
581 616
582 return; 617 return;
583 } 618 }
584 NOTREACHED(); 619 NOTREACHED();
585 } 620 }
586 621
622 void VolumeManager::OnProvidedFileSystemRegistered(
623 const chromeos::file_system_provider::ProvidedFileSystem& file_system) {
624 VolumeInfo volume_info = CreateProvidedFileSystemVolumeInfo(file_system);
625 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, false /* remounting */);
626 }
627
628 void VolumeManager::OnProvidedFileSystemUnregistered(
629 const chromeos::file_system_provider::ProvidedFileSystem& file_system) {
630 VolumeInfo volume_info = CreateProvidedFileSystemVolumeInfo(file_system);
631 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, volume_info);
632 }
633
587 void VolumeManager::OnExternalStorageDisabledChanged() { 634 void VolumeManager::OnExternalStorageDisabledChanged() {
588 // If the policy just got disabled we have to unmount every device currently 635 // If the policy just got disabled we have to unmount every device currently
589 // mounted. The opposite is fine - we can let the user re-plug her device to 636 // mounted. The opposite is fine - we can let the user re-plug her device to
590 // make it available. 637 // make it available.
591 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { 638 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) {
592 // We do not iterate on mount_points directly, because mount_points can 639 // We do not iterate on mount_points directly, because mount_points can
593 // be changed by UnmountPath(). 640 // be changed by UnmountPath().
594 // TODO(hidehiko): Is it necessary to unmount mounted archives, too, here? 641 // TODO(hidehiko): Is it necessary to unmount mounted archives, too, here?
595 while (!disk_mount_manager_->mount_points().empty()) { 642 while (!disk_mount_manager_->mount_points().empty()) {
596 std::string mount_path = 643 std::string mount_path =
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 return; 701 return;
655 if (error_code == chromeos::MOUNT_ERROR_NONE) 702 if (error_code == chromeos::MOUNT_ERROR_NONE)
656 mounted_volumes_.erase(volume_info.volume_id); 703 mounted_volumes_.erase(volume_info.volume_id);
657 704
658 FOR_EACH_OBSERVER(VolumeManagerObserver, 705 FOR_EACH_OBSERVER(VolumeManagerObserver,
659 observers_, 706 observers_,
660 OnVolumeUnmounted(error_code, volume_info)); 707 OnVolumeUnmounted(error_code, volume_info));
661 } 708 }
662 709
663 } // namespace file_manager 710 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698