Commit c3d638b3 authored by kinuko@chromium.org's avatar kinuko@chromium.org

Split Media-related code from IsolatedMountPointProvider

- Add MediaFileSystemMountPointProvider
- Change CopyOrMoveFileValidatorUnittest not to rely on Media-FS types

BUG=175936
TEST=content_unittests:CopyOrMoveValidatorTest.*

Review URL: https://codereview.chromium.org/14352004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195432 0039d316-1c4b-4281-b951-d872f2087c98
parent c9cb8bff
......@@ -7,6 +7,7 @@
#include "base/callback.h"
#include "base/platform_file.h"
#include "webkit/storage/webkit_storage_export.h"
namespace base {
class FilePath;
......@@ -16,7 +17,7 @@ namespace fileapi {
class FileSystemURL;
class CopyOrMoveFileValidator {
class WEBKIT_STORAGE_EXPORT CopyOrMoveFileValidator {
public:
// Callback that is invoked when validation completes. A result of
// base::PLATFORM_FILE_OK means the file validated.
......
......@@ -17,10 +17,16 @@
#include "webkit/fileapi/file_system_util.h"
#include "webkit/fileapi/isolated_context.h"
#include "webkit/fileapi/mock_file_system_context.h"
#include "webkit/fileapi/test_mount_point_provider.h"
#include "webkit/quota/mock_special_storage_policy.h"
namespace fileapi {
namespace {
const FileSystemType kNoValidatorType = kFileSystemTypeTemporary;
const FileSystemType kWithValidatorType = kFileSystemTypeTest;
class CopyOrMoveFileValidatorTestHelper {
public:
CopyOrMoveFileValidatorTestHelper(
......@@ -39,25 +45,25 @@ class CopyOrMoveFileValidatorTestHelper {
void SetUp() {
ASSERT_TRUE(base_.CreateUniqueTempDir());
base::FilePath base_dir = base_.path();
file_system_context_ = CreateFileSystemContextForTesting(NULL, base_dir);
// Prepare the origin's root directory.
if (src_type_ == kFileSystemTypeNativeMedia) {
base::FilePath src_path = base_dir.Append(FILE_PATH_LITERAL("src_media"));
file_util::CreateDirectory(src_path);
src_fsid_ = IsolatedContext::GetInstance()->RegisterFileSystemForPath(
kFileSystemTypeNativeMedia, src_path, NULL);
} else {
FileSystemMountPointProvider* mount_point_provider =
file_system_context_->GetMountPointProvider(src_type_);
mount_point_provider->GetFileSystemRootPathOnFileThread(
SourceURL(std::string()), true /* create */);
}
DCHECK_EQ(kFileSystemTypeNativeMedia, dest_type_);
base::FilePath dest_path = base_dir.Append(FILE_PATH_LITERAL("dest_media"));
file_util::CreateDirectory(dest_path);
dest_fsid_ = IsolatedContext::GetInstance()->RegisterFileSystemForPath(
kFileSystemTypeNativeMedia, dest_path, NULL);
// Set up TestMountPointProvider to require CopyOrMoveFileValidator.
FileSystemMountPointProvider* test_mount_point_provider =
file_system_context_->GetMountPointProvider(kWithValidatorType);
static_cast<TestMountPointProvider*>(test_mount_point_provider)->
set_require_copy_or_move_validator(true);
// Sets up source.
FileSystemMountPointProvider* src_mount_point_provider =
file_system_context_->GetMountPointProvider(src_type_);
src_mount_point_provider->GetFileSystemRootPathOnFileThread(
SourceURL(std::string()), true /* create */);
ASSERT_EQ(base::PLATFORM_FILE_OK, CreateDirectory(SourceURL("")));
// Sets up dest.
DCHECK_EQ(kWithValidatorType, dest_type_);
ASSERT_EQ(base::PLATFORM_FILE_OK, CreateDirectory(DestURL("")));
copy_src_ = SourceURL("copy_src.jpg");
move_src_ = SourceURL("move_src.jpg");
......@@ -76,9 +82,9 @@ class CopyOrMoveFileValidatorTestHelper {
void SetMediaCopyOrMoveFileValidatorFactory(
scoped_ptr<CopyOrMoveFileValidatorFactory> factory) {
FileSystemMountPointProvider* mount_point_provider =
file_system_context_->GetMountPointProvider(kFileSystemTypeNativeMedia);
file_system_context_->GetMountPointProvider(kWithValidatorType);
mount_point_provider->InitializeCopyOrMoveFileValidatorFactory(
kFileSystemTypeNativeMedia, factory.Pass());
kWithValidatorType, factory.Pass());
}
void CopyTest(base::PlatformFileError expected) {
......@@ -115,19 +121,15 @@ class CopyOrMoveFileValidatorTestHelper {
private:
FileSystemURL SourceURL(const std::string& path) {
if (src_type_ == kFileSystemTypeNativeMedia) {
std::string root_fs_url = GetIsolatedFileSystemRootURIString(
origin_, src_fsid_, "src_media/");
return file_system_context_->CrackURL(GURL(root_fs_url + path));
}
return file_system_context_->CreateCrackedFileSystemURL(
origin_, src_type_, base::FilePath::FromUTF8Unsafe(path));
origin_, src_type_,
base::FilePath().AppendASCII("src").AppendASCII(path));
}
FileSystemURL DestURL(const std::string& path) {
std::string root_fs_url = GetIsolatedFileSystemRootURIString(
origin_, dest_fsid_, "dest_media/");
return file_system_context_->CrackURL(GURL(root_fs_url + path));
return file_system_context_->CreateCrackedFileSystemURL(
origin_, dest_type_,
base::FilePath().AppendASCII("dest").AppendASCII(path));
}
base::PlatformFileError CreateFile(const FileSystemURL& url, size_t size) {
......@@ -138,6 +140,10 @@ class CopyOrMoveFileValidatorTestHelper {
return AsyncFileTestHelper::TruncateFile(file_system_context_, url, size);
}
base::PlatformFileError CreateDirectory(const FileSystemURL& url) {
return AsyncFileTestHelper::CreateDirectory(file_system_context_, url);
}
bool FileExists(const FileSystemURL& url, int64 expected_size) {
return AsyncFileTestHelper::FileExists(
file_system_context_, url, expected_size);
......@@ -202,23 +208,25 @@ class TestCopyOrMoveFileValidatorFactory
DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidatorFactory);
};
} // namespace
TEST(CopyOrMoveFileValidatorTest, NoValidatorWithin6ameFSType) {
// Within a file system type, validation is not expected, so it should
// work for kFileSystemTypeNativeMedia without a validator set.
// work for kWithValidatorType without a validator set.
CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"),
kFileSystemTypeNativeMedia,
kFileSystemTypeNativeMedia);
kWithValidatorType,
kWithValidatorType);
helper.SetUp();
helper.CopyTest(base::PLATFORM_FILE_OK);
helper.MoveTest(base::PLATFORM_FILE_OK);
}
TEST(CopyOrMoveFileValidatorTest, MissingValidator) {
// Copying or moving into a kFileSystemTypeNativeMedia requires a file
// Copying or moving into a kWithValidatorType requires a file
// validator. An error is expect if copy is attempted without a validator.
CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"),
kFileSystemTypeTemporary,
kFileSystemTypeNativeMedia);
kNoValidatorType,
kWithValidatorType);
helper.SetUp();
helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY);
helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY);
......@@ -226,8 +234,8 @@ TEST(CopyOrMoveFileValidatorTest, MissingValidator) {
TEST(CopyOrMoveFileValidatorTest, AcceptAll) {
CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"),
kFileSystemTypeTemporary,
kFileSystemTypeNativeMedia);
kNoValidatorType,
kWithValidatorType);
helper.SetUp();
scoped_ptr<CopyOrMoveFileValidatorFactory> factory(
new TestCopyOrMoveFileValidatorFactory(true /*accept_all*/));
......@@ -239,8 +247,8 @@ TEST(CopyOrMoveFileValidatorTest, AcceptAll) {
TEST(CopyOrMoveFileValidatorTest, AcceptNone) {
CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"),
kFileSystemTypeTemporary,
kFileSystemTypeNativeMedia);
kNoValidatorType,
kWithValidatorType);
helper.SetUp();
scoped_ptr<CopyOrMoveFileValidatorFactory> factory(
new TestCopyOrMoveFileValidatorFactory(false /*accept_all*/));
......@@ -253,8 +261,8 @@ TEST(CopyOrMoveFileValidatorTest, AcceptNone) {
TEST(CopyOrMoveFileValidatorTest, OverrideValidator) {
// Once set, you can not override the validator.
CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"),
kFileSystemTypeTemporary,
kFileSystemTypeNativeMedia);
kNoValidatorType,
kWithValidatorType);
helper.SetUp();
scoped_ptr<CopyOrMoveFileValidatorFactory> reject_factory(
new TestCopyOrMoveFileValidatorFactory(false /*accept_all*/));
......
......@@ -5,8 +5,8 @@
#include "webkit/fileapi/file_system_context.h"
#include "base/bind.h"
#include "base/stl_util.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "googleurl/src/gurl.h"
#include "webkit/blob/file_stream_reader.h"
#include "webkit/fileapi/copy_or_move_file_validator.h"
......@@ -21,6 +21,7 @@
#include "webkit/fileapi/file_system_util.h"
#include "webkit/fileapi/isolated_context.h"
#include "webkit/fileapi/isolated_mount_point_provider.h"
#include "webkit/fileapi/media/media_file_system_mount_point_provider.h"
#include "webkit/fileapi/mount_points.h"
#include "webkit/fileapi/sandbox_mount_point_provider.h"
#include "webkit/fileapi/syncable/local_file_change_tracker.h"
......@@ -72,7 +73,8 @@ FileSystemContext::FileSystemContext(
task_runners_->file_task_runner(),
partition_path,
options)),
isolated_provider_(new IsolatedMountPointProvider(partition_path)),
isolated_provider_(new IsolatedMountPointProvider()),
media_provider_(new MediaFileSystemMountPointProvider(partition_path)),
additional_providers_(additional_providers.Pass()),
external_mount_points_(external_mount_points),
partition_path_(partition_path) {
......@@ -85,6 +87,7 @@ FileSystemContext::FileSystemContext(
RegisterMountPointProvider(sandbox_provider_.get());
RegisterMountPointProvider(isolated_provider_.get());
RegisterMountPointProvider(media_provider_.get());
#if defined(OS_CHROMEOS)
// TODO(kinuko): Move this out of webkit/fileapi layer.
......
......@@ -55,6 +55,7 @@ class FileSystemTaskRunners;
class FileSystemURL;
class IsolatedMountPointProvider;
class MountPoints;
class MediaFileSystemMountPointProvider;
class SandboxMountPointProvider;
struct DefaultContextDeleter;
......@@ -278,6 +279,10 @@ class WEBKIT_STORAGE_EXPORT FileSystemContext
scoped_ptr<IsolatedMountPointProvider> isolated_provider_;
scoped_ptr<ExternalFileSystemMountPointProvider> external_provider_;
// TODO(kinuko,vandebo): Move this out of webkit/fileapi layer and
// give this provider as additional_providers.
scoped_ptr<MediaFileSystemMountPointProvider> media_provider_;
// Additional mount point providers.
ScopedVector<FileSystemMountPointProvider> additional_providers_;
......
......@@ -34,6 +34,10 @@ class RemoteFileSystemProxyInterface;
// An interface to provide mount-point-specific path-related utilities
// and specialized FileSystemFileUtil instance.
//
// NOTE: when you implement a new MountPointProvider for your own
// FileSystem module, please contact to kinuko@chromium.org.
//
class WEBKIT_STORAGE_EXPORT FileSystemMountPointProvider {
public:
// Callback for ValidateFileSystemRoot.
......
......@@ -26,35 +26,13 @@
#include "webkit/fileapi/isolated_file_util.h"
#include "webkit/fileapi/local_file_stream_writer.h"
#include "webkit/fileapi/local_file_system_operation.h"
#include "webkit/fileapi/media/media_path_filter.h"
#include "webkit/fileapi/media/native_media_file_util.h"
#include "webkit/fileapi/native_file_util.h"
#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
#include "webkit/fileapi/media/device_media_async_file_util.h"
#endif
namespace fileapi {
const char IsolatedMountPointProvider::kMediaPathFilterKey[] =
"MediaPathFilterKey";
const char IsolatedMountPointProvider::kMTPDeviceDelegateURLKey[] =
"MTPDeviceDelegateKey";
IsolatedMountPointProvider::IsolatedMountPointProvider(
const base::FilePath& profile_path)
: profile_path_(profile_path),
media_path_filter_(new MediaPathFilter()),
isolated_file_util_(new AsyncFileUtilAdapter(new IsolatedFileUtil())),
dragged_file_util_(new AsyncFileUtilAdapter(new DraggedFileUtil())),
native_media_file_util_(
new AsyncFileUtilAdapter(new NativeMediaFileUtil())) {
#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
// TODO(kmadhusu): Initialize |device_media_file_util_| in
// initialization list.
device_media_async_file_util_.reset(
DeviceMediaAsyncFileUtil::Create(profile_path_));
#endif
IsolatedMountPointProvider::IsolatedMountPointProvider()
: isolated_file_util_(new AsyncFileUtilAdapter(new IsolatedFileUtil())),
dragged_file_util_(new AsyncFileUtilAdapter(new DraggedFileUtil())) {
}
IsolatedMountPointProvider::~IsolatedMountPointProvider() {
......@@ -64,8 +42,6 @@ bool IsolatedMountPointProvider::CanHandleType(FileSystemType type) const {
switch (type) {
case kFileSystemTypeIsolated:
case kFileSystemTypeDragged:
case kFileSystemTypeNativeMedia:
case kFileSystemTypeDeviceMedia:
return true;
#if !defined(OS_CHROMEOS)
case kFileSystemTypeNativeLocal:
......@@ -103,8 +79,6 @@ FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil(
return isolated_file_util_->sync_file_util();
case kFileSystemTypeDragged:
return dragged_file_util_->sync_file_util();
case kFileSystemTypeNativeMedia:
return native_media_file_util_->sync_file_util();
default:
NOTREACHED();
}
......@@ -118,12 +92,6 @@ AsyncFileUtil* IsolatedMountPointProvider::GetAsyncFileUtil(
return isolated_file_util_.get();
case kFileSystemTypeDragged:
return dragged_file_util_.get();
case kFileSystemTypeNativeMedia:
return native_media_file_util_.get();
case kFileSystemTypeDeviceMedia:
#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
return device_media_async_file_util_.get();
#endif
default:
NOTREACHED();
}
......@@ -135,39 +103,13 @@ IsolatedMountPointProvider::GetCopyOrMoveFileValidatorFactory(
FileSystemType type, base::PlatformFileError* error_code) {
DCHECK(error_code);
*error_code = base::PLATFORM_FILE_OK;
switch (type) {
case kFileSystemTypeNativeLocal:
case kFileSystemTypeDragged:
return NULL;
case kFileSystemTypeNativeMedia:
case kFileSystemTypeDeviceMedia:
if (!media_copy_or_move_file_validator_factory_) {
*error_code = base::PLATFORM_FILE_ERROR_SECURITY;
return NULL;
}
return media_copy_or_move_file_validator_factory_.get();
default:
NOTREACHED();
}
return NULL;
}
void IsolatedMountPointProvider::InitializeCopyOrMoveFileValidatorFactory(
FileSystemType type,
scoped_ptr<CopyOrMoveFileValidatorFactory> factory) {
switch (type) {
case kFileSystemTypeNativeLocal:
case kFileSystemTypeDragged:
DCHECK(factory == NULL);
break;
case kFileSystemTypeNativeMedia:
case kFileSystemTypeDeviceMedia:
if (!media_copy_or_move_file_validator_factory_)
media_copy_or_move_file_validator_factory_.reset(factory.release());
break;
default:
NOTREACHED();
}
DCHECK(!factory);
}
FilePermissionPolicy IsolatedMountPointProvider::GetPermissionPolicy(
......@@ -186,28 +128,8 @@ FileSystemOperation* IsolatedMountPointProvider::CreateFileSystemOperation(
const FileSystemURL& url,
FileSystemContext* context,
base::PlatformFileError* error_code) const {
if (url.type() != kFileSystemTypeNativeMedia &&
url.type() != kFileSystemTypeDeviceMedia) {
return new LocalFileSystemOperation(
context, make_scoped_ptr(new FileSystemOperationContext(context)));
}
// For media filesystems.
scoped_ptr<FileSystemOperationContext> operation_context(
new FileSystemOperationContext(
context, context->task_runners()->media_task_runner()));
operation_context->SetUserValue(kMediaPathFilterKey,
media_path_filter_.get());
#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
if (url.type() == kFileSystemTypeDeviceMedia) {
operation_context->SetUserValue(kMTPDeviceDelegateURLKey,
url.filesystem_id());
}
#endif
return new LocalFileSystemOperation(context, operation_context.Pass());
return new LocalFileSystemOperation(
context, make_scoped_ptr(new FileSystemOperationContext(context)));
}
scoped_ptr<webkit_blob::FileStreamReader>
......
......@@ -7,24 +7,14 @@
#include "base/memory/scoped_ptr.h"
#include "webkit/fileapi/file_system_mount_point_provider.h"
#include "webkit/fileapi/media/mtp_device_file_system_config.h"
namespace fileapi {
class AsyncFileUtilAdapter;
class IsolatedContext;
class MediaPathFilter;
#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
class DeviceMediaAsyncFileUtil;
#endif
class IsolatedMountPointProvider : public FileSystemMountPointProvider {
public:
static const char kMediaPathFilterKey[];
static const char kMTPDeviceDelegateURLKey[];
explicit IsolatedMountPointProvider(const base::FilePath& profile_path);
IsolatedMountPointProvider();
virtual ~IsolatedMountPointProvider();
// FileSystemMountPointProvider implementation.
......@@ -69,20 +59,8 @@ class IsolatedMountPointProvider : public FileSystemMountPointProvider {
const DeleteFileSystemCallback& callback) OVERRIDE;
private:
// Store the profile path. We need this to create temporary snapshot files.
const base::FilePath profile_path_;
scoped_ptr<MediaPathFilter> media_path_filter_;
scoped_ptr<CopyOrMoveFileValidatorFactory>
media_copy_or_move_file_validator_factory_;
scoped_ptr<AsyncFileUtilAdapter> isolated_file_util_;
scoped_ptr<AsyncFileUtilAdapter> dragged_file_util_;
scoped_ptr<AsyncFileUtilAdapter> native_media_file_util_;
#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
scoped_ptr<DeviceMediaAsyncFileUtil> device_media_async_file_util_;
#endif
};
} // namespace fileapi
......
......@@ -12,8 +12,8 @@
#include "webkit/fileapi/file_system_task_runners.h"
#include "webkit/fileapi/file_system_url.h"
#include "webkit/fileapi/isolated_context.h"
#include "webkit/fileapi/isolated_mount_point_provider.h"
#include "webkit/fileapi/media/filtering_file_enumerator.h"
#include "webkit/fileapi/media/media_file_system_mount_point_provider.h"
#include "webkit/fileapi/media/media_path_filter.h"
#include "webkit/fileapi/media/mtp_device_async_delegate.h"
#include "webkit/fileapi/media/mtp_device_map_service.h"
......@@ -37,7 +37,7 @@ MTPDeviceAsyncDelegate* GetMTPDeviceDelegate(
DCHECK(IsOnIOThread(context));
return MTPDeviceMapService::GetInstance()->GetMTPDeviceAsyncDelegate(
context->GetUserValue<std::string>(
IsolatedMountPointProvider::kMTPDeviceDelegateURLKey));
MediaFileSystemMountPointProvider::kMTPDeviceDelegateURLKey));
}
// Called on a blocking pool thread to create a snapshot file to hold the
......
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webkit/fileapi/media/media_file_system_mount_point_provider.h"
#include <string>
#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/message_loop_proxy.h"
#include "base/platform_file.h"
#include "base/sequenced_task_runner.h"
#include "webkit/blob/local_file_stream_reader.h"
#include "webkit/fileapi/async_file_util_adapter.h"
#include "webkit/fileapi/copy_or_move_file_validator.h"
#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_file_stream_reader.h"
#include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/file_system_task_runners.h"
#include "webkit/fileapi/file_system_types.h"
#include "webkit/fileapi/file_system_util.h"
#include "webkit/fileapi/isolated_context.h"
#include "webkit/fileapi/isolated_file_util.h"
#include "webkit/fileapi/local_file_stream_writer.h"
#include "webkit/fileapi/local_file_system_operation.h"
#include "webkit/fileapi/media/media_path_filter.h"
#include "webkit/fileapi/media/native_media_file_util.h"
#include "webkit/fileapi/native_file_util.h"
#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
#include "webkit/fileapi/media/device_media_async_file_util.h"
#endif
namespace fileapi {
const char MediaFileSystemMountPointProvider::kMediaPathFilterKey[] =
"MediaPathFilterKey";
const char MediaFileSystemMountPointProvider::kMTPDeviceDelegateURLKey[] =
"MTPDeviceDelegateKey";
MediaFileSystemMountPointProvider::MediaFileSystemMountPointProvider(
const base::FilePath& profile_path)
: profile_path_(profile_path),
media_path_filter_(new MediaPathFilter()),
native_media_file_util_(
new AsyncFileUtilAdapter(new NativeMediaFileUtil())) {
#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
// TODO(kmadhusu): Initialize |device_media_file_util_| in
// initialization list.
device_media_async_file_util_.reset(
DeviceMediaAsyncFileUtil::Create(profile_path_));
#endif
}
MediaFileSystemMountPointProvider::~MediaFileSystemMountPointProvider() {
}
bool MediaFileSystemMountPointProvider::CanHandleType(
FileSystemType type) const {
switch (type) {
case kFileSystemTypeNativeMedia:
case kFileSystemTypeDeviceMedia:
return true;
default:
return false;
}
}
void MediaFileSystemMountPointProvider::ValidateFileSystemRoot(
const GURL& origin_url,
FileSystemType type,
bool create,
const ValidateFileSystemCallback& callback) {
// We never allow opening a new isolated FileSystem via usual OpenFileSystem.
base::MessageLoopProxy::current()->PostTask(
FROM_HERE,
base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY));
}
base::FilePath
MediaFileSystemMountPointProvider::GetFileSystemRootPathOnFileThread(
const FileSystemURL& url,
bool create) {
// This is not supposed to be used.
NOTREACHED();
return base::FilePath();
}
FileSystemFileUtil* MediaFileSystemMountPointProvider::GetFileUtil(
FileSystemType type) {
switch (type) {
case kFileSystemTypeNativeMedia:
return native_media_file_util_->sync_file_util();
default:
NOTREACHED();
}
return NULL;
}
AsyncFileUtil* MediaFileSystemMountPointProvider::GetAsyncFileUtil(
FileSystemType type) {
switch (type) {
case kFileSystemTypeNativeMedia:
return native_media_file_util_.get();
case kFileSystemTypeDeviceMedia:
#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
return device_media_async_file_util_.get();
#endif
default:
NOTREACHED();
}
return NULL;
}
CopyOrMoveFileValidatorFactory*
MediaFileSystemMountPointProvider::GetCopyOrMoveFileValidatorFactory(
FileSystemType type, base::PlatformFileError* error_code) {
DCHECK(error_code);
*error_code = base::PLATFORM_FILE_OK;
switch (type) {
case kFileSystemTypeNativeMedia:
case kFileSystemTypeDeviceMedia:
if (!media_copy_or_move_file_validator_factory_) {
*error_code = base::PLATFORM_FILE_ERROR_SECURITY;
return NULL;
}
return media_copy_or_move_file_validator_factory_.get();
default:
NOTREACHED();
}
return NULL;
}
void
MediaFileSystemMountPointProvider::InitializeCopyOrMoveFileValidatorFactory(
FileSystemType type,
scoped_ptr<CopyOrMoveFileValidatorFactory> factory) {
switch (type) {
case kFileSystemTypeNativeMedia:
case kFileSystemTypeDeviceMedia:
if (!media_copy_or_move_file_validator_factory_)
media_copy_or_move_file_validator_factory_.reset(factory.release());
break;
default:
NOTREACHED();
}
}
FilePermissionPolicy MediaFileSystemMountPointProvider::GetPermissionPolicy(
const FileSystemURL& url, int permissions) const {
// Access to media file systems should be checked using per-filesystem
// access permission.
return FILE_PERMISSION_USE_FILESYSTEM_PERMISSION;
}
FileSystemOperation*
MediaFileSystemMountPointProvider::CreateFileSystemOperation(
const FileSystemURL& url,
FileSystemContext* context,
base::PlatformFileError* error_code) const {
scoped_ptr<FileSystemOperationContext> operation_context(
new FileSystemOperationContext(
context, context->task_runners()->media_task_runner()));
operation_context->SetUserValue(kMediaPathFilterKey,
media_path_filter_.get());
#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
if (url.type() == kFileSystemTypeDeviceMedia) {
operation_context->SetUserValue(kMTPDeviceDelegateURLKey,
url.filesystem_id());
}
#endif
return new LocalFileSystemOperation(context, operation_context.Pass());
}
scoped_ptr<webkit_blob::FileStreamReader>
MediaFileSystemMountPointProvider::CreateFileStreamReader(
const FileSystemURL& url,
int64 offset,
const base::Time& expected_modification_time,
FileSystemContext* context) const {
return scoped_ptr<webkit_blob::FileStreamReader>(
new webkit_blob::LocalFileStreamReader(
context->task_runners()->file_task_runner(),
url.path(), offset, expected_modification_time));
}
scoped_ptr<FileStreamWriter>
MediaFileSystemMountPointProvider::CreateFileStreamWriter(
const FileSystemURL& url,
int64 offset,
FileSystemContext* context) const {
return scoped_ptr<FileStreamWriter>(
new LocalFileStreamWriter(url.path(), offset));
}
FileSystemQuotaUtil* MediaFileSystemMountPointProvider::GetQuotaUtil() {
// No quota support.
return NULL;
}
void MediaFileSystemMountPointProvider::DeleteFileSystem(
const GURL& origin_url,
FileSystemType type,
FileSystemContext* context,
const DeleteFileSystemCallback& callback) {
NOTREACHED();
callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION);
}
} // namespace fileapi
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WEBKIT_FILEAPI_MEDIA_MEDIA_FILE_SYSTEM_MOUNT_POINT_PROVIDER_H_
#define WEBKIT_FILEAPI_MEDIA_MEDIA_FILE_SYSTEM_MOUNT_POINT_PROVIDER_H_
#include "base/memory/scoped_ptr.h"
#include "webkit/fileapi/file_system_mount_point_provider.h"
#include "webkit/fileapi/media/mtp_device_file_system_config.h"
namespace fileapi {
class AsyncFileUtilAdapter;
class MediaPathFilter;
#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
class DeviceMediaAsyncFileUtil;
#endif
class MediaFileSystemMountPointProvider : public FileSystemMountPointProvider {
public:
static const char kMediaPathFilterKey[];
static const char kMTPDeviceDelegateURLKey[];
explicit MediaFileSystemMountPointProvider(
const base::FilePath& profile_path);
virtual ~MediaFileSystemMountPointProvider();
// FileSystemMountPointProvider implementation.
virtual bool CanHandleType(FileSystemType type) const OVERRIDE;
virtual void ValidateFileSystemRoot(
const GURL& origin_url,
FileSystemType type,
bool create,
const ValidateFileSystemCallback& callback) OVERRIDE;
virtual base::FilePath GetFileSystemRootPathOnFileThread(
const FileSystemURL& url,
bool create) OVERRIDE;
virtual FileSystemFileUtil* GetFileUtil(FileSystemType type) OVERRIDE;
virtual AsyncFileUtil* GetAsyncFileUtil(FileSystemType type) OVERRIDE;
virtual CopyOrMoveFileValidatorFactory* GetCopyOrMoveFileValidatorFactory(
FileSystemType type,
base::PlatformFileError* error_code) OVERRIDE;
virtual void InitializeCopyOrMoveFileValidatorFactory(
FileSystemType type,
scoped_ptr<CopyOrMoveFileValidatorFactory> factory) OVERRIDE;
virtual FilePermissionPolicy GetPermissionPolicy(
const FileSystemURL& url,
int permissions) const OVERRIDE;
virtual FileSystemOperation* CreateFileSystemOperation(
const FileSystemURL& url,
FileSystemContext* context,
base::PlatformFileError* error_code) const OVERRIDE;
virtual scoped_ptr<webkit_blob::FileStreamReader> CreateFileStreamReader(
const FileSystemURL& url,
int64 offset,
const base::Time& expected_modification_time,
FileSystemContext* context) const OVERRIDE;
virtual scoped_ptr<FileStreamWriter> CreateFileStreamWriter(
const FileSystemURL& url,
int64 offset,
FileSystemContext* context) const OVERRIDE;
virtual FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE;
virtual void DeleteFileSystem(
const GURL& origin_url,
FileSystemType type,
FileSystemContext* context,
const DeleteFileSystemCallback& callback) OVERRIDE;
private:
// Store the profile path. We need this to create temporary snapshot files.
const base::FilePath profile_path_;
scoped_ptr<MediaPathFilter> media_path_filter_;
scoped_ptr<CopyOrMoveFileValidatorFactory>
media_copy_or_move_file_validator_factory_;
scoped_ptr<AsyncFileUtilAdapter> native_media_file_util_;
#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
scoped_ptr<DeviceMediaAsyncFileUtil> device_media_async_file_util_;
#endif
DISALLOW_COPY_AND_ASSIGN(MediaFileSystemMountPointProvider);
};
} // namespace fileapi
#endif // WEBKIT_FILEAPI_MEDIA_MEDIA_FILE_SYSTEM_MOUNT_POINT_PROVIDER_H_
......@@ -5,8 +5,8 @@
#include "webkit/fileapi/media/native_media_file_util.h"
#include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/isolated_mount_point_provider.h"
#include "webkit/fileapi/media/filtering_file_enumerator.h"
#include "webkit/fileapi/media/media_file_system_mount_point_provider.h"
#include "webkit/fileapi/media/media_path_filter.h"
#include "webkit/fileapi/native_file_util.h"
......@@ -20,7 +20,7 @@ namespace {
MediaPathFilter* GetMediaPathFilter(FileSystemOperationContext* context) {
return context->GetUserValue<MediaPathFilter*>(
IsolatedMountPointProvider::kMediaPathFilterKey);
MediaFileSystemMountPointProvider::kMediaPathFilterKey);
}
} // namespace
......
......@@ -72,7 +72,8 @@ TestMountPointProvider::TestMountPointProvider(
: base_path_(base_path),
task_runner_(task_runner),
local_file_util_(new AsyncFileUtilAdapter(new LocalFileUtil())),
quota_util_(new QuotaUtil) {
quota_util_(new QuotaUtil),
require_copy_or_move_validator_(false) {
UpdateObserverList::Source source;
source.AddObserver(quota_util_.get(), task_runner_);
observers_ = UpdateObserverList(source);
......@@ -121,12 +122,22 @@ TestMountPointProvider::GetCopyOrMoveFileValidatorFactory(
FileSystemType type, base::PlatformFileError* error_code) {
DCHECK(error_code);
*error_code = base::PLATFORM_FILE_OK;
if (require_copy_or_move_validator_) {
if (!copy_or_move_file_validator_factory_)
*error_code = base::PLATFORM_FILE_ERROR_SECURITY;
return copy_or_move_file_validator_factory_.get();
}
return NULL;
}
void TestMountPointProvider::InitializeCopyOrMoveFileValidatorFactory(
FileSystemType type, scoped_ptr<CopyOrMoveFileValidatorFactory> factory) {
DCHECK(!factory);
if (!require_copy_or_move_validator_) {
DCHECK(!factory);
return;
}
if (!copy_or_move_file_validator_factory_)
copy_or_move_file_validator_factory_ = factory.Pass();
}
FilePermissionPolicy TestMountPointProvider::GetPermissionPolicy(
......
......@@ -76,6 +76,13 @@ class WEBKIT_STORAGE_EXPORT_PRIVATE TestMountPointProvider
const UpdateObserverList* GetUpdateObservers(FileSystemType type) const;
// For CopyOrMoveFileValidatorFactory testing. Once it's set to true
// GetCopyOrMoveFileValidatorFactory will start returning security
// error if validator is not initialized.
void set_require_copy_or_move_validator(bool flag) {
require_copy_or_move_validator_ = flag;
}
private:
class QuotaUtil;
......@@ -84,6 +91,12 @@ class WEBKIT_STORAGE_EXPORT_PRIVATE TestMountPointProvider
scoped_ptr<AsyncFileUtilAdapter> local_file_util_;
scoped_ptr<QuotaUtil> quota_util_;
UpdateObserverList observers_;
bool require_copy_or_move_validator_;
scoped_ptr<CopyOrMoveFileValidatorFactory>
copy_or_move_file_validator_factory_;
DISALLOW_COPY_AND_ASSIGN(TestMountPointProvider);
};
} // namespace fileapi
......
......@@ -69,6 +69,8 @@
'../fileapi/local_file_util.h',
'../fileapi/media/filtering_file_enumerator.cc',
'../fileapi/media/filtering_file_enumerator.h',
'../fileapi/media/media_file_system_mount_point_provider.cc',
'../fileapi/media/media_file_system_mount_point_provider.h',
'../fileapi/media/media_path_filter.cc',
'../fileapi/media/media_path_filter.h',
'../fileapi/media/mtp_device_file_system_config.h',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment