Commit 84780b40 authored by kinuko@chromium.org's avatar kinuko@chromium.org

FileAPI code should not rely on or assume specific MountPointProvider types

To move some non-regular MountPointProviders out of webkit/fileapi,
we should not:
- Require FileAPI code change for a new MountPointProvider to
  get/set provider-specific operation context value (e.g.  MediaPathFilter)
- Require a new MountPointProvider type to be listed as a 'frined' of
  FileAPI code

To avoid having these dependencies, this change:
- Makes FileSystemOperationContext inherit from SupportsUserData so that
  MountPointProviders can get/set arbitrary user values with string keys.
- Makes some private methods public (with proper comments) and remove
  the friend list of MountPointProviders

This patch is a part of following change plan (internal only doc):
https://docs.google.com/a/google.com/document/d/1XEtX0OO_RIA_c0KuKvd9yqK5l3XtsTulwXs3c-mAQ1o/view

BUG=175936
TEST=content_unittests:*File*
TEST=browser_tests:*MediaGalleries*

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195193 0039d316-1c4b-4281-b951-d872f2087c98
parent a5d181f5
...@@ -16,11 +16,13 @@ FileSystemOperationContext::FileSystemOperationContext( ...@@ -16,11 +16,13 @@ FileSystemOperationContext::FileSystemOperationContext(
task_runner_(file_system_context_->task_runners()->file_task_runner()), task_runner_(file_system_context_->task_runners()->file_task_runner()),
allowed_bytes_growth_(0) {} allowed_bytes_growth_(0) {}
FileSystemOperationContext::~FileSystemOperationContext() {} FileSystemOperationContext::FileSystemOperationContext(
FileSystemContext* context,
base::SequencedTaskRunner* task_runner)
: file_system_context_(context),
task_runner_(task_runner),
allowed_bytes_growth_(0) {}
void FileSystemOperationContext::set_task_runner( FileSystemOperationContext::~FileSystemOperationContext() {}
base::SequencedTaskRunner* task_runner) {
task_runner_ = task_runner;
}
} // namespace fileapi } // namespace fileapi
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CONTEXT_H_ #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CONTEXT_H_
#define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CONTEXT_H_ #define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CONTEXT_H_
#include "webkit/fileapi/media/mtp_device_file_system_config.h" #include "base/supports_user_data.h"
#include "webkit/fileapi/task_runner_bound_observer_list.h" #include "webkit/fileapi/task_runner_bound_observer_list.h"
#include "webkit/storage/webkit_storage_export.h" #include "webkit/storage/webkit_storage_export.h"
...@@ -16,7 +16,6 @@ class SequencedTaskRunner; ...@@ -16,7 +16,6 @@ class SequencedTaskRunner;
namespace fileapi { namespace fileapi {
class FileSystemContext; class FileSystemContext;
class MediaPathFilter;
// A context class which is carried around by FileSystemOperation and // A context class which is carried around by FileSystemOperation and
// its delegated tasks. It is valid to reuse one context instance across // its delegated tasks. It is valid to reuse one context instance across
...@@ -24,10 +23,16 @@ class MediaPathFilter; ...@@ -24,10 +23,16 @@ class MediaPathFilter;
// the same context (e.g. use the same task runner, share the quota etc). // the same context (e.g. use the same task runner, share the quota etc).
// Note that the remaining quota bytes (allowed_bytes_growth) may be // Note that the remaining quota bytes (allowed_bytes_growth) may be
// updated during the execution of write operations. // updated during the execution of write operations.
class WEBKIT_STORAGE_EXPORT_PRIVATE FileSystemOperationContext { class WEBKIT_STORAGE_EXPORT_PRIVATE FileSystemOperationContext
: public base::SupportsUserData {
public: public:
explicit FileSystemOperationContext(FileSystemContext* context); explicit FileSystemOperationContext(FileSystemContext* context);
~FileSystemOperationContext();
// Specifies |task_runner| which the operation is performed on.
FileSystemOperationContext(FileSystemContext* context,
base::SequencedTaskRunner* task_runner);
virtual ~FileSystemOperationContext();
FileSystemContext* file_system_context() const { FileSystemContext* file_system_context() const {
return file_system_context_; return file_system_context_;
...@@ -41,26 +46,37 @@ class WEBKIT_STORAGE_EXPORT_PRIVATE FileSystemOperationContext { ...@@ -41,26 +46,37 @@ class WEBKIT_STORAGE_EXPORT_PRIVATE FileSystemOperationContext {
// Returns the current remaining quota. // Returns the current remaining quota.
int64 allowed_bytes_growth() const { return allowed_bytes_growth_; } int64 allowed_bytes_growth() const { return allowed_bytes_growth_; }
#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
// Reads |mtp_device_delegate_url_| on |task_runner_|.
const std::string& mtp_device_delegate_url() const {
return mtp_device_delegate_url_;
}
#endif
// Returns TaskRunner which the operation is performed on. // Returns TaskRunner which the operation is performed on.
base::SequencedTaskRunner* task_runner() const { base::SequencedTaskRunner* task_runner() const {
return task_runner_.get(); return task_runner_.get();
} }
MediaPathFilter* media_path_filter() { return media_path_filter_; }
ChangeObserverList* change_observers() { return &change_observers_; } ChangeObserverList* change_observers() { return &change_observers_; }
AccessObserverList* access_observers() { return &access_observers_; } AccessObserverList* access_observers() { return &access_observers_; }
UpdateObserverList* update_observers() { return &update_observers_; } UpdateObserverList* update_observers() { return &update_observers_; }
// Gets and sets value-type (or not-owned) variable as UserData.
template <typename T> T GetUserValue(const char* key) const {
ValueAdapter<T>* v = static_cast<ValueAdapter<T>*>(GetUserData(key));
return v ? v->value() : T();
}
template <typename T> void SetUserValue(const char* key, const T& value) {
SetUserData(key, new ValueAdapter<T>(value));
}
private: private:
// Only MountPointProviders can access these setters. // An adapter for setting a value-type (or not owned) data as UserData.
friend class CrosMountPointProvider; template <typename T> class ValueAdapter
: public base::SupportsUserData::Data {
public:
ValueAdapter(const T& value) : value_(value) {}
const T& value() const { return value_; }
private:
T value_;
DISALLOW_COPY_AND_ASSIGN(ValueAdapter);
};
// Only regular (and test) MountPointProviders can access following setters.
friend class IsolatedMountPointProvider; friend class IsolatedMountPointProvider;
friend class SandboxMountPointProvider; friend class SandboxMountPointProvider;
friend class TestMountPointProvider; friend class TestMountPointProvider;
...@@ -72,13 +88,6 @@ class WEBKIT_STORAGE_EXPORT_PRIVATE FileSystemOperationContext { ...@@ -72,13 +88,6 @@ class WEBKIT_STORAGE_EXPORT_PRIVATE FileSystemOperationContext {
friend class LocalFileSystemTestOriginHelper; friend class LocalFileSystemTestOriginHelper;
friend class ObfuscatedFileUtilTest; friend class ObfuscatedFileUtilTest;
// Overrides TaskRunner which the operation is performed on.
// file_system_context_->task_runners()->file_task_runner() is used otherwise.
void set_task_runner(base::SequencedTaskRunner* task_runner);
void set_media_path_filter(MediaPathFilter* media_path_filter) {
media_path_filter_ = media_path_filter;
}
void set_change_observers(const ChangeObserverList& list) { void set_change_observers(const ChangeObserverList& list) {
change_observers_ = list; change_observers_ = list;
} }
...@@ -88,29 +97,16 @@ class WEBKIT_STORAGE_EXPORT_PRIVATE FileSystemOperationContext { ...@@ -88,29 +97,16 @@ class WEBKIT_STORAGE_EXPORT_PRIVATE FileSystemOperationContext {
void set_update_observers(const UpdateObserverList& list) { void set_update_observers(const UpdateObserverList& list) {
update_observers_ = list; update_observers_ = list;
} }
#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
// Initializes |mtp_device_delegate_url_| on the IO thread.
void set_mtp_device_delegate_url(const std::string& delegate_url) {
mtp_device_delegate_url_ = delegate_url;
}
#endif
FileSystemContext* file_system_context_; FileSystemContext* file_system_context_;
scoped_refptr<base::SequencedTaskRunner> task_runner_; scoped_refptr<base::SequencedTaskRunner> task_runner_;
int64 allowed_bytes_growth_; int64 allowed_bytes_growth_;
MediaPathFilter* media_path_filter_;
AccessObserverList access_observers_; AccessObserverList access_observers_;
ChangeObserverList change_observers_; ChangeObserverList change_observers_;
UpdateObserverList update_observers_; UpdateObserverList update_observers_;
#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
// URL for the media transfer protocol (MTP) device delegate.
// Initialized on IO thread and used on |task_runner_|.
std::string mtp_device_delegate_url_;
#endif
DISALLOW_COPY_AND_ASSIGN(FileSystemOperationContext); DISALLOW_COPY_AND_ASSIGN(FileSystemOperationContext);
}; };
......
...@@ -36,6 +36,11 @@ ...@@ -36,6 +36,11 @@
namespace fileapi { namespace fileapi {
const char IsolatedMountPointProvider::kMediaPathFilterKey[] =
"MediaPathFilterKey";
const char IsolatedMountPointProvider::kMTPDeviceDelegateURLKey[] =
"MTPDeviceDelegateKey";
IsolatedMountPointProvider::IsolatedMountPointProvider( IsolatedMountPointProvider::IsolatedMountPointProvider(
const base::FilePath& profile_path) const base::FilePath& profile_path)
: profile_path_(profile_path), : profile_path_(profile_path),
...@@ -181,18 +186,25 @@ FileSystemOperation* IsolatedMountPointProvider::CreateFileSystemOperation( ...@@ -181,18 +186,25 @@ FileSystemOperation* IsolatedMountPointProvider::CreateFileSystemOperation(
const FileSystemURL& url, const FileSystemURL& url,
FileSystemContext* context, FileSystemContext* context,
base::PlatformFileError* error_code) const { base::PlatformFileError* error_code) const {
scoped_ptr<FileSystemOperationContext> operation_context( if (url.type() != kFileSystemTypeNativeMedia &&
new FileSystemOperationContext(context)); url.type() != kFileSystemTypeDeviceMedia) {
if (url.type() == kFileSystemTypeNativeMedia || return new LocalFileSystemOperation(
url.type() == kFileSystemTypeDeviceMedia) { context, make_scoped_ptr(new FileSystemOperationContext(context)));
operation_context->set_media_path_filter(media_path_filter_.get());
operation_context->set_task_runner(
context->task_runners()->media_task_runner());
} }
// 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 defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
if (url.type() == kFileSystemTypeDeviceMedia) if (url.type() == kFileSystemTypeDeviceMedia) {
operation_context->set_mtp_device_delegate_url(url.filesystem_id()); operation_context->SetUserValue(kMTPDeviceDelegateURLKey,
url.filesystem_id());
}
#endif #endif
return new LocalFileSystemOperation(context, operation_context.Pass()); return new LocalFileSystemOperation(context, operation_context.Pass());
......
...@@ -21,6 +21,9 @@ class DeviceMediaAsyncFileUtil; ...@@ -21,6 +21,9 @@ class DeviceMediaAsyncFileUtil;
class IsolatedMountPointProvider : public FileSystemMountPointProvider { class IsolatedMountPointProvider : public FileSystemMountPointProvider {
public: public:
static const char kMediaPathFilterKey[];
static const char kMTPDeviceDelegateURLKey[];
explicit IsolatedMountPointProvider(const base::FilePath& profile_path); explicit IsolatedMountPointProvider(const base::FilePath& profile_path);
virtual ~IsolatedMountPointProvider(); virtual ~IsolatedMountPointProvider();
......
...@@ -32,7 +32,23 @@ using webkit_blob::ShareableFileReference; ...@@ -32,7 +32,23 @@ using webkit_blob::ShareableFileReference;
namespace fileapi { namespace fileapi {
LocalFileSystemOperation::LocalFileSystemOperation(
FileSystemContext* file_system_context,
scoped_ptr<FileSystemOperationContext> operation_context)
: file_system_context_(file_system_context),
operation_context_(operation_context.Pass()),
async_file_util_(NULL),
peer_handle_(base::kNullProcessHandle),
pending_operation_(kOperationNone),
weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
DCHECK(operation_context_.get());
operation_context_->DetachUserDataThread();
}
LocalFileSystemOperation::~LocalFileSystemOperation() { LocalFileSystemOperation::~LocalFileSystemOperation() {
if (!operation_context())
return;
operation_context()->DetachUserDataThread();
if (write_target_url_.is_valid()) { if (write_target_url_.is_valid()) {
operation_context()->update_observers()->Notify( operation_context()->update_observers()->Notify(
&FileUpdateObserver::OnEndUpdate, MakeTuple(write_target_url_)); &FileUpdateObserver::OnEndUpdate, MakeTuple(write_target_url_));
...@@ -430,7 +446,7 @@ LocalFileSystemOperation* LocalFileSystemOperation::CreateNestedOperation() { ...@@ -430,7 +446,7 @@ LocalFileSystemOperation* LocalFileSystemOperation::CreateNestedOperation() {
LocalFileSystemOperation* operation = new LocalFileSystemOperation( LocalFileSystemOperation* operation = new LocalFileSystemOperation(
file_system_context(), file_system_context(),
make_scoped_ptr(new FileSystemOperationContext(file_system_context()))); make_scoped_ptr(new FileSystemOperationContext(file_system_context())));
operation->parent_operation_ = this; operation->parent_operation_ = weak_factory_.GetWeakPtr();
return operation; return operation;
} }
...@@ -535,19 +551,6 @@ void LocalFileSystemOperation::MoveFileLocal( ...@@ -535,19 +551,6 @@ void LocalFileSystemOperation::MoveFileLocal(
base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
} }
LocalFileSystemOperation::LocalFileSystemOperation(
FileSystemContext* file_system_context,
scoped_ptr<FileSystemOperationContext> operation_context)
: file_system_context_(file_system_context),
operation_context_(operation_context.Pass()),
async_file_util_(NULL),
parent_operation_(NULL),
peer_handle_(base::kNullProcessHandle),
pending_operation_(kOperationNone),
weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
DCHECK(operation_context_.get());
}
void LocalFileSystemOperation::GetUsageAndQuotaThenRunTask( void LocalFileSystemOperation::GetUsageAndQuotaThenRunTask(
const FileSystemURL& url, const FileSystemURL& url,
const base::Closure& task, const base::Closure& task,
......
...@@ -34,6 +34,14 @@ class RecursiveOperationDelegate; ...@@ -34,6 +34,14 @@ class RecursiveOperationDelegate;
class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation
: public NON_EXPORTED_BASE(FileSystemOperation) { : public NON_EXPORTED_BASE(FileSystemOperation) {
public: public:
// NOTE: This constructor should not be called outside MountPointProviders;
// instead please consider using
// file_system_context->CreateFileSystemOperation() to instantiate
// an appropriate FileSystemOperation.
LocalFileSystemOperation(
FileSystemContext* file_system_context,
scoped_ptr<FileSystemOperationContext> operation_context);
virtual ~LocalFileSystemOperation(); virtual ~LocalFileSystemOperation();
// FileSystemOperation overrides. // FileSystemOperation overrides.
...@@ -158,34 +166,6 @@ class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation ...@@ -158,34 +166,6 @@ class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation
void SyncGetPlatformPath(const FileSystemURL& url, void SyncGetPlatformPath(const FileSystemURL& url,
base::FilePath* platform_path); base::FilePath* platform_path);
private:
enum OperationMode {
OPERATION_MODE_READ,
OPERATION_MODE_WRITE,
};
// Only MountPointProviders or testing class can create a
// new operation directly.
friend class FileSystemTestHelper;
friend class IsolatedMountPointProvider;
friend class SandboxMountPointProvider;
friend class TestMountPointProvider;
friend class chromeos::CrosMountPointProvider;
friend class LocalFileSystemOperationTest;
friend class LocalFileSystemOperationWriteTest;
friend class FileWriterDelegateTest;
friend class FileSystemQuotaTest;
friend class LocalFileSystemTestOriginHelper;
friend class RecursiveOperationDelegate;
friend class CrossOperationDelegate;
friend class sync_file_system::SyncableFileSystemOperation;
LocalFileSystemOperation(
FileSystemContext* file_system_context,
scoped_ptr<FileSystemOperationContext> operation_context);
FileSystemContext* file_system_context() const { FileSystemContext* file_system_context() const {
return file_system_context_; return file_system_context_;
} }
...@@ -196,6 +176,14 @@ class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation ...@@ -196,6 +176,14 @@ class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation
return operation_context_.get(); return operation_context_.get();
} }
private:
enum OperationMode {
OPERATION_MODE_READ,
OPERATION_MODE_WRITE,
};
friend class sync_file_system::SyncableFileSystemOperation;
// Queries the quota and usage and then runs the given |task|. // Queries the quota and usage and then runs the given |task|.
// If an error occurs during the quota query it runs |error_callback| instead. // If an error occurs during the quota query it runs |error_callback| instead.
void GetUsageAndQuotaThenRunTask( void GetUsageAndQuotaThenRunTask(
...@@ -316,7 +304,7 @@ class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation ...@@ -316,7 +304,7 @@ class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation
// this holds non-null value and points to the parent operation. // this holds non-null value and points to the parent operation.
// TODO(kinuko): Cleanup this when we finish cleaning up the // TODO(kinuko): Cleanup this when we finish cleaning up the
// FileSystemOperation lifetime issue. // FileSystemOperation lifetime issue.
LocalFileSystemOperation* parent_operation_; base::WeakPtr<LocalFileSystemOperation> parent_operation_;
// These are all used only by Write(). // These are all used only by Write().
friend class FileWriterDelegate; friend class FileWriterDelegate;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "webkit/fileapi/file_system_task_runners.h" #include "webkit/fileapi/file_system_task_runners.h"
#include "webkit/fileapi/file_system_url.h" #include "webkit/fileapi/file_system_url.h"
#include "webkit/fileapi/isolated_context.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/filtering_file_enumerator.h"
#include "webkit/fileapi/media/media_path_filter.h" #include "webkit/fileapi/media/media_path_filter.h"
#include "webkit/fileapi/media/mtp_device_async_delegate.h" #include "webkit/fileapi/media/mtp_device_async_delegate.h"
...@@ -35,7 +36,8 @@ MTPDeviceAsyncDelegate* GetMTPDeviceDelegate( ...@@ -35,7 +36,8 @@ MTPDeviceAsyncDelegate* GetMTPDeviceDelegate(
FileSystemOperationContext* context) { FileSystemOperationContext* context) {
DCHECK(IsOnIOThread(context)); DCHECK(IsOnIOThread(context));
return MTPDeviceMapService::GetInstance()->GetMTPDeviceAsyncDelegate( return MTPDeviceMapService::GetInstance()->GetMTPDeviceAsyncDelegate(
context->mtp_device_delegate_url()); context->GetUserValue<std::string>(
IsolatedMountPointProvider::kMTPDeviceDelegateURLKey));
} }
// Called on a blocking pool thread to create a snapshot file to hold the // Called on a blocking pool thread to create a snapshot file to hold the
...@@ -251,8 +253,7 @@ bool DeviceMediaAsyncFileUtil::CreateSnapshotFile( ...@@ -251,8 +253,7 @@ bool DeviceMediaAsyncFileUtil::CreateSnapshotFile(
return true; return true;
} }
base::FilePath* snapshot_file_path = new base::FilePath; base::FilePath* snapshot_file_path = new base::FilePath;
return context->file_system_context()->task_runners()->media_task_runner()-> return context->task_runner()->PostTaskAndReply(
PostTaskAndReply(
FROM_HERE, FROM_HERE,
base::Bind(&CreateSnapshotFileOnBlockingPool, base::Bind(&CreateSnapshotFileOnBlockingPool,
url.path(), url.path(),
......
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
#include "webkit/fileapi/media/native_media_file_util.h" #include "webkit/fileapi/media/native_media_file_util.h"
#include "webkit/fileapi/file_system_operation_context.h" #include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/media/media_path_filter.h" #include "webkit/fileapi/isolated_mount_point_provider.h"
#include "webkit/fileapi/media/filtering_file_enumerator.h" #include "webkit/fileapi/media/filtering_file_enumerator.h"
#include "webkit/fileapi/media/media_path_filter.h"
#include "webkit/fileapi/native_file_util.h" #include "webkit/fileapi/native_file_util.h"
using base::PlatformFile; using base::PlatformFile;
...@@ -15,6 +16,15 @@ using base::PlatformFileInfo; ...@@ -15,6 +16,15 @@ using base::PlatformFileInfo;
namespace fileapi { namespace fileapi {
namespace {
MediaPathFilter* GetMediaPathFilter(FileSystemOperationContext* context) {
return context->GetUserValue<MediaPathFilter*>(
IsolatedMountPointProvider::kMediaPathFilterKey);
}
} // namespace
NativeMediaFileUtil::NativeMediaFileUtil() { NativeMediaFileUtil::NativeMediaFileUtil() {
} }
...@@ -45,7 +55,7 @@ NativeMediaFileUtil::CreateFileEnumerator( ...@@ -45,7 +55,7 @@ NativeMediaFileUtil::CreateFileEnumerator(
DCHECK(context); DCHECK(context);
return make_scoped_ptr(new FilteringFileEnumerator( return make_scoped_ptr(new FilteringFileEnumerator(
IsolatedFileUtil::CreateFileEnumerator(context, root_url), IsolatedFileUtil::CreateFileEnumerator(context, root_url),
context->media_path_filter())) GetMediaPathFilter(context)))
.PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); .PassAs<FileSystemFileUtil::AbstractFileEnumerator>();
} }
...@@ -109,7 +119,7 @@ PlatformFileError NativeMediaFileUtil::CopyOrMoveFile( ...@@ -109,7 +119,7 @@ PlatformFileError NativeMediaFileUtil::CopyOrMoveFile(
return error; return error;
if (error == base::PLATFORM_FILE_OK && file_info.is_directory) if (error == base::PLATFORM_FILE_OK && file_info.is_directory)
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
if (!context->media_path_filter()->Match(dest_file_path)) if (!GetMediaPathFilter(context)->Match(dest_file_path))
return base::PLATFORM_FILE_ERROR_SECURITY; return base::PLATFORM_FILE_ERROR_SECURITY;
return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, copy); return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, copy);
...@@ -143,7 +153,7 @@ PlatformFileError NativeMediaFileUtil::DeleteFile( ...@@ -143,7 +153,7 @@ PlatformFileError NativeMediaFileUtil::DeleteFile(
return error; return error;
if (file_info.is_directory) if (file_info.is_directory)
return base::PLATFORM_FILE_ERROR_NOT_A_FILE; return base::PLATFORM_FILE_ERROR_NOT_A_FILE;
if (!context->media_path_filter()->Match(file_path)) if (!GetMediaPathFilter(context)->Match(file_path))
return base::PLATFORM_FILE_ERROR_NOT_FOUND; return base::PLATFORM_FILE_ERROR_NOT_FOUND;
return NativeFileUtil::DeleteFile(file_path); return NativeFileUtil::DeleteFile(file_path);
} }
...@@ -154,7 +164,7 @@ PlatformFileError NativeMediaFileUtil::GetFileInfo( ...@@ -154,7 +164,7 @@ PlatformFileError NativeMediaFileUtil::GetFileInfo(
PlatformFileInfo* file_info, PlatformFileInfo* file_info,
base::FilePath* platform_path) { base::FilePath* platform_path) {
DCHECK(context); DCHECK(context);
DCHECK(context->media_path_filter()); DCHECK(GetMediaPathFilter(context));
DCHECK(file_info); DCHECK(file_info);
DCHECK(platform_path); DCHECK(platform_path);
...@@ -164,7 +174,7 @@ PlatformFileError NativeMediaFileUtil::GetFileInfo( ...@@ -164,7 +174,7 @@ PlatformFileError NativeMediaFileUtil::GetFileInfo(
return error; return error;
if (file_info->is_directory || if (file_info->is_directory ||
context->media_path_filter()->Match(*platform_path)) { GetMediaPathFilter(context)->Match(*platform_path)) {
return base::PLATFORM_FILE_OK; return base::PLATFORM_FILE_OK;
} }
return base::PLATFORM_FILE_ERROR_NOT_FOUND; return base::PLATFORM_FILE_ERROR_NOT_FOUND;
...@@ -179,7 +189,7 @@ PlatformFileError NativeMediaFileUtil::GetFilteredLocalFilePath( ...@@ -179,7 +189,7 @@ PlatformFileError NativeMediaFileUtil::GetFilteredLocalFilePath(
IsolatedFileUtil::GetLocalFilePath(context, file_system_url, &file_path); IsolatedFileUtil::GetLocalFilePath(context, file_system_url, &file_path);
if (error != base::PLATFORM_FILE_OK) if (error != base::PLATFORM_FILE_OK)
return error; return error;
if (!context->media_path_filter()->Match(file_path)) if (!GetMediaPathFilter(context)->Match(file_path))
return base::PLATFORM_FILE_ERROR_SECURITY; return base::PLATFORM_FILE_ERROR_SECURITY;
*local_file_path = file_path; *local_file_path = file_path;
...@@ -205,7 +215,7 @@ NativeMediaFileUtil::GetFilteredLocalFilePathForExistingFileOrDirectory( ...@@ -205,7 +215,7 @@ NativeMediaFileUtil::GetFilteredLocalFilePathForExistingFileOrDirectory(
return base::PLATFORM_FILE_ERROR_FAILED; return base::PLATFORM_FILE_ERROR_FAILED;
if (!file_info.is_directory && if (!file_info.is_directory &&
!context->media_path_filter()->Match(file_path)) { !GetMediaPathFilter(context)->Match(file_path)) {
return failure_error; return failure_error;
} }
......
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