summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-29 07:10:05 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-29 07:10:05 +0000
commit25b6979911b3fbcc4e6ee95a47db88c4d5a5930f (patch)
treeb60353dc6c32a5571ee865025e10713fb1c1c2f9 /webkit/fileapi
parent3de8e61f52c73ab6435bb96abbacd862ad68c8ac (diff)
downloadchromium_src-25b6979911b3fbcc4e6ee95a47db88c4d5a5930f.zip
chromium_src-25b6979911b3fbcc4e6ee95a47db88c4d5a5930f.tar.gz
chromium_src-25b6979911b3fbcc4e6ee95a47db88c4d5a5930f.tar.bz2
Introduce AsyncFileUtil and deprecate FileSystemFileUtilProxy
In LocalFileSystemOperation we used to use a synchronous implementation (implemented as FileSystemFileUtil) to perform subtasks (e.g. file_util::Copy type operation), but it's not always natural to have synchronous implementation depending on filesystem types. For example async interface works much better if we need to talk to a remote server or a device. This patch introduces an async version of FileUtil, AsyncFileUtil, and replaces FileSystemFileUtil+Proxy implementation with it. After this patch, each filesystem can choose either: - implement synchronous FileSystemFileUtil and use it with AsyncFileUtilAdapter, or - directly implement asynchronous AsyncFileUtil BUG=154835 TEST=existing tests Review URL: https://codereview.chromium.org/12035049 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@179299 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi')
-rw-r--r--webkit/fileapi/async_file_util.h317
-rw-r--r--webkit/fileapi/async_file_util_adapter.cc306
-rw-r--r--webkit/fileapi/async_file_util_adapter.h109
-rw-r--r--webkit/fileapi/file_snapshot_policy.h26
-rw-r--r--webkit/fileapi/file_system_context.cc13
-rw-r--r--webkit/fileapi/file_system_context.h30
-rw-r--r--webkit/fileapi/file_system_file_util.h98
-rw-r--r--webkit/fileapi/file_system_mount_point_provider.h6
-rw-r--r--webkit/fileapi/file_util_helper.cc4
-rw-r--r--webkit/fileapi/isolated_mount_point_provider.cc31
-rw-r--r--webkit/fileapi/isolated_mount_point_provider.h17
-rw-r--r--webkit/fileapi/local_file_system_operation.cc130
-rw-r--r--webkit/fileapi/local_file_system_operation.h7
-rw-r--r--webkit/fileapi/local_file_system_test_helper.cc5
-rw-r--r--webkit/fileapi/media/device_media_file_util.cc2
-rw-r--r--webkit/fileapi/media/native_media_file_util_unittest.cc1
-rw-r--r--webkit/fileapi/sandbox_mount_point_provider.cc44
-rw-r--r--webkit/fileapi/sandbox_mount_point_provider.h12
-rw-r--r--webkit/fileapi/test_mount_point_provider.cc7
-rw-r--r--webkit/fileapi/test_mount_point_provider.h6
-rw-r--r--webkit/fileapi/webkit_fileapi.gypi5
21 files changed, 975 insertions, 201 deletions
diff --git a/webkit/fileapi/async_file_util.h b/webkit/fileapi/async_file_util.h
new file mode 100644
index 0000000..651d0a51
--- /dev/null
+++ b/webkit/fileapi/async_file_util.h
@@ -0,0 +1,317 @@
+// 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_ASYNC_FILE_UTIL_H_
+#define WEBKIT_FILEAPI_ASYNC_FILE_UTIL_H_
+
+#include "base/basictypes.h"
+#include "base/callback_forward.h"
+#include "base/files/file_util_proxy.h"
+#include "base/platform_file.h"
+#include "webkit/fileapi/file_snapshot_policy.h"
+#include "webkit/storage/webkit_storage_export.h"
+
+namespace base {
+class Time;
+}
+
+namespace fileapi {
+
+class FileSystemOperationContext;
+class FileSystemURL;
+
+// An interface which provides filesystem-specific file operations for
+// LocalFileSystemOperation.
+//
+// Each filesystem which needs to be dispatched from LocalFileSystemOperation
+// must implement this interface or a synchronous version of interface:
+// FileSystemFileUtil.
+//
+class WEBKIT_STORAGE_EXPORT AsyncFileUtil {
+ public:
+ typedef base::Callback<
+ void(base::PlatformFileError result)> StatusCallback;
+
+ typedef base::FileUtilProxy::CreateOrOpenCallback CreateOrOpenCallback;
+
+ typedef base::Callback<
+ void(base::PlatformFileError result,
+ bool created)> EnsureFileExistsCallback;
+
+ typedef base::Callback<
+ void(base::PlatformFileError result,
+ const base::PlatformFileInfo& file_info,
+ const FilePath& platform_path)> GetFileInfoCallback;
+
+ typedef base::FileUtilProxy::Entry Entry;
+ typedef std::vector<base::FileUtilProxy::Entry> EntryList;
+ typedef base::Callback<
+ void(base::PlatformFileError result,
+ const EntryList& file_list,
+ bool has_more)> ReadDirectoryCallback;
+
+ typedef base::Callback<
+ void(base::PlatformFileError result,
+ const base::PlatformFileInfo& file_info,
+ const FilePath& platform_path,
+ SnapshotFilePolicy policy)> CreateSnapshotFileCallback;
+
+ AsyncFileUtil() {}
+ virtual ~AsyncFileUtil() {}
+
+ // Creates or opens a file with the given flags.
+ // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create
+ // a new file at the given |url| and calls back with
+ // PLATFORM_FILE_ERROR_FILE_EXISTS if the |url| already exists.
+ //
+ // LocalFileSystemOperation::OpenFile calls this.
+ // This is used only by Pepper/NaCL File API.
+ //
+ // This returns false if it fails to post an async task.
+ //
+ virtual bool CreateOrOpen(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ int file_flags,
+ const CreateOrOpenCallback& callback) = 0;
+
+ // Ensures that the given |url| exist. This creates a empty new file
+ // at |url| if the |url| does not exist.
+ //
+ // LocalFileSystemOperation::CreateFile calls this.
+ //
+ // This returns false if it fails to post an async task.
+ //
+ // This reports following error code via |callback|:
+ // - PLATFORM_FILE_OK and created==true if a file has not existed and
+ // is created at |url|.
+ // - PLATFORM_FILE_OK and created==false if the file already exists.
+ // - Other error code (with created=false) if a file hasn't existed yet
+ // and there was an error while creating a new file.
+ //
+ virtual bool EnsureFileExists(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const EnsureFileExistsCallback& callback) = 0;
+
+ // Creates directory at given url.
+ //
+ // LocalFileSystemOperation::CreateDirectory calls this.
+ //
+ // This returns false if it fails to post an async task.
+ //
+ // This reports following error code via |callback|:
+ // - PLATFORM_FILE_ERROR_NOT_FOUND if the |url|'s parent directory
+ // does not exist and |recursive| is false.
+ // - PLATFORM_FILE_ERROR_EXISTS if a directory already exists at |url|
+ // and |exclusive| is true.
+ // - PLATFORM_FILE_ERROR_EXISTS if a file already exists at |url|
+ // (regardless of |exclusive| value).
+ // - Other error code if it failed to create a directory.
+ //
+ virtual bool CreateDirectory(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ bool exclusive,
+ bool recursive,
+ const StatusCallback& callback) = 0;
+
+ // Retrieves the information about a file.
+ //
+ // LocalFileSystemOperation::GetMetadata calls this.
+ //
+ // This returns false if it fails to post an async task.
+ //
+ // This reports following error code via |callback|:
+ // - PLATFORM_FILE_ERROR_NOT_FOUND if the file doesn't exist.
+ // - Other error code if there was an error while retrieving the file info.
+ //
+ virtual bool GetFileInfo(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const GetFileInfoCallback& callback) = 0;
+
+ // Reads contents of a directory at |path|.
+ //
+ // LocalFileSystemOperation::ReadDirectory calls this.
+ //
+ // This returns false if it fails to post an async task.
+ //
+ // This reports following error code via |callback|:
+ // - PLATFORM_FILE_ERROR_NOT_FOUND if the target directory doesn't exist.
+ // - PLATFORM_FILE_ERROR_NOT_A_DIRECTORY if an entry exists at |url| but
+ // is a file (not a directory).
+ //
+ virtual bool ReadDirectory(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const ReadDirectoryCallback& callback) = 0;
+
+ // Modifies timestamps of a file or directory at |url| with
+ // |last_access_time| and |last_modified_time|. The function DOES NOT
+ // create a file unlike 'touch' command on Linux.
+ //
+ // LocalFileSystemOperation::TouchFile calls this.
+ // This is used only by Pepper/NaCL File API.
+ //
+ // This returns false if it fails to post an async task.
+ virtual bool Touch(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const base::Time& last_access_time,
+ const base::Time& last_modified_time,
+ const StatusCallback& callback) = 0;
+
+ // Truncates a file at |path| to |length|. If |length| is larger than
+ // the original file size, the file will be extended, and the extended
+ // part is filled with null bytes.
+ //
+ // LocalFileSystemOperation::Truncate calls this.
+ //
+ // This returns false if it fails to post an async task.
+ //
+ // This reports following error code via |callback|:
+ // - PLATFORM_FILE_ERROR_NOT_FOUND if the file doesn't exist.
+ //
+ virtual bool Truncate(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ int64 length,
+ const StatusCallback& callback) = 0;
+
+ // Copies a file from |src_url| to |dest_url|.
+ // This must be called for files that belong to the same filesystem
+ // (i.e. type() and origin() of the |src_url| and |dest_url| must match).
+ //
+ // LocalFileSystemOperation::Copy calls this for same-filesystem copy case.
+ //
+ // This returns false if it fails to post an async task.
+ //
+ // This reports following error code via |callback|:
+ // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url|
+ // or the parent directory of |dest_url| does not exist.
+ // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file.
+ // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and
+ // is not a file.
+ // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and
+ // its parent path is a file.
+ //
+ virtual bool CopyFileLocal(
+ FileSystemOperationContext* context,
+ const FileSystemURL& src_url,
+ const FileSystemURL& dest_url,
+ const StatusCallback& callback) = 0;
+
+ // Moves a local file from |src_url| to |dest_url|.
+ // This must be called for files that belong to the same filesystem
+ // (i.e. type() and origin() of the |src_url| and |dest_url| must match).
+ //
+ // LocalFileSystemOperation::Move calls this for same-filesystem move case.
+ //
+ // This returns false if it fails to post an async task.
+ //
+ // This reports following error code via |callback|:
+ // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url|
+ // or the parent directory of |dest_url| does not exist.
+ // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file.
+ // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and
+ // is not a file.
+ // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and
+ // its parent path is a file.
+ //
+ virtual bool MoveFileLocal(
+ FileSystemOperationContext* context,
+ const FileSystemURL& src_url,
+ const FileSystemURL& dest_url,
+ const StatusCallback& callback) = 0;
+
+ // Copies in a single file from a different filesystem.
+ //
+ // LocalFileSystemOperation::Copy or Move calls this for cross-filesystem
+ // cases.
+ //
+ // This returns false if it fails to post an async task.
+ //
+ // This reports following error code via |callback|:
+ // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_file_path|
+ // or the parent directory of |dest_url| does not exist.
+ // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and
+ // is not a file.
+ // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and
+ // its parent path is a file.
+ //
+ virtual bool CopyInForeignFile(
+ FileSystemOperationContext* context,
+ const FilePath& src_file_path,
+ const FileSystemURL& dest_url,
+ const StatusCallback& callback) = 0;
+
+ // Deletes a single file.
+ //
+ // LocalFileSystemOperation::RemoveFile calls this.
+ //
+ // This returns false if it fails to post an async task.
+ //
+ // This reports following error code via |callback|:
+ // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist.
+ // - PLATFORM_FILE_ERROR_NOT_A_FILE if |url| is not a file.
+ //
+ virtual bool DeleteFile(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const StatusCallback& callback) = 0;
+
+ // Removes a single empty directory.
+ //
+ // LocalFileSystemOperation::RemoveDirectory calls this.
+ //
+ // This returns false if it fails to post an async task.
+ //
+ // This reports following error code via |callback|:
+ // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist.
+ // - PLATFORM_FILE_ERROR_NOT_A_DIRECTORY if |url| is not a directory.
+ // - PLATFORM_FILE_ERROR_NOT_EMPTY if |url| is not empty.
+ //
+ virtual bool DeleteDirectory(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const StatusCallback& callback) = 0;
+
+ // Creates a local snapshot file for a given |url| and returns the
+ // metadata and platform path of the snapshot file via |callback|.
+ // In regular filesystem cases the implementation may simply return
+ // the metadata of the file itself (as well as GetMetadata does),
+ // while in non-regular filesystem case the backend may create a
+ // temporary snapshot file which holds the file data and return
+ // the metadata of the temporary file.
+ //
+ // In the callback, it returns:
+ // |file_info| is the metadata of the snapshot file created.
+ // |platform_path| is the path to the snapshot file created.
+ // |policy| should indicate the policy how the fileapi backend
+ // should handle the returned file.
+ //
+ // LocalFileSystemOperation::CreateSnapshotFile calls this.
+ //
+ // This returns false if it fails to post an async task.
+ //
+ // This reports following error code via |callback|:
+ // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist.
+ // - PLATFORM_FILE_ERROR_NOT_A_FILE if |url| exists but is a directory.
+ //
+ // The field values of |file_info| are undefined (implementation
+ // dependent) in error cases, and the caller should always
+ // check the return code.
+ virtual bool CreateSnapshotFile(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const CreateSnapshotFileCallback& callback) = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AsyncFileUtil);
+};
+
+} // namespace fileapi
+
+#endif // WEBKIT_FILEAPI_ASYNC_FILE_UTIL_H_
diff --git a/webkit/fileapi/async_file_util_adapter.cc b/webkit/fileapi/async_file_util_adapter.cc
new file mode 100644
index 0000000..4c6dca1
--- /dev/null
+++ b/webkit/fileapi/async_file_util_adapter.cc
@@ -0,0 +1,306 @@
+// 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/async_file_util_adapter.h"
+
+#include "base/bind.h"
+#include "base/sequenced_task_runner.h"
+#include "base/task_runner_util.h"
+#include "webkit/fileapi/file_system_context.h"
+#include "webkit/fileapi/file_system_file_util.h"
+#include "webkit/fileapi/file_system_operation_context.h"
+#include "webkit/fileapi/file_system_url.h"
+#include "webkit/fileapi/file_system_util.h"
+
+namespace fileapi {
+
+using base::Bind;
+using base::Callback;
+using base::Owned;
+using base::PlatformFileError;
+using base::Unretained;
+
+namespace {
+
+class EnsureFileExistsHelper {
+ public:
+ EnsureFileExistsHelper() : error_(base::PLATFORM_FILE_OK), created_(false) {}
+
+ void RunWork(FileSystemFileUtil* file_util,
+ FileSystemOperationContext* context,
+ const FileSystemURL& url) {
+ error_ = file_util->EnsureFileExists(context, url, &created_);
+ }
+
+ void Reply(const AsyncFileUtil::EnsureFileExistsCallback& callback) {
+ if (!callback.is_null())
+ callback.Run(error_, created_);
+ }
+
+ private:
+ base::PlatformFileError error_;
+ bool created_;
+ DISALLOW_COPY_AND_ASSIGN(EnsureFileExistsHelper);
+};
+
+class GetFileInfoHelper {
+ public:
+ GetFileInfoHelper()
+ : error_(base::PLATFORM_FILE_OK),
+ snapshot_policy_(kSnapshotFileUnknown) {}
+
+ void GetFileInfo(FileSystemFileUtil* file_util,
+ FileSystemOperationContext* context,
+ const FileSystemURL& url) {
+ error_ = file_util->GetFileInfo(context, url, &file_info_, &platform_path_);
+ }
+
+ void CreateSnapshotFile(FileSystemFileUtil* file_util,
+ FileSystemOperationContext* context,
+ const FileSystemURL& url) {
+ error_ = file_util->CreateSnapshotFile(
+ context, url, &file_info_, &platform_path_, &snapshot_policy_);
+ }
+
+ void ReplyFileInfo(const AsyncFileUtil::GetFileInfoCallback& callback) {
+ if (!callback.is_null())
+ callback.Run(error_, file_info_, platform_path_);
+ }
+
+ void ReplySnapshotFile(
+ const AsyncFileUtil::CreateSnapshotFileCallback& callback) {
+ DCHECK(snapshot_policy_ != kSnapshotFileUnknown);
+ if (!callback.is_null())
+ callback.Run(error_, file_info_, platform_path_, snapshot_policy_);
+ }
+
+ private:
+ base::PlatformFileError error_;
+ base::PlatformFileInfo file_info_;
+ FilePath platform_path_;
+ SnapshotFilePolicy snapshot_policy_;
+ DISALLOW_COPY_AND_ASSIGN(GetFileInfoHelper);
+};
+
+class ReadDirectoryHelper {
+ public:
+ ReadDirectoryHelper() : error_(base::PLATFORM_FILE_OK) {}
+
+ void RunWork(FileSystemFileUtil* file_util,
+ FileSystemOperationContext* context,
+ const FileSystemURL& url) {
+ base::PlatformFileInfo file_info;
+ FilePath platform_path;
+ PlatformFileError error = file_util->GetFileInfo(
+ context, url, &file_info, &platform_path);
+ if (error != base::PLATFORM_FILE_OK) {
+ error_ = error;
+ return;
+ }
+ if (!file_info.is_directory) {
+ error_ = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY;
+ return;
+ }
+
+ scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum(
+ file_util->CreateFileEnumerator(context, url, false /* recursive */));
+
+ FilePath current;
+ while (!(current = file_enum->Next()).empty()) {
+ AsyncFileUtil::Entry entry;
+ entry.is_directory = file_enum->IsDirectory();
+ entry.name = VirtualPath::BaseName(current).value();
+ entry.size = file_enum->Size();
+ entry.last_modified_time = file_enum->LastModifiedTime();
+ entries_.push_back(entry);
+ }
+ error_ = base::PLATFORM_FILE_OK;
+ }
+
+ void Reply(const AsyncFileUtil::ReadDirectoryCallback& callback) {
+ if (!callback.is_null())
+ callback.Run(error_, entries_, false /* has_more */);
+ }
+
+ private:
+ base::PlatformFileError error_;
+ std::vector<AsyncFileUtil::Entry> entries_;
+ DISALLOW_COPY_AND_ASSIGN(ReadDirectoryHelper);
+};
+
+} // namespace
+
+AsyncFileUtilAdapter::AsyncFileUtilAdapter(
+ FileSystemFileUtil* sync_file_util)
+ : sync_file_util_(sync_file_util) {
+ DCHECK(sync_file_util_.get());
+}
+
+AsyncFileUtilAdapter::~AsyncFileUtilAdapter() {
+}
+
+bool AsyncFileUtilAdapter::CreateOrOpen(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ int file_flags,
+ const CreateOrOpenCallback& callback) {
+ return base::FileUtilProxy::RelayCreateOrOpen(
+ context->task_runner(),
+ Bind(&FileSystemFileUtil::CreateOrOpen, Unretained(sync_file_util_.get()),
+ context, url, file_flags),
+ Bind(&FileSystemFileUtil::Close, Unretained(sync_file_util_.get()),
+ context),
+ callback);
+}
+
+bool AsyncFileUtilAdapter::EnsureFileExists(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const EnsureFileExistsCallback& callback) {
+ EnsureFileExistsHelper* helper = new EnsureFileExistsHelper;
+ return context->task_runner()->PostTaskAndReply(
+ FROM_HERE,
+ Bind(&EnsureFileExistsHelper::RunWork, Unretained(helper),
+ sync_file_util_.get(), context, url),
+ Bind(&EnsureFileExistsHelper::Reply, Owned(helper), callback));
+}
+
+bool AsyncFileUtilAdapter::CreateDirectory(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ bool exclusive,
+ bool recursive,
+ const StatusCallback& callback) {
+ return base::PostTaskAndReplyWithResult(
+ context->task_runner(), FROM_HERE,
+ Bind(&FileSystemFileUtil::CreateDirectory,
+ Unretained(sync_file_util_.get()),
+ context, url, exclusive, recursive),
+ callback);
+}
+
+bool AsyncFileUtilAdapter::GetFileInfo(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const GetFileInfoCallback& callback) {
+ GetFileInfoHelper* helper = new GetFileInfoHelper;
+ return context->task_runner()->PostTaskAndReply(
+ FROM_HERE,
+ Bind(&GetFileInfoHelper::GetFileInfo, Unretained(helper),
+ sync_file_util_.get(), context, url),
+ Bind(&GetFileInfoHelper::ReplyFileInfo, Owned(helper), callback));
+}
+
+bool AsyncFileUtilAdapter::ReadDirectory(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const ReadDirectoryCallback& callback) {
+ ReadDirectoryHelper* helper = new ReadDirectoryHelper;
+ return context->task_runner()->PostTaskAndReply(
+ FROM_HERE,
+ Bind(&ReadDirectoryHelper::RunWork, Unretained(helper),
+ sync_file_util_.get(), context, url),
+ Bind(&ReadDirectoryHelper::Reply, Owned(helper), callback));
+}
+
+bool AsyncFileUtilAdapter::Touch(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const base::Time& last_access_time,
+ const base::Time& last_modified_time,
+ const StatusCallback& callback) {
+ return base::PostTaskAndReplyWithResult(
+ context->task_runner(), FROM_HERE,
+ Bind(&FileSystemFileUtil::Touch, Unretained(sync_file_util_.get()),
+ context, url, last_access_time, last_modified_time),
+ callback);
+}
+
+bool AsyncFileUtilAdapter::Truncate(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ int64 length,
+ const StatusCallback& callback) {
+ return base::PostTaskAndReplyWithResult(
+ context->task_runner(), FROM_HERE,
+ Bind(&FileSystemFileUtil::Truncate, Unretained(sync_file_util_.get()),
+ context, url, length),
+ callback);
+}
+
+bool AsyncFileUtilAdapter::CopyFileLocal(
+ FileSystemOperationContext* context,
+ const FileSystemURL& src_url,
+ const FileSystemURL& dest_url,
+ const StatusCallback& callback) {
+ return base::PostTaskAndReplyWithResult(
+ context->task_runner(), FROM_HERE,
+ Bind(&FileSystemFileUtil::CopyOrMoveFile,
+ Unretained(sync_file_util_.get()),
+ context, src_url, dest_url, true /* copy */),
+ callback);
+}
+
+bool AsyncFileUtilAdapter::MoveFileLocal(
+ FileSystemOperationContext* context,
+ const FileSystemURL& src_url,
+ const FileSystemURL& dest_url,
+ const StatusCallback& callback) {
+ return base::PostTaskAndReplyWithResult(
+ context->task_runner(), FROM_HERE,
+ Bind(&FileSystemFileUtil::CopyOrMoveFile,
+ Unretained(sync_file_util_.get()),
+ context, src_url, dest_url, false /* copy */),
+ callback);
+}
+
+bool AsyncFileUtilAdapter::CopyInForeignFile(
+ FileSystemOperationContext* context,
+ const FilePath& src_file_path,
+ const FileSystemURL& dest_url,
+ const StatusCallback& callback) {
+ return base::PostTaskAndReplyWithResult(
+ context->task_runner(), FROM_HERE,
+ Bind(&FileSystemFileUtil::CopyInForeignFile,
+ Unretained(sync_file_util_.get()),
+ context, src_file_path, dest_url),
+ callback);
+}
+
+bool AsyncFileUtilAdapter::DeleteFile(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const StatusCallback& callback) {
+ return base::PostTaskAndReplyWithResult(
+ context->task_runner(), FROM_HERE,
+ Bind(&FileSystemFileUtil::DeleteFile,
+ Unretained(sync_file_util_.get()), context, url),
+ callback);
+}
+
+bool AsyncFileUtilAdapter::DeleteDirectory(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const StatusCallback& callback) {
+ return base::PostTaskAndReplyWithResult(
+ context->task_runner(), FROM_HERE,
+ Bind(&FileSystemFileUtil::DeleteDirectory,
+ Unretained(sync_file_util_.get()),
+ context, url),
+ callback);
+}
+
+bool AsyncFileUtilAdapter::CreateSnapshotFile(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const CreateSnapshotFileCallback& callback) {
+ GetFileInfoHelper* helper = new GetFileInfoHelper;
+ return context->task_runner()->PostTaskAndReply(
+ FROM_HERE,
+ Bind(&GetFileInfoHelper::CreateSnapshotFile, Unretained(helper),
+ sync_file_util_.get(), context, url),
+ Bind(&GetFileInfoHelper::ReplySnapshotFile, Owned(helper), callback));
+}
+
+} // namespace fileapi
diff --git a/webkit/fileapi/async_file_util_adapter.h b/webkit/fileapi/async_file_util_adapter.h
new file mode 100644
index 0000000..da8bb4c
--- /dev/null
+++ b/webkit/fileapi/async_file_util_adapter.h
@@ -0,0 +1,109 @@
+// 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_ASYNC_FILE_UTIL_ADAPTER_H_
+#define WEBKIT_FILEAPI_ASYNC_FILE_UTIL_ADAPTER_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "webkit/fileapi/async_file_util.h"
+
+namespace fileapi {
+
+class FileSystemFileUtil;
+
+// An adapter class for FileSystemFileUtil classes to provide asynchronous
+// interface.
+//
+// A filesystem can do either:
+// - implement a synchronous version of FileUtil by extending
+// FileSystemFileUtil and atach it to this adapter, or
+// - directly implement AsyncFileUtil.
+//
+class WEBKIT_STORAGE_EXPORT_PRIVATE AsyncFileUtilAdapter
+ : public AsyncFileUtil {
+ public:
+ // Creates a new AsyncFileUtil for |sync_file_util|. This takes the
+ // ownership of |sync_file_util|. (This doesn't take scoped_ptr<> just
+ // to save extra make_scoped_ptr; in all use cases a new fresh FileUtil is
+ // created only for this adapter.)
+ explicit AsyncFileUtilAdapter(FileSystemFileUtil* sync_file_util);
+
+ virtual ~AsyncFileUtilAdapter();
+
+ FileSystemFileUtil* sync_file_util() {
+ return sync_file_util_.get();
+ }
+
+ // AsyncFileUtil overrides.
+ virtual bool CreateOrOpen(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ int file_flags,
+ const CreateOrOpenCallback& callback) OVERRIDE;
+ virtual bool EnsureFileExists(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const EnsureFileExistsCallback& callback) OVERRIDE;
+ virtual bool CreateDirectory(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ bool exclusive,
+ bool recursive,
+ const StatusCallback& callback) OVERRIDE;
+ virtual bool GetFileInfo(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const GetFileInfoCallback& callback) OVERRIDE;
+ virtual bool ReadDirectory(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const ReadDirectoryCallback& callback) OVERRIDE;
+ virtual bool Touch(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const base::Time& last_access_time,
+ const base::Time& last_modified_time,
+ const StatusCallback& callback) OVERRIDE;
+ virtual bool Truncate(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ int64 length,
+ const StatusCallback& callback) OVERRIDE;
+ virtual bool CopyFileLocal(
+ FileSystemOperationContext* context,
+ const FileSystemURL& src_url,
+ const FileSystemURL& dest_url,
+ const StatusCallback& callback) OVERRIDE;
+ virtual bool MoveFileLocal(
+ FileSystemOperationContext* context,
+ const FileSystemURL& src_url,
+ const FileSystemURL& dest_url,
+ const StatusCallback& callback) OVERRIDE;
+ virtual bool CopyInForeignFile(
+ FileSystemOperationContext* context,
+ const FilePath& src_file_path,
+ const FileSystemURL& dest_url,
+ const StatusCallback& callback) OVERRIDE;
+ virtual bool DeleteFile(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const StatusCallback& callback) OVERRIDE;
+ virtual bool DeleteDirectory(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const StatusCallback& callback) OVERRIDE;
+ virtual bool CreateSnapshotFile(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ const CreateSnapshotFileCallback& callback) OVERRIDE;
+
+ private:
+ scoped_ptr<FileSystemFileUtil> sync_file_util_;
+
+ DISALLOW_COPY_AND_ASSIGN(AsyncFileUtilAdapter);
+};
+
+} // namespace fileapi
+
+#endif // WEBKIT_FILEAPI_ASYNC_FILE_UTIL_ADAPTER_H_
diff --git a/webkit/fileapi/file_snapshot_policy.h b/webkit/fileapi/file_snapshot_policy.h
new file mode 100644
index 0000000..7386684
--- /dev/null
+++ b/webkit/fileapi/file_snapshot_policy.h
@@ -0,0 +1,26 @@
+// 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_FILE_SNAPSHOT_POLICY_H_
+#define WEBKIT_FILEAPI_FILE_SNAPSHOT_POLICY_H_
+
+namespace fileapi {
+
+// A policy flag for CreateSnapshotFile.
+enum SnapshotFilePolicy {
+ kSnapshotFileUnknown,
+
+ // The implementation just uses the local file as the snapshot file.
+ // The FileAPI backend does nothing on the returned file.
+ kSnapshotFileLocal,
+
+ // The implementation returns a temporary file as the snapshot file.
+ // The FileAPI backend takes care of the lifetime of the returned file
+ // and will delete when the last reference of the file is dropped.
+ kSnapshotFileTemporary,
+};
+
+} // namespace fileapi
+
+#endif // WEBKIT_FILEAPI_FILE_SNAPSHOT_POLICY_H_
diff --git a/webkit/fileapi/file_system_context.cc b/webkit/fileapi/file_system_context.cc
index 4539ca8..67cbc6d 100644
--- a/webkit/fileapi/file_system_context.cc
+++ b/webkit/fileapi/file_system_context.cc
@@ -124,13 +124,13 @@ FileSystemContext::GetQuotaUtil(FileSystemType type) const {
return mount_point_provider->GetQuotaUtil();
}
-FileSystemFileUtil* FileSystemContext::GetFileUtil(
+AsyncFileUtil* FileSystemContext::GetAsyncFileUtil(
FileSystemType type) const {
FileSystemMountPointProvider* mount_point_provider =
GetMountPointProvider(type);
if (!mount_point_provider)
return NULL;
- return mount_point_provider->GetFileUtil(type);
+ return mount_point_provider->GetAsyncFileUtil(type);
}
FileSystemMountPointProvider* FileSystemContext::GetMountPointProvider(
@@ -364,4 +364,13 @@ FileSystemURL FileSystemContext::CrackFileSystemURL(
return result;
}
+FileSystemFileUtil* FileSystemContext::GetFileUtil(
+ FileSystemType type) const {
+ FileSystemMountPointProvider* mount_point_provider =
+ GetMountPointProvider(type);
+ if (!mount_point_provider)
+ return NULL;
+ return mount_point_provider->GetFileUtil(type);
+}
+
} // namespace fileapi
diff --git a/webkit/fileapi/file_system_context.h b/webkit/fileapi/file_system_context.h
index 55e79a3..c5db158 100644
--- a/webkit/fileapi/file_system_context.h
+++ b/webkit/fileapi/file_system_context.h
@@ -27,11 +27,13 @@ class SpecialStoragePolicy;
}
namespace webkit_blob {
+class BlobURLRequestJobTest;
class FileStreamReader;
}
namespace fileapi {
+class AsyncFileUtil;
class ExternalFileSystemMountPointProvider;
class ExternalMountPoints;
class FileSystemFileUtil;
@@ -87,10 +89,8 @@ class WEBKIT_STORAGE_EXPORT FileSystemContext
// it is not a quota-managed storage.
FileSystemQuotaUtil* GetQuotaUtil(FileSystemType type) const;
- // Returns the appropriate FileUtil instance for the given |type|.
- // This may return NULL if it is given an invalid or unsupported filesystem
- // type.
- FileSystemFileUtil* GetFileUtil(FileSystemType type) const;
+ // Returns the appropriate AsyncFileUtil instance for the given |type|.
+ AsyncFileUtil* GetAsyncFileUtil(FileSystemType type) const;
// Returns the mount point provider instance for the given |type|.
// This may return NULL if it is given an invalid or unsupported filesystem
@@ -197,6 +197,23 @@ class WEBKIT_STORAGE_EXPORT FileSystemContext
const FilePath& path) const;
private:
+ // Friended for GetFileUtil.
+ // These classes know the target filesystem (i.e. sandbox filesystem)
+ // supports synchronous FileUtil.
+ friend class LocalFileSystemOperation;
+ friend class LocalFileChangeTracker;
+ friend class LocalFileSyncContext;
+
+ // Friended for GetFileUtil.
+ // Test classes that rely on synchronous FileUtils.
+ friend class webkit_blob::BlobURLRequestJobTest;
+ friend class FileSystemQuotaClientTest;
+ friend class LocalFileSystemTestOriginHelper;
+ friend class NativeMediaFileUtilTest;
+ friend class FileSystemURLRequestJobTest;
+ friend class UploadFileSystemFileElementReaderTest;
+
+ // Deleters.
friend struct DefaultContextDeleter;
friend class base::DeleteHelper<FileSystemContext>;
friend class base::RefCountedThreadSafe<FileSystemContext,
@@ -214,6 +231,11 @@ class WEBKIT_STORAGE_EXPORT FileSystemContext
// returns the original url, without attempting to crack it.
FileSystemURL CrackFileSystemURL(const FileSystemURL& url) const;
+ // Returns the appropriate FileUtil instance for the given |type|.
+ // This may return NULL if it is given an invalid type or the filesystem
+ // does not support synchronous file operations.
+ FileSystemFileUtil* GetFileUtil(FileSystemType type) const;
+
scoped_ptr<FileSystemTaskRunners> task_runners_;
scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_;
diff --git a/webkit/fileapi/file_system_file_util.h b/webkit/fileapi/file_system_file_util.h
index 8c05c1d7..5d4b72c 100644
--- a/webkit/fileapi/file_system_file_util.h
+++ b/webkit/fileapi/file_system_file_util.h
@@ -8,20 +8,17 @@
#include "base/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/platform_file.h"
-#include "webkit/fileapi/file_system_url.h"
+#include "webkit/fileapi/file_snapshot_policy.h"
#include "webkit/storage/webkit_storage_export.h"
namespace base {
class Time;
}
-namespace webkit_blob {
-class ShareableFileReference;
-}
-
namespace fileapi {
class FileSystemOperationContext;
+class FileSystemURL;
// A file utility interface that provides basic file utility methods for
// FileSystem API.
@@ -47,20 +44,6 @@ class WEBKIT_STORAGE_EXPORT FileSystemFileUtil {
virtual bool IsDirectory() = 0;
};
- // A policy flag for CreateSnapshotFile.
- enum SnapshotFilePolicy {
- kSnapshotFileUnknown,
-
- // The implementation just uses the local file as the snapshot file.
- // The FileAPI backend does nothing on the returned file.
- kSnapshotFileLocal,
-
- // The implementation returns a temporary file as the snapshot file.
- // The FileAPI backend takes care of the lifetime of the returned file
- // and will delete when the last reference of the file is dropped.
- kSnapshotFileTemporary,
- };
-
class WEBKIT_STORAGE_EXPORT EmptyFileEnumerator
: public AbstractFileEnumerator {
virtual FilePath Next() OVERRIDE;
@@ -72,11 +55,8 @@ class WEBKIT_STORAGE_EXPORT FileSystemFileUtil {
virtual ~FileSystemFileUtil() {}
// Creates or opens a file with the given flags.
- // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create
- // a new file at the given |url| and calls back with
- // PLATFORM_FILE_ERROR_FILE_EXISTS if the |url| already exists.
- //
- // This is used only for Pepper/NaCL File API.
+ // See header comments for AsyncFileUtil::CreateOrOpen() for more details.
+ // This is used only by Pepper/NaCL File API.
virtual base::PlatformFileError CreateOrOpen(
FileSystemOperationContext* context,
const FileSystemURL& url,
@@ -85,7 +65,6 @@ class WEBKIT_STORAGE_EXPORT FileSystemFileUtil {
bool* created) = 0;
// Closes the given file handle.
- //
// This is used only for Pepper/NaCL File API.
virtual base::PlatformFileError Close(
FileSystemOperationContext* context,
@@ -93,19 +72,13 @@ class WEBKIT_STORAGE_EXPORT FileSystemFileUtil {
// Ensures that the given |url| exist. This creates a empty new file
// at |url| if the |url| does not exist.
- // If a new file han not existed and is created at the |url|,
- // |created| is set true and |error code|
- // is set PLATFORM_FILE_OK.
- // If the file already exists, |created| is set false and |error code|
- // is set PLATFORM_FILE_OK.
- // If the file hasn't existed but it couldn't be created for some other
- // reasons, |created| is set false and |error code| indicates the error.
+ // See header comments for AsyncFileUtil::EnsureFileExists() for more details.
virtual base::PlatformFileError EnsureFileExists(
FileSystemOperationContext* context,
const FileSystemURL& url, bool* created) = 0;
- // Creates directory at given url. It's an error to create
- // if |exclusive| is true and dir already exists.
+ // Creates directory at given url.
+ // See header comments for AsyncFileUtil::CreateDirectory() for more details.
virtual base::PlatformFileError CreateDirectory(
FileSystemOperationContext* context,
const FileSystemURL& url,
@@ -113,6 +86,7 @@ class WEBKIT_STORAGE_EXPORT FileSystemFileUtil {
bool recursive) = 0;
// Retrieves the information about a file.
+ // See header comments for AsyncFileUtil::GetFileInfo() for more details.
virtual base::PlatformFileError GetFileInfo(
FileSystemOperationContext* context,
const FileSystemURL& url,
@@ -126,6 +100,9 @@ class WEBKIT_STORAGE_EXPORT FileSystemFileUtil {
//
// The supplied context must remain valid at least lifetime of the enumerator
// instance.
+ //
+ // TODO(kinuko): Drop recursive flag so that each FileUtil no longer
+ // needs to implement recursive logic.
virtual scoped_ptr<AbstractFileEnumerator> CreateFileEnumerator(
FileSystemOperationContext* context,
const FileSystemURL& root_url,
@@ -139,17 +116,16 @@ class WEBKIT_STORAGE_EXPORT FileSystemFileUtil {
const FileSystemURL& file_system_url,
FilePath* local_file_path) = 0;
- // Updates the file metadata information. Unlike posix's touch, it does
- // not create a file even if |url| does not exist, but instead fails
- // with PLATFORM_FILE_ERROR_NOT_FOUND.
+ // Updates the file metadata information.
+ // See header comments for AsyncFileUtil::Touch() for more details.
virtual base::PlatformFileError Touch(
FileSystemOperationContext* context,
const FileSystemURL& url,
const base::Time& last_access_time,
const base::Time& last_modified_time) = 0;
- // Truncates a file to the given length. If |length| is greater than the
- // current length of the file, the file will be extended with zeroes.
+ // Truncates a file to the given length.
+ // See header comments for AsyncFileUtil::Truncate() for more details.
virtual base::PlatformFileError Truncate(
FileSystemOperationContext* context,
const FileSystemURL& url,
@@ -174,62 +150,30 @@ class WEBKIT_STORAGE_EXPORT FileSystemFileUtil {
bool copy) = 0;
// Copies in a single file from a different filesystem.
- //
- // This returns:
- // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_file_path|
- // or the parent directory of |dest_url| does not exist.
- // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and
- // is not a file.
- // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and
- // its parent path is a file.
- //
+ // See header comments for AsyncFileUtil::CopyInForeignFile() for
+ // more details.
virtual base::PlatformFileError CopyInForeignFile(
FileSystemOperationContext* context,
const FilePath& src_file_path,
const FileSystemURL& dest_url) = 0;
// Deletes a single file.
- //
- // This returns:
- // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist.
- // - PLATFORM_FILE_ERROR_NOT_A_FILE if |url| is not a file.
- //
+ // See header comments for AsyncFileUtil::DeleteFile() for more details.
virtual base::PlatformFileError DeleteFile(
FileSystemOperationContext* context,
const FileSystemURL& url) = 0;
// Deletes a single empty directory.
- //
- // This returns:
- // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist.
- // - PLATFORM_FILE_ERROR_NOT_A_DIRECTORY if |url| is not a directory.
- // - PLATFORM_FILE_ERROR_NOT_EMPTY if |url| is not empty.
- //
+ // See header comments for AsyncFileUtil::DeleteDirectory() for more details.
virtual base::PlatformFileError DeleteDirectory(
FileSystemOperationContext* context,
const FileSystemURL& url) = 0;
// Creates a local snapshot file for a given |url| and returns the
// metadata and platform path of the snapshot file via |callback|.
- // In regular filesystem cases the implementation may simply return
- // the metadata of the file itself (as well as GetMetadata does),
- // while in non-regular filesystem case the backend may create a
- // temporary snapshot file which holds the file data and return
- // the metadata of the temporary file.
- //
- // |file_info| is the metadata of the snapshot file created.
- // |platform_path| is the path to the snapshot file created.
- // |policy| should indicate the policy how the fileapi backend
- // should handle the returned file.
- //
- // This returns:
- // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist.
- // - PLATFORM_FILE_ERROR_NOT_A_FILE if |url| is not a file.
- //
- // The field values of |file_info| are undefined (implementation
- // dependent) in error cases, and the caller should always
- // check the return code.
//
+ // See header comments for AsyncFileUtil::CreateSnapshotFile() for
+ // more details.
virtual base::PlatformFileError CreateSnapshotFile(
FileSystemOperationContext* context,
const FileSystemURL& url,
diff --git a/webkit/fileapi/file_system_mount_point_provider.h b/webkit/fileapi/file_system_mount_point_provider.h
index 24c00fe..7d45844 100644
--- a/webkit/fileapi/file_system_mount_point_provider.h
+++ b/webkit/fileapi/file_system_mount_point_provider.h
@@ -21,6 +21,7 @@ class FileStreamReader;
namespace fileapi {
+class AsyncFileUtil;
class FileSystemURL;
class FileStreamWriter;
class FileSystemContext;
@@ -67,8 +68,13 @@ class WEBKIT_STORAGE_EXPORT FileSystemMountPointProvider {
virtual bool IsRestrictedFileName(const FilePath& filename) const = 0;
// Returns the specialized FileSystemFileUtil for this mount point.
+ // It is ok to return NULL if the filesystem doesn't support synchronous
+ // version of FileUtil.
virtual FileSystemFileUtil* GetFileUtil(FileSystemType type) = 0;
+ // Returns the specialized AsyncFileUtil for this mount point.
+ virtual AsyncFileUtil* GetAsyncFileUtil(FileSystemType type) = 0;
+
// Returns file permission policy we should apply for the given |url|.
virtual FilePermissionPolicy GetPermissionPolicy(
const FileSystemURL& url,
diff --git a/webkit/fileapi/file_util_helper.cc b/webkit/fileapi/file_util_helper.cc
index aed0ba2..2582f8a 100644
--- a/webkit/fileapi/file_util_helper.cc
+++ b/webkit/fileapi/file_util_helper.cc
@@ -230,7 +230,7 @@ PlatformFileError CrossFileUtilHelper::CopyOrMoveFile(
// Resolve the src_url's underlying file path.
base::PlatformFileInfo file_info;
FilePath platform_file_path;
- FileSystemFileUtil::SnapshotFilePolicy snapshot_policy;
+ SnapshotFilePolicy snapshot_policy;
PlatformFileError error = src_util_->CreateSnapshotFile(
context_, src_url, &file_info, &platform_file_path, &snapshot_policy);
@@ -242,7 +242,7 @@ PlatformFileError CrossFileUtilHelper::CopyOrMoveFile(
DCHECK(!platform_file_path.empty());
scoped_ptr<ScopedFileDeleter> file_deleter;
- if (snapshot_policy == FileSystemFileUtil::kSnapshotFileTemporary)
+ if (snapshot_policy == kSnapshotFileTemporary)
file_deleter.reset(new ScopedFileDeleter(platform_file_path));
// Call CopyInForeignFile() on the dest_util_ with the resolved source path
diff --git a/webkit/fileapi/isolated_mount_point_provider.cc b/webkit/fileapi/isolated_mount_point_provider.cc
index 1bbb940..f21909c 100644
--- a/webkit/fileapi/isolated_mount_point_provider.cc
+++ b/webkit/fileapi/isolated_mount_point_provider.cc
@@ -13,6 +13,7 @@
#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/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_file_stream_reader.h"
@@ -37,13 +38,15 @@ IsolatedMountPointProvider::IsolatedMountPointProvider(
const FilePath& profile_path)
: profile_path_(profile_path),
media_path_filter_(new MediaPathFilter()),
- isolated_file_util_(new IsolatedFileUtil()),
- dragged_file_util_(new DraggedFileUtil()),
- native_media_file_util_(new NativeMediaFileUtil()) {
+ 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_file_util_.reset(new DeviceMediaFileUtil(profile_path_));
+ device_media_file_util_.reset(
+ new AsyncFileUtilAdapter(new DeviceMediaFileUtil(profile_path_)));
#endif
}
@@ -84,6 +87,25 @@ FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil(
FileSystemType type) {
switch (type) {
case kFileSystemTypeNativeLocal:
+ 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();
+ case kFileSystemTypeDeviceMedia:
+#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
+ return device_media_file_util_->sync_file_util();
+#endif
+ default:
+ NOTREACHED();
+ }
+ return NULL;
+}
+
+AsyncFileUtil* IsolatedMountPointProvider::GetAsyncFileUtil(
+ FileSystemType type) {
+ switch (type) {
+ case kFileSystemTypeNativeLocal:
return isolated_file_util_.get();
case kFileSystemTypeDragged:
return dragged_file_util_.get();
@@ -93,7 +115,6 @@ FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil(
#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
return device_media_file_util_.get();
#endif
-
default:
NOTREACHED();
}
diff --git a/webkit/fileapi/isolated_mount_point_provider.h b/webkit/fileapi/isolated_mount_point_provider.h
index 63964d1..5c89f11 100644
--- a/webkit/fileapi/isolated_mount_point_provider.h
+++ b/webkit/fileapi/isolated_mount_point_provider.h
@@ -11,15 +11,9 @@
namespace fileapi {
-class DraggedFileUtil;
+class AsyncFileUtilAdapter;
class IsolatedContext;
-class IsolatedFileUtil;
class MediaPathFilter;
-class NativeMediaFileUtil;
-
-#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
-class DeviceMediaFileUtil;
-#endif
class IsolatedMountPointProvider : public FileSystemMountPointProvider {
public:
@@ -38,6 +32,7 @@ class IsolatedMountPointProvider : public FileSystemMountPointProvider {
virtual bool IsAccessAllowed(const FileSystemURL& url) OVERRIDE;
virtual bool IsRestrictedFileName(const FilePath& filename) const OVERRIDE;
virtual FileSystemFileUtil* GetFileUtil(FileSystemType type) OVERRIDE;
+ virtual AsyncFileUtil* GetAsyncFileUtil(FileSystemType type) OVERRIDE;
virtual FilePermissionPolicy GetPermissionPolicy(
const FileSystemURL& url,
int permissions) const OVERRIDE;
@@ -67,12 +62,12 @@ class IsolatedMountPointProvider : public FileSystemMountPointProvider {
scoped_ptr<MediaPathFilter> media_path_filter_;
- scoped_ptr<IsolatedFileUtil> isolated_file_util_;
- scoped_ptr<DraggedFileUtil> dragged_file_util_;
- scoped_ptr<NativeMediaFileUtil> native_media_file_util_;
+ 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<DeviceMediaFileUtil> device_media_file_util_;
+ scoped_ptr<AsyncFileUtilAdapter> device_media_file_util_;
#endif
};
diff --git a/webkit/fileapi/local_file_system_operation.cc b/webkit/fileapi/local_file_system_operation.cc
index 2debced..edf26b0 100644
--- a/webkit/fileapi/local_file_system_operation.cc
+++ b/webkit/fileapi/local_file_system_operation.cc
@@ -11,10 +11,10 @@
#include "net/base/escape.h"
#include "net/url_request/url_request_context.h"
#include "webkit/blob/shareable_file_reference.h"
+#include "webkit/fileapi/async_file_util.h"
#include "webkit/fileapi/cross_operation_delegate.h"
#include "webkit/fileapi/file_observers.h"
#include "webkit/fileapi/file_system_context.h"
-#include "webkit/fileapi/file_system_file_util_proxy.h"
#include "webkit/fileapi/file_system_mount_point_provider.h"
#include "webkit/fileapi/file_system_task_runners.h"
#include "webkit/fileapi/file_system_types.h"
@@ -76,7 +76,7 @@ void LocalFileSystemOperation::CreateFile(const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCreateFile));
- base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_CREATE);
+ base::PlatformFileError result = SetUp(url, SETUP_FOR_CREATE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -96,7 +96,7 @@ void LocalFileSystemOperation::CreateDirectory(const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCreateDirectory));
- base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_CREATE);
+ base::PlatformFileError result = SetUp(url, SETUP_FOR_CREATE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -114,8 +114,7 @@ void LocalFileSystemOperation::Copy(const FileSystemURL& src_url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCopy));
- base::PlatformFileError result = SetUp(
- dest_url, &file_util_, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(dest_url, SETUP_FOR_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -137,8 +136,7 @@ void LocalFileSystemOperation::Move(const FileSystemURL& src_url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationMove));
- base::PlatformFileError result = SetUp(
- src_url, &file_util_, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(src_url, SETUP_FOR_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -159,15 +157,15 @@ void LocalFileSystemOperation::DirectoryExists(const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationDirectoryExists));
- base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, SETUP_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
return;
}
- FileSystemFileUtilProxy::GetFileInfo(
- operation_context(), file_util_, url,
+ async_file_util_->GetFileInfo(
+ operation_context(), url,
base::Bind(&LocalFileSystemOperation::DidDirectoryExists,
base::Owned(this), callback));
}
@@ -176,15 +174,15 @@ void LocalFileSystemOperation::FileExists(const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationFileExists));
- base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, SETUP_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
return;
}
- FileSystemFileUtilProxy::GetFileInfo(
- operation_context(), file_util_, url,
+ async_file_util_->GetFileInfo(
+ operation_context(), url,
base::Bind(&LocalFileSystemOperation::DidFileExists,
base::Owned(this), callback));
}
@@ -193,15 +191,15 @@ void LocalFileSystemOperation::GetMetadata(
const FileSystemURL& url, const GetMetadataCallback& callback) {
DCHECK(SetPendingOperationType(kOperationGetMetadata));
- base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, SETUP_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, base::PlatformFileInfo(), FilePath());
delete this;
return;
}
- FileSystemFileUtilProxy::GetFileInfo(
- operation_context(), file_util_, url,
+ async_file_util_->GetFileInfo(
+ operation_context(), url,
base::Bind(&LocalFileSystemOperation::DidGetMetadata,
base::Owned(this), callback));
}
@@ -210,15 +208,15 @@ void LocalFileSystemOperation::ReadDirectory(
const FileSystemURL& url, const ReadDirectoryCallback& callback) {
DCHECK(SetPendingOperationType(kOperationReadDirectory));
- base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, SETUP_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false);
delete this;
return;
}
- FileSystemFileUtilProxy::ReadDirectory(
- operation_context(), file_util_, url,
+ async_file_util_->ReadDirectory(
+ operation_context(), url,
base::Bind(&LocalFileSystemOperation::DidReadDirectory,
base::Owned(this), callback));
}
@@ -252,7 +250,7 @@ void LocalFileSystemOperation::Truncate(const FileSystemURL& url, int64 length,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationTruncate));
- base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(url, SETUP_FOR_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -271,15 +269,15 @@ void LocalFileSystemOperation::TouchFile(const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationTouchFile));
- base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(url, SETUP_FOR_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
return;
}
- FileSystemFileUtilProxy::Touch(
- operation_context(), file_util_, url,
+ async_file_util_->Touch(
+ operation_context(), url,
last_access_time, last_modified_time,
base::Bind(&LocalFileSystemOperation::DidTouchFile,
base::Owned(this), callback));
@@ -307,13 +305,13 @@ void LocalFileSystemOperation::OpenFile(const FileSystemURL& url,
base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE |
base::PLATFORM_FILE_DELETE_ON_CLOSE |
base::PLATFORM_FILE_WRITE_ATTRIBUTES)) {
- base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_CREATE);
+ base::PlatformFileError result = SetUp(url, SETUP_FOR_CREATE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, base::PlatformFile(), base::ProcessHandle());
return;
}
} else {
- base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, SETUP_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, base::PlatformFile(), base::ProcessHandle());
return;
@@ -377,13 +375,16 @@ void LocalFileSystemOperation::SyncGetPlatformPath(const FileSystemURL& url,
FilePath* platform_path) {
DCHECK(SetPendingOperationType(kOperationGetLocalPath));
- base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, SETUP_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
delete this;
return;
}
- file_util_->GetLocalFilePath(operation_context(), url, platform_path);
+ FileSystemFileUtil* file_util = file_system_context()->GetFileUtil(
+ url.type());
+ DCHECK(file_util);
+ file_util->GetLocalFilePath(operation_context(), url, platform_path);
delete this;
}
@@ -393,15 +394,15 @@ void LocalFileSystemOperation::CreateSnapshotFile(
const SnapshotFileCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile));
- base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, SETUP_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, base::PlatformFileInfo(), FilePath(), NULL);
delete this;
return;
}
- FileSystemFileUtilProxy::CreateSnapshotFile(
- operation_context(), file_util_, url,
+ async_file_util_->CreateSnapshotFile(
+ operation_context(), url,
base::Bind(&LocalFileSystemOperation::DidCreateSnapshotFile,
base::Owned(this), callback));
}
@@ -412,8 +413,7 @@ void LocalFileSystemOperation::CopyInForeignFile(
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCopyInForeignFile));
- base::PlatformFileError result = SetUp(
- dest_url, &file_util_, SETUP_FOR_CREATE);
+ base::PlatformFileError result = SetUp(dest_url, SETUP_FOR_CREATE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -432,15 +432,15 @@ void LocalFileSystemOperation::RemoveFile(
const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationRemove));
- base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(url, SETUP_FOR_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
return;
}
- FileSystemFileUtilProxy::DeleteFile(
- operation_context(), file_util_, url,
+ async_file_util_->DeleteFile(
+ operation_context(), url,
base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
base::Owned(this), callback));
}
@@ -449,15 +449,15 @@ void LocalFileSystemOperation::RemoveDirectory(
const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationRemove));
- base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(url, SETUP_FOR_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
return;
}
- FileSystemFileUtilProxy::DeleteDirectory(
- operation_context(), file_util_, url,
+ async_file_util_->DeleteDirectory(
+ operation_context(), url,
base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
base::Owned(this), callback));
}
@@ -470,9 +470,9 @@ void LocalFileSystemOperation::CopyFileLocal(
DCHECK_EQ(src_url.origin(), dest_url.origin());
DCHECK_EQ(src_url.type(), dest_url.type());
- base::PlatformFileError result = SetUp(src_url, &file_util_, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(src_url, SETUP_FOR_READ);
if (result == base::PLATFORM_FILE_OK)
- result = SetUp(dest_url, &file_util_, SETUP_FOR_CREATE);
+ result = SetUp(dest_url, SETUP_FOR_CREATE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -501,9 +501,9 @@ void LocalFileSystemOperation::MoveFileLocal(
DCHECK_EQ(src_url.origin(), dest_url.origin());
DCHECK_EQ(src_url.type(), dest_url.type());
- base::PlatformFileError result = SetUp(src_url, &file_util_, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(src_url, SETUP_FOR_WRITE);
if (result == base::PLATFORM_FILE_OK)
- result = SetUp(dest_url, &file_util_, SETUP_FOR_CREATE);
+ result = SetUp(dest_url, SETUP_FOR_CREATE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -526,7 +526,7 @@ LocalFileSystemOperation::LocalFileSystemOperation(
scoped_ptr<FileSystemOperationContext> operation_context)
: file_system_context_(file_system_context),
operation_context_(operation_context.Pass()),
- file_util_(NULL),
+ async_file_util_(NULL),
overriding_operation_context_(NULL),
peer_handle_(base::kNullProcessHandle),
pending_operation_(kOperationNone),
@@ -581,7 +581,7 @@ base::Closure LocalFileSystemOperation::GetWriteClosure(
const WriteCallback& callback) {
DCHECK(SetPendingOperationType(kOperationWrite));
- base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(url, SETUP_FOR_WRITE);
if (result != base::PLATFORM_FILE_OK) {
return base::Bind(&LocalFileSystemOperation::DidFailWrite,
base::Owned(this), callback, result);
@@ -625,9 +625,8 @@ void LocalFileSystemOperation::DoCreateFile(
const FileSystemURL& url,
const StatusCallback& callback,
bool exclusive) {
- FileSystemFileUtilProxy::EnsureFileExists(
- operation_context(),
- file_util_, url,
+ async_file_util_->EnsureFileExists(
+ operation_context(), url,
base::Bind(
exclusive ?
&LocalFileSystemOperation::DidEnsureFileExistsExclusive :
@@ -639,9 +638,9 @@ void LocalFileSystemOperation::DoCreateDirectory(
const FileSystemURL& url,
const StatusCallback& callback,
bool exclusive, bool recursive) {
- FileSystemFileUtilProxy::CreateDirectory(
+ async_file_util_->CreateDirectory(
operation_context(),
- file_util_, url, exclusive, recursive,
+ url, exclusive, recursive,
base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
base::Owned(this), callback));
}
@@ -650,9 +649,8 @@ void LocalFileSystemOperation::DoCopyFileLocal(
const FileSystemURL& src_url,
const FileSystemURL& dest_url,
const StatusCallback& callback) {
- FileSystemFileUtilProxy::CopyFileLocal(
- operation_context(),
- file_util_, src_url, dest_url,
+ async_file_util_->CopyFileLocal(
+ operation_context(), src_url, dest_url,
base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
base::Owned(this), callback));
}
@@ -661,9 +659,8 @@ void LocalFileSystemOperation::DoMoveFileLocal(
const FileSystemURL& src_url,
const FileSystemURL& dest_url,
const StatusCallback& callback) {
- FileSystemFileUtilProxy::MoveFileLocal(
- operation_context(),
- file_util_, src_url, dest_url,
+ async_file_util_->MoveFileLocal(
+ operation_context(), src_url, dest_url,
base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
base::Owned(this), callback));
}
@@ -672,9 +669,9 @@ void LocalFileSystemOperation::DoCopyInForeignFile(
const FilePath& src_local_disk_file_path,
const FileSystemURL& dest_url,
const StatusCallback& callback) {
- FileSystemFileUtilProxy::CopyInForeignFile(
+ async_file_util_->CopyInForeignFile(
operation_context(),
- file_util_, src_local_disk_file_path, dest_url,
+ src_local_disk_file_path, dest_url,
base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
base::Owned(this), callback));
}
@@ -682,8 +679,8 @@ void LocalFileSystemOperation::DoCopyInForeignFile(
void LocalFileSystemOperation::DoTruncate(const FileSystemURL& url,
const StatusCallback& callback,
int64 length) {
- FileSystemFileUtilProxy::Truncate(
- operation_context(), file_util_, url, length,
+ async_file_util_->Truncate(
+ operation_context(), url, length,
base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
base::Owned(this), callback));
}
@@ -691,8 +688,8 @@ void LocalFileSystemOperation::DoTruncate(const FileSystemURL& url,
void LocalFileSystemOperation::DoOpenFile(const FileSystemURL& url,
const OpenFileCallback& callback,
int file_flags) {
- FileSystemFileUtilProxy::CreateOrOpen(
- operation_context(), file_util_, url, file_flags,
+ async_file_util_->CreateOrOpen(
+ operation_context(), url, file_flags,
base::Bind(&LocalFileSystemOperation::DidOpenFile,
base::Owned(this), callback));
}
@@ -816,10 +813,10 @@ void LocalFileSystemOperation::DidCreateSnapshotFile(
base::PlatformFileError result,
const base::PlatformFileInfo& file_info,
const FilePath& platform_path,
- FileSystemFileUtil::SnapshotFilePolicy snapshot_policy) {
+ SnapshotFilePolicy snapshot_policy) {
scoped_refptr<ShareableFileReference> file_ref;
if (result == base::PLATFORM_FILE_OK &&
- snapshot_policy == FileSystemFileUtil::kSnapshotFileTemporary) {
+ snapshot_policy == kSnapshotFileTemporary) {
file_ref = ShareableFileReference::GetOrCreate(
platform_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE,
file_system_context()->task_runners()->file_task_runner());
@@ -829,7 +826,6 @@ void LocalFileSystemOperation::DidCreateSnapshotFile(
base::PlatformFileError LocalFileSystemOperation::SetUp(
const FileSystemURL& url,
- FileSystemFileUtil** file_util,
SetUpMode mode) {
if (!url.is_valid())
return base::PLATFORM_FILE_ERROR_INVALID_URL;
@@ -839,10 +835,8 @@ base::PlatformFileError LocalFileSystemOperation::SetUp(
mode != SETUP_FOR_READ)
return base::PLATFORM_FILE_ERROR_SECURITY;
- DCHECK(file_util);
- if (!*file_util)
- *file_util = file_system_context()->GetFileUtil(url.type());
- if (!*file_util)
+ async_file_util_ = file_system_context()->GetAsyncFileUtil(url.type());
+ if (!async_file_util_)
return base::PLATFORM_FILE_ERROR_SECURITY;
// If this operation is created for recursive sub-operations (i.e.
diff --git a/webkit/fileapi/local_file_system_operation.h b/webkit/fileapi/local_file_system_operation.h
index d5f33d8..cd828d8 100644
--- a/webkit/fileapi/local_file_system_operation.h
+++ b/webkit/fileapi/local_file_system_operation.h
@@ -10,6 +10,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
+#include "webkit/fileapi/file_snapshot_policy.h"
#include "webkit/fileapi/file_system_file_util.h"
#include "webkit/fileapi/file_system_operation.h"
#include "webkit/fileapi/file_system_operation_context.h"
@@ -24,6 +25,7 @@ class CrosMountPointProvider;
namespace fileapi {
+class AsyncFileUtil;
class FileSystemContext;
class RecursiveOperationDelegate;
@@ -290,12 +292,11 @@ class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation
base::PlatformFileError rv,
const base::PlatformFileInfo& file_info,
const FilePath& platform_path,
- FileSystemFileUtil::SnapshotFilePolicy snapshot_policy);
+ SnapshotFilePolicy snapshot_policy);
// Checks the validity of a given |url| and populates |file_util| for |mode|.
base::PlatformFileError SetUp(
const FileSystemURL& url,
- FileSystemFileUtil** file_util,
SetUpMode mode);
// Used only for internal assertions.
@@ -321,7 +322,7 @@ class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation
scoped_refptr<FileSystemContext> file_system_context_;
scoped_ptr<FileSystemOperationContext> operation_context_;
- FileSystemFileUtil* file_util_; // Not owned.
+ AsyncFileUtil* async_file_util_; // Not owned.
FileSystemOperationContext* overriding_operation_context_;
diff --git a/webkit/fileapi/local_file_system_test_helper.cc b/webkit/fileapi/local_file_system_test_helper.cc
index bbc9b2d..e3dbe61 100644
--- a/webkit/fileapi/local_file_system_test_helper.cc
+++ b/webkit/fileapi/local_file_system_test_helper.cc
@@ -186,10 +186,7 @@ void LocalFileSystemTestOriginHelper::SetUpFileUtil() {
file_system_context_->task_runners()->file_task_runner(),
file_system_context_->partition_path()));
}
- FileSystemMountPointProvider* mount_point_provider =
- file_system_context_->GetMountPointProvider(type_);
- DCHECK(mount_point_provider);
- file_util_ = mount_point_provider->GetFileUtil(type_);
+ file_util_ = file_system_context_->GetFileUtil(type_);
DCHECK(file_util_);
}
diff --git a/webkit/fileapi/media/device_media_file_util.cc b/webkit/fileapi/media/device_media_file_util.cc
index 14304ed..a5db4a8 100644
--- a/webkit/fileapi/media/device_media_file_util.cc
+++ b/webkit/fileapi/media/device_media_file_util.cc
@@ -160,7 +160,7 @@ base::PlatformFileError DeviceMediaFileUtil::CreateSnapshotFile(
DCHECK(local_path);
DCHECK(snapshot_policy);
// We return a temporary file as a snapshot.
- *snapshot_policy = FileSystemFileUtil::kSnapshotFileTemporary;
+ *snapshot_policy = kSnapshotFileTemporary;
MTPDeviceDelegate* delegate = GetMTPDeviceDelegate(context);
if (!delegate)
diff --git a/webkit/fileapi/media/native_media_file_util_unittest.cc b/webkit/fileapi/media/native_media_file_util_unittest.cc
index 48f9c29..8fab4d3 100644
--- a/webkit/fileapi/media/native_media_file_util_unittest.cc
+++ b/webkit/fileapi/media/native_media_file_util_unittest.cc
@@ -16,6 +16,7 @@
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_operation.h"
#include "webkit/fileapi/file_system_task_runners.h"
+#include "webkit/fileapi/file_system_url.h"
#include "webkit/fileapi/isolated_context.h"
#include "webkit/fileapi/media/native_media_file_util.h"
#include "webkit/fileapi/mock_file_system_options.h"
diff --git a/webkit/fileapi/sandbox_mount_point_provider.cc b/webkit/fileapi/sandbox_mount_point_provider.cc
index 3f71d48..baf7cac 100644
--- a/webkit/fileapi/sandbox_mount_point_provider.cc
+++ b/webkit/fileapi/sandbox_mount_point_provider.cc
@@ -12,6 +12,7 @@
#include "base/task_runner_util.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_util.h"
+#include "webkit/fileapi/async_file_util_adapter.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"
@@ -143,12 +144,14 @@ SandboxMountPointProvider::SandboxMountPointProvider(
: file_task_runner_(file_task_runner),
profile_path_(profile_path),
file_system_options_(file_system_options),
- sandbox_file_util_(new ObfuscatedFileUtil(
- profile_path.Append(kFileSystemDirectory))),
+ sandbox_file_util_(
+ new AsyncFileUtilAdapter(
+ new ObfuscatedFileUtil(
+ profile_path.Append(kFileSystemDirectory)))),
quota_observer_(new SandboxQuotaObserver(
quota_manager_proxy,
file_task_runner,
- sandbox_file_util_.get())),
+ sandbox_sync_file_util())),
enable_sync_directory_operation_(
CommandLine::ForCurrentProcess()->HasSwitch(
kEnableSyncDirectoryOperation)),
@@ -167,7 +170,7 @@ SandboxMountPointProvider::SandboxMountPointProvider(
SandboxMountPointProvider::~SandboxMountPointProvider() {
if (!file_task_runner_->RunsTasksOnCurrentThread()) {
- ObfuscatedFileUtil* sandbox_file_util = sandbox_file_util_.release();
+ AsyncFileUtilAdapter* sandbox_file_util = sandbox_file_util_.release();
SandboxQuotaObserver* quota_observer = quota_observer_.release();
if (!file_task_runner_->DeleteSoon(FROM_HERE, sandbox_file_util))
delete sandbox_file_util;
@@ -200,7 +203,7 @@ void SandboxMountPointProvider::ValidateFileSystemRoot(
file_task_runner_->PostTaskAndReply(
FROM_HERE,
base::Bind(&ValidateRootOnFileThread,
- sandbox_file_util_.get(),
+ sandbox_sync_file_util(),
origin_url, type, create,
base::Unretained(error_ptr)),
base::Bind(&DidValidateFileSystemRoot,
@@ -252,6 +255,12 @@ bool SandboxMountPointProvider::IsRestrictedFileName(const FilePath& filename)
FileSystemFileUtil* SandboxMountPointProvider::GetFileUtil(
FileSystemType type) {
+ DCHECK(sandbox_file_util_.get());
+ return sandbox_file_util_->sync_file_util();
+}
+
+AsyncFileUtil* SandboxMountPointProvider::GetAsyncFileUtil(
+ FileSystemType type) {
return sandbox_file_util_.get();
}
@@ -328,15 +337,15 @@ void SandboxMountPointProvider::DeleteFileSystem(
}
SandboxMountPointProvider::OriginEnumerator*
-SandboxMountPointProvider::CreateOriginEnumerator() const {
- return new ObfuscatedOriginEnumerator(sandbox_file_util_.get());
+SandboxMountPointProvider::CreateOriginEnumerator() {
+ return new ObfuscatedOriginEnumerator(sandbox_sync_file_util());
}
FilePath SandboxMountPointProvider::GetBaseDirectoryForOriginAndType(
- const GURL& origin_url, fileapi::FileSystemType type, bool create) const {
+ const GURL& origin_url, fileapi::FileSystemType type, bool create) {
base::PlatformFileError error = base::PLATFORM_FILE_OK;
- FilePath path = sandbox_file_util_->GetDirectoryForOriginAndType(
+ FilePath path = sandbox_sync_file_util()->GetDirectoryForOriginAndType(
origin_url, type, create, &error);
if (error != base::PLATFORM_FILE_OK)
return FilePath();
@@ -353,8 +362,8 @@ SandboxMountPointProvider::DeleteOriginDataOnFileThread(
int64 usage = GetOriginUsageOnFileThread(file_system_context,
origin_url, type);
- bool result =
- sandbox_file_util_->DeleteDirectoryForOriginAndType(origin_url, type);
+ bool result = sandbox_sync_file_util()->DeleteDirectoryForOriginAndType(
+ origin_url, type);
if (result && proxy) {
proxy->NotifyStorageModified(
quota::QuotaClient::kFileSystem,
@@ -432,7 +441,7 @@ int64 SandboxMountPointProvider::GetOriginUsageOnFileThread(
FileSystemURL url = file_system_context->CreateCrackedFileSystemURL(
origin_url, type, FilePath());
scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> enumerator(
- sandbox_file_util_->CreateFileEnumerator(&context, url, true));
+ sandbox_sync_file_util()->CreateFileEnumerator(&context, url, true));
FilePath file_path_each;
int64 usage = 0;
@@ -451,7 +460,7 @@ void SandboxMountPointProvider::InvalidateUsageCache(
DCHECK(CanHandleType(type));
base::PlatformFileError error = base::PLATFORM_FILE_OK;
FilePath usage_file_path = GetUsageCachePathForOriginAndType(
- sandbox_file_util_.get(), origin_url, type, &error);
+ sandbox_sync_file_util(), origin_url, type, &error);
if (error != base::PLATFORM_FILE_OK)
return;
FileSystemUsageCache::IncrementDirty(usage_file_path);
@@ -533,10 +542,10 @@ SandboxMountPointProvider::CreateFileSystemOperationForSync(
FilePath SandboxMountPointProvider::GetUsageCachePathForOriginAndType(
const GURL& origin_url,
- FileSystemType type) const {
+ FileSystemType type) {
base::PlatformFileError error;
FilePath path = GetUsageCachePathForOriginAndType(
- sandbox_file_util_.get(), origin_url, type, &error);
+ sandbox_sync_file_util(), origin_url, type, &error);
if (error != base::PLATFORM_FILE_OK)
return FilePath();
return path;
@@ -575,4 +584,9 @@ bool SandboxMountPointProvider::IsAllowedScheme(const GURL& url) const {
return false;
}
+ObfuscatedFileUtil* SandboxMountPointProvider::sandbox_sync_file_util() {
+ DCHECK(sandbox_file_util_.get());
+ return static_cast<ObfuscatedFileUtil*>(sandbox_file_util_->sync_file_util());
+}
+
} // namespace fileapi
diff --git a/webkit/fileapi/sandbox_mount_point_provider.h b/webkit/fileapi/sandbox_mount_point_provider.h
index 1302cc4..2a8a3ff 100644
--- a/webkit/fileapi/sandbox_mount_point_provider.h
+++ b/webkit/fileapi/sandbox_mount_point_provider.h
@@ -31,6 +31,7 @@ class QuotaManagerProxy;
namespace fileapi {
+class AsyncFileUtilAdapter;
class LocalFileSystemOperation;
class ObfuscatedFileUtil;
class SandboxQuotaObserver;
@@ -83,6 +84,7 @@ class WEBKIT_STORAGE_EXPORT SandboxMountPointProvider
virtual bool IsAccessAllowed(const FileSystemURL& url) OVERRIDE;
virtual bool IsRestrictedFileName(const FilePath& filename) const OVERRIDE;
virtual FileSystemFileUtil* GetFileUtil(FileSystemType type) OVERRIDE;
+ virtual AsyncFileUtil* GetAsyncFileUtil(FileSystemType type) OVERRIDE;
virtual FilePermissionPolicy GetPermissionPolicy(
const FileSystemURL& url,
int permissions) const OVERRIDE;
@@ -108,7 +110,7 @@ class WEBKIT_STORAGE_EXPORT SandboxMountPointProvider
// Returns an origin enumerator of this provider.
// This method can only be called on the file thread.
- OriginEnumerator* CreateOriginEnumerator() const;
+ OriginEnumerator* CreateOriginEnumerator();
// Gets a base directory path of the sandboxed filesystem that is
// specified by |origin_url| and |type|.
@@ -119,7 +121,7 @@ class WEBKIT_STORAGE_EXPORT SandboxMountPointProvider
FilePath GetBaseDirectoryForOriginAndType(
const GURL& origin_url,
FileSystemType type,
- bool create) const;
+ bool create);
// Deletes the data on the origin and reports the amount of deleted data
// to the quota manager via |proxy|.
@@ -174,7 +176,7 @@ class WEBKIT_STORAGE_EXPORT SandboxMountPointProvider
// Returns a path to the usage cache file.
FilePath GetUsageCachePathForOriginAndType(
const GURL& origin_url,
- FileSystemType type) const;
+ FileSystemType type);
// Returns a path to the usage cache file (static version).
static FilePath GetUsageCachePathForOriginAndType(
@@ -196,13 +198,15 @@ class WEBKIT_STORAGE_EXPORT SandboxMountPointProvider
return enable_sync_directory_operation_;
}
+ ObfuscatedFileUtil* sandbox_sync_file_util();
+
scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
const FilePath profile_path_;
FileSystemOptions file_system_options_;
- scoped_ptr<ObfuscatedFileUtil> sandbox_file_util_;
+ scoped_ptr<AsyncFileUtilAdapter> sandbox_file_util_;
scoped_ptr<SandboxQuotaObserver> quota_observer_;
diff --git a/webkit/fileapi/test_mount_point_provider.cc b/webkit/fileapi/test_mount_point_provider.cc
index 4ec5ede..d062763 100644
--- a/webkit/fileapi/test_mount_point_provider.cc
+++ b/webkit/fileapi/test_mount_point_provider.cc
@@ -69,7 +69,7 @@ TestMountPointProvider::TestMountPointProvider(
const FilePath& base_path)
: base_path_(base_path),
task_runner_(task_runner),
- local_file_util_(new LocalFileUtil()),
+ local_file_util_(new AsyncFileUtilAdapter(new LocalFileUtil())),
quota_util_(new QuotaUtil) {
UpdateObserverList::Source source;
source.AddObserver(quota_util_.get(), task_runner_);
@@ -111,6 +111,11 @@ bool TestMountPointProvider::IsRestrictedFileName(
}
FileSystemFileUtil* TestMountPointProvider::GetFileUtil(FileSystemType type) {
+ DCHECK(local_file_util_.get());
+ return local_file_util_->sync_file_util();
+}
+
+AsyncFileUtil* TestMountPointProvider::GetAsyncFileUtil(FileSystemType type) {
return local_file_util_.get();
}
diff --git a/webkit/fileapi/test_mount_point_provider.h b/webkit/fileapi/test_mount_point_provider.h
index d61c1e9..4bee102 100644
--- a/webkit/fileapi/test_mount_point_provider.h
+++ b/webkit/fileapi/test_mount_point_provider.h
@@ -8,6 +8,7 @@
#include "base/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "webkit/fileapi/async_file_util_adapter.h"
#include "webkit/fileapi/file_system_mount_point_provider.h"
#include "webkit/fileapi/task_runner_bound_observer_list.h"
#include "webkit/storage/webkit_storage_export.h"
@@ -18,7 +19,7 @@ class SequencedTaskRunner;
namespace fileapi {
-class LocalFileUtil;
+class AsyncFileUtilAdapter;
class FileSystemQuotaUtil;
// This should be only used for testing.
@@ -44,6 +45,7 @@ class WEBKIT_STORAGE_EXPORT_PRIVATE TestMountPointProvider
virtual bool IsAccessAllowed(const FileSystemURL& url) OVERRIDE;
virtual bool IsRestrictedFileName(const FilePath& filename) const OVERRIDE;
virtual FileSystemFileUtil* GetFileUtil(FileSystemType type) OVERRIDE;
+ virtual AsyncFileUtil* GetAsyncFileUtil(FileSystemType type) OVERRIDE;
virtual FilePermissionPolicy GetPermissionPolicy(
const FileSystemURL& url,
int permissions) const OVERRIDE;
@@ -74,7 +76,7 @@ class WEBKIT_STORAGE_EXPORT_PRIVATE TestMountPointProvider
FilePath base_path_;
scoped_refptr<base::SequencedTaskRunner> task_runner_;
- scoped_ptr<LocalFileUtil> local_file_util_;
+ scoped_ptr<AsyncFileUtilAdapter> local_file_util_;
scoped_ptr<QuotaUtil> quota_util_;
UpdateObserverList observers_;
};
diff --git a/webkit/fileapi/webkit_fileapi.gypi b/webkit/fileapi/webkit_fileapi.gypi
index 15a7a6b..471f415 100644
--- a/webkit/fileapi/webkit_fileapi.gypi
+++ b/webkit/fileapi/webkit_fileapi.gypi
@@ -5,6 +5,9 @@
{
'variables': {
'webkit_fileapi_sources': [
+ '../fileapi/async_file_util.h',
+ '../fileapi/async_file_util_adapter.cc',
+ '../fileapi/async_file_util_adapter.h',
'../fileapi/cross_operation_delegate.cc',
'../fileapi/cross_operation_delegate.h',
'../fileapi/external_mount_points.cc',
@@ -25,8 +28,6 @@
'../fileapi/file_system_file_stream_reader.h',
'../fileapi/file_system_file_util.cc',
'../fileapi/file_system_file_util.h',
- '../fileapi/file_system_file_util_proxy.cc',
- '../fileapi/file_system_file_util_proxy.h',
'../fileapi/file_system_mount_point_provider.h',
'../fileapi/file_system_operation.h',
'../fileapi/file_system_operation_context.cc',