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/files/file_path.h" | 13 #include "base/files/file_path.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
15 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
18 #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" | |
22 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_service.h" | |
23 #include "chrome/browser/chromeos/arc/fileapi/arc_media_view_util.h" | |
19 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 24 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
20 #include "chrome/browser/chromeos/drive/file_system_util.h" | 25 #include "chrome/browser/chromeos/drive/file_system_util.h" |
21 #include "chrome/browser/chromeos/file_manager/path_util.h" | 26 #include "chrome/browser/chromeos/file_manager/path_util.h" |
22 #include "chrome/browser/chromeos/file_manager/snapshot_manager.h" | 27 #include "chrome/browser/chromeos/file_manager/snapshot_manager.h" |
23 #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h" | 28 #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h" |
24 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" | 29 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" |
25 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h" | 30 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h" |
26 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 31 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
27 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" | 32 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" |
28 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
29 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
30 #include "chromeos/chromeos_switches.h" | 35 #include "chromeos/chromeos_switches.h" |
31 #include "chromeos/disks/disk_mount_manager.h" | 36 #include "chromeos/disks/disk_mount_manager.h" |
37 #include "components/arc/arc_service_manager.h" | |
32 #include "components/drive/chromeos/file_system_interface.h" | 38 #include "components/drive/chromeos/file_system_interface.h" |
33 #include "components/drive/file_system_core_util.h" | 39 #include "components/drive/file_system_core_util.h" |
34 #include "components/prefs/pref_service.h" | 40 #include "components/prefs/pref_service.h" |
35 #include "components/storage_monitor/storage_monitor.h" | 41 #include "components/storage_monitor/storage_monitor.h" |
36 #include "content/public/browser/browser_context.h" | 42 #include "content/public/browser/browser_context.h" |
37 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
38 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" | 44 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" |
39 #include "storage/browser/fileapi/external_mount_points.h" | 45 #include "storage/browser/fileapi/external_mount_points.h" |
40 | 46 |
41 namespace file_manager { | 47 namespace file_manager { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 case VOLUME_TYPE_DOWNLOADS_DIRECTORY: | 110 case VOLUME_TYPE_DOWNLOADS_DIRECTORY: |
105 return "downloads"; | 111 return "downloads"; |
106 case VOLUME_TYPE_REMOVABLE_DISK_PARTITION: | 112 case VOLUME_TYPE_REMOVABLE_DISK_PARTITION: |
107 return "removable"; | 113 return "removable"; |
108 case VOLUME_TYPE_MOUNTED_ARCHIVE_FILE: | 114 case VOLUME_TYPE_MOUNTED_ARCHIVE_FILE: |
109 return "archive"; | 115 return "archive"; |
110 case VOLUME_TYPE_PROVIDED: | 116 case VOLUME_TYPE_PROVIDED: |
111 return "provided"; | 117 return "provided"; |
112 case VOLUME_TYPE_MTP: | 118 case VOLUME_TYPE_MTP: |
113 return "mtp"; | 119 return "mtp"; |
120 case VOLUME_TYPE_MEDIA_VIEW: | |
121 return "media_view"; | |
114 case VOLUME_TYPE_TESTING: | 122 case VOLUME_TYPE_TESTING: |
115 return "testing"; | 123 return "testing"; |
116 case NUM_VOLUME_TYPE: | 124 case NUM_VOLUME_TYPE: |
117 break; | 125 break; |
118 } | 126 } |
119 NOTREACHED(); | 127 NOTREACHED(); |
120 return ""; | 128 return ""; |
121 } | 129 } |
122 | 130 |
123 // Generates a unique volume ID for the given volume info. | 131 // Generates a unique volume ID for the given volume info. |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 volume->is_read_only_ = read_only; | 272 volume->is_read_only_ = read_only; |
265 volume->volume_id_ = kMtpVolumeIdPrefix + label; | 273 volume->volume_id_ = kMtpVolumeIdPrefix + label; |
266 volume->volume_label_ = label; | 274 volume->volume_label_ = label; |
267 volume->source_path_ = mount_path; | 275 volume->source_path_ = mount_path; |
268 volume->source_ = SOURCE_DEVICE; | 276 volume->source_ = SOURCE_DEVICE; |
269 volume->device_type_ = chromeos::DEVICE_TYPE_MOBILE; | 277 volume->device_type_ = chromeos::DEVICE_TYPE_MOBILE; |
270 return volume; | 278 return volume; |
271 } | 279 } |
272 | 280 |
273 // static | 281 // static |
282 Volume* Volume::CreateForMediaView(const std::string& root_document_id) { | |
283 Volume* const volume = new Volume; | |
284 volume->type_ = VOLUME_TYPE_MEDIA_VIEW; | |
285 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; | |
286 volume->source_ = SOURCE_SYSTEM; | |
287 volume->mount_path_ = arc::GetDocumentsProviderMountPath( | |
288 arc::kMediaDocumentsProviderAuthority, root_document_id); | |
289 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; | |
290 volume->volume_label_ = root_document_id; | |
291 volume->is_read_only_ = true; | |
292 volume->watchable_ = false; | |
293 volume->volume_id_ = arc::GetMediaViewVolumeId(root_document_id); | |
294 return volume; | |
295 } | |
296 | |
297 // static | |
274 Volume* Volume::CreateForTesting(const base::FilePath& path, | 298 Volume* Volume::CreateForTesting(const base::FilePath& path, |
275 VolumeType volume_type, | 299 VolumeType volume_type, |
276 chromeos::DeviceType device_type, | 300 chromeos::DeviceType device_type, |
277 bool read_only) { | 301 bool read_only) { |
278 Volume* const volume = new Volume; | 302 Volume* const volume = new Volume; |
279 volume->type_ = volume_type; | 303 volume->type_ = volume_type; |
280 volume->device_type_ = device_type; | 304 volume->device_type_ = device_type; |
281 // Keep source_path empty. | 305 // Keep source_path empty. |
282 volume->source_ = SOURCE_DEVICE; | 306 volume->source_ = SOURCE_DEVICE; |
283 volume->mount_path_ = path; | 307 volume->mount_path_ = path; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 prefs::kExternalStorageReadOnly, | 399 prefs::kExternalStorageReadOnly, |
376 base::Bind(&VolumeManager::OnExternalStorageReadOnlyChanged, | 400 base::Bind(&VolumeManager::OnExternalStorageReadOnlyChanged, |
377 weak_ptr_factory_.GetWeakPtr())); | 401 weak_ptr_factory_.GetWeakPtr())); |
378 | 402 |
379 // Subscribe to storage monitor for MTP notifications. | 403 // Subscribe to storage monitor for MTP notifications. |
380 if (storage_monitor::StorageMonitor::GetInstance()) { | 404 if (storage_monitor::StorageMonitor::GetInstance()) { |
381 storage_monitor::StorageMonitor::GetInstance()->EnsureInitialized( | 405 storage_monitor::StorageMonitor::GetInstance()->EnsureInitialized( |
382 base::Bind(&VolumeManager::OnStorageMonitorInitialized, | 406 base::Bind(&VolumeManager::OnStorageMonitorInitialized, |
383 weak_ptr_factory_.GetWeakPtr())); | 407 weak_ptr_factory_.GetWeakPtr())); |
384 } | 408 } |
409 | |
410 // Subscribe to ARC file system events. | |
411 if (base::FeatureList::IsEnabled(arc::kMediaViewFeature) && | |
412 arc::ArcSessionManager::IsAllowedForProfile(profile_)) { | |
413 arc::ArcServiceManager::Get()->file_system_service()->AddObserver(this); | |
414 } | |
385 } | 415 } |
386 | 416 |
387 void VolumeManager::Shutdown() { | 417 void VolumeManager::Shutdown() { |
388 weak_ptr_factory_.InvalidateWeakPtrs(); | 418 weak_ptr_factory_.InvalidateWeakPtrs(); |
389 | 419 |
390 snapshot_manager_.reset(); | 420 snapshot_manager_.reset(); |
391 pref_change_registrar_.RemoveAll(); | 421 pref_change_registrar_.RemoveAll(); |
392 disk_mount_manager_->RemoveObserver(this); | 422 disk_mount_manager_->RemoveObserver(this); |
393 if (storage_monitor::StorageMonitor::GetInstance()) | 423 if (storage_monitor::StorageMonitor::GetInstance()) |
394 storage_monitor::StorageMonitor::GetInstance()->RemoveObserver(this); | 424 storage_monitor::StorageMonitor::GetInstance()->RemoveObserver(this); |
395 | 425 |
396 if (drive_integration_service_) | 426 if (drive_integration_service_) |
397 drive_integration_service_->RemoveObserver(this); | 427 drive_integration_service_->RemoveObserver(this); |
398 | 428 |
399 if (file_system_provider_service_) | 429 if (file_system_provider_service_) |
400 file_system_provider_service_->RemoveObserver(this); | 430 file_system_provider_service_->RemoveObserver(this); |
431 | |
432 // Unsubscribe from ARC file system events. | |
433 if (base::FeatureList::IsEnabled(arc::kMediaViewFeature) && | |
434 arc::ArcSessionManager::IsAllowedForProfile(profile_)) { | |
435 arc::ArcServiceManager::Get()->file_system_service()->RemoveObserver(this); | |
Luis Héctor Chávez
2017/01/11 16:48:45
Should you call OnFileSystemsClosed() here?
| |
436 } | |
401 } | 437 } |
402 | 438 |
403 void VolumeManager::AddObserver(VolumeManagerObserver* observer) { | 439 void VolumeManager::AddObserver(VolumeManagerObserver* observer) { |
404 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 440 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
405 DCHECK(observer); | 441 DCHECK(observer); |
406 observers_.AddObserver(observer); | 442 observers_.AddObserver(observer); |
407 } | 443 } |
408 | 444 |
409 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) { | 445 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) { |
410 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 446 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
695 // Repeat until unmount all paths | 731 // Repeat until unmount all paths |
696 const std::string& mount_path = | 732 const std::string& mount_path = |
697 disk_mount_manager_->mount_points().begin()->second.mount_path; | 733 disk_mount_manager_->mount_points().begin()->second.mount_path; |
698 disk_mount_manager_->UnmountPath( | 734 disk_mount_manager_->UnmountPath( |
699 mount_path, chromeos::UNMOUNT_OPTIONS_NONE, | 735 mount_path, chromeos::UNMOUNT_OPTIONS_NONE, |
700 base::Bind( | 736 base::Bind( |
701 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback, | 737 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback, |
702 weak_ptr_factory_.GetWeakPtr())); | 738 weak_ptr_factory_.GetWeakPtr())); |
703 } | 739 } |
704 | 740 |
741 void VolumeManager::OnFileSystemsReady() { | |
742 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
743 DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature)); | |
744 DCHECK(arc::ArcSessionManager::IsAllowedForProfile(profile_)); | |
745 | |
746 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | |
747 linked_ptr<Volume>( | |
748 Volume::CreateForMediaView(arc::kImagesRootDocumentId))); | |
749 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | |
750 linked_ptr<Volume>( | |
751 Volume::CreateForMediaView(arc::kVideosRootDocumentId))); | |
752 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | |
753 linked_ptr<Volume>( | |
754 Volume::CreateForMediaView(arc::kAudioRootDocumentId))); | |
755 } | |
756 | |
757 void VolumeManager::OnFileSystemsClosed() { | |
758 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
759 DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature)); | |
760 DCHECK(arc::ArcSessionManager::IsAllowedForProfile(profile_)); | |
761 | |
762 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, | |
763 linked_ptr<Volume>( | |
764 Volume::CreateForMediaView(arc::kImagesRootDocumentId))); | |
765 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, | |
766 linked_ptr<Volume>( | |
767 Volume::CreateForMediaView(arc::kVideosRootDocumentId))); | |
768 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, | |
769 linked_ptr<Volume>( | |
770 Volume::CreateForMediaView(arc::kAudioRootDocumentId))); | |
771 } | |
772 | |
705 void VolumeManager::OnExternalStorageDisabledChanged() { | 773 void VolumeManager::OnExternalStorageDisabledChanged() { |
706 // If the policy just got disabled we have to unmount every device currently | 774 // If the policy just got disabled we have to unmount every device currently |
707 // mounted. The opposite is fine - we can let the user re-plug their device to | 775 // mounted. The opposite is fine - we can let the user re-plug their device to |
708 // make it available. | 776 // make it available. |
709 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { | 777 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { |
710 // We do not iterate on mount_points directly, because mount_points can | 778 // We do not iterate on mount_points directly, because mount_points can |
711 // be changed by UnmountPath(). | 779 // be changed by UnmountPath(). |
712 // TODO(hidehiko): Is it necessary to unmount mounted archives, too, here? | 780 // TODO(hidehiko): Is it necessary to unmount mounted archives, too, here? |
713 if (disk_mount_manager_->mount_points().empty()) | 781 if (disk_mount_manager_->mount_points().empty()) |
714 return; | 782 return; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
913 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) | 981 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) |
914 return; | 982 return; |
915 if (error_code == chromeos::MOUNT_ERROR_NONE) | 983 if (error_code == chromeos::MOUNT_ERROR_NONE) |
916 mounted_volumes_.erase(volume->volume_id()); | 984 mounted_volumes_.erase(volume->volume_id()); |
917 | 985 |
918 for (auto& observer : observers_) | 986 for (auto& observer : observers_) |
919 observer.OnVolumeUnmounted(error_code, *volume.get()); | 987 observer.OnVolumeUnmounted(error_code, *volume.get()); |
920 } | 988 } |
921 | 989 |
922 } // namespace file_manager | 990 } // namespace file_manager |
OLD | NEW |