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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/feature_list.h" | 12 #include "base/feature_list.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | |
21 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" | 20 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" |
22 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_service.h" | 21 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_service.h" |
23 #include "chrome/browser/chromeos/arc/fileapi/arc_media_view_util.h" | 22 #include "chrome/browser/chromeos/arc/fileapi/arc_media_view_util.h" |
24 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 23 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
25 #include "chrome/browser/chromeos/drive/file_system_util.h" | 24 #include "chrome/browser/chromeos/drive/file_system_util.h" |
26 #include "chrome/browser/chromeos/file_manager/path_util.h" | 25 #include "chrome/browser/chromeos/file_manager/path_util.h" |
27 #include "chrome/browser/chromeos/file_manager/snapshot_manager.h" | 26 #include "chrome/browser/chromeos/file_manager/snapshot_manager.h" |
28 #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h" | 27 #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h" |
29 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" | 28 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" |
30 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" | 29 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" |
31 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 30 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
32 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" | 31 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" |
33 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
34 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
35 #include "chromeos/chromeos_switches.h" | 34 #include "chromeos/chromeos_switches.h" |
36 #include "chromeos/disks/disk_mount_manager.h" | 35 #include "chromeos/disks/disk_mount_manager.h" |
37 #include "components/arc/arc_service_manager.h" | |
38 #include "components/drive/chromeos/file_system_interface.h" | 36 #include "components/drive/chromeos/file_system_interface.h" |
39 #include "components/drive/file_system_core_util.h" | 37 #include "components/drive/file_system_core_util.h" |
40 #include "components/prefs/pref_service.h" | 38 #include "components/prefs/pref_service.h" |
41 #include "components/storage_monitor/storage_monitor.h" | 39 #include "components/storage_monitor/storage_monitor.h" |
42 #include "content/public/browser/browser_context.h" | 40 #include "content/public/browser/browser_context.h" |
43 #include "content/public/browser/browser_thread.h" | 41 #include "content/public/browser/browser_thread.h" |
44 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" | 42 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" |
45 #include "storage/browser/fileapi/external_mount_points.h" | 43 #include "storage/browser/fileapi/external_mount_points.h" |
46 | 44 |
47 namespace file_manager { | 45 namespace file_manager { |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 // Subscribe to storage monitor for MTP notifications. | 401 // Subscribe to storage monitor for MTP notifications. |
404 if (storage_monitor::StorageMonitor::GetInstance()) { | 402 if (storage_monitor::StorageMonitor::GetInstance()) { |
405 storage_monitor::StorageMonitor::GetInstance()->EnsureInitialized( | 403 storage_monitor::StorageMonitor::GetInstance()->EnsureInitialized( |
406 base::Bind(&VolumeManager::OnStorageMonitorInitialized, | 404 base::Bind(&VolumeManager::OnStorageMonitorInitialized, |
407 weak_ptr_factory_.GetWeakPtr())); | 405 weak_ptr_factory_.GetWeakPtr())); |
408 } | 406 } |
409 | 407 |
410 // Subscribe to ARC file system events. | 408 // Subscribe to ARC file system events. |
411 if (base::FeatureList::IsEnabled(arc::kMediaViewFeature) && | 409 if (base::FeatureList::IsEnabled(arc::kMediaViewFeature) && |
412 arc::ArcSessionManager::IsAllowedForProfile(profile_)) { | 410 arc::ArcSessionManager::IsAllowedForProfile(profile_)) { |
413 arc::ArcServiceManager::GetGlobalService<arc::ArcFileSystemService>() | 411 arc::ArcSessionManager::Get()->AddObserver(this); |
414 ->AddObserver(this); | 412 OnArcOptInChanged(arc::ArcSessionManager::Get()->IsArcEnabled()); |
415 } | 413 } |
416 } | 414 } |
417 | 415 |
418 void VolumeManager::Shutdown() { | 416 void VolumeManager::Shutdown() { |
419 weak_ptr_factory_.InvalidateWeakPtrs(); | 417 weak_ptr_factory_.InvalidateWeakPtrs(); |
420 | 418 |
421 snapshot_manager_.reset(); | 419 snapshot_manager_.reset(); |
422 pref_change_registrar_.RemoveAll(); | 420 pref_change_registrar_.RemoveAll(); |
423 disk_mount_manager_->RemoveObserver(this); | 421 disk_mount_manager_->RemoveObserver(this); |
424 if (storage_monitor::StorageMonitor::GetInstance()) | 422 if (storage_monitor::StorageMonitor::GetInstance()) |
425 storage_monitor::StorageMonitor::GetInstance()->RemoveObserver(this); | 423 storage_monitor::StorageMonitor::GetInstance()->RemoveObserver(this); |
426 | 424 |
427 if (drive_integration_service_) | 425 if (drive_integration_service_) |
428 drive_integration_service_->RemoveObserver(this); | 426 drive_integration_service_->RemoveObserver(this); |
429 | 427 |
430 if (file_system_provider_service_) | 428 if (file_system_provider_service_) |
431 file_system_provider_service_->RemoveObserver(this); | 429 file_system_provider_service_->RemoveObserver(this); |
432 | 430 |
433 // Unsubscribe from ARC file system events. | 431 // Unsubscribe from ARC file system events. |
434 if (base::FeatureList::IsEnabled(arc::kMediaViewFeature) && | 432 if (base::FeatureList::IsEnabled(arc::kMediaViewFeature) && |
435 arc::ArcSessionManager::IsAllowedForProfile(profile_)) { | 433 arc::ArcSessionManager::IsAllowedForProfile(profile_)) { |
436 arc::ArcFileSystemService* file_system_service = | 434 auto* session_manager = arc::ArcSessionManager::Get(); |
437 arc::ArcServiceManager::GetGlobalService<arc::ArcFileSystemService>(); | |
438 // TODO(crbug.com/672829): We need nullptr check here because | 435 // TODO(crbug.com/672829): We need nullptr check here because |
439 // ArcServiceManager may or may not be alive at this point. | 436 // ArcSessionManager may or may not be alive at this point. |
440 if (file_system_service) | 437 if (session_manager) |
441 file_system_service->RemoveObserver(this); | 438 session_manager->RemoveObserver(this); |
442 } | 439 } |
443 } | 440 } |
444 | 441 |
445 void VolumeManager::AddObserver(VolumeManagerObserver* observer) { | 442 void VolumeManager::AddObserver(VolumeManagerObserver* observer) { |
446 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 443 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
447 DCHECK(observer); | 444 DCHECK(observer); |
448 observers_.AddObserver(observer); | 445 observers_.AddObserver(observer); |
449 } | 446 } |
450 | 447 |
451 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) { | 448 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) { |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 // Repeat until unmount all paths | 734 // Repeat until unmount all paths |
738 const std::string& mount_path = | 735 const std::string& mount_path = |
739 disk_mount_manager_->mount_points().begin()->second.mount_path; | 736 disk_mount_manager_->mount_points().begin()->second.mount_path; |
740 disk_mount_manager_->UnmountPath( | 737 disk_mount_manager_->UnmountPath( |
741 mount_path, chromeos::UNMOUNT_OPTIONS_NONE, | 738 mount_path, chromeos::UNMOUNT_OPTIONS_NONE, |
742 base::Bind( | 739 base::Bind( |
743 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback, | 740 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback, |
744 weak_ptr_factory_.GetWeakPtr())); | 741 weak_ptr_factory_.GetWeakPtr())); |
745 } | 742 } |
746 | 743 |
747 void VolumeManager::OnFileSystemsReady() { | 744 void VolumeManager::OnArcOptInChanged(bool enabled) { |
748 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 745 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
749 DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature)); | 746 DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature)); |
750 DCHECK(arc::ArcSessionManager::IsAllowedForProfile(profile_)); | 747 DCHECK(arc::ArcSessionManager::IsAllowedForProfile(profile_)); |
751 | 748 |
752 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | 749 if (enabled == arc_volumes_mounted_) |
753 linked_ptr<Volume>( | 750 return; |
754 Volume::CreateForMediaView(arc::kImagesRootDocumentId))); | |
755 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | |
756 linked_ptr<Volume>( | |
757 Volume::CreateForMediaView(arc::kVideosRootDocumentId))); | |
758 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | |
759 linked_ptr<Volume>( | |
760 Volume::CreateForMediaView(arc::kAudioRootDocumentId))); | |
761 } | |
762 | 751 |
763 void VolumeManager::OnFileSystemsClosed() { | 752 if (enabled) { |
764 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 753 DoMountEvent(chromeos::MOUNT_ERROR_NONE, |
765 DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature)); | |
766 DCHECK(arc::ArcSessionManager::IsAllowedForProfile(profile_)); | |
767 | |
768 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, | |
769 linked_ptr<Volume>( | 754 linked_ptr<Volume>( |
770 Volume::CreateForMediaView(arc::kImagesRootDocumentId))); | 755 Volume::CreateForMediaView(arc::kImagesRootDocumentId))); |
771 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, | 756 DoMountEvent(chromeos::MOUNT_ERROR_NONE, |
772 linked_ptr<Volume>( | 757 linked_ptr<Volume>( |
773 Volume::CreateForMediaView(arc::kVideosRootDocumentId))); | 758 Volume::CreateForMediaView(arc::kVideosRootDocumentId))); |
774 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, | 759 DoMountEvent(chromeos::MOUNT_ERROR_NONE, |
775 linked_ptr<Volume>( | 760 linked_ptr<Volume>( |
776 Volume::CreateForMediaView(arc::kAudioRootDocumentId))); | 761 Volume::CreateForMediaView(arc::kAudioRootDocumentId))); |
| 762 arc_volumes_mounted_ = true; |
| 763 } else { |
| 764 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, |
| 765 linked_ptr<Volume>( |
| 766 Volume::CreateForMediaView(arc::kImagesRootDocumentId))); |
| 767 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, |
| 768 linked_ptr<Volume>( |
| 769 Volume::CreateForMediaView(arc::kVideosRootDocumentId))); |
| 770 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, |
| 771 linked_ptr<Volume>( |
| 772 Volume::CreateForMediaView(arc::kAudioRootDocumentId))); |
| 773 arc_volumes_mounted_ = false; |
| 774 } |
777 } | 775 } |
778 | 776 |
779 void VolumeManager::OnExternalStorageDisabledChanged() { | 777 void VolumeManager::OnExternalStorageDisabledChanged() { |
780 // If the policy just got disabled we have to unmount every device currently | 778 // If the policy just got disabled we have to unmount every device currently |
781 // mounted. The opposite is fine - we can let the user re-plug their device to | 779 // mounted. The opposite is fine - we can let the user re-plug their device to |
782 // make it available. | 780 // make it available. |
783 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { | 781 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { |
784 // We do not iterate on mount_points directly, because mount_points can | 782 // We do not iterate on mount_points directly, because mount_points can |
785 // be changed by UnmountPath(). | 783 // be changed by UnmountPath(). |
786 // TODO(hidehiko): Is it necessary to unmount mounted archives, too, here? | 784 // TODO(hidehiko): Is it necessary to unmount mounted archives, too, here? |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) | 985 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) |
988 return; | 986 return; |
989 if (error_code == chromeos::MOUNT_ERROR_NONE) | 987 if (error_code == chromeos::MOUNT_ERROR_NONE) |
990 mounted_volumes_.erase(volume->volume_id()); | 988 mounted_volumes_.erase(volume->volume_id()); |
991 | 989 |
992 for (auto& observer : observers_) | 990 for (auto& observer : observers_) |
993 observer.OnVolumeUnmounted(error_code, *volume.get()); | 991 observer.OnVolumeUnmounted(error_code, *volume.get()); |
994 } | 992 } |
995 | 993 |
996 } // namespace file_manager | 994 } // namespace file_manager |
OLD | NEW |