| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 16 #include "chrome/browser/chromeos/drive/drive_integration_service.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" | |
| 20 #include "chrome/browser/chromeos/file_manager/path_util.h" | 19 #include "chrome/browser/chromeos/file_manager/path_util.h" |
| 21 #include "chrome/browser/chromeos/file_manager/snapshot_manager.h" | 20 #include "chrome/browser/chromeos/file_manager/snapshot_manager.h" |
| 22 #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h" | 21 #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h" |
| 23 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" | 22 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" |
| 24 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" | 23 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" |
| 25 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 24 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 26 #include "chrome/browser/local_discovery/storage/privet_filesystem_constants.h" | 25 #include "chrome/browser/local_discovery/storage/privet_filesystem_constants.h" |
| 27 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" | 26 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 31 #include "chromeos/chromeos_switches.h" | 30 #include "chromeos/chromeos_switches.h" |
| 32 #include "chromeos/disks/disk_mount_manager.h" | 31 #include "chromeos/disks/disk_mount_manager.h" |
| 33 #include "components/storage_monitor/storage_monitor.h" | 32 #include "components/storage_monitor/storage_monitor.h" |
| 34 #include "content/public/browser/browser_context.h" | 33 #include "content/public/browser/browser_context.h" |
| 35 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 36 #include "webkit/browser/fileapi/external_mount_points.h" | 35 #include "webkit/browser/fileapi/external_mount_points.h" |
| 37 | 36 |
| 38 namespace file_manager { | 37 namespace file_manager { |
| 39 namespace { | 38 namespace { |
| 40 | 39 |
| 41 // A named constant to be passed to the |is_remounting| parameter. | |
| 42 const bool kNotRemounting = false; | |
| 43 | |
| 44 const char kFileManagerMTPMountNamePrefix[] = "fileman-mtp-"; | 40 const char kFileManagerMTPMountNamePrefix[] = "fileman-mtp-"; |
| 45 const char kMtpVolumeIdPrefix [] = "mtp:"; | 41 const char kMtpVolumeIdPrefix [] = "mtp:"; |
| 46 | 42 |
| 47 // Registers |path| as the "Downloads" folder to the FileSystem API backend. | 43 // Registers |path| as the "Downloads" folder to the FileSystem API backend. |
| 48 // If another folder is already mounted. It revokes and overrides the old one. | 44 // If another folder is already mounted. It revokes and overrides the old one. |
| 49 bool RegisterDownloadsMountPoint(Profile* profile, const base::FilePath& path) { | 45 bool RegisterDownloadsMountPoint(Profile* profile, const base::FilePath& path) { |
| 50 // Although we show only profile's own "Downloads" folder in Files.app, | 46 // Although we show only profile's own "Downloads" folder in Files.app, |
| 51 // in the backend we need to mount all profile's download directory globally. | 47 // in the backend we need to mount all profile's download directory globally. |
| 52 // Otherwise, Files.app cannot support cross-profile file copies, etc. | 48 // Otherwise, Files.app cannot support cross-profile file copies, etc. |
| 53 // For this reason, we need to register to the global GetSystemInstance(). | 49 // For this reason, we need to register to the global GetSystemInstance(). |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 244 |
| 249 VolumeManager::VolumeManager( | 245 VolumeManager::VolumeManager( |
| 250 Profile* profile, | 246 Profile* profile, |
| 251 drive::DriveIntegrationService* drive_integration_service, | 247 drive::DriveIntegrationService* drive_integration_service, |
| 252 chromeos::PowerManagerClient* power_manager_client, | 248 chromeos::PowerManagerClient* power_manager_client, |
| 253 chromeos::disks::DiskMountManager* disk_mount_manager, | 249 chromeos::disks::DiskMountManager* disk_mount_manager, |
| 254 chromeos::file_system_provider::Service* file_system_provider_service) | 250 chromeos::file_system_provider::Service* file_system_provider_service) |
| 255 : profile_(profile), | 251 : profile_(profile), |
| 256 drive_integration_service_(drive_integration_service), | 252 drive_integration_service_(drive_integration_service), |
| 257 disk_mount_manager_(disk_mount_manager), | 253 disk_mount_manager_(disk_mount_manager), |
| 258 mounted_disk_monitor_(new MountedDiskMonitor(power_manager_client)), | |
| 259 file_system_provider_service_(file_system_provider_service), | 254 file_system_provider_service_(file_system_provider_service), |
| 260 snapshot_manager_(new SnapshotManager(profile_)), | 255 snapshot_manager_(new SnapshotManager(profile_)), |
| 261 weak_ptr_factory_(this) { | 256 weak_ptr_factory_(this) { |
| 262 DCHECK(disk_mount_manager); | 257 DCHECK(disk_mount_manager); |
| 263 } | 258 } |
| 264 | 259 |
| 265 VolumeManager::~VolumeManager() { | 260 VolumeManager::~VolumeManager() { |
| 266 } | 261 } |
| 267 | 262 |
| 268 VolumeManager* VolumeManager::Get(content::BrowserContext* context) { | 263 VolumeManager* VolumeManager::Get(content::BrowserContext* context) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 289 new_path); | 284 new_path); |
| 290 } | 285 } |
| 291 | 286 |
| 292 // Register 'Downloads' folder for the profile to the file system. | 287 // Register 'Downloads' folder for the profile to the file system. |
| 293 const base::FilePath downloads = | 288 const base::FilePath downloads = |
| 294 file_manager::util::GetDownloadsFolderForProfile(profile_); | 289 file_manager::util::GetDownloadsFolderForProfile(profile_); |
| 295 const bool success = RegisterDownloadsMountPoint(profile_, downloads); | 290 const bool success = RegisterDownloadsMountPoint(profile_, downloads); |
| 296 DCHECK(success); | 291 DCHECK(success); |
| 297 | 292 |
| 298 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | 293 DoMountEvent(chromeos::MOUNT_ERROR_NONE, |
| 299 CreateDownloadsVolumeInfo(downloads), | 294 CreateDownloadsVolumeInfo(downloads)); |
| 300 kNotRemounting); | |
| 301 | 295 |
| 302 // Subscribe to DriveIntegrationService. | 296 // Subscribe to DriveIntegrationService. |
| 303 if (drive_integration_service_) { | 297 if (drive_integration_service_) { |
| 304 drive_integration_service_->AddObserver(this); | 298 drive_integration_service_->AddObserver(this); |
| 305 if (drive_integration_service_->IsMounted()) { | 299 if (drive_integration_service_->IsMounted()) { |
| 306 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | 300 DoMountEvent(chromeos::MOUNT_ERROR_NONE, |
| 307 CreateDriveVolumeInfo(profile_), | 301 CreateDriveVolumeInfo(profile_)); |
| 308 kNotRemounting); | |
| 309 } | 302 } |
| 310 } | 303 } |
| 311 | 304 |
| 312 // Subscribe to DiskMountManager. | 305 // Subscribe to DiskMountManager. |
| 313 disk_mount_manager_->AddObserver(this); | 306 disk_mount_manager_->AddObserver(this); |
| 314 disk_mount_manager_->EnsureMountInfoRefreshed( | 307 disk_mount_manager_->EnsureMountInfoRefreshed( |
| 315 base::Bind(&VolumeManager::OnDiskMountManagerRefreshed, | 308 base::Bind(&VolumeManager::OnDiskMountManagerRefreshed, |
| 316 weak_ptr_factory_.GetWeakPtr())); | 309 weak_ptr_factory_.GetWeakPtr())); |
| 317 | 310 |
| 318 // Subscribe to FileSystemProviderService and register currently mounted | 311 // Subscribe to FileSystemProviderService and register currently mounted |
| 319 // volumes for the profile. | 312 // volumes for the profile. |
| 320 if (file_system_provider_service_) { | 313 if (file_system_provider_service_) { |
| 321 using chromeos::file_system_provider::ProvidedFileSystemInfo; | 314 using chromeos::file_system_provider::ProvidedFileSystemInfo; |
| 322 file_system_provider_service_->AddObserver(this); | 315 file_system_provider_service_->AddObserver(this); |
| 323 | 316 |
| 324 std::vector<ProvidedFileSystemInfo> file_system_info_list = | 317 std::vector<ProvidedFileSystemInfo> file_system_info_list = |
| 325 file_system_provider_service_->GetProvidedFileSystemInfoList(); | 318 file_system_provider_service_->GetProvidedFileSystemInfoList(); |
| 326 for (size_t i = 0; i < file_system_info_list.size(); ++i) { | 319 for (size_t i = 0; i < file_system_info_list.size(); ++i) { |
| 327 VolumeInfo volume_info = | 320 VolumeInfo volume_info = |
| 328 CreateProvidedFileSystemVolumeInfo(file_system_info_list[i]); | 321 CreateProvidedFileSystemVolumeInfo(file_system_info_list[i]); |
| 329 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, kNotRemounting); | 322 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info); |
| 330 } | 323 } |
| 331 } | 324 } |
| 332 | 325 |
| 333 // Subscribe to Profile Preference change. | 326 // Subscribe to Profile Preference change. |
| 334 pref_change_registrar_.Init(profile_->GetPrefs()); | 327 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 335 pref_change_registrar_.Add( | 328 pref_change_registrar_.Add( |
| 336 prefs::kExternalStorageDisabled, | 329 prefs::kExternalStorageDisabled, |
| 337 base::Bind(&VolumeManager::OnExternalStorageDisabledChanged, | 330 base::Bind(&VolumeManager::OnExternalStorageDisabledChanged, |
| 338 weak_ptr_factory_.GetWeakPtr())); | 331 weak_ptr_factory_.GetWeakPtr())); |
| 339 | 332 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 | 410 |
| 418 base::FilePath old_path; | 411 base::FilePath old_path; |
| 419 if (FindDownloadsMountPointPath(profile_, &old_path)) { | 412 if (FindDownloadsMountPointPath(profile_, &old_path)) { |
| 420 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, | 413 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, |
| 421 CreateDownloadsVolumeInfo(old_path)); | 414 CreateDownloadsVolumeInfo(old_path)); |
| 422 } | 415 } |
| 423 | 416 |
| 424 bool success = RegisterDownloadsMountPoint(profile_, path); | 417 bool success = RegisterDownloadsMountPoint(profile_, path); |
| 425 DoMountEvent( | 418 DoMountEvent( |
| 426 success ? chromeos::MOUNT_ERROR_NONE : chromeos::MOUNT_ERROR_INVALID_PATH, | 419 success ? chromeos::MOUNT_ERROR_NONE : chromeos::MOUNT_ERROR_INVALID_PATH, |
| 427 CreateDownloadsVolumeInfo(path), | 420 CreateDownloadsVolumeInfo(path)); |
| 428 kNotRemounting); | |
| 429 return success; | 421 return success; |
| 430 } | 422 } |
| 431 | 423 |
| 432 void VolumeManager::AddVolumeInfoForTesting(const base::FilePath& path, | 424 void VolumeManager::AddVolumeInfoForTesting(const base::FilePath& path, |
| 433 VolumeType volume_type, | 425 VolumeType volume_type, |
| 434 chromeos::DeviceType device_type) { | 426 chromeos::DeviceType device_type) { |
| 435 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 427 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 436 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | 428 DoMountEvent(chromeos::MOUNT_ERROR_NONE, |
| 437 CreateTestingVolumeInfo(path, volume_type, device_type), | 429 CreateTestingVolumeInfo(path, volume_type, device_type)); |
| 438 kNotRemounting); | |
| 439 } | 430 } |
| 440 | 431 |
| 441 void VolumeManager::OnFileSystemMounted() { | 432 void VolumeManager::OnFileSystemMounted() { |
| 442 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 433 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 443 | 434 |
| 444 // Raise mount event. | 435 // Raise mount event. |
| 445 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed | 436 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed |
| 446 // or network is unreachable. These two errors will be handled later. | 437 // or network is unreachable. These two errors will be handled later. |
| 447 VolumeInfo volume_info = CreateDriveVolumeInfo(profile_); | 438 VolumeInfo volume_info = CreateDriveVolumeInfo(profile_); |
| 448 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, kNotRemounting); | 439 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info); |
| 449 } | 440 } |
| 450 | 441 |
| 451 void VolumeManager::OnFileSystemBeingUnmounted() { | 442 void VolumeManager::OnFileSystemBeingUnmounted() { |
| 452 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 443 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 453 | 444 |
| 454 VolumeInfo volume_info = CreateDriveVolumeInfo(profile_); | 445 VolumeInfo volume_info = CreateDriveVolumeInfo(profile_); |
| 455 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, volume_info); | 446 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, volume_info); |
| 456 } | 447 } |
| 457 | 448 |
| 458 void VolumeManager::OnDiskEvent( | 449 void VolumeManager::OnDiskEvent( |
| 459 chromeos::disks::DiskMountManager::DiskEvent event, | 450 chromeos::disks::DiskMountManager::DiskEvent event, |
| 460 const chromeos::disks::DiskMountManager::Disk* disk) { | 451 const chromeos::disks::DiskMountManager::Disk* disk) { |
| 461 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 452 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 462 | 453 |
| 463 mounted_disk_monitor_->OnDiskEvent(event, disk); | |
| 464 | |
| 465 // Disregard hidden devices. | 454 // Disregard hidden devices. |
| 466 if (disk->is_hidden()) | 455 if (disk->is_hidden()) |
| 467 return; | 456 return; |
| 468 | 457 |
| 469 switch (event) { | 458 switch (event) { |
| 470 case chromeos::disks::DiskMountManager::DISK_ADDED: | 459 case chromeos::disks::DiskMountManager::DISK_ADDED: |
| 471 case chromeos::disks::DiskMountManager::DISK_CHANGED: { | 460 case chromeos::disks::DiskMountManager::DISK_CHANGED: { |
| 472 if (disk->device_path().empty()) { | 461 if (disk->device_path().empty()) { |
| 473 DVLOG(1) << "Empty system path for " << disk->device_path(); | 462 DVLOG(1) << "Empty system path for " << disk->device_path(); |
| 474 return; | 463 return; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 499 if (!disk->mount_path().empty()) { | 488 if (!disk->mount_path().empty()) { |
| 500 disk_mount_manager_->UnmountPath( | 489 disk_mount_manager_->UnmountPath( |
| 501 disk->mount_path(), | 490 disk->mount_path(), |
| 502 chromeos::UNMOUNT_OPTIONS_LAZY, | 491 chromeos::UNMOUNT_OPTIONS_LAZY, |
| 503 chromeos::disks::DiskMountManager::UnmountPathCallback()); | 492 chromeos::disks::DiskMountManager::UnmountPathCallback()); |
| 504 } | 493 } |
| 505 | 494 |
| 506 // Notify to observers. | 495 // Notify to observers. |
| 507 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, | 496 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, |
| 508 OnDiskRemoved(*disk)); | 497 OnDiskRemoved(*disk)); |
| 509 const std::string& device_path = disk->system_path_prefix(); | |
| 510 if (mounted_disk_monitor_->DeviceIsHardUnpluggedButNotReported( | |
| 511 device_path)) { | |
| 512 mounted_disk_monitor_->MarkAsHardUnpluggedReported(device_path); | |
| 513 } | |
| 514 return; | 498 return; |
| 515 } | 499 } |
| 516 NOTREACHED(); | 500 NOTREACHED(); |
| 517 } | 501 } |
| 518 | 502 |
| 519 void VolumeManager::OnDeviceEvent( | 503 void VolumeManager::OnDeviceEvent( |
| 520 chromeos::disks::DiskMountManager::DeviceEvent event, | 504 chromeos::disks::DiskMountManager::DeviceEvent event, |
| 521 const std::string& device_path) { | 505 const std::string& device_path) { |
| 522 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 506 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 523 | 507 |
| 524 mounted_disk_monitor_->OnDeviceEvent(event, device_path); | |
| 525 | |
| 526 DVLOG(1) << "OnDeviceEvent: " << event << ", " << device_path; | 508 DVLOG(1) << "OnDeviceEvent: " << event << ", " << device_path; |
| 527 switch (event) { | 509 switch (event) { |
| 528 case chromeos::disks::DiskMountManager::DEVICE_ADDED: | 510 case chromeos::disks::DiskMountManager::DEVICE_ADDED: |
| 529 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, | 511 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, |
| 530 OnDeviceAdded(device_path)); | 512 OnDeviceAdded(device_path)); |
| 531 return; | 513 return; |
| 532 case chromeos::disks::DiskMountManager::DEVICE_REMOVED: { | 514 case chromeos::disks::DiskMountManager::DEVICE_REMOVED: { |
| 533 FOR_EACH_OBSERVER( | 515 FOR_EACH_OBSERVER( |
| 534 VolumeManagerObserver, observers_, OnDeviceRemoved(device_path)); | 516 VolumeManagerObserver, observers_, OnDeviceRemoved(device_path)); |
| 535 return; | 517 return; |
| 536 } | 518 } |
| 537 case chromeos::disks::DiskMountManager::DEVICE_SCANNED: | 519 case chromeos::disks::DiskMountManager::DEVICE_SCANNED: |
| 538 DVLOG(1) << "Ignore SCANNED event: " << device_path; | 520 DVLOG(1) << "Ignore SCANNED event: " << device_path; |
| 539 return; | 521 return; |
| 540 } | 522 } |
| 541 NOTREACHED(); | 523 NOTREACHED(); |
| 542 } | 524 } |
| 543 | 525 |
| 544 void VolumeManager::OnMountEvent( | 526 void VolumeManager::OnMountEvent( |
| 545 chromeos::disks::DiskMountManager::MountEvent event, | 527 chromeos::disks::DiskMountManager::MountEvent event, |
| 546 chromeos::MountError error_code, | 528 chromeos::MountError error_code, |
| 547 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) { | 529 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) { |
| 548 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 530 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 549 DCHECK_NE(chromeos::MOUNT_TYPE_INVALID, mount_info.mount_type); | 531 DCHECK_NE(chromeos::MOUNT_TYPE_INVALID, mount_info.mount_type); |
| 550 | 532 |
| 551 const chromeos::disks::DiskMountManager::Disk* disk = | |
| 552 disk_mount_manager_->FindDiskBySourcePath(mount_info.source_path); | |
| 553 mounted_disk_monitor_->OnMountEvent(event, error_code, mount_info, disk); | |
| 554 | |
| 555 if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { | 533 if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { |
| 556 // If the file is not mounted now, tell it to drive file system so that | 534 // If the file is not mounted now, tell it to drive file system so that |
| 557 // it can handle file caching correctly. | 535 // it can handle file caching correctly. |
| 558 // Note that drive file system knows if the file is managed by drive file | 536 // Note that drive file system knows if the file is managed by drive file |
| 559 // system or not, so here we report all paths. | 537 // system or not, so here we report all paths. |
| 560 if ((event == chromeos::disks::DiskMountManager::MOUNTING && | 538 if ((event == chromeos::disks::DiskMountManager::MOUNTING && |
| 561 error_code != chromeos::MOUNT_ERROR_NONE) || | 539 error_code != chromeos::MOUNT_ERROR_NONE) || |
| 562 (event == chromeos::disks::DiskMountManager::UNMOUNTING && | 540 (event == chromeos::disks::DiskMountManager::UNMOUNTING && |
| 563 error_code == chromeos::MOUNT_ERROR_NONE)) { | 541 error_code == chromeos::MOUNT_ERROR_NONE)) { |
| 564 drive::FileSystemInterface* file_system = | 542 drive::FileSystemInterface* const file_system = |
| 565 drive::util::GetFileSystemByProfile(profile_); | 543 drive::util::GetFileSystemByProfile(profile_); |
| 566 if (file_system) { | 544 if (file_system) { |
| 567 file_system->MarkCacheFileAsUnmounted( | 545 file_system->MarkCacheFileAsUnmounted( |
| 568 base::FilePath(mount_info.source_path), | 546 base::FilePath(mount_info.source_path), |
| 569 base::Bind(&drive::util::EmptyFileOperationCallback)); | 547 base::Bind(&drive::util::EmptyFileOperationCallback)); |
| 570 } | 548 } |
| 571 } | 549 } |
| 572 } | 550 } |
| 573 | 551 |
| 574 // Notify a mounting/unmounting event to observers. | 552 // Notify a mounting/unmounting event to observers. |
| 575 VolumeInfo volume_info = | 553 const chromeos::disks::DiskMountManager::Disk* const disk = |
| 554 disk_mount_manager_->FindDiskBySourcePath(mount_info.source_path); |
| 555 const VolumeInfo volume_info = |
| 576 CreateVolumeInfoFromMountPointInfo(mount_info, disk); | 556 CreateVolumeInfoFromMountPointInfo(mount_info, disk); |
| 577 switch (event) { | 557 switch (event) { |
| 578 case chromeos::disks::DiskMountManager::MOUNTING: { | 558 case chromeos::disks::DiskMountManager::MOUNTING: { |
| 579 bool is_remounting = | 559 DoMountEvent(error_code, volume_info); |
| 580 disk && mounted_disk_monitor_->DiskIsRemounting(*disk); | |
| 581 DoMountEvent(error_code, volume_info, is_remounting); | |
| 582 return; | 560 return; |
| 583 } | 561 } |
| 584 case chromeos::disks::DiskMountManager::UNMOUNTING: | 562 case chromeos::disks::DiskMountManager::UNMOUNTING: |
| 585 DoUnmountEvent(error_code, volume_info); | 563 DoUnmountEvent(error_code, volume_info); |
| 586 return; | 564 return; |
| 587 } | 565 } |
| 588 NOTREACHED(); | 566 NOTREACHED(); |
| 589 } | 567 } |
| 590 | 568 |
| 591 void VolumeManager::OnFormatEvent( | 569 void VolumeManager::OnFormatEvent( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 void VolumeManager::OnProvidedFileSystemMount( | 605 void VolumeManager::OnProvidedFileSystemMount( |
| 628 const chromeos::file_system_provider::ProvidedFileSystemInfo& | 606 const chromeos::file_system_provider::ProvidedFileSystemInfo& |
| 629 file_system_info, | 607 file_system_info, |
| 630 base::File::Error error) { | 608 base::File::Error error) { |
| 631 VolumeInfo volume_info = CreateProvidedFileSystemVolumeInfo(file_system_info); | 609 VolumeInfo volume_info = CreateProvidedFileSystemVolumeInfo(file_system_info); |
| 632 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, | 610 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, |
| 633 // since it is related to cros disks only. | 611 // since it is related to cros disks only. |
| 634 const chromeos::MountError mount_error = error == base::File::FILE_OK | 612 const chromeos::MountError mount_error = error == base::File::FILE_OK |
| 635 ? chromeos::MOUNT_ERROR_NONE | 613 ? chromeos::MOUNT_ERROR_NONE |
| 636 : chromeos::MOUNT_ERROR_UNKNOWN; | 614 : chromeos::MOUNT_ERROR_UNKNOWN; |
| 637 DoMountEvent(mount_error, volume_info, kNotRemounting); | 615 DoMountEvent(mount_error, volume_info); |
| 638 } | 616 } |
| 639 | 617 |
| 640 void VolumeManager::OnProvidedFileSystemUnmount( | 618 void VolumeManager::OnProvidedFileSystemUnmount( |
| 641 const chromeos::file_system_provider::ProvidedFileSystemInfo& | 619 const chromeos::file_system_provider::ProvidedFileSystemInfo& |
| 642 file_system_info, | 620 file_system_info, |
| 643 base::File::Error error) { | 621 base::File::Error error) { |
| 644 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, | 622 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, |
| 645 // since it is related to cros disks only. | 623 // since it is related to cros disks only. |
| 646 const chromeos::MountError mount_error = error == base::File::FILE_OK | 624 const chromeos::MountError mount_error = error == base::File::FILE_OK |
| 647 ? chromeos::MOUNT_ERROR_NONE | 625 ? chromeos::MOUNT_ERROR_NONE |
| (...skipping 19 matching lines...) Expand all Loading... |
| 667 chromeos::disks::DiskMountManager::UnmountPathCallback()); | 645 chromeos::disks::DiskMountManager::UnmountPathCallback()); |
| 668 } | 646 } |
| 669 } | 647 } |
| 670 } | 648 } |
| 671 | 649 |
| 672 void VolumeManager::OnPrivetVolumesAvailable( | 650 void VolumeManager::OnPrivetVolumesAvailable( |
| 673 const local_discovery::PrivetVolumeLister::VolumeList& volumes) { | 651 const local_discovery::PrivetVolumeLister::VolumeList& volumes) { |
| 674 for (local_discovery::PrivetVolumeLister::VolumeList::const_iterator i = | 652 for (local_discovery::PrivetVolumeLister::VolumeList::const_iterator i = |
| 675 volumes.begin(); i != volumes.end(); i++) { | 653 volumes.begin(); i != volumes.end(); i++) { |
| 676 VolumeInfo volume_info = CreatePrivetVolumeInfo(*i); | 654 VolumeInfo volume_info = CreatePrivetVolumeInfo(*i); |
| 677 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, false); | 655 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info); |
| 678 } | 656 } |
| 679 } | 657 } |
| 680 | 658 |
| 681 void VolumeManager::OnRemovableStorageAttached( | 659 void VolumeManager::OnRemovableStorageAttached( |
| 682 const storage_monitor::StorageInfo& info) { | 660 const storage_monitor::StorageInfo& info) { |
| 683 if (!storage_monitor::StorageInfo::IsMTPDevice(info.device_id())) | 661 if (!storage_monitor::StorageInfo::IsMTPDevice(info.device_id())) |
| 684 return; | 662 return; |
| 685 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) | 663 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) |
| 686 return; | 664 return; |
| 687 | 665 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 710 VolumeInfo volume_info; | 688 VolumeInfo volume_info; |
| 711 volume_info.type = VOLUME_TYPE_MTP; | 689 volume_info.type = VOLUME_TYPE_MTP; |
| 712 volume_info.mount_path = path; | 690 volume_info.mount_path = path; |
| 713 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE; | 691 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE; |
| 714 volume_info.is_parent = true; | 692 volume_info.is_parent = true; |
| 715 volume_info.is_read_only = true; | 693 volume_info.is_read_only = true; |
| 716 volume_info.volume_id = kMtpVolumeIdPrefix + label; | 694 volume_info.volume_id = kMtpVolumeIdPrefix + label; |
| 717 volume_info.volume_label = label; | 695 volume_info.volume_label = label; |
| 718 volume_info.source_path = path; | 696 volume_info.source_path = path; |
| 719 volume_info.device_type = chromeos::DEVICE_TYPE_MOBILE; | 697 volume_info.device_type = chromeos::DEVICE_TYPE_MOBILE; |
| 720 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, false); | 698 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info); |
| 721 } | 699 } |
| 722 | 700 |
| 723 void VolumeManager::OnRemovableStorageDetached( | 701 void VolumeManager::OnRemovableStorageDetached( |
| 724 const storage_monitor::StorageInfo& info) { | 702 const storage_monitor::StorageInfo& info) { |
| 725 if (!storage_monitor::StorageInfo::IsMTPDevice(info.device_id())) | 703 if (!storage_monitor::StorageInfo::IsMTPDevice(info.device_id())) |
| 726 return; | 704 return; |
| 727 | 705 |
| 728 for (std::map<std::string, VolumeInfo>::iterator it = | 706 for (std::map<std::string, VolumeInfo>::iterator it = |
| 729 mounted_volumes_.begin(); it != mounted_volumes_.end(); ++it) { | 707 mounted_volumes_.begin(); it != mounted_volumes_.end(); ++it) { |
| 730 if (it->second.source_path.value() == info.location()) { | 708 if (it->second.source_path.value() == info.location()) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 758 ++it) { | 736 ++it) { |
| 759 if (it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { | 737 if (it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { |
| 760 // Archives are mounted after other types of volume. See below. | 738 // Archives are mounted after other types of volume. See below. |
| 761 archives.push_back(CreateVolumeInfoFromMountPointInfo(it->second, NULL)); | 739 archives.push_back(CreateVolumeInfoFromMountPointInfo(it->second, NULL)); |
| 762 continue; | 740 continue; |
| 763 } | 741 } |
| 764 DoMountEvent( | 742 DoMountEvent( |
| 765 chromeos::MOUNT_ERROR_NONE, | 743 chromeos::MOUNT_ERROR_NONE, |
| 766 CreateVolumeInfoFromMountPointInfo( | 744 CreateVolumeInfoFromMountPointInfo( |
| 767 it->second, | 745 it->second, |
| 768 disk_mount_manager_->FindDiskBySourcePath(it->second.source_path)), | 746 disk_mount_manager_->FindDiskBySourcePath(it->second.source_path))); |
| 769 kNotRemounting); | |
| 770 } | 747 } |
| 771 | 748 |
| 772 // We mount archives only if they are opened from currently mounted volumes. | 749 // We mount archives only if they are opened from currently mounted volumes. |
| 773 // To check the condition correctly in DoMountEvent, we care about the order. | 750 // To check the condition correctly in DoMountEvent, we care about the order. |
| 774 std::vector<bool> done(archives.size(), false); | 751 std::vector<bool> done(archives.size(), false); |
| 775 for (size_t i = 0; i < archives.size(); ++i) { | 752 for (size_t i = 0; i < archives.size(); ++i) { |
| 776 if (done[i]) | 753 if (done[i]) |
| 777 continue; | 754 continue; |
| 778 | 755 |
| 779 std::vector<VolumeInfo> chain; | 756 std::vector<VolumeInfo> chain; |
| 780 done[i] = true; | 757 done[i] = true; |
| 781 chain.push_back(archives[i]); | 758 chain.push_back(archives[i]); |
| 782 | 759 |
| 783 // If archives[i]'s source_path is in another archive, mount it first. | 760 // If archives[i]'s source_path is in another archive, mount it first. |
| 784 for (size_t parent = i + 1; parent < archives.size(); ++parent) { | 761 for (size_t parent = i + 1; parent < archives.size(); ++parent) { |
| 785 if (!done[parent] && | 762 if (!done[parent] && |
| 786 archives[parent].mount_path.IsParent(chain.back().source_path)) { | 763 archives[parent].mount_path.IsParent(chain.back().source_path)) { |
| 787 done[parent] = true; | 764 done[parent] = true; |
| 788 chain.push_back(archives[parent]); | 765 chain.push_back(archives[parent]); |
| 789 parent = i + 1; // Search archives[parent]'s parent from the beginning. | 766 parent = i + 1; // Search archives[parent]'s parent from the beginning. |
| 790 } | 767 } |
| 791 } | 768 } |
| 792 | 769 |
| 793 // Mount from the tail of chain. | 770 // Mount from the tail of chain. |
| 794 for (size_t i = chain.size(); i > 0; --i) | 771 for (size_t i = chain.size(); i > 0; --i) |
| 795 DoMountEvent(chromeos::MOUNT_ERROR_NONE, chain[i - 1], kNotRemounting); | 772 DoMountEvent(chromeos::MOUNT_ERROR_NONE, chain[i - 1]); |
| 796 } | 773 } |
| 797 } | 774 } |
| 798 | 775 |
| 799 void VolumeManager::OnStorageMonitorInitialized() { | 776 void VolumeManager::OnStorageMonitorInitialized() { |
| 800 std::vector<storage_monitor::StorageInfo> storages = | 777 std::vector<storage_monitor::StorageInfo> storages = |
| 801 storage_monitor::StorageMonitor::GetInstance()->GetAllAvailableStorages(); | 778 storage_monitor::StorageMonitor::GetInstance()->GetAllAvailableStorages(); |
| 802 for (size_t i = 0; i < storages.size(); ++i) | 779 for (size_t i = 0; i < storages.size(); ++i) |
| 803 OnRemovableStorageAttached(storages[i]); | 780 OnRemovableStorageAttached(storages[i]); |
| 804 storage_monitor::StorageMonitor::GetInstance()->AddObserver(this); | 781 storage_monitor::StorageMonitor::GetInstance()->AddObserver(this); |
| 805 } | 782 } |
| 806 | 783 |
| 807 void VolumeManager::DoMountEvent(chromeos::MountError error_code, | 784 void VolumeManager::DoMountEvent(chromeos::MountError error_code, |
| 808 const VolumeInfo& volume_info, | 785 const VolumeInfo& volume_info) { |
| 809 bool is_remounting) { | |
| 810 // Archive files are mounted globally in system. We however don't want to show | 786 // Archive files are mounted globally in system. We however don't want to show |
| 811 // archives from profile-specific folders (Drive/Downloads) of other users in | 787 // archives from profile-specific folders (Drive/Downloads) of other users in |
| 812 // multi-profile session. To this end, we filter out archives not on the | 788 // multi-profile session. To this end, we filter out archives not on the |
| 813 // volumes already mounted on this VolumeManager instance. | 789 // volumes already mounted on this VolumeManager instance. |
| 814 if (volume_info.type == VOLUME_TYPE_MOUNTED_ARCHIVE_FILE) { | 790 if (volume_info.type == VOLUME_TYPE_MOUNTED_ARCHIVE_FILE) { |
| 815 // Source may be in Drive cache folder under the current profile directory. | 791 // Source may be in Drive cache folder under the current profile directory. |
| 816 bool from_current_profile = | 792 bool from_current_profile = |
| 817 profile_->GetPath().IsParent(volume_info.source_path); | 793 profile_->GetPath().IsParent(volume_info.source_path); |
| 818 for (std::map<std::string, VolumeInfo>::const_iterator iter = | 794 for (std::map<std::string, VolumeInfo>::const_iterator iter = |
| 819 mounted_volumes_.begin(); | 795 mounted_volumes_.begin(); |
| 820 !from_current_profile && iter != mounted_volumes_.end(); | 796 !from_current_profile && iter != mounted_volumes_.end(); |
| 821 ++iter) { | 797 ++iter) { |
| 822 if (iter->second.mount_path.IsParent(volume_info.source_path)) | 798 if (iter->second.mount_path.IsParent(volume_info.source_path)) |
| 823 from_current_profile = true; | 799 from_current_profile = true; |
| 824 } | 800 } |
| 825 if (!from_current_profile) | 801 if (!from_current_profile) |
| 826 return; | 802 return; |
| 827 } | 803 } |
| 828 | 804 |
| 829 // Filter out removable disks if forbidden by policy for this profile. | 805 // Filter out removable disks if forbidden by policy for this profile. |
| 830 if (volume_info.type == VOLUME_TYPE_REMOVABLE_DISK_PARTITION && | 806 if (volume_info.type == VOLUME_TYPE_REMOVABLE_DISK_PARTITION && |
| 831 profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { | 807 profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { |
| 832 return; | 808 return; |
| 833 } | 809 } |
| 834 | 810 |
| 835 if (error_code == chromeos::MOUNT_ERROR_NONE || volume_info.mount_condition) { | 811 if (error_code == chromeos::MOUNT_ERROR_NONE || volume_info.mount_condition) { |
| 836 mounted_volumes_[volume_info.volume_id] = volume_info; | 812 mounted_volumes_[volume_info.volume_id] = volume_info; |
| 837 | 813 |
| 838 if (!is_remounting) { | 814 |
| 839 UMA_HISTOGRAM_ENUMERATION("FileBrowser.VolumeType", | 815 UMA_HISTOGRAM_ENUMERATION("FileBrowser.VolumeType", |
| 840 volume_info.type, | 816 volume_info.type, |
| 841 NUM_VOLUME_TYPE); | 817 NUM_VOLUME_TYPE); |
| 842 } | |
| 843 } | 818 } |
| 844 | 819 |
| 845 FOR_EACH_OBSERVER(VolumeManagerObserver, | 820 FOR_EACH_OBSERVER(VolumeManagerObserver, |
| 846 observers_, | 821 observers_, |
| 847 OnVolumeMounted(error_code, volume_info, is_remounting)); | 822 OnVolumeMounted(error_code, volume_info)); |
| 848 } | 823 } |
| 849 | 824 |
| 850 void VolumeManager::DoUnmountEvent(chromeos::MountError error_code, | 825 void VolumeManager::DoUnmountEvent(chromeos::MountError error_code, |
| 851 const VolumeInfo& volume_info) { | 826 const VolumeInfo& volume_info) { |
| 852 if (mounted_volumes_.find(volume_info.volume_id) == mounted_volumes_.end()) | 827 if (mounted_volumes_.find(volume_info.volume_id) == mounted_volumes_.end()) |
| 853 return; | 828 return; |
| 854 if (error_code == chromeos::MOUNT_ERROR_NONE) | 829 if (error_code == chromeos::MOUNT_ERROR_NONE) |
| 855 mounted_volumes_.erase(volume_info.volume_id); | 830 mounted_volumes_.erase(volume_info.volume_id); |
| 856 | 831 |
| 857 FOR_EACH_OBSERVER(VolumeManagerObserver, | 832 FOR_EACH_OBSERVER(VolumeManagerObserver, |
| 858 observers_, | 833 observers_, |
| 859 OnVolumeUnmounted(error_code, volume_info)); | 834 OnVolumeUnmounted(error_code, volume_info)); |
| 860 } | 835 } |
| 861 | 836 |
| 862 } // namespace file_manager | 837 } // namespace file_manager |
| OLD | NEW |