| Index: chrome/browser/chromeos/file_manager/volume_manager.cc
|
| diff --git a/chrome/browser/chromeos/file_manager/volume_manager.cc b/chrome/browser/chromeos/file_manager/volume_manager.cc
|
| index 4464bb60c0cb9c27c5c8e5bd8ed3986cf3e1eee1..392914fab273a9fa107ffdc177e12eff87808256 100644
|
| --- a/chrome/browser/chromeos/file_manager/volume_manager.cc
|
| +++ b/chrome/browser/chromeos/file_manager/volume_manager.cc
|
| @@ -9,6 +9,7 @@
|
|
|
| #include "base/bind.h"
|
| #include "base/command_line.h"
|
| +#include "base/feature_list.h"
|
| #include "base/files/file_path.h"
|
| #include "base/logging.h"
|
| #include "base/memory/weak_ptr.h"
|
| @@ -16,6 +17,10 @@
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| +#include "chrome/browser/chromeos/arc/arc_session_manager.h"
|
| +#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h"
|
| +#include "chrome/browser/chromeos/arc/fileapi/arc_file_system_service.h"
|
| +#include "chrome/browser/chromeos/arc/fileapi/arc_media_view_util.h"
|
| #include "chrome/browser/chromeos/drive/drive_integration_service.h"
|
| #include "chrome/browser/chromeos/drive/file_system_util.h"
|
| #include "chrome/browser/chromeos/file_manager/path_util.h"
|
| @@ -29,6 +34,7 @@
|
| #include "chrome/common/pref_names.h"
|
| #include "chromeos/chromeos_switches.h"
|
| #include "chromeos/disks/disk_mount_manager.h"
|
| +#include "components/arc/arc_service_manager.h"
|
| #include "components/drive/chromeos/file_system_interface.h"
|
| #include "components/drive/file_system_core_util.h"
|
| #include "components/prefs/pref_service.h"
|
| @@ -111,6 +117,8 @@ std::string VolumeTypeToString(VolumeType type) {
|
| return "provided";
|
| case VOLUME_TYPE_MTP:
|
| return "mtp";
|
| + case VOLUME_TYPE_MEDIA_VIEW:
|
| + return "media_view";
|
| case VOLUME_TYPE_TESTING:
|
| return "testing";
|
| case NUM_VOLUME_TYPE:
|
| @@ -271,6 +279,22 @@ Volume* Volume::CreateForMTP(const base::FilePath& mount_path,
|
| }
|
|
|
| // static
|
| +Volume* Volume::CreateForMediaView(const std::string& root_document_id) {
|
| + Volume* const volume = new Volume;
|
| + volume->type_ = VOLUME_TYPE_MEDIA_VIEW;
|
| + volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN;
|
| + volume->source_ = SOURCE_SYSTEM;
|
| + volume->mount_path_ = arc::GetDocumentsProviderMountPath(
|
| + arc::kMediaDocumentsProviderAuthority, root_document_id);
|
| + volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE;
|
| + volume->volume_label_ = root_document_id;
|
| + volume->is_read_only_ = true;
|
| + volume->watchable_ = false;
|
| + volume->volume_id_ = arc::GetMediaViewVolumeId(root_document_id);
|
| + return volume;
|
| +}
|
| +
|
| +// static
|
| Volume* Volume::CreateForTesting(const base::FilePath& path,
|
| VolumeType volume_type,
|
| chromeos::DeviceType device_type,
|
| @@ -382,6 +406,13 @@ void VolumeManager::Initialize() {
|
| base::Bind(&VolumeManager::OnStorageMonitorInitialized,
|
| weak_ptr_factory_.GetWeakPtr()));
|
| }
|
| +
|
| + // Subscribe to ARC file system events.
|
| + if (base::FeatureList::IsEnabled(arc::kMediaViewFeature) &&
|
| + arc::ArcSessionManager::IsAllowedForProfile(profile_)) {
|
| + arc::ArcServiceManager::GetGlobalService<arc::ArcFileSystemService>()
|
| + ->AddObserver(this);
|
| + }
|
| }
|
|
|
| void VolumeManager::Shutdown() {
|
| @@ -398,6 +429,17 @@ void VolumeManager::Shutdown() {
|
|
|
| if (file_system_provider_service_)
|
| file_system_provider_service_->RemoveObserver(this);
|
| +
|
| + // Unsubscribe from ARC file system events.
|
| + if (base::FeatureList::IsEnabled(arc::kMediaViewFeature) &&
|
| + arc::ArcSessionManager::IsAllowedForProfile(profile_)) {
|
| + arc::ArcFileSystemService* file_system_service =
|
| + arc::ArcServiceManager::GetGlobalService<arc::ArcFileSystemService>();
|
| + // TODO(crbug.com/672829): We need nullptr check here because
|
| + // ArcServiceManager may or may not be alive at this point.
|
| + if (file_system_service)
|
| + file_system_service->RemoveObserver(this);
|
| + }
|
| }
|
|
|
| void VolumeManager::AddObserver(VolumeManagerObserver* observer) {
|
| @@ -702,6 +744,38 @@ void VolumeManager::OnExternalStorageDisabledChangedUnmountCallback(
|
| weak_ptr_factory_.GetWeakPtr()));
|
| }
|
|
|
| +void VolumeManager::OnFileSystemsReady() {
|
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| + DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature));
|
| + DCHECK(arc::ArcSessionManager::IsAllowedForProfile(profile_));
|
| +
|
| + DoMountEvent(chromeos::MOUNT_ERROR_NONE,
|
| + linked_ptr<Volume>(
|
| + Volume::CreateForMediaView(arc::kImagesRootDocumentId)));
|
| + DoMountEvent(chromeos::MOUNT_ERROR_NONE,
|
| + linked_ptr<Volume>(
|
| + Volume::CreateForMediaView(arc::kVideosRootDocumentId)));
|
| + DoMountEvent(chromeos::MOUNT_ERROR_NONE,
|
| + linked_ptr<Volume>(
|
| + Volume::CreateForMediaView(arc::kAudioRootDocumentId)));
|
| +}
|
| +
|
| +void VolumeManager::OnFileSystemsClosed() {
|
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| + DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature));
|
| + DCHECK(arc::ArcSessionManager::IsAllowedForProfile(profile_));
|
| +
|
| + DoUnmountEvent(chromeos::MOUNT_ERROR_NONE,
|
| + linked_ptr<Volume>(
|
| + Volume::CreateForMediaView(arc::kImagesRootDocumentId)));
|
| + DoUnmountEvent(chromeos::MOUNT_ERROR_NONE,
|
| + linked_ptr<Volume>(
|
| + Volume::CreateForMediaView(arc::kVideosRootDocumentId)));
|
| + DoUnmountEvent(chromeos::MOUNT_ERROR_NONE,
|
| + linked_ptr<Volume>(
|
| + Volume::CreateForMediaView(arc::kAudioRootDocumentId)));
|
| +}
|
| +
|
| void VolumeManager::OnExternalStorageDisabledChanged() {
|
| // If the policy just got disabled we have to unmount every device currently
|
| // mounted. The opposite is fine - we can let the user re-plug their device to
|
|
|