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

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: Rebased. 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_media_view_util.h"
19 #include "chrome/browser/chromeos/drive/drive_integration_service.h" 23 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
20 #include "chrome/browser/chromeos/drive/file_system_util.h" 24 #include "chrome/browser/chromeos/drive/file_system_util.h"
21 #include "chrome/browser/chromeos/file_manager/path_util.h" 25 #include "chrome/browser/chromeos/file_manager/path_util.h"
22 #include "chrome/browser/chromeos/file_manager/snapshot_manager.h" 26 #include "chrome/browser/chromeos/file_manager/snapshot_manager.h"
23 #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h" 27 #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h"
24 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" 28 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h"
25 #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"
26 #include "chrome/browser/chromeos/profiles/profile_helper.h" 30 #include "chrome/browser/chromeos/profiles/profile_helper.h"
27 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" 31 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h"
28 #include "chrome/browser/profiles/profile.h" 32 #include "chrome/browser/profiles/profile.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 case VOLUME_TYPE_DOWNLOADS_DIRECTORY: 108 case VOLUME_TYPE_DOWNLOADS_DIRECTORY:
105 return "downloads"; 109 return "downloads";
106 case VOLUME_TYPE_REMOVABLE_DISK_PARTITION: 110 case VOLUME_TYPE_REMOVABLE_DISK_PARTITION:
107 return "removable"; 111 return "removable";
108 case VOLUME_TYPE_MOUNTED_ARCHIVE_FILE: 112 case VOLUME_TYPE_MOUNTED_ARCHIVE_FILE:
109 return "archive"; 113 return "archive";
110 case VOLUME_TYPE_PROVIDED: 114 case VOLUME_TYPE_PROVIDED:
111 return "provided"; 115 return "provided";
112 case VOLUME_TYPE_MTP: 116 case VOLUME_TYPE_MTP:
113 return "mtp"; 117 return "mtp";
118 case VOLUME_TYPE_MEDIA_VIEW:
119 return "media_view";
114 case VOLUME_TYPE_TESTING: 120 case VOLUME_TYPE_TESTING:
115 return "testing"; 121 return "testing";
116 case NUM_VOLUME_TYPE: 122 case NUM_VOLUME_TYPE:
117 break; 123 break;
118 } 124 }
119 NOTREACHED(); 125 NOTREACHED();
120 return ""; 126 return "";
121 } 127 }
122 128
123 // Generates a unique volume ID for the given volume info. 129 // 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; 270 volume->is_read_only_ = read_only;
265 volume->volume_id_ = kMtpVolumeIdPrefix + label; 271 volume->volume_id_ = kMtpVolumeIdPrefix + label;
266 volume->volume_label_ = label; 272 volume->volume_label_ = label;
267 volume->source_path_ = mount_path; 273 volume->source_path_ = mount_path;
268 volume->source_ = SOURCE_DEVICE; 274 volume->source_ = SOURCE_DEVICE;
269 volume->device_type_ = chromeos::DEVICE_TYPE_MOBILE; 275 volume->device_type_ = chromeos::DEVICE_TYPE_MOBILE;
270 return volume; 276 return volume;
271 } 277 }
272 278
273 // static 279 // static
280 Volume* Volume::CreateForMediaView(const std::string& root_document_id) {
281 Volume* const volume = new Volume;
282 volume->type_ = VOLUME_TYPE_MEDIA_VIEW;
283 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN;
284 volume->source_ = SOURCE_SYSTEM;
285 volume->mount_path_ = arc::GetDocumentsProviderMountPath(
286 arc::kMediaDocumentsProviderAuthority, root_document_id);
287 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE;
288 volume->volume_label_ = root_document_id;
289 volume->is_read_only_ = true;
290 volume->watchable_ = false;
291 volume->volume_id_ = arc::GetMediaViewVolumeId(root_document_id);
292 return volume;
293 }
294
295 // static
274 Volume* Volume::CreateForTesting(const base::FilePath& path, 296 Volume* Volume::CreateForTesting(const base::FilePath& path,
275 VolumeType volume_type, 297 VolumeType volume_type,
276 chromeos::DeviceType device_type, 298 chromeos::DeviceType device_type,
277 bool read_only) { 299 bool read_only) {
278 Volume* const volume = new Volume; 300 Volume* const volume = new Volume;
279 volume->type_ = volume_type; 301 volume->type_ = volume_type;
280 volume->device_type_ = device_type; 302 volume->device_type_ = device_type;
281 // Keep source_path empty. 303 // Keep source_path empty.
282 volume->source_ = SOURCE_DEVICE; 304 volume->source_ = SOURCE_DEVICE;
283 volume->mount_path_ = path; 305 volume->mount_path_ = path;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 prefs::kExternalStorageReadOnly, 397 prefs::kExternalStorageReadOnly,
376 base::Bind(&VolumeManager::OnExternalStorageReadOnlyChanged, 398 base::Bind(&VolumeManager::OnExternalStorageReadOnlyChanged,
377 weak_ptr_factory_.GetWeakPtr())); 399 weak_ptr_factory_.GetWeakPtr()));
378 400
379 // Subscribe to storage monitor for MTP notifications. 401 // Subscribe to storage monitor for MTP notifications.
380 if (storage_monitor::StorageMonitor::GetInstance()) { 402 if (storage_monitor::StorageMonitor::GetInstance()) {
381 storage_monitor::StorageMonitor::GetInstance()->EnsureInitialized( 403 storage_monitor::StorageMonitor::GetInstance()->EnsureInitialized(
382 base::Bind(&VolumeManager::OnStorageMonitorInitialized, 404 base::Bind(&VolumeManager::OnStorageMonitorInitialized,
383 weak_ptr_factory_.GetWeakPtr())); 405 weak_ptr_factory_.GetWeakPtr()));
384 } 406 }
407
408 // Subscribe to ARC events.
409 if (base::FeatureList::IsEnabled(arc::kMediaViewFeature) &&
410 arc::ArcSessionManager::IsAllowedForProfile(profile_)) {
411 arc::ArcServiceManager::Get()->AddObserver(this);
412 }
385 } 413 }
386 414
387 void VolumeManager::Shutdown() { 415 void VolumeManager::Shutdown() {
388 weak_ptr_factory_.InvalidateWeakPtrs(); 416 weak_ptr_factory_.InvalidateWeakPtrs();
389 417
390 snapshot_manager_.reset(); 418 snapshot_manager_.reset();
391 pref_change_registrar_.RemoveAll(); 419 pref_change_registrar_.RemoveAll();
392 disk_mount_manager_->RemoveObserver(this); 420 disk_mount_manager_->RemoveObserver(this);
393 if (storage_monitor::StorageMonitor::GetInstance()) 421 if (storage_monitor::StorageMonitor::GetInstance())
394 storage_monitor::StorageMonitor::GetInstance()->RemoveObserver(this); 422 storage_monitor::StorageMonitor::GetInstance()->RemoveObserver(this);
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 // Repeat until unmount all paths 723 // Repeat until unmount all paths
696 const std::string& mount_path = 724 const std::string& mount_path =
697 disk_mount_manager_->mount_points().begin()->second.mount_path; 725 disk_mount_manager_->mount_points().begin()->second.mount_path;
698 disk_mount_manager_->UnmountPath( 726 disk_mount_manager_->UnmountPath(
699 mount_path, chromeos::UNMOUNT_OPTIONS_NONE, 727 mount_path, chromeos::UNMOUNT_OPTIONS_NONE,
700 base::Bind( 728 base::Bind(
701 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback, 729 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback,
702 weak_ptr_factory_.GetWeakPtr())); 730 weak_ptr_factory_.GetWeakPtr()));
703 } 731 }
704 732
733 void VolumeManager::OnFileSystemsReady() {
734 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
735 DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature));
736 DCHECK(arc::ArcSessionManager::IsAllowedForProfile(profile_));
737
738 DoMountEvent(chromeos::MOUNT_ERROR_NONE,
739 linked_ptr<Volume>(
740 Volume::CreateForMediaView(arc::kImagesRootDocumentId)));
741 DoMountEvent(chromeos::MOUNT_ERROR_NONE,
742 linked_ptr<Volume>(
743 Volume::CreateForMediaView(arc::kVideosRootDocumentId)));
744 DoMountEvent(chromeos::MOUNT_ERROR_NONE,
745 linked_ptr<Volume>(
746 Volume::CreateForMediaView(arc::kAudioRootDocumentId)));
747 }
748
749 void VolumeManager::OnArcShutdown() {
750 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
751 DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature));
752 DCHECK(arc::ArcSessionManager::IsAllowedForProfile(profile_));
753
754 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE,
755 linked_ptr<Volume>(
756 Volume::CreateForMediaView(arc::kImagesRootDocumentId)));
757 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE,
758 linked_ptr<Volume>(
759 Volume::CreateForMediaView(arc::kVideosRootDocumentId)));
760 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE,
761 linked_ptr<Volume>(
762 Volume::CreateForMediaView(arc::kAudioRootDocumentId)));
763
764 // Unsubscribe from ARC events.
765 arc::ArcServiceManager::Get()->RemoveObserver(this);
766 }
767
705 void VolumeManager::OnExternalStorageDisabledChanged() { 768 void VolumeManager::OnExternalStorageDisabledChanged() {
706 // If the policy just got disabled we have to unmount every device currently 769 // 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 770 // mounted. The opposite is fine - we can let the user re-plug their device to
708 // make it available. 771 // make it available.
709 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { 772 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) {
710 // We do not iterate on mount_points directly, because mount_points can 773 // We do not iterate on mount_points directly, because mount_points can
711 // be changed by UnmountPath(). 774 // be changed by UnmountPath().
712 // TODO(hidehiko): Is it necessary to unmount mounted archives, too, here? 775 // TODO(hidehiko): Is it necessary to unmount mounted archives, too, here?
713 if (disk_mount_manager_->mount_points().empty()) 776 if (disk_mount_manager_->mount_points().empty())
714 return; 777 return;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) 976 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end())
914 return; 977 return;
915 if (error_code == chromeos::MOUNT_ERROR_NONE) 978 if (error_code == chromeos::MOUNT_ERROR_NONE)
916 mounted_volumes_.erase(volume->volume_id()); 979 mounted_volumes_.erase(volume->volume_id());
917 980
918 for (auto& observer : observers_) 981 for (auto& observer : observers_)
919 observer.OnVolumeUnmounted(error_code, *volume.get()); 982 observer.OnVolumeUnmounted(error_code, *volume.get());
920 } 983 }
921 984
922 } // namespace file_manager 985 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698