| Index: chrome/browser/media_galleries/media_file_system_registry.cc
|
| diff --git a/chrome/browser/media_galleries/media_file_system_registry.cc b/chrome/browser/media_galleries/media_file_system_registry.cc
|
| index 1010eb6a1694891baed271dd9b6ecef2eb6122b2..faf3c0c21890de43f6efefcd707e72f16b630dc8 100644
|
| --- a/chrome/browser/media_galleries/media_file_system_registry.cc
|
| +++ b/chrome/browser/media_galleries/media_file_system_registry.cc
|
| @@ -12,6 +12,8 @@
|
| #include "base/files/file_path.h"
|
| #include "base/prefs/pref_service.h"
|
| #include "base/stl_util.h"
|
| +#include "base/strings/string_number_conversions.h"
|
| +#include "base/strings/string_util.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h"
|
| #include "chrome/browser/media_galleries/imported_media_gallery_registry.h"
|
| @@ -36,17 +38,18 @@
|
| #include "extensions/browser/extension_system.h"
|
| #include "extensions/common/extension.h"
|
| #include "extensions/common/extension_set.h"
|
| -#include "webkit/browser/fileapi/isolated_context.h"
|
| +#include "webkit/browser/fileapi/external_mount_points.h"
|
| +#include "webkit/common/fileapi/file_system_mount_option.h"
|
| #include "webkit/common/fileapi/file_system_types.h"
|
|
|
| using content::BrowserThread;
|
| using content::NavigationController;
|
| using content::RenderProcessHost;
|
| using content::WebContents;
|
| -using fileapi::IsolatedContext;
|
| using storage_monitor::MediaStorageUtil;
|
| using storage_monitor::StorageInfo;
|
| using storage_monitor::StorageMonitor;
|
| +using fileapi::ExternalMountPoints;
|
|
|
| namespace {
|
|
|
| @@ -261,8 +264,10 @@ class ExtensionGalleriesHost
|
| // |no_references_callback| is called when the last RenderViewHost reference
|
| // goes away. RenderViewHost references are added through ReferenceFromRVH().
|
| ExtensionGalleriesHost(MediaFileSystemContext* file_system_context,
|
| + const std::string file_system_name_prefix,
|
| const base::Closure& no_references_callback)
|
| : file_system_context_(file_system_context),
|
| + file_system_name_prefix_(file_system_name_prefix),
|
| no_references_callback_(no_references_callback),
|
| rph_refs_(base::Bind(&ExtensionGalleriesHost::CleanUp,
|
| base::Unretained(this))) {
|
| @@ -354,18 +359,19 @@ class ExtensionGalleriesHost
|
| }
|
|
|
| base::FilePath path = gallery_info.AbsolutePath();
|
| - if (!MediaStorageUtil::CanCreateFileSystem(device_id, path))
|
| + if (path.empty() ||
|
| + !MediaStorageUtil::CanCreateFileSystem(device_id, path))
|
| continue;
|
|
|
| - std::string fsid =
|
| - file_system_context_->RegisterFileSystem(device_id, path);
|
| - if (fsid.empty())
|
| + std::string fs_name = file_system_name_prefix_;
|
| + fs_name.append(base::Uint64ToString(pref_id));
|
| + if (!file_system_context_->RegisterFileSystem(device_id, fs_name, path))
|
| continue;
|
|
|
| MediaFileSystemInfo new_entry(
|
| gallery_info.GetGalleryDisplayName(),
|
| - path,
|
| - fsid,
|
| + file_system_context_->GetRegisteredPath(fs_name),
|
| + fs_name,
|
| pref_id,
|
| GetTransientIdForRemovableDeviceId(device_id),
|
| StorageInfo::IsRemovableDevice(device_id),
|
| @@ -406,6 +412,9 @@ class ExtensionGalleriesHost
|
| // safe to store a raw pointer.
|
| MediaFileSystemContext* file_system_context_;
|
|
|
| + // A unique name prefix for filesystems.
|
| + std::string file_system_name_prefix_;
|
| +
|
| // A callback to call when the last RVH reference goes away.
|
| base::Closure no_references_callback_;
|
|
|
| @@ -448,8 +457,15 @@ void MediaFileSystemRegistry::GetMediaFileSystemsForExtension(
|
| ExtensionGalleriesHost* extension_host =
|
| extension_hosts->second[extension->id()].get();
|
| if (!extension_host) {
|
| + std::string name_prefix = "media_galleries-";
|
| + name_prefix.append(profile->GetPath().BaseName().MaybeAsASCII());
|
| + name_prefix.append("-");
|
| + name_prefix.append(extension->id());
|
| + name_prefix.append("-");
|
| + base::ReplaceChars(name_prefix, " /", "_", &name_prefix);
|
| extension_host = new ExtensionGalleriesHost(
|
| file_system_context_.get(),
|
| + name_prefix,
|
| base::Bind(&MediaFileSystemRegistry::OnExtensionGalleriesHostEmpty,
|
| base::Unretained(this),
|
| profile,
|
| @@ -538,41 +554,50 @@ void MediaFileSystemRegistry::OnRemovableStorageDetached(
|
| class MediaFileSystemRegistry::MediaFileSystemContextImpl
|
| : public MediaFileSystemContext {
|
| public:
|
| - explicit MediaFileSystemContextImpl(MediaFileSystemRegistry* registry)
|
| - : registry_(registry) {
|
| - DCHECK(registry_); // Suppresses unused warning on Android.
|
| - }
|
| + MediaFileSystemContextImpl() {}
|
| virtual ~MediaFileSystemContextImpl() {}
|
|
|
| - virtual std::string RegisterFileSystem(
|
| - const std::string& device_id, const base::FilePath& path) OVERRIDE {
|
| + virtual bool RegisterFileSystem(const std::string& device_id,
|
| + const std::string& fs_name,
|
| + const base::FilePath& path) OVERRIDE {
|
| if (StorageInfo::IsMassStorageDevice(device_id)) {
|
| - return RegisterFileSystemForMassStorage(device_id, path);
|
| + return RegisterFileSystemForMassStorage(device_id, fs_name, path);
|
| } else {
|
| - return RegisterFileSystemForMTPDevice(device_id, path);
|
| + return RegisterFileSystemForMTPDevice(device_id, fs_name, path);
|
| }
|
| }
|
|
|
| - virtual void RevokeFileSystem(const std::string& fsid) OVERRIDE {
|
| + virtual void RevokeFileSystem(const std::string& fs_name) OVERRIDE {
|
| ImportedMediaGalleryRegistry* imported_registry =
|
| ImportedMediaGalleryRegistry::GetInstance();
|
| - if (imported_registry->RevokeImportedFilesystemOnUIThread(fsid))
|
| + if (imported_registry->RevokeImportedFilesystemOnUIThread(fs_name))
|
| return;
|
|
|
| - IsolatedContext::GetInstance()->RevokeFileSystem(fsid);
|
| + ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(fs_name);
|
|
|
| content::BrowserThread::PostTask(
|
| content::BrowserThread::IO, FROM_HERE, base::Bind(
|
| &MTPDeviceMapService::RevokeMTPFileSystem,
|
| base::Unretained(MTPDeviceMapService::GetInstance()),
|
| - fsid));
|
| + fs_name));
|
| + }
|
| +
|
| + virtual base::FilePath GetRegisteredPath(
|
| + const std::string& fs_name) const OVERRIDE {
|
| + base::FilePath result;
|
| + if (!ExternalMountPoints::GetSystemInstance()->GetRegisteredPath(fs_name,
|
| + &result)) {
|
| + return base::FilePath();
|
| + }
|
| + return result;
|
| }
|
|
|
| private:
|
| // Registers and returns the file system id for the mass storage device
|
| // specified by |device_id| and |path|.
|
| - std::string RegisterFileSystemForMassStorage(
|
| - const std::string& device_id, const base::FilePath& path) {
|
| + bool RegisterFileSystemForMassStorage(const std::string& device_id,
|
| + const std::string& fs_name,
|
| + const base::FilePath& path) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| DCHECK(StorageInfo::IsMassStorageDevice(device_id));
|
|
|
| @@ -584,57 +609,53 @@ class MediaFileSystemRegistry::MediaFileSystemContextImpl
|
| // call tree, probably by having it figure out by device id what
|
| // registration is needed, or having per-device-type handlers at the
|
| // next higher level.
|
| - std::string fsid;
|
| + bool result = false;
|
| if (StorageInfo::IsITunesDevice(device_id)) {
|
| - ImportedMediaGalleryRegistry* imported_registry =
|
| + ImportedMediaGalleryRegistry* registry =
|
| ImportedMediaGalleryRegistry::GetInstance();
|
| - fsid = imported_registry->RegisterITunesFilesystemOnUIThread(path);
|
| + result = registry->RegisterITunesFilesystemOnUIThread(fs_name, path);
|
| } else if (StorageInfo::IsPicasaDevice(device_id)) {
|
| - ImportedMediaGalleryRegistry* imported_registry =
|
| + ImportedMediaGalleryRegistry* registry =
|
| ImportedMediaGalleryRegistry::GetInstance();
|
| - fsid = imported_registry->RegisterPicasaFilesystemOnUIThread(
|
| - path);
|
| + result = registry->RegisterPicasaFilesystemOnUIThread(fs_name, path);
|
| } else if (StorageInfo::IsIPhotoDevice(device_id)) {
|
| - ImportedMediaGalleryRegistry* imported_registry =
|
| + ImportedMediaGalleryRegistry* registry =
|
| ImportedMediaGalleryRegistry::GetInstance();
|
| - fsid = imported_registry->RegisterIPhotoFilesystemOnUIThread(
|
| - path);
|
| + result = registry->RegisterIPhotoFilesystemOnUIThread(fs_name, path);
|
| } else {
|
| - std::string fs_name(extension_misc::kMediaFileSystemPathPart);
|
| - fsid = IsolatedContext::GetInstance()->RegisterFileSystemForPath(
|
| - fileapi::kFileSystemTypeNativeMedia, path, &fs_name);
|
| + result = ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
|
| + fs_name, fileapi::kFileSystemTypeNativeMedia,
|
| + fileapi::FileSystemMountOption(), path);
|
| }
|
| - return fsid;
|
| + return result;
|
| }
|
|
|
| - std::string RegisterFileSystemForMTPDevice(
|
| - const std::string& device_id, const base::FilePath& path) {
|
| + bool RegisterFileSystemForMTPDevice(const std::string& device_id,
|
| + const std::string fs_name,
|
| + const base::FilePath& path) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| DCHECK(!StorageInfo::IsMassStorageDevice(device_id));
|
|
|
| // Sanity checks for |path|.
|
| CHECK(MediaStorageUtil::CanCreateFileSystem(device_id, path));
|
| - std::string fs_name(extension_misc::kMediaFileSystemPathPart);
|
| - const std::string fsid =
|
| - IsolatedContext::GetInstance()->RegisterFileSystemForPath(
|
| - fileapi::kFileSystemTypeDeviceMedia, path, &fs_name);
|
| - CHECK(!fsid.empty());
|
| + bool result = ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
|
| + fs_name, fileapi::kFileSystemTypeDeviceMedia,
|
| + fileapi::FileSystemMountOption(), path);
|
| + CHECK(result);
|
| content::BrowserThread::PostTask(
|
| content::BrowserThread::IO, FROM_HERE, base::Bind(
|
| &MTPDeviceMapService::RegisterMTPFileSystem,
|
| base::Unretained(MTPDeviceMapService::GetInstance()),
|
| - path.value(), fsid));
|
| - return fsid;
|
| + path.value(), fs_name));
|
| + return result;
|
| }
|
|
|
| - MediaFileSystemRegistry* registry_;
|
| -
|
| DISALLOW_COPY_AND_ASSIGN(MediaFileSystemContextImpl);
|
| };
|
|
|
| // Constructor in 'private' section because depends on private class definition.
|
| MediaFileSystemRegistry::MediaFileSystemRegistry()
|
| - : file_system_context_(new MediaFileSystemContextImpl(this)) {
|
| + : file_system_context_(new MediaFileSystemContextImpl) {
|
| StorageMonitor::GetInstance()->AddObserver(this);
|
| }
|
|
|
|
|