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

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

Issue 2580303002: mediaview: Mount ARC documents provider file system volumes. (Closed)
Patch Set: Consistently use GetGlobalService(). Created 3 years, 11 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
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 <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
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
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
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::GetGlobalService<arc::ArcFileSystemService>()
414 ->AddObserver(this);
415 }
385 } 416 }
386 417
387 void VolumeManager::Shutdown() { 418 void VolumeManager::Shutdown() {
388 weak_ptr_factory_.InvalidateWeakPtrs(); 419 weak_ptr_factory_.InvalidateWeakPtrs();
389 420
390 snapshot_manager_.reset(); 421 snapshot_manager_.reset();
391 pref_change_registrar_.RemoveAll(); 422 pref_change_registrar_.RemoveAll();
392 disk_mount_manager_->RemoveObserver(this); 423 disk_mount_manager_->RemoveObserver(this);
393 if (storage_monitor::StorageMonitor::GetInstance()) 424 if (storage_monitor::StorageMonitor::GetInstance())
394 storage_monitor::StorageMonitor::GetInstance()->RemoveObserver(this); 425 storage_monitor::StorageMonitor::GetInstance()->RemoveObserver(this);
395 426
396 if (drive_integration_service_) 427 if (drive_integration_service_)
397 drive_integration_service_->RemoveObserver(this); 428 drive_integration_service_->RemoveObserver(this);
398 429
399 if (file_system_provider_service_) 430 if (file_system_provider_service_)
400 file_system_provider_service_->RemoveObserver(this); 431 file_system_provider_service_->RemoveObserver(this);
432
433 // Unsubscribe from ARC file system events.
434 if (base::FeatureList::IsEnabled(arc::kMediaViewFeature) &&
435 arc::ArcSessionManager::IsAllowedForProfile(profile_)) {
436 arc::ArcFileSystemService* file_system_service =
437 arc::ArcServiceManager::GetGlobalService<arc::ArcFileSystemService>();
438 // TODO(crbug.com/672829): We need nullptr check here because
439 // ArcServiceManager may or may not be alive at this point.
440 if (file_system_service)
441 file_system_service->RemoveObserver(this);
442 }
401 } 443 }
402 444
403 void VolumeManager::AddObserver(VolumeManagerObserver* observer) { 445 void VolumeManager::AddObserver(VolumeManagerObserver* observer) {
404 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 446 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
405 DCHECK(observer); 447 DCHECK(observer);
406 observers_.AddObserver(observer); 448 observers_.AddObserver(observer);
407 } 449 }
408 450
409 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) { 451 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) {
410 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 452 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 // Repeat until unmount all paths 737 // Repeat until unmount all paths
696 const std::string& mount_path = 738 const std::string& mount_path =
697 disk_mount_manager_->mount_points().begin()->second.mount_path; 739 disk_mount_manager_->mount_points().begin()->second.mount_path;
698 disk_mount_manager_->UnmountPath( 740 disk_mount_manager_->UnmountPath(
699 mount_path, chromeos::UNMOUNT_OPTIONS_NONE, 741 mount_path, chromeos::UNMOUNT_OPTIONS_NONE,
700 base::Bind( 742 base::Bind(
701 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback, 743 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback,
702 weak_ptr_factory_.GetWeakPtr())); 744 weak_ptr_factory_.GetWeakPtr()));
703 } 745 }
704 746
747 void VolumeManager::OnFileSystemsReady() {
748 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
749 DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature));
750 DCHECK(arc::ArcSessionManager::IsAllowedForProfile(profile_));
751
752 DoMountEvent(chromeos::MOUNT_ERROR_NONE,
753 linked_ptr<Volume>(
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
763 void VolumeManager::OnFileSystemsClosed() {
764 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
765 DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature));
766 DCHECK(arc::ArcSessionManager::IsAllowedForProfile(profile_));
767
768 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE,
769 linked_ptr<Volume>(
770 Volume::CreateForMediaView(arc::kImagesRootDocumentId)));
771 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE,
772 linked_ptr<Volume>(
773 Volume::CreateForMediaView(arc::kVideosRootDocumentId)));
774 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE,
775 linked_ptr<Volume>(
776 Volume::CreateForMediaView(arc::kAudioRootDocumentId)));
777 }
778
705 void VolumeManager::OnExternalStorageDisabledChanged() { 779 void VolumeManager::OnExternalStorageDisabledChanged() {
706 // If the policy just got disabled we have to unmount every device currently 780 // 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 781 // mounted. The opposite is fine - we can let the user re-plug their device to
708 // make it available. 782 // make it available.
709 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { 783 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) {
710 // We do not iterate on mount_points directly, because mount_points can 784 // We do not iterate on mount_points directly, because mount_points can
711 // be changed by UnmountPath(). 785 // be changed by UnmountPath().
712 // TODO(hidehiko): Is it necessary to unmount mounted archives, too, here? 786 // TODO(hidehiko): Is it necessary to unmount mounted archives, too, here?
713 if (disk_mount_manager_->mount_points().empty()) 787 if (disk_mount_manager_->mount_points().empty())
714 return; 788 return;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) 987 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end())
914 return; 988 return;
915 if (error_code == chromeos::MOUNT_ERROR_NONE) 989 if (error_code == chromeos::MOUNT_ERROR_NONE)
916 mounted_volumes_.erase(volume->volume_id()); 990 mounted_volumes_.erase(volume->volume_id());
917 991
918 for (auto& observer : observers_) 992 for (auto& observer : observers_)
919 observer.OnVolumeUnmounted(error_code, *volume.get()); 993 observer.OnVolumeUnmounted(error_code, *volume.get());
920 } 994 }
921 995
922 } // namespace file_manager 996 } // namespace file_manager
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_manager/volume_manager.h ('k') | chrome/browser/chromeos/fileapi/file_system_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698