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

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: Simplified. 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 VolumeInfo volume_info; 195 VolumeInfo volume_info;
193 volume_info.type = VOLUME_TYPE_CLOUD_DEVICE; 196 volume_info.type = VOLUME_TYPE_CLOUD_DEVICE;
194 volume_info.mount_path = privet_volume_info.volume_path; 197 volume_info.mount_path = privet_volume_info.volume_path;
195 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE; 198 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE;
196 volume_info.is_parent = true; 199 volume_info.is_parent = true;
197 volume_info.is_read_only = true; 200 volume_info.is_read_only = true;
198 volume_info.volume_id = GenerateVolumeId(volume_info); 201 volume_info.volume_id = GenerateVolumeId(volume_info);
199 return volume_info; 202 return volume_info;
200 } 203 }
201 204
205 VolumeInfo CreateProvidedFileSystemVolumeInfo(
206 const chromeos::file_system_provider::ProvidedFileSystem& file_system) {
207 VolumeInfo volume_info;
208 volume_info.type = VOLUME_TYPE_PROVIDED;
209 volume_info.mount_path = file_system.mount_path();
210 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE;
211 volume_info.is_parent = true;
212 volume_info.is_read_only = true;
213 volume_info.volume_id = GenerateVolumeId(volume_info);
214 return volume_info;
215 }
216
202 } // namespace 217 } // namespace
203 218
204 VolumeInfo::VolumeInfo() { 219 VolumeInfo::VolumeInfo() {
205 } 220 }
206 221
207 VolumeInfo::~VolumeInfo() { 222 VolumeInfo::~VolumeInfo() {
208 } 223 }
209 224
210 VolumeManager::VolumeManager( 225 VolumeManager::VolumeManager(
211 Profile* profile, 226 Profile* profile,
212 drive::DriveIntegrationService* drive_integration_service, 227 drive::DriveIntegrationService* drive_integration_service,
213 chromeos::PowerManagerClient* power_manager_client, 228 chromeos::PowerManagerClient* power_manager_client,
214 chromeos::disks::DiskMountManager* disk_mount_manager) 229 chromeos::disks::DiskMountManager* disk_mount_manager,
230 chromeos::file_system_provider::Service* file_system_provider_service)
215 : profile_(profile), 231 : profile_(profile),
216 drive_integration_service_(drive_integration_service), 232 drive_integration_service_(drive_integration_service),
217 disk_mount_manager_(disk_mount_manager), 233 disk_mount_manager_(disk_mount_manager),
218 mounted_disk_monitor_( 234 mounted_disk_monitor_(
219 new MountedDiskMonitor(power_manager_client, disk_mount_manager)) { 235 new MountedDiskMonitor(power_manager_client, disk_mount_manager)),
236 file_system_provider_service_(file_system_provider_service) {
220 DCHECK(disk_mount_manager); 237 DCHECK(disk_mount_manager);
221 } 238 }
222 239
223 VolumeManager::~VolumeManager() { 240 VolumeManager::~VolumeManager() {
224 } 241 }
225 242
226 VolumeManager* VolumeManager::Get(content::BrowserContext* context) { 243 VolumeManager* VolumeManager::Get(content::BrowserContext* context) {
227 return VolumeManagerFactory::Get(context); 244 return VolumeManagerFactory::Get(context);
228 } 245 }
229 246
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 if (drive_integration_service_->IsMounted()) { 282 if (drive_integration_service_->IsMounted()) {
266 DoMountEvent(chromeos::MOUNT_ERROR_NONE, 283 DoMountEvent(chromeos::MOUNT_ERROR_NONE,
267 CreateDriveVolumeInfo(profile_), 284 CreateDriveVolumeInfo(profile_),
268 kNotRemounting); 285 kNotRemounting);
269 } 286 }
270 } 287 }
271 288
272 // Subscribe to DiskMountManager. 289 // Subscribe to DiskMountManager.
273 disk_mount_manager_->AddObserver(this); 290 disk_mount_manager_->AddObserver(this);
274 291
292 // Subscribe to FileSystemProviderService and register currently mounted
293 // volumes for the profile.
294 if (file_system_provider_service_) {
295 using chromeos::file_system_provider::ProvidedFileSystem;
296 file_system_provider_service_->AddObserver(this);
297
298 std::vector<ProvidedFileSystem> provided_file_systems =
299 file_system_provider_service_->GetRegisteredFileSystems();
300 for (size_t i = 0; i < provided_file_systems.size(); ++i) {
301 VolumeInfo volume_info =
302 CreateProvidedFileSystemVolumeInfo(provided_file_systems[i]);
303 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, kNotRemounting);
304 }
305 }
306
275 std::vector<VolumeInfo> archives; 307 std::vector<VolumeInfo> archives;
276 308
277 const chromeos::disks::DiskMountManager::MountPointMap& mount_points = 309 const chromeos::disks::DiskMountManager::MountPointMap& mount_points =
278 disk_mount_manager_->mount_points(); 310 disk_mount_manager_->mount_points();
279 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it = 311 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it =
280 mount_points.begin(); 312 mount_points.begin();
281 it != mount_points.end(); 313 it != mount_points.end();
282 ++it) { 314 ++it) {
283 if (it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { 315 if (it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) {
284 // Archives are mounted after other type of volumes. See below. 316 // Archives are mounted after other type of volumes. See below.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 privet_volume_lister_->Start(); 367 privet_volume_lister_->Start();
336 } 368 }
337 } 369 }
338 370
339 void VolumeManager::Shutdown() { 371 void VolumeManager::Shutdown() {
340 pref_change_registrar_.RemoveAll(); 372 pref_change_registrar_.RemoveAll();
341 disk_mount_manager_->RemoveObserver(this); 373 disk_mount_manager_->RemoveObserver(this);
342 374
343 if (drive_integration_service_) 375 if (drive_integration_service_)
344 drive_integration_service_->RemoveObserver(this); 376 drive_integration_service_->RemoveObserver(this);
377
378 if (file_system_provider_service_)
379 file_system_provider_service_->RemoveObserver(this);
345 } 380 }
346 381
347 void VolumeManager::AddObserver(VolumeManagerObserver* observer) { 382 void VolumeManager::AddObserver(VolumeManagerObserver* observer) {
348 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 383 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
349 DCHECK(observer); 384 DCHECK(observer);
350 observers_.AddObserver(observer); 385 observers_.AddObserver(observer);
351 } 386 }
352 387
353 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) { 388 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) {
354 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 389 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
(...skipping 222 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
« no previous file with comments | « chrome/browser/chromeos/file_manager/volume_manager.h ('k') | chrome/browser/chromeos/file_manager/volume_manager_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698