summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-11 02:44:53 +0000
committerkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-11 02:44:53 +0000
commitda36b9cb2d717020b2544d4c9179d75685a4092c (patch)
tree4822dbe599b806284c560ad66a17434f8e4badd9 /webkit
parent46d5304577719a2cd312b28db6410abd23fd2f45 (diff)
downloadchromium_src-da36b9cb2d717020b2544d4c9179d75685a4092c.zip
chromium_src-da36b9cb2d717020b2544d4c9179d75685a4092c.tar.gz
chromium_src-da36b9cb2d717020b2544d4c9179d75685a4092c.tar.bz2
Revert 121620 - Refactor FileSystemOperation to take callback for each method.
This patch is the first step for supporting cross-filesystem copy/move on the Filesystem API implementation. To accomplish it, I'm planning to crack FileSystemOperation::{Move,Copy} to a series of other FSO operations. For it, per-method callback is more handy. BUG=110121 TEST=*File* Review URL: http://codereview.chromium.org/9372044 TBR=kinaba@chromium.org Review URL: https://chromiumcodereview.appspot.com/9380040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121623 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/chromeos/fileapi/cros_mount_point_provider.cc5
-rw-r--r--webkit/chromeos/fileapi/cros_mount_point_provider.h1
-rw-r--r--webkit/fileapi/file_system_context.cc22
-rw-r--r--webkit/fileapi/file_system_context.h12
-rw-r--r--webkit/fileapi/file_system_dir_url_request_job.cc73
-rw-r--r--webkit/fileapi/file_system_dir_url_request_job.h3
-rw-r--r--webkit/fileapi/file_system_mount_point_provider.h2
-rw-r--r--webkit/fileapi/file_system_operation.cc348
-rw-r--r--webkit/fileapi/file_system_operation.h169
-rw-r--r--webkit/fileapi/file_system_operation_interface.h99
-rw-r--r--webkit/fileapi/file_system_operation_unittest.cc247
-rw-r--r--webkit/fileapi/file_system_operation_write_unittest.cc85
-rw-r--r--webkit/fileapi/file_system_quota_unittest.cc95
-rw-r--r--webkit/fileapi/file_system_test_helper.cc8
-rw-r--r--webkit/fileapi/file_system_test_helper.h4
-rw-r--r--webkit/fileapi/file_system_url_request_job.cc67
-rw-r--r--webkit/fileapi/file_system_url_request_job.h5
-rw-r--r--webkit/fileapi/file_writer_delegate_unittest.cc66
-rw-r--r--webkit/fileapi/sandbox_mount_point_provider.cc4
-rw-r--r--webkit/fileapi/sandbox_mount_point_provider.h1
-rw-r--r--webkit/tools/test_shell/simple_file_system.cc207
-rw-r--r--webkit/tools/test_shell/simple_file_system.h29
-rw-r--r--webkit/tools/test_shell/simple_file_writer.cc98
23 files changed, 863 insertions, 787 deletions
diff --git a/webkit/chromeos/fileapi/cros_mount_point_provider.cc b/webkit/chromeos/fileapi/cros_mount_point_provider.cc
index 07ab125..011ed76 100644
--- a/webkit/chromeos/fileapi/cros_mount_point_provider.cc
+++ b/webkit/chromeos/fileapi/cros_mount_point_provider.cc
@@ -16,6 +16,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSystem.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
#include "webkit/chromeos/fileapi/file_access_permissions.h"
+#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_operation.h"
#include "webkit/fileapi/file_system_util.h"
#include "webkit/fileapi/native_file_util.h"
@@ -184,11 +185,13 @@ CrosMountPointProvider::CreateFileSystemOperation(
const GURL& origin_url,
fileapi::FileSystemType file_system_type,
const FilePath& virtual_path,
+ scoped_ptr<fileapi::FileSystemCallbackDispatcher> dispatcher,
base::MessageLoopProxy* file_proxy,
fileapi::FileSystemContext* context) const {
// TODO(satorux,zel): instantiate appropriate FileSystemOperation that
// implements async/remote operations.
- return new fileapi::FileSystemOperation(file_proxy, context);
+ return new fileapi::FileSystemOperation(
+ dispatcher.Pass(), file_proxy, context);
}
bool CrosMountPointProvider::GetVirtualPath(const FilePath& filesystem_path,
diff --git a/webkit/chromeos/fileapi/cros_mount_point_provider.h b/webkit/chromeos/fileapi/cros_mount_point_provider.h
index 1ebdab8..a509c11 100644
--- a/webkit/chromeos/fileapi/cros_mount_point_provider.h
+++ b/webkit/chromeos/fileapi/cros_mount_point_provider.h
@@ -57,6 +57,7 @@ class CrosMountPointProvider
const GURL& origin_url,
fileapi::FileSystemType file_system_type,
const FilePath& virtual_path,
+ scoped_ptr<fileapi::FileSystemCallbackDispatcher> dispatcher,
base::MessageLoopProxy* file_proxy,
fileapi::FileSystemContext* context) const OVERRIDE;
diff --git a/webkit/fileapi/file_system_context.cc b/webkit/fileapi/file_system_context.cc
index 2bee4f3..2a806c0 100644
--- a/webkit/fileapi/file_system_context.cc
+++ b/webkit/fileapi/file_system_context.cc
@@ -8,6 +8,7 @@
#include "base/file_util.h"
#include "base/message_loop_proxy.h"
#include "googleurl/src/gurl.h"
+#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_file_util.h"
#include "webkit/fileapi/file_system_operation_interface.h"
#include "webkit/fileapi/file_system_options.h"
@@ -34,11 +35,15 @@ QuotaClient* CreateQuotaClient(
return new FileSystemQuotaClient(file_message_loop, context, is_incognito);
}
-void DidOpenFileSystem(FileSystemContext::OpenFileSystemCallback callback,
+void DidOpenFileSystem(scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
const GURL& filesystem_root,
const std::string& filesystem_name,
base::PlatformFileError error) {
- callback.Run(error, filesystem_name, filesystem_root);
+ if (error == base::PLATFORM_FILE_OK) {
+ dispatcher->DidOpenFileSystem(filesystem_name, filesystem_root);
+ } else {
+ dispatcher->DidFail(error);
+ }
}
} // anonymous namespace
@@ -152,13 +157,13 @@ void FileSystemContext::OpenFileSystem(
const GURL& origin_url,
FileSystemType type,
bool create,
- OpenFileSystemCallback callback) {
- DCHECK(!callback.is_null());
+ scoped_ptr<FileSystemCallbackDispatcher> dispatcher) {
+ DCHECK(dispatcher.get());
FileSystemMountPointProvider* mount_point_provider =
GetMountPointProvider(type);
if (!mount_point_provider) {
- callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, std::string(), GURL());
+ dispatcher->DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
return;
}
@@ -167,11 +172,13 @@ void FileSystemContext::OpenFileSystem(
mount_point_provider->ValidateFileSystemRoot(
origin_url, type, create,
- base::Bind(&DidOpenFileSystem, callback, root_url, name));
+ base::Bind(&DidOpenFileSystem,
+ base::Passed(&dispatcher), root_url, name));
}
FileSystemOperationInterface* FileSystemContext::CreateFileSystemOperation(
const GURL& url,
+ scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
base::MessageLoopProxy* file_proxy) {
GURL origin_url;
FileSystemType file_system_type = kFileSystemTypeUnknown;
@@ -183,7 +190,8 @@ FileSystemOperationInterface* FileSystemContext::CreateFileSystemOperation(
if (!mount_point_provider)
return NULL;
return mount_point_provider->CreateFileSystemOperation(
- origin_url, file_system_type, file_path, file_proxy, this);
+ origin_url, file_system_type, file_path,
+ dispatcher.Pass(), file_proxy, this);
}
} // namespace fileapi
diff --git a/webkit/fileapi/file_system_context.h b/webkit/fileapi/file_system_context.h
index 2a6b211..d57b2e3 100644
--- a/webkit/fileapi/file_system_context.h
+++ b/webkit/fileapi/file_system_context.h
@@ -5,7 +5,6 @@
#ifndef WEBKIT_FILEAPI_FILE_SYSTEM_CONTEXT_H_
#define WEBKIT_FILEAPI_FILE_SYSTEM_CONTEXT_H_
-#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/platform_file.h"
@@ -26,6 +25,8 @@ class QuotaManagerProxy;
namespace fileapi {
class ExternalFileSystemMountPointProvider;
+class FileSystemCallbackDispatcher;
+class FileSystemContext;
class FileSystemFileUtil;
class FileSystemMountPointProvider;
class FileSystemOperationInterface;
@@ -86,21 +87,17 @@ class FileSystemContext
// calling GetMountPointProvider(kFileSystemTypeExternal).
ExternalFileSystemMountPointProvider* external_provider() const;
- // Used for OpenFileSystem.
- typedef base::Callback<void(base::PlatformFileError result,
- const std::string& name,
- const GURL& root)> OpenFileSystemCallback;
-
// Opens the filesystem for the given |origin_url| and |type|, and dispatches
// the DidOpenFileSystem callback of the given |dispatcher|.
// If |create| is true this may actually set up a filesystem instance
// (e.g. by creating the root directory or initializing the database
// entry etc).
+ // TODO(kinuko): replace the dispatcher with a regular callback.
void OpenFileSystem(
const GURL& origin_url,
FileSystemType type,
bool create,
- OpenFileSystemCallback callback);
+ scoped_ptr<FileSystemCallbackDispatcher> dispatcher);
// Creates a new FileSystemOperation instance by cracking
// the given filesystem URL |url| to get an appropriate MountPointProvider
@@ -109,6 +106,7 @@ class FileSystemContext
// depending on the filesystem type pointed by the |url|.
FileSystemOperationInterface* CreateFileSystemOperation(
const GURL& url,
+ scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
base::MessageLoopProxy* file_proxy);
private:
diff --git a/webkit/fileapi/file_system_dir_url_request_job.cc b/webkit/fileapi/file_system_dir_url_request_job.cc
index dc104ff..b96d7e4 100644
--- a/webkit/fileapi/file_system_dir_url_request_job.cc
+++ b/webkit/fileapi/file_system_dir_url_request_job.cc
@@ -20,6 +20,7 @@
#include "net/base/net_errors.h"
#include "net/base/net_util.h"
#include "net/url_request/url_request.h"
+#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_operation.h"
#include "webkit/fileapi/file_system_util.h"
@@ -38,6 +39,60 @@ static FilePath GetRelativePath(const GURL& url) {
return relative_path;
}
+class FileSystemDirURLRequestJob::CallbackDispatcher
+ : public FileSystemCallbackDispatcher {
+ public:
+ // An instance of this class must be created by Create()
+ // (so that we do not leak ownership).
+ static scoped_ptr<FileSystemCallbackDispatcher> Create(
+ FileSystemDirURLRequestJob* job) {
+ return scoped_ptr<FileSystemCallbackDispatcher>(
+ new CallbackDispatcher(job));
+ }
+
+ // fileapi::FileSystemCallbackDispatcher overrides.
+ virtual void DidSucceed() OVERRIDE {
+ NOTREACHED();
+ }
+
+ virtual void DidReadMetadata(const base::PlatformFileInfo& file_info,
+ const FilePath& platform_path) OVERRIDE {
+ NOTREACHED();
+ }
+
+ virtual void DidReadDirectory(
+ const std::vector<base::FileUtilProxy::Entry>& entries,
+ bool has_more) OVERRIDE {
+ job_->DidReadDirectory(entries, has_more);
+ }
+
+ virtual void DidWrite(int64 bytes, bool complete) OVERRIDE {
+ NOTREACHED();
+ }
+
+ virtual void DidOpenFileSystem(const std::string& name,
+ const GURL& root_path) OVERRIDE {
+ NOTREACHED();
+ }
+
+ virtual void DidFail(base::PlatformFileError error_code) OVERRIDE {
+ int rv = net::ERR_FILE_NOT_FOUND;
+ if (error_code == base::PLATFORM_FILE_ERROR_INVALID_URL)
+ rv = net::ERR_INVALID_URL;
+ job_->NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
+ }
+
+ private:
+ explicit CallbackDispatcher(FileSystemDirURLRequestJob* job) : job_(job) {
+ DCHECK(job_);
+ }
+
+ // TODO(adamk): Get rid of the need for refcounting here by
+ // allowing FileSystemOperations to be cancelled.
+ scoped_refptr<FileSystemDirURLRequestJob> job_;
+ DISALLOW_COPY_AND_ASSIGN(CallbackDispatcher);
+};
+
FileSystemDirURLRequestJob::FileSystemDirURLRequestJob(
URLRequest* request, FileSystemContext* file_system_context,
scoped_refptr<base::MessageLoopProxy> file_thread_proxy)
@@ -93,23 +148,12 @@ void FileSystemDirURLRequestJob::StartAsync() {
net::ERR_INVALID_URL));
return;
}
- operation->ReadDirectory(
- request_->url(),
- base::Bind(&FileSystemDirURLRequestJob::DidReadDirectory, this));
+ operation->ReadDirectory(request_->url());
}
void FileSystemDirURLRequestJob::DidReadDirectory(
- base::PlatformFileError result,
const std::vector<base::FileUtilProxy::Entry>& entries,
bool has_more) {
- if (result != base::PLATFORM_FILE_OK) {
- int rv = net::ERR_FILE_NOT_FOUND;
- if (result == base::PLATFORM_FILE_ERROR_INVALID_URL)
- rv = net::ERR_INVALID_URL;
- NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
- return;
- }
-
if (!request_)
return;
@@ -138,9 +182,7 @@ void FileSystemDirURLRequestJob::DidReadDirectory(
}
if (has_more) {
- GetNewOperation(request_->url())->ReadDirectory(
- request_->url(),
- base::Bind(&FileSystemDirURLRequestJob::DidReadDirectory, this));
+ GetNewOperation(request_->url())->ReadDirectory(request_->url());
} else {
set_expected_content_size(data_.size());
NotifyHeadersComplete();
@@ -151,6 +193,7 @@ FileSystemOperationInterface*
FileSystemDirURLRequestJob::GetNewOperation(const GURL& url) {
return file_system_context_->CreateFileSystemOperation(
url,
+ CallbackDispatcher::Create(this),
file_thread_proxy_);
}
diff --git a/webkit/fileapi/file_system_dir_url_request_job.h b/webkit/fileapi/file_system_dir_url_request_job.h
index fd95130..1e7179b 100644
--- a/webkit/fileapi/file_system_dir_url_request_job.h
+++ b/webkit/fileapi/file_system_dir_url_request_job.h
@@ -47,8 +47,7 @@ class FileSystemDirURLRequestJob : public net::URLRequestJob {
virtual ~FileSystemDirURLRequestJob();
void StartAsync();
- void DidReadDirectory(base::PlatformFileError result,
- const std::vector<base::FileUtilProxy::Entry>& entries,
+ void DidReadDirectory(const std::vector<base::FileUtilProxy::Entry>& entries,
bool has_more);
FileSystemOperationInterface* GetNewOperation(const GURL& url);
diff --git a/webkit/fileapi/file_system_mount_point_provider.h b/webkit/fileapi/file_system_mount_point_provider.h
index cbd56b7..1ea6182 100644
--- a/webkit/fileapi/file_system_mount_point_provider.h
+++ b/webkit/fileapi/file_system_mount_point_provider.h
@@ -23,6 +23,7 @@ class MessageLoopProxy;
namespace fileapi {
+class FileSystemCallbackDispatcher;
class FileSystemContext;
class FileSystemFileUtil;
class FileSystemOperationInterface;
@@ -83,6 +84,7 @@ class FileSystemMountPointProvider {
const GURL& origin_url,
FileSystemType file_system_type,
const FilePath& virtual_path,
+ scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
base::MessageLoopProxy* file_proxy,
FileSystemContext* context) const = 0;
};
diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc
index 2be9c4e..b12c5bf 100644
--- a/webkit/fileapi/file_system_operation.cc
+++ b/webkit/fileapi/file_system_operation.cc
@@ -9,6 +9,7 @@
#include "base/utf_string_conversions.h"
#include "net/base/escape.h"
#include "net/url_request/url_request_context.h"
+#include "webkit/fileapi/file_system_callback_dispatcher.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"
@@ -71,26 +72,22 @@ FileSystemOperation::~FileSystemOperation() {
}
void FileSystemOperation::CreateFile(const GURL& path,
- bool exclusive,
- const StatusCallback& callback) {
+ bool exclusive) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationCreateFile;
#endif
- base::PlatformFileError result = SetupSrcContextForWrite(path, true);
- if (result != base::PLATFORM_FILE_OK) {
- callback.Run(result);
+ if (!SetupSrcContextForWrite(path, true)) {
delete this;
return;
}
GetUsageAndQuotaThenCallback(
operation_context_.src_origin_url(),
base::Bind(&FileSystemOperation::DelayedCreateFileForQuota,
- base::Unretained(this), callback, exclusive));
+ base::Unretained(this), exclusive));
}
void FileSystemOperation::DelayedCreateFileForQuota(
- const StatusCallback& callback,
bool exclusive,
quota::QuotaStatusCode status, int64 usage, int64 quota) {
operation_context_.set_allowed_bytes_growth(quota - usage);
@@ -108,31 +105,27 @@ void FileSystemOperation::DelayedCreateFileForQuota(
base::Bind(
exclusive ? &FileSystemOperation::DidEnsureFileExistsExclusive
: &FileSystemOperation::DidEnsureFileExistsNonExclusive,
- base::Owned(this), callback));
+ base::Owned(this)));
}
void FileSystemOperation::CreateDirectory(const GURL& path,
bool exclusive,
- bool recursive,
- const StatusCallback& callback) {
+ bool recursive) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationCreateDirectory;
#endif
- base::PlatformFileError result = SetupSrcContextForWrite(path, true);
- if (result != base::PLATFORM_FILE_OK) {
- callback.Run(result);
+ if (!SetupSrcContextForWrite(path, true)) {
delete this;
return;
}
GetUsageAndQuotaThenCallback(
operation_context_.src_origin_url(),
base::Bind(&FileSystemOperation::DelayedCreateDirectoryForQuota,
- base::Unretained(this), callback, exclusive, recursive));
+ base::Unretained(this), exclusive, recursive));
}
void FileSystemOperation::DelayedCreateDirectoryForQuota(
- const StatusCallback& callback,
bool exclusive, bool recursive,
quota::QuotaStatusCode status, int64 usage, int64 quota) {
operation_context_.set_allowed_bytes_growth(quota - usage);
@@ -149,21 +142,17 @@ void FileSystemOperation::DelayedCreateDirectoryForQuota(
&operation_context_,
src_virtual_path_, exclusive, recursive),
base::Bind(&FileSystemOperation::DidFinishFileOperation,
- base::Owned(this), callback));
+ base::Owned(this)));
}
void FileSystemOperation::Copy(const GURL& src_path,
- const GURL& dest_path,
- const StatusCallback& callback) {
+ const GURL& dest_path) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationCopy;
#endif
- base::PlatformFileError result = SetupSrcContextForRead(src_path);
- if (result == base::PLATFORM_FILE_OK)
- result = SetupDestContextForWrite(dest_path, true);
- if (result != base::PLATFORM_FILE_OK) {
- callback.Run(result);
+ if (!SetupSrcContextForRead(src_path) ||
+ !SetupDestContextForWrite(dest_path, true)) {
delete this;
return;
}
@@ -171,11 +160,10 @@ void FileSystemOperation::Copy(const GURL& src_path,
GetUsageAndQuotaThenCallback(
operation_context_.dest_origin_url(),
base::Bind(&FileSystemOperation::DelayedCopyForQuota,
- base::Unretained(this), callback));
+ base::Unretained(this)));
}
-void FileSystemOperation::DelayedCopyForQuota(const StatusCallback& callback,
- quota::QuotaStatusCode status,
+void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status,
int64 usage, int64 quota) {
operation_context_.set_allowed_bytes_growth(quota - usage);
@@ -191,21 +179,17 @@ void FileSystemOperation::DelayedCopyForQuota(const StatusCallback& callback,
&operation_context_,
src_virtual_path_, dest_virtual_path_),
base::Bind(&FileSystemOperation::DidFinishFileOperation,
- base::Owned(this), callback));
+ base::Owned(this)));
}
void FileSystemOperation::Move(const GURL& src_path,
- const GURL& dest_path,
- const StatusCallback& callback) {
+ const GURL& dest_path) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationMove;
#endif
- base::PlatformFileError result = SetupSrcContextForWrite(src_path, false);
- if (result == base::PLATFORM_FILE_OK)
- result = SetupDestContextForWrite(dest_path, true);
- if (result != base::PLATFORM_FILE_OK) {
- callback.Run(result);
+ if (!SetupSrcContextForWrite(src_path, false) ||
+ !SetupDestContextForWrite(dest_path, true)) {
delete this;
return;
}
@@ -213,11 +197,10 @@ void FileSystemOperation::Move(const GURL& src_path,
GetUsageAndQuotaThenCallback(
operation_context_.dest_origin_url(),
base::Bind(&FileSystemOperation::DelayedMoveForQuota,
- base::Unretained(this), callback));
+ base::Unretained(this)));
}
-void FileSystemOperation::DelayedMoveForQuota(const StatusCallback& callback,
- quota::QuotaStatusCode status,
+void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status,
int64 usage, int64 quota) {
operation_context_.set_allowed_bytes_growth(quota - usage);
@@ -233,18 +216,15 @@ void FileSystemOperation::DelayedMoveForQuota(const StatusCallback& callback,
&operation_context_,
src_virtual_path_, dest_virtual_path_),
base::Bind(&FileSystemOperation::DidFinishFileOperation,
- base::Owned(this), callback));
+ base::Owned(this)));
}
-void FileSystemOperation::DirectoryExists(const GURL& path,
- const StatusCallback& callback) {
+void FileSystemOperation::DirectoryExists(const GURL& path) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationDirectoryExists;
#endif
- base::PlatformFileError result = SetupSrcContextForRead(path);
- if (result != base::PLATFORM_FILE_OK) {
- callback.Run(result);
+ if (!SetupSrcContextForRead(path)) {
delete this;
return;
}
@@ -254,19 +234,15 @@ void FileSystemOperation::DirectoryExists(const GURL& path,
base::Bind(&FileSystemFileUtil::GetFileInfo,
base::Unretained(operation_context_.src_file_util()),
&operation_context_, src_virtual_path_),
- base::Bind(&FileSystemOperation::DidDirectoryExists,
- base::Owned(this), callback));
+ base::Bind(&FileSystemOperation::DidDirectoryExists, base::Owned(this)));
}
-void FileSystemOperation::FileExists(const GURL& path,
- const StatusCallback& callback) {
+void FileSystemOperation::FileExists(const GURL& path) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationFileExists;
#endif
- base::PlatformFileError result = SetupSrcContextForRead(path);
- if (result != base::PLATFORM_FILE_OK) {
- callback.Run(result);
+ if (!SetupSrcContextForRead(path)) {
delete this;
return;
}
@@ -276,19 +252,15 @@ void FileSystemOperation::FileExists(const GURL& path,
base::Bind(&FileSystemFileUtil::GetFileInfo,
base::Unretained(operation_context_.src_file_util()),
&operation_context_, src_virtual_path_),
- base::Bind(&FileSystemOperation::DidFileExists,
- base::Owned(this), callback));
+ base::Bind(&FileSystemOperation::DidFileExists, base::Owned(this)));
}
-void FileSystemOperation::GetMetadata(const GURL& path,
- const GetMetadataCallback& callback) {
+void FileSystemOperation::GetMetadata(const GURL& path) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationGetMetadata;
#endif
- base::PlatformFileError result = SetupSrcContextForRead(path);
- if (result != base::PLATFORM_FILE_OK) {
- callback.Run(result, base::PlatformFileInfo(), FilePath());
+ if (!SetupSrcContextForRead(path)) {
delete this;
return;
}
@@ -298,19 +270,15 @@ void FileSystemOperation::GetMetadata(const GURL& path,
base::Bind(&FileSystemFileUtil::GetFileInfo,
base::Unretained(operation_context_.src_file_util()),
&operation_context_, src_virtual_path_),
- base::Bind(&FileSystemOperation::DidGetMetadata,
- base::Owned(this), callback));
+ base::Bind(&FileSystemOperation::DidGetMetadata, base::Owned(this)));
}
-void FileSystemOperation::ReadDirectory(const GURL& path,
- const ReadDirectoryCallback& callback) {
+void FileSystemOperation::ReadDirectory(const GURL& path) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationReadDirectory;
#endif
- base::PlatformFileError result = SetupSrcContextForRead(path);
- if (result != base::PLATFORM_FILE_OK) {
- callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false);
+ if (!SetupSrcContextForRead(path)) {
delete this;
return;
}
@@ -320,19 +288,15 @@ void FileSystemOperation::ReadDirectory(const GURL& path,
base::Bind(&FileSystemFileUtil::ReadDirectory,
base::Unretained(operation_context_.src_file_util()),
&operation_context_, src_virtual_path_),
- base::Bind(&FileSystemOperation::DidReadDirectory,
- base::Owned(this), callback));
+ base::Bind(&FileSystemOperation::DidReadDirectory, base::Owned(this)));
}
-void FileSystemOperation::Remove(const GURL& path, bool recursive,
- const StatusCallback& callback) {
+void FileSystemOperation::Remove(const GURL& path, bool recursive) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationRemove;
#endif
- base::PlatformFileError result = SetupSrcContextForWrite(path, false);
- if (result != base::PLATFORM_FILE_OK) {
- callback.Run(result);
+ if (!SetupSrcContextForWrite(path, false)) {
delete this;
return;
}
@@ -343,28 +307,24 @@ void FileSystemOperation::Remove(const GURL& path, bool recursive,
base::Unretained(operation_context_.src_file_util()),
&operation_context_, src_virtual_path_, recursive),
base::Bind(&FileSystemOperation::DidFinishFileOperation,
- base::Owned(this), callback));
+ base::Owned(this)));
}
void FileSystemOperation::Write(
const net::URLRequestContext* url_request_context,
const GURL& path,
const GURL& blob_url,
- int64 offset,
- const WriteCallback& callback) {
+ int64 offset) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationWrite;
#endif
- base::PlatformFileError result = SetupSrcContextForWrite(path, true);
- if (result != base::PLATFORM_FILE_OK) {
- callback.Run(result, 0, false);
+ if (!SetupSrcContextForWrite(path, true)) {
delete this;
return;
}
DCHECK(blob_url.is_valid());
file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_));
- set_write_callback(callback);
blob_request_.reset(
new net::URLRequest(blob_url, file_writer_delegate_.get()));
blob_request_->set_context(url_request_context);
@@ -400,27 +360,24 @@ void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status,
base::Unretained(this)));
}
-void FileSystemOperation::Truncate(const GURL& path, int64 length,
- const StatusCallback& callback) {
+void FileSystemOperation::Truncate(const GURL& path, int64 length) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationTruncate;
#endif
- base::PlatformFileError result = SetupSrcContextForWrite(path, false);
- if (result != base::PLATFORM_FILE_OK) {
- callback.Run(result);
+ if (!SetupSrcContextForWrite(path, false)) {
delete this;
return;
}
GetUsageAndQuotaThenCallback(
operation_context_.src_origin_url(),
base::Bind(&FileSystemOperation::DelayedTruncateForQuota,
- base::Unretained(this), callback, length));
+ base::Unretained(this), length));
}
-void FileSystemOperation::DelayedTruncateForQuota(
- const StatusCallback& callback,
- int64 length, quota::QuotaStatusCode status, int64 usage, int64 quota) {
+void FileSystemOperation::DelayedTruncateForQuota(int64 length,
+ quota::QuotaStatusCode status,
+ int64 usage, int64 quota) {
operation_context_.set_allowed_bytes_growth(quota - usage);
quota_util_helper_.reset(new ScopedQuotaUtilHelper(
@@ -434,20 +391,17 @@ void FileSystemOperation::DelayedTruncateForQuota(
base::Unretained(operation_context_.src_file_util()),
&operation_context_, src_virtual_path_, length),
base::Bind(&FileSystemOperation::DidFinishFileOperation,
- base::Owned(this), callback));
+ base::Owned(this)));
}
void FileSystemOperation::TouchFile(const GURL& path,
const base::Time& last_access_time,
- const base::Time& last_modified_time,
- const StatusCallback& callback) {
+ const base::Time& last_modified_time) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationTouchFile;
#endif
- base::PlatformFileError result = SetupSrcContextForWrite(path, true);
- if (result != base::PLATFORM_FILE_OK) {
- callback.Run(result);
+ if (!SetupSrcContextForWrite(path, true)) {
delete this;
return;
}
@@ -458,14 +412,12 @@ void FileSystemOperation::TouchFile(const GURL& path,
base::Unretained(operation_context_.src_file_util()),
&operation_context_,
src_virtual_path_, last_access_time, last_modified_time),
- base::Bind(&FileSystemOperation::DidTouchFile,
- base::Owned(this), callback));
+ base::Bind(&FileSystemOperation::DidTouchFile, base::Owned(this)));
}
void FileSystemOperation::OpenFile(const GURL& path,
int file_flags,
- base::ProcessHandle peer_handle,
- const OpenFileCallback& callback) {
+ base::ProcessHandle peer_handle) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationOpenFile;
@@ -475,8 +427,6 @@ void FileSystemOperation::OpenFile(const GURL& path,
if (file_flags & (
(base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY |
base::PLATFORM_FILE_HIDDEN))) {
- callback.Run(base::PLATFORM_FILE_ERROR_FAILED,
- base::PlatformFile(), base::ProcessHandle());
delete this;
return;
}
@@ -486,16 +436,12 @@ void FileSystemOperation::OpenFile(const GURL& path,
base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE |
base::PLATFORM_FILE_DELETE_ON_CLOSE |
base::PLATFORM_FILE_WRITE_ATTRIBUTES)) {
- base::PlatformFileError result = SetupSrcContextForWrite(path, true);
- if (result != base::PLATFORM_FILE_OK) {
- callback.Run(result, base::PlatformFile(), base::ProcessHandle());
+ if (!SetupSrcContextForWrite(path, true)) {
delete this;
return;
}
} else {
- base::PlatformFileError result = SetupSrcContextForRead(path);
- if (result != base::PLATFORM_FILE_OK) {
- callback.Run(result, base::PlatformFile(), base::ProcessHandle());
+ if (!SetupSrcContextForRead(path)) {
delete this;
return;
}
@@ -503,12 +449,12 @@ void FileSystemOperation::OpenFile(const GURL& path,
GetUsageAndQuotaThenCallback(
operation_context_.src_origin_url(),
base::Bind(&FileSystemOperation::DelayedOpenFileForQuota,
- base::Unretained(this), callback, file_flags));
+ base::Unretained(this), file_flags));
}
-void FileSystemOperation::DelayedOpenFileForQuota(
- const OpenFileCallback& callback,
- int file_flags, quota::QuotaStatusCode status, int64 usage, int64 quota) {
+void FileSystemOperation::DelayedOpenFileForQuota(int file_flags,
+ quota::QuotaStatusCode status,
+ int64 usage, int64 quota) {
operation_context_.set_allowed_bytes_growth(quota - usage);
quota_util_helper_.reset(new ScopedQuotaUtilHelper(
@@ -525,13 +471,13 @@ void FileSystemOperation::DelayedOpenFileForQuota(
base::Bind(&FileSystemFileUtil::Close,
base::Unretained(operation_context_.src_file_util()),
&operation_context_),
- base::Bind(&FileSystemOperation::DidOpenFile,
- base::Owned(this), callback));
+ base::Bind(&FileSystemOperation::DidOpenFile, base::Owned(this)));
}
// We can only get here on a write or truncate that's not yet completed.
// We don't support cancelling any other operation at this time.
-void FileSystemOperation::Cancel(const StatusCallback& cancel_callback) {
+void FileSystemOperation::Cancel(
+ scoped_ptr<FileSystemCallbackDispatcher> cancel_dispatcher) {
if (file_writer_delegate_.get()) {
#ifndef NDEBUG
DCHECK(kOperationWrite == pending_operation_);
@@ -545,19 +491,20 @@ void FileSystemOperation::Cancel(const StatusCallback& cancel_callback) {
// This halts any calls to file_writer_delegate_ from blob_request_.
blob_request_->Cancel();
- // DidWrite deletes this object.
- DidWrite(base::PLATFORM_FILE_ERROR_ABORT, 0, false);
- cancel_callback.Run(base::PLATFORM_FILE_OK);
+ if (dispatcher_.get())
+ dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_ABORT);
+ cancel_dispatcher->DidSucceed();
+ dispatcher_.reset();
} else {
#ifndef NDEBUG
DCHECK(kOperationTruncate == pending_operation_);
#endif
// We're cancelling a truncate operation, but we can't actually stop it
// since it's been proxied to another thread. We need to save the
- // cancel_callback so that when the truncate returns, it can see that it's
+ // cancel_dispatcher so that when the truncate returns, it can see that it's
// been cancelled, report it, and report that the cancel has succeeded.
- DCHECK(cancel_callback_.is_null());
- cancel_callback_ = cancel_callback;
+ DCHECK(!cancel_dispatcher_.get());
+ cancel_dispatcher_ = cancel_dispatcher.Pass();
}
}
@@ -571,8 +518,7 @@ void FileSystemOperation::SyncGetPlatformPath(const GURL& path,
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationGetLocalPath;
#endif
- base::PlatformFileError result = SetupSrcContextForRead(path);
- if (result != base::PLATFORM_FILE_OK) {
+ if (!SetupSrcContextForRead(path)) {
delete this;
return;
}
@@ -584,9 +530,11 @@ void FileSystemOperation::SyncGetPlatformPath(const GURL& path,
}
FileSystemOperation::FileSystemOperation(
+ scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
scoped_refptr<base::MessageLoopProxy> proxy,
FileSystemContext* file_system_context)
: proxy_(proxy),
+ dispatcher_(dispatcher.Pass()),
operation_context_(file_system_context, NULL),
peer_handle_(base::kNullProcessHandle) {
#ifndef NDEBUG
@@ -617,114 +565,151 @@ void FileSystemOperation::GetUsageAndQuotaThenCallback(
}
void FileSystemOperation::DidEnsureFileExistsExclusive(
- const StatusCallback& callback,
base::PlatformFileError rv, bool created) {
if (rv == base::PLATFORM_FILE_OK && !created) {
- callback.Run(base::PLATFORM_FILE_ERROR_EXISTS);
+ if (dispatcher_.get())
+ dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_EXISTS);
} else {
- DidFinishFileOperation(callback, rv);
+ DidFinishFileOperation(rv);
}
}
void FileSystemOperation::DidEnsureFileExistsNonExclusive(
- const StatusCallback& callback,
base::PlatformFileError rv, bool /* created */) {
- DidFinishFileOperation(callback, rv);
+ DidFinishFileOperation(rv);
}
void FileSystemOperation::DidFinishFileOperation(
- const StatusCallback& callback,
base::PlatformFileError rv) {
- if (!cancel_callback_.is_null()) {
+ if (cancel_dispatcher_.get()) {
#ifndef NDEBUG
DCHECK(kOperationTruncate == pending_operation_);
#endif
- callback.Run(base::PLATFORM_FILE_ERROR_ABORT);
- cancel_callback_.Run(base::PLATFORM_FILE_OK);
- cancel_callback_.Reset();
- } else {
- callback.Run(rv);
+
+ if (dispatcher_.get())
+ dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_ABORT);
+ cancel_dispatcher_->DidSucceed();
+ } else if (dispatcher_.get()) {
+ if (rv == base::PLATFORM_FILE_OK)
+ dispatcher_->DidSucceed();
+ else
+ dispatcher_->DidFail(rv);
}
}
void FileSystemOperation::DidDirectoryExists(
- const StatusCallback& callback,
base::PlatformFileError rv,
const base::PlatformFileInfo& file_info,
const FilePath& unused) {
- if (rv == base::PLATFORM_FILE_OK && !file_info.is_directory)
- rv = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY;
- callback.Run(rv);
+ if (!dispatcher_.get())
+ return;
+ if (rv == base::PLATFORM_FILE_OK) {
+ if (file_info.is_directory)
+ dispatcher_->DidSucceed();
+ else
+ dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY);
+ } else {
+ dispatcher_->DidFail(rv);
+ }
}
void FileSystemOperation::DidFileExists(
- const StatusCallback& callback,
base::PlatformFileError rv,
const base::PlatformFileInfo& file_info,
const FilePath& unused) {
- if (rv == base::PLATFORM_FILE_OK && file_info.is_directory)
- rv = base::PLATFORM_FILE_ERROR_NOT_A_FILE;
- callback.Run(rv);
+ if (!dispatcher_.get())
+ return;
+ if (rv == base::PLATFORM_FILE_OK) {
+ if (file_info.is_directory)
+ dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NOT_A_FILE);
+ else
+ dispatcher_->DidSucceed();
+ } else {
+ dispatcher_->DidFail(rv);
+ }
}
void FileSystemOperation::DidGetMetadata(
- const GetMetadataCallback& callback,
base::PlatformFileError rv,
const base::PlatformFileInfo& file_info,
const FilePath& platform_path) {
- callback.Run(rv, file_info, platform_path);
+ if (!dispatcher_.get())
+ return;
+ if (rv == base::PLATFORM_FILE_OK)
+ dispatcher_->DidReadMetadata(file_info, platform_path);
+ else
+ dispatcher_->DidFail(rv);
}
void FileSystemOperation::DidReadDirectory(
- const ReadDirectoryCallback& callback,
base::PlatformFileError rv,
const std::vector<base::FileUtilProxy::Entry>& entries) {
- callback.Run(rv, entries, false /* has_more */);
+ if (!dispatcher_.get())
+ return;
+
+ if (rv == base::PLATFORM_FILE_OK)
+ dispatcher_->DidReadDirectory(entries, false /* has_more */);
+ else
+ dispatcher_->DidFail(rv);
}
void FileSystemOperation::DidWrite(
base::PlatformFileError rv,
int64 bytes,
bool complete) {
- write_callback_.Run(rv, bytes, complete);
+ if (!dispatcher_.get()) {
+ delete this;
+ return;
+ }
+ if (rv == base::PLATFORM_FILE_OK)
+ dispatcher_->DidWrite(bytes, complete);
+ else
+ dispatcher_->DidFail(rv);
if (complete || rv != base::PLATFORM_FILE_OK)
delete this;
}
-void FileSystemOperation::DidTouchFile(const StatusCallback& callback,
- base::PlatformFileError rv) {
- callback.Run(rv);
+void FileSystemOperation::DidTouchFile(base::PlatformFileError rv) {
+ if (!dispatcher_.get())
+ return;
+ if (rv == base::PLATFORM_FILE_OK)
+ dispatcher_->DidSucceed();
+ else
+ dispatcher_->DidFail(rv);
}
void FileSystemOperation::DidOpenFile(
- const OpenFileCallback& callback,
base::PlatformFileError rv,
base::PassPlatformFile file,
bool unused) {
- if (rv == base::PLATFORM_FILE_OK)
+ if (!dispatcher_.get())
+ return;
+ if (rv == base::PLATFORM_FILE_OK) {
CHECK_NE(base::kNullProcessHandle, peer_handle_);
- callback.Run(rv, file.ReleaseValue(), peer_handle_);
+ dispatcher_->DidOpenFile(file.ReleaseValue(), peer_handle_);
+ } else {
+ dispatcher_->DidFail(rv);
+ }
}
void FileSystemOperation::OnFileOpenedForWrite(
base::PlatformFileError rv,
base::PassPlatformFile file,
bool created) {
- if (rv != base::PLATFORM_FILE_OK) {
- write_callback_.Run(rv, 0, false);
+ if (base::PLATFORM_FILE_OK != rv || !dispatcher_.get()) {
+ if (dispatcher_.get())
+ dispatcher_->DidFail(rv);
delete this;
return;
}
file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get());
}
-base::PlatformFileError FileSystemOperation::VerifyFileSystemPathForRead(
+bool FileSystemOperation::VerifyFileSystemPathForRead(
const GURL& path, GURL* origin_url, FileSystemType* type,
FilePath* virtual_path, FileSystemFileUtil** file_util) {
- base::PlatformFileError rv =
- VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util);
- if (rv != base::PLATFORM_FILE_OK)
- return rv;
+ if (!VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util))
+ return false;
// We notify this read access whether the read access succeeds or not.
// This must be ok since this is used to let the QM's eviction logic know
@@ -738,56 +723,57 @@ base::PlatformFileError FileSystemOperation::VerifyFileSystemPathForRead(
*type);
}
- return base::PLATFORM_FILE_OK;
+ return true;
}
-base::PlatformFileError FileSystemOperation::VerifyFileSystemPathForWrite(
+bool FileSystemOperation::VerifyFileSystemPathForWrite(
const GURL& path, bool create, GURL* origin_url, FileSystemType* type,
FilePath* virtual_path, FileSystemFileUtil** file_util) {
- base::PlatformFileError rv =
- VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util);
- if (rv != base::PLATFORM_FILE_OK)
- return rv;
+ if (!VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util))
+ return false;
// Any write access is disallowed on the root path.
if (virtual_path->value().length() == 0 ||
virtual_path->DirName().value() == virtual_path->value()) {
- return base::PLATFORM_FILE_ERROR_SECURITY;
+ dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
+ return false;
}
if (create &&
file_system_context()->GetMountPointProvider(*type)->IsRestrictedFileName(
virtual_path->BaseName())) {
- return base::PLATFORM_FILE_ERROR_SECURITY;
+ dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
+ return false;
}
- return base::PLATFORM_FILE_OK;
+ return true;
}
-base::PlatformFileError FileSystemOperation::VerifyFileSystemPath(
+bool FileSystemOperation::VerifyFileSystemPath(
const GURL& path, GURL* origin_url, FileSystemType* type,
FilePath* virtual_path, FileSystemFileUtil** file_util) {
DCHECK(file_system_context());
if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) {
- return base::PLATFORM_FILE_ERROR_INVALID_URL;
+ dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_URL);
+ return false;
}
if (!file_system_context()->GetMountPointProvider(*type)->IsAccessAllowed(
*origin_url, *type, *virtual_path)) {
- return base::PLATFORM_FILE_ERROR_SECURITY;
+ dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
+ return false;
}
DCHECK(file_util);
*file_util = file_system_context()->GetFileUtil(*type);
DCHECK(*file_util);
- return base::PLATFORM_FILE_OK;
+ return true;
}
-base::PlatformFileError FileSystemOperation::SetupSrcContextForRead(
- const GURL& path) {
+bool FileSystemOperation::SetupSrcContextForRead(const GURL& path) {
GURL origin_url;
FileSystemType type;
FileSystemFileUtil* file_util;
- base::PlatformFileError result = VerifyFileSystemPathForRead(
+ bool result = VerifyFileSystemPathForRead(
path, &origin_url, &type, &src_virtual_path_, &file_util);
operation_context_.set_src_origin_url(origin_url);
operation_context_.set_src_type(type);
@@ -796,13 +782,12 @@ base::PlatformFileError FileSystemOperation::SetupSrcContextForRead(
return result;
}
-base::PlatformFileError FileSystemOperation::SetupSrcContextForWrite(
- const GURL& path,
- bool create) {
+bool FileSystemOperation::SetupSrcContextForWrite(const GURL& path,
+ bool create) {
GURL origin_url;
FileSystemType type;
FileSystemFileUtil* file_util = NULL;
- base::PlatformFileError result = VerifyFileSystemPathForWrite(
+ bool result = VerifyFileSystemPathForWrite(
path, create, &origin_url, &type, &src_virtual_path_, &file_util);
operation_context_.set_src_origin_url(origin_url);
operation_context_.set_src_type(type);
@@ -811,13 +796,12 @@ base::PlatformFileError FileSystemOperation::SetupSrcContextForWrite(
return result;
}
-base::PlatformFileError FileSystemOperation::SetupDestContextForWrite(
- const GURL& path,
- bool create) {
+bool FileSystemOperation::SetupDestContextForWrite(const GURL& path,
+ bool create) {
GURL origin_url;
FileSystemType type;
FileSystemFileUtil* file_util = NULL;
- base::PlatformFileError result = VerifyFileSystemPathForWrite(
+ bool result = VerifyFileSystemPathForWrite(
path, create, &origin_url, &type, &dest_virtual_path_, &file_util);
operation_context_.set_dest_origin_url(origin_url);
operation_context_.set_dest_type(type);
diff --git a/webkit/fileapi/file_system_operation.h b/webkit/fileapi/file_system_operation.h
index 270406f..fa3161c 100644
--- a/webkit/fileapi/file_system_operation.h
+++ b/webkit/fileapi/file_system_operation.h
@@ -39,6 +39,7 @@ class GURL;
namespace fileapi {
+class FileSystemCallbackDispatcher;
class FileSystemContext;
class FileWriterDelegate;
class FileSystemOperationTest;
@@ -50,44 +51,33 @@ class FileSystemOperation : public FileSystemOperationInterface {
// FileSystemOperation overrides.
virtual void CreateFile(const GURL& path,
- bool exclusive,
- const StatusCallback& callback) OVERRIDE;
+ bool exclusive) OVERRIDE;
virtual void CreateDirectory(const GURL& path,
bool exclusive,
- bool recursive,
- const StatusCallback& callback) OVERRIDE;
+ bool recursive) OVERRIDE;
virtual void Copy(const GURL& src_path,
- const GURL& dest_path,
- const StatusCallback& callback) OVERRIDE;
+ const GURL& dest_path) OVERRIDE;
virtual void Move(const GURL& src_path,
- const GURL& dest_path,
- const StatusCallback& callback) OVERRIDE;
- virtual void DirectoryExists(const GURL& path,
- const StatusCallback& callback) OVERRIDE;
- virtual void FileExists(const GURL& path,
- const StatusCallback& callback) OVERRIDE;
- virtual void GetMetadata(const GURL& path,
- const GetMetadataCallback& callback) OVERRIDE;
- virtual void ReadDirectory(const GURL& path,
- const ReadDirectoryCallback& callback) OVERRIDE;
- virtual void Remove(const GURL& path, bool recursive,
- const StatusCallback& callback) OVERRIDE;
+ const GURL& dest_path) OVERRIDE;
+ virtual void DirectoryExists(const GURL& path) OVERRIDE;
+ virtual void FileExists(const GURL& path) OVERRIDE;
+ virtual void GetMetadata(const GURL& path) OVERRIDE;
+ virtual void ReadDirectory(const GURL& path) OVERRIDE;
+ virtual void Remove(const GURL& path, bool recursive) OVERRIDE;
virtual void Write(const net::URLRequestContext* url_request_context,
const GURL& path,
const GURL& blob_url,
- int64 offset,
- const WriteCallback& callback) OVERRIDE;
- virtual void Truncate(const GURL& path, int64 length,
- const StatusCallback& callback) OVERRIDE;
+ int64 offset) OVERRIDE;
+ virtual void Truncate(const GURL& path, int64 length) OVERRIDE;
virtual void TouchFile(const GURL& path,
const base::Time& last_access_time,
- const base::Time& last_modified_time,
- const StatusCallback& callback) OVERRIDE;
- virtual void OpenFile(const GURL& path,
- int file_flags,
- base::ProcessHandle peer_handle,
- const OpenFileCallback& callback) OVERRIDE;
- virtual void Cancel(const StatusCallback& cancel_callback) OVERRIDE;
+ const base::Time& last_modified_time) OVERRIDE;
+ virtual void OpenFile(
+ const GURL& path,
+ int file_flags,
+ base::ProcessHandle peer_handle) OVERRIDE;
+ virtual void Cancel(
+ scoped_ptr<FileSystemCallbackDispatcher> cancel_dispatcher) OVERRIDE;
virtual FileSystemOperation* AsFileSystemOperation() OVERRIDE;
// Synchronously gets the platform path for the given |path|.
@@ -102,7 +92,8 @@ class FileSystemOperation : public FileSystemOperationInterface {
friend class FileSystemTestHelper;
friend class chromeos::CrosMountPointProvider;
- FileSystemOperation(scoped_refptr<base::MessageLoopProxy> proxy,
+ FileSystemOperation(scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
+ scoped_refptr<base::MessageLoopProxy> proxy,
FileSystemContext* file_system_context);
FileSystemContext* file_system_context() const {
@@ -131,75 +122,63 @@ class FileSystemOperation : public FileSystemOperationInterface {
const GURL& origin_url,
const quota::QuotaManager::GetUsageAndQuotaCallback& callback);
- void DelayedCreateFileForQuota(const StatusCallback& callback,
- bool exclusive,
+ void DelayedCreateFileForQuota(bool exclusive,
quota::QuotaStatusCode status,
int64 usage, int64 quota);
- void DelayedCreateDirectoryForQuota(const StatusCallback& callback,
- bool exclusive, bool recursive,
+ void DelayedCreateDirectoryForQuota(bool exclusive, bool recursive,
quota::QuotaStatusCode status,
int64 usage, int64 quota);
- void DelayedCopyForQuota(const StatusCallback& callback,
- quota::QuotaStatusCode status,
+ void DelayedCopyForQuota(quota::QuotaStatusCode status,
int64 usage, int64 quota);
- void DelayedMoveForQuota(const StatusCallback& callback,
- quota::QuotaStatusCode status,
+ void DelayedMoveForQuota(quota::QuotaStatusCode status,
int64 usage, int64 quota);
void DelayedWriteForQuota(quota::QuotaStatusCode status,
int64 usage, int64 quota);
- void DelayedTruncateForQuota(const StatusCallback& callback,
- int64 length,
+ void DelayedTruncateForQuota(int64 length,
quota::QuotaStatusCode status,
int64 usage, int64 quota);
- void DelayedOpenFileForQuota(const OpenFileCallback& callback,
- int file_flags,
+ void DelayedOpenFileForQuota(int file_flags,
quota::QuotaStatusCode status,
int64 usage, int64 quota);
// Callback for CreateFile for |exclusive|=true cases.
- void DidEnsureFileExistsExclusive(const StatusCallback& callback,
- base::PlatformFileError rv,
+ void DidEnsureFileExistsExclusive(base::PlatformFileError rv,
bool created);
// Callback for CreateFile for |exclusive|=false cases.
- void DidEnsureFileExistsNonExclusive(const StatusCallback& callback,
- base::PlatformFileError rv,
+ void DidEnsureFileExistsNonExclusive(base::PlatformFileError rv,
bool created);
// Generic callback that translates platform errors to WebKit error codes.
- void DidFinishFileOperation(const StatusCallback& callback,
- base::PlatformFileError rv);
+ void DidFinishFileOperation(base::PlatformFileError rv);
- void DidDirectoryExists(const StatusCallback& callback,
- base::PlatformFileError rv,
+ void DidDirectoryExists(base::PlatformFileError rv,
const base::PlatformFileInfo& file_info,
const FilePath& unused);
- void DidFileExists(const StatusCallback& callback,
- base::PlatformFileError rv,
+ void DidFileExists(base::PlatformFileError rv,
const base::PlatformFileInfo& file_info,
const FilePath& unused);
- void DidGetMetadata(const GetMetadataCallback& callback,
- base::PlatformFileError rv,
+ void DidGetMetadata(base::PlatformFileError rv,
const base::PlatformFileInfo& file_info,
const FilePath& platform_path);
void DidReadDirectory(
- const ReadDirectoryCallback& callback,
base::PlatformFileError rv,
const std::vector<base::FileUtilProxy::Entry>& entries);
- void DidWrite(base::PlatformFileError rv,
- int64 bytes,
- bool complete);
- void DidTouchFile(const StatusCallback& callback,
- base::PlatformFileError rv);
- void DidOpenFile(const OpenFileCallback& callback,
- base::PlatformFileError rv,
- base::PassPlatformFile file,
- bool created);
+ void DidWrite(
+ base::PlatformFileError rv,
+ int64 bytes,
+ bool complete);
+ void DidTouchFile(base::PlatformFileError rv);
+ void DidOpenFile(
+ base::PlatformFileError rv,
+ base::PassPlatformFile file,
+ bool created);
// Helper for Write().
- void OnFileOpenedForWrite(base::PlatformFileError rv,
- base::PassPlatformFile file,
- bool created);
+ void OnFileOpenedForWrite(
+ base::PlatformFileError rv,
+ base::PassPlatformFile file,
+ bool created);
// Checks the validity of a given |path| for reading, cracks the path into
// root URL and virtual path components, and returns the correct
@@ -209,12 +188,11 @@ class FileSystemOperation : public FileSystemOperationInterface {
// PLATFORM_FILE_ERROR_SECURITY and returns false.
// (Note: this doesn't delete this when it calls DidFail and returns false;
// it's the caller's responsibility.)
- base::PlatformFileError VerifyFileSystemPathForRead(
- const GURL& path,
- GURL* root_url,
- FileSystemType* type,
- FilePath* virtual_path,
- FileSystemFileUtil** file_util);
+ bool VerifyFileSystemPathForRead(const GURL& path,
+ GURL* root_url,
+ FileSystemType* type,
+ FilePath* virtual_path,
+ FileSystemFileUtil** file_util);
// Checks the validity of a given |path| for writing, cracks the path into
// root URL and virtual path components, and returns the correct
@@ -231,30 +209,27 @@ class FileSystemOperation : public FileSystemOperationInterface {
// DidFail with PLATFORM_FILE_ERROR_SECURITY and returns false.
// (Note: this doesn't delete this when it calls DidFail and returns false;
// it's the caller's responsibility.)
- base::PlatformFileError VerifyFileSystemPathForWrite(
- const GURL& path,
- bool create,
- GURL* root_url,
- FileSystemType* type,
- FilePath* virtual_path,
- FileSystemFileUtil** file_util);
+ bool VerifyFileSystemPathForWrite(const GURL& path,
+ bool create,
+ GURL* root_url,
+ FileSystemType* type,
+ FilePath* virtual_path,
+ FileSystemFileUtil** file_util);
// Common internal routine for VerifyFileSystemPathFor{Read,Write}.
- base::PlatformFileError VerifyFileSystemPath(const GURL& path,
- GURL* root_url,
- FileSystemType* type,
- FilePath* virtual_path,
- FileSystemFileUtil** file_util);
+ bool VerifyFileSystemPath(const GURL& path,
+ GURL* root_url,
+ FileSystemType* type,
+ FilePath* virtual_path,
+ FileSystemFileUtil** file_util);
// Setup*Context*() functions will call the appropriate VerifyFileSystem
// function and store the results to operation_context_ and
// *_virtual_path_.
// Return the result of VerifyFileSystem*().
- base::PlatformFileError SetupSrcContextForRead(const GURL& path);
- base::PlatformFileError SetupSrcContextForWrite(const GURL& path,
- bool create);
- base::PlatformFileError SetupDestContextForWrite(const GURL& path,
- bool create);
+ bool SetupSrcContextForRead(const GURL& path);
+ bool SetupSrcContextForWrite(const GURL& path, bool create);
+ bool SetupDestContextForWrite(const GURL& path, bool create);
#ifndef NDEBUG
enum OperationType {
@@ -283,6 +258,9 @@ class FileSystemOperation : public FileSystemOperationInterface {
// Proxy for calling file_util_proxy methods.
scoped_refptr<base::MessageLoopProxy> proxy_;
+ // This can be NULL if the operation is cancelled on the way.
+ scoped_ptr<FileSystemCallbackDispatcher> dispatcher_;
+
FileSystemOperationContext operation_context_;
scoped_ptr<ScopedQuotaUtilHelper> quota_util_helper_;
@@ -291,16 +269,7 @@ class FileSystemOperation : public FileSystemOperationInterface {
friend class FileWriterDelegate;
scoped_ptr<FileWriterDelegate> file_writer_delegate_;
scoped_ptr<net::URLRequest> blob_request_;
-
- // write_callback is kept in this class for so that we can dispatch it when
- // the operation is cancelled. calcel_callback is kept for canceling a
- // Truncate() operation. We can't actually stop Truncate in another thread;
- // after it resumed from the working thread, cancellation takes place.
- WriteCallback write_callback_;
- StatusCallback cancel_callback_;
- void set_write_callback(const WriteCallback& write_callback) {
- write_callback_ = write_callback;
- }
+ scoped_ptr<FileSystemCallbackDispatcher> cancel_dispatcher_;
// Used only by OpenFile, in order to clone the file handle back to the
// requesting process.
diff --git a/webkit/fileapi/file_system_operation_interface.h b/webkit/fileapi/file_system_operation_interface.h
index bdc81ab..6a8a894 100644
--- a/webkit/fileapi/file_system_operation_interface.h
+++ b/webkit/fileapi/file_system_operation_interface.h
@@ -5,8 +5,6 @@
#ifndef WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_INTERFACE_H_
#define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_INTERFACE_H_
-#include "base/file_util_proxy.h"
-#include "base/platform_file.h"
#include "base/process.h"
namespace base {
@@ -22,6 +20,7 @@ class GURL;
namespace fileapi {
+class FileSystemCallbackDispatcher;
class FileSystemOperation;
// The interface class for FileSystemOperation implementations.
@@ -42,48 +41,18 @@ class FileSystemOperation;
// 2) Be self-destructed, or get deleted via base::Owned() after the
// operation finishes and completion callback is called.
//
-// 3) Deliver the results of operations to the client via the callback function
-// passed as the last parameter of the method.
+// 3) Deliver the results of operations to the client via
+// FileSystemCallbackDispatcher.
+// TODO(kinuko): Change the functions to take callbacks instead.
//
class FileSystemOperationInterface {
public:
virtual ~FileSystemOperationInterface() {}
- // Used for CreateFile(), etc. |result| is the return code of the operation.
- typedef base::Callback<void(base::PlatformFileError result)> StatusCallback;
-
- // Used for GetMetadata(). |result| is the return code of the operation,
- // |file_info| is the obtained file info, and |platform_path| is the path
- // of the file.
- typedef base::Callback<void(
- base::PlatformFileError result,
- const base::PlatformFileInfo& file_info,
- const FilePath& platform_path)> GetMetadataCallback;
-
- // Used for OpenFile(). |result| is the return code of the operation.
- typedef base::Callback<void(
- base::PlatformFileError result,
- base::PlatformFile file,
- base::ProcessHandle peer_handle)> OpenFileCallback;
-
- // Used for ReadDirectory(). |result| is the return code of the operation,
- // |file_list| is the list of files read, and |has_more| is true if some files
- // are yet to be read.
- typedef base::Callback<void(
- base::PlatformFileError result,
- const std::vector<base::FileUtilProxy::Entry>& file_list,
- bool has_more)> ReadDirectoryCallback;
-
- // Used for Write().
- typedef base::Callback<void(base::PlatformFileError result,
- int64 bytes,
- bool complete)> WriteCallback;
-
// Creates a file at |path|. If |exclusive| is true, an error is raised
// in case a file is already present at the URL.
virtual void CreateFile(const GURL& path,
- bool exclusive,
- const StatusCallback& callback) = 0;
+ bool exclusive) = 0;
// Creates a directory at |path|. If |exclusive| is true, an error is
// raised in case a directory is already present at the URL. If
@@ -91,57 +60,47 @@ class FileSystemOperationInterface {
// mkdir -p does.
virtual void CreateDirectory(const GURL& path,
bool exclusive,
- bool recursive,
- const StatusCallback& callback) = 0;
+ bool recursive) = 0;
// Copes a file or directory from |src_path| to |dest_path|. If
// |src_path| is a directory, the contents of |src_path| are copied to
// |dest_path| recursively. A new file or directory is created at
// |dest_path| as needed.
virtual void Copy(const GURL& src_path,
- const GURL& dest_path,
- const StatusCallback& callback) = 0;
+ const GURL& dest_path) = 0;
// Moves a file or directory from |src_path| to |dest_path|. A new file
// or directory is created at |dest_path| as needed.
virtual void Move(const GURL& src_path,
- const GURL& dest_path,
- const StatusCallback& callback) = 0;
+ const GURL& dest_path) = 0;
// Checks if a directory is present at |path|.
- virtual void DirectoryExists(const GURL& path,
- const StatusCallback& callback) = 0;
+ virtual void DirectoryExists(const GURL& path) = 0;
// Checks if a file is present at |path|.
- virtual void FileExists(const GURL& path,
- const StatusCallback& callback) = 0;
+ virtual void FileExists(const GURL& path) = 0;
// Gets the metadata of a file or directory at |path|.
- virtual void GetMetadata(const GURL& path,
- const GetMetadataCallback& callback) = 0;
+ virtual void GetMetadata(const GURL& path) = 0;
// Reads contents of a directory at |path|.
- virtual void ReadDirectory(const GURL& path,
- const ReadDirectoryCallback& callback) = 0;
+ virtual void ReadDirectory(const GURL& path) = 0;
// Removes a file or directory at |path|. If |recursive| is true, remove
// all files and directories under the directory at |path| recursively.
- virtual void Remove(const GURL& path, bool recursive,
- const StatusCallback& callback) = 0;
+ virtual void Remove(const GURL& path, bool recursive) = 0;
// Writes contents of |blob_url| to |path| at |offset|.
// |url_request_context| is used to read contents in |blob_url|.
virtual void Write(const net::URLRequestContext* url_request_context,
const GURL& path,
const GURL& blob_url,
- int64 offset,
- const WriteCallback& callback) = 0;
+ int64 offset) = 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.
- virtual void Truncate(const GURL& path, int64 length,
- const StatusCallback& callback) = 0;
+ virtual void Truncate(const GURL& path, int64 length) = 0;
// Tries to cancel the current operation [we support cancelling write or
// truncate only]. Reports failure for the current operation, then reports
@@ -150,23 +109,22 @@ class FileSystemOperationInterface {
// E.g. a typical cancel implementation would look like:
//
// virtual void SomeOperationImpl::Cancel(
- // const StatusCallback& cancel_callback) {
+ // scoped_ptr<FileSystemCallbackDispatcher> cancel_dispatcher) {
// // Abort the current inflight operation first.
// ...
//
- // // Dispatch ABORT error for the current operation by invoking
- // // the callback function for the ongoing operation,
- // operation_callback.Run(base::PLATFORM_FILE_ERROR_ABORT, ...);
+ // // Dispatch ABORT error for the current operation by calling
+ // // DidFail() callback of the dispatcher attached to this operation.
+ // // (dispatcher_ in this example)
+ // dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_ABORT);
//
// // Dispatch 'success' for the cancel (or dispatch appropriate
// // error code with DidFail() if the cancel has somehow failed).
- // cancel_callback.Run(base::PLATFORM_FILE_OK);
+ // cancel_dispatcher->DidSucceed();
// }
//
- // Note that, for reporting failure, the callback function passed to a
- // cancellable operations are kept around with the operation instance
- // (as |operation_callback_| in the code example).
- virtual void Cancel(const StatusCallback& cancel_callback) = 0;
+ virtual void Cancel(
+ scoped_ptr<FileSystemCallbackDispatcher> cancel_dispatcher) = 0;
// Modifies timestamps of a file or directory at |path| with
// |last_access_time| and |last_modified_time|. The function DOES NOT
@@ -175,8 +133,7 @@ class FileSystemOperationInterface {
// This function is used only by Pepper as of writing.
virtual void TouchFile(const GURL& path,
const base::Time& last_access_time,
- const base::Time& last_modified_time,
- const StatusCallback& callback) = 0;
+ const base::Time& last_modified_time) = 0;
// Opens a file at |path| with |file_flags|, where flags are OR'ed
// values of base::PlatformFileFlags.
@@ -185,10 +142,10 @@ class FileSystemOperationInterface {
// is necessary for underlying IPC calls with Pepper plugins.
//
// This function is used only by Pepper as of writing.
- virtual void OpenFile(const GURL& path,
- int file_flags,
- base::ProcessHandle peer_handle,
- const OpenFileCallback& callback) = 0;
+ virtual void OpenFile(
+ const GURL& path,
+ int file_flags,
+ base::ProcessHandle peer_handle) = 0;
// For downcasting to FileSystemOperation.
// TODO(kinuko): this hack should go away once appropriate upload-stream
diff --git a/webkit/fileapi/file_system_operation_unittest.cc b/webkit/fileapi/file_system_operation_unittest.cc
index b8b86c4..ad2da4f 100644
--- a/webkit/fileapi/file_system_operation_unittest.cc
+++ b/webkit/fileapi/file_system_operation_unittest.cc
@@ -4,15 +4,14 @@
#include "webkit/fileapi/file_system_operation.h"
-#include "base/bind.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "base/scoped_temp_dir.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_file_util.h"
#include "webkit/fileapi/file_system_mount_point_provider.h"
@@ -151,9 +150,7 @@ FilePath ASCIIToFilePath(const std::string& str) {
// Test class for FileSystemOperation. Note that this just tests low-level
// operations but doesn't test OpenFileSystem.
-class FileSystemOperationTest
- : public testing::Test,
- public base::SupportsWeakPtr<FileSystemOperationTest> {
+class FileSystemOperationTest : public testing::Test {
public:
FileSystemOperationTest()
: status_(kFileOperationStatusNotSet),
@@ -163,9 +160,15 @@ class FileSystemOperationTest
FileSystemOperation* operation();
+ void set_status(int status) { status_ = status; }
int status() const { return status_; }
+ void set_info(const base::PlatformFileInfo& info) { info_ = info; }
const base::PlatformFileInfo& info() const { return info_; }
+ void set_path(const FilePath& path) { path_ = path; }
const FilePath& path() const { return path_; }
+ void set_entries(const std::vector<base::FileUtilProxy::Entry>& entries) {
+ entries_ = entries;
+ }
const std::vector<base::FileUtilProxy::Entry>& entries() const {
return entries_;
}
@@ -238,53 +241,61 @@ class FileSystemOperationTest
FileSystemTestOriginHelper test_helper_;
- // Callbacks for recording test results.
- FileSystemOperationInterface::StatusCallback RecordStatusCallback() {
- return base::Bind(&FileSystemOperationTest::DidFinish, AsWeakPtr());
- }
+ // For post-operation status.
+ int status_;
+ base::PlatformFileInfo info_;
+ FilePath path_;
+ std::vector<base::FileUtilProxy::Entry> entries_;
+
+ private:
+ scoped_ptr<LocalFileUtil> local_file_util_;
+ scoped_refptr<QuotaManager> quota_manager_;
+ scoped_refptr<QuotaManagerProxy> quota_manager_proxy_;
+ DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest);
+};
+
+namespace {
- FileSystemOperationInterface::ReadDirectoryCallback
- RecordReadDirectoryCallback() {
- return base::Bind(&FileSystemOperationTest::DidReadDirectory, AsWeakPtr());
+class MockDispatcher : public FileSystemCallbackDispatcher {
+ public:
+ explicit MockDispatcher(FileSystemOperationTest* test) : test_(test) { }
+
+ virtual void DidFail(base::PlatformFileError status) {
+ test_->set_status(status);
}
- FileSystemOperationInterface::GetMetadataCallback RecordMetadataCallback() {
- return base::Bind(&FileSystemOperationTest::DidGetMetadata, AsWeakPtr());
+ virtual void DidSucceed() {
+ test_->set_status(base::PLATFORM_FILE_OK);
}
- void DidFinish(base::PlatformFileError status) {
- status_ = status;
+ virtual void DidReadMetadata(
+ const base::PlatformFileInfo& info,
+ const FilePath& platform_path) {
+ test_->set_info(info);
+ test_->set_path(platform_path);
+ test_->set_status(base::PLATFORM_FILE_OK);
}
- void DidReadDirectory(
- base::PlatformFileError status,
+ virtual void DidReadDirectory(
const std::vector<base::FileUtilProxy::Entry>& entries,
bool /* has_more */) {
- entries_ = entries;
- status_ = status;
+ test_->set_entries(entries);
}
- void DidGetMetadata(base::PlatformFileError status,
- const base::PlatformFileInfo& info,
- const FilePath& platform_path) {
- info_ = info;
- path_ = platform_path;
- status_ = status;
+ virtual void DidOpenFileSystem(const std::string&, const GURL&) {
+ NOTREACHED();
}
- // For post-operation status.
- int status_;
- base::PlatformFileInfo info_;
- FilePath path_;
- std::vector<base::FileUtilProxy::Entry> entries_;
+ virtual void DidWrite(int64 bytes, bool complete) {
+ NOTREACHED();
+ }
private:
- scoped_ptr<LocalFileUtil> local_file_util_;
- scoped_refptr<QuotaManager> quota_manager_;
- scoped_refptr<QuotaManagerProxy> quota_manager_proxy_;
- DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest);
+ FileSystemOperationTest* test_;
};
+} // namespace (anonymous)
+
void FileSystemOperationTest::SetUp() {
FilePath base_dir = base_.path().AppendASCII("filesystem");
quota_manager_ = new MockQuotaManager(
@@ -305,13 +316,13 @@ void FileSystemOperationTest::TearDown() {
}
FileSystemOperation* FileSystemOperationTest::operation() {
- return test_helper_.NewOperation();
+ return test_helper_.NewOperation(new MockDispatcher(this));
}
TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) {
GURL src(URLForPath(FilePath(FILE_PATH_LITERAL("a"))));
GURL dest(URLForPath(FilePath(FILE_PATH_LITERAL("b"))));
- operation()->Move(src, dest, RecordStatusCallback());
+ operation()->Move(src, dest);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
}
@@ -319,8 +330,7 @@ TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) {
TEST_F(FileSystemOperationTest, TestMoveFailureContainsPath) {
FilePath src_dir_path(CreateVirtualTemporaryDir());
FilePath dest_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path));
- operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path),
- RecordStatusCallback());
+ operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
}
@@ -331,8 +341,7 @@ TEST_F(FileSystemOperationTest, TestMoveFailureSrcDirExistsDestFile) {
FilePath dest_dir_path(CreateVirtualTemporaryDir());
FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path));
- operation()->Move(URLForPath(src_dir_path), URLForPath(dest_file_path),
- RecordStatusCallback());
+ operation()->Move(URLForPath(src_dir_path), URLForPath(dest_file_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
}
@@ -343,8 +352,7 @@ TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestNonEmptyDir) {
FilePath dest_dir_path(CreateVirtualTemporaryDir());
FilePath child_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path));
- operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path),
- RecordStatusCallback());
+ operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status());
}
@@ -355,8 +363,7 @@ TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestDir) {
FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path));
FilePath dest_dir_path(CreateVirtualTemporaryDir());
- operation()->Move(URLForPath(src_file_path), URLForPath(dest_dir_path),
- RecordStatusCallback());
+ operation()->Move(URLForPath(src_file_path), URLForPath(dest_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
}
@@ -367,8 +374,7 @@ TEST_F(FileSystemOperationTest, TestMoveFailureDestParentDoesntExist) {
FilePath nonexisting_file = FilePath(FILE_PATH_LITERAL("NonexistingDir")).
Append(FILE_PATH_LITERAL("NonexistingFile"));
- operation()->Move(URLForPath(src_dir_path), URLForPath(nonexisting_file),
- RecordStatusCallback());
+ operation()->Move(URLForPath(src_dir_path), URLForPath(nonexisting_file));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
}
@@ -379,8 +385,7 @@ TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndOverwrite) {
FilePath dest_dir_path(CreateVirtualTemporaryDir());
FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path));
- operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path),
- RecordStatusCallback());
+ operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualFileExists(dest_file_path));
@@ -396,8 +401,7 @@ TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndNew) {
FilePath dest_dir_path(CreateVirtualTemporaryDir());
FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile")));
- operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path),
- RecordStatusCallback());
+ operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualFileExists(dest_file_path));
@@ -407,8 +411,7 @@ TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndOverwrite) {
FilePath src_dir_path(CreateVirtualTemporaryDir());
FilePath dest_dir_path(CreateVirtualTemporaryDir());
- operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path),
- RecordStatusCallback());
+ operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_FALSE(VirtualDirectoryExists(src_dir_path));
@@ -425,8 +428,7 @@ TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndNew) {
FilePath dest_child_dir_path(dest_parent_dir_path.
Append(FILE_PATH_LITERAL("NewDirectory")));
- operation()->Move(URLForPath(src_dir_path), URLForPath(dest_child_dir_path),
- RecordStatusCallback());
+ operation()->Move(URLForPath(src_dir_path), URLForPath(dest_child_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_FALSE(VirtualDirectoryExists(src_dir_path));
@@ -441,8 +443,7 @@ TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirRecursive) {
FilePath dest_dir_path(CreateVirtualTemporaryDir());
- operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path),
- RecordStatusCallback());
+ operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append(
@@ -454,8 +455,7 @@ TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirRecursive) {
TEST_F(FileSystemOperationTest, TestCopyFailureSrcDoesntExist) {
operation()->Copy(URLForPath(FilePath(FILE_PATH_LITERAL("a"))),
- URLForPath(FilePath(FILE_PATH_LITERAL("b"))),
- RecordStatusCallback());
+ URLForPath(FilePath(FILE_PATH_LITERAL("b"))));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
}
@@ -463,8 +463,7 @@ TEST_F(FileSystemOperationTest, TestCopyFailureSrcDoesntExist) {
TEST_F(FileSystemOperationTest, TestCopyFailureContainsPath) {
FilePath src_dir_path(CreateVirtualTemporaryDir());
FilePath dest_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path));
- operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path),
- RecordStatusCallback());
+ operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
}
@@ -475,8 +474,7 @@ TEST_F(FileSystemOperationTest, TestCopyFailureSrcDirExistsDestFile) {
FilePath dest_dir_path(CreateVirtualTemporaryDir());
FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path));
- operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_file_path),
- RecordStatusCallback());
+ operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_file_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
}
@@ -487,8 +485,7 @@ TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestNonEmptyDir) {
FilePath dest_dir_path(CreateVirtualTemporaryDir());
FilePath child_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path));
- operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path),
- RecordStatusCallback());
+ operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status());
}
@@ -499,8 +496,7 @@ TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestDir) {
FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path));
FilePath dest_dir_path(CreateVirtualTemporaryDir());
- operation()->Copy(URLForPath(src_file_path), URLForPath(dest_dir_path),
- RecordStatusCallback());
+ operation()->Copy(URLForPath(src_file_path), URLForPath(dest_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
}
@@ -514,8 +510,7 @@ TEST_F(FileSystemOperationTest, TestCopyFailureDestParentDoesntExist) {
FILE_PATH_LITERAL("DontExistFile")));
operation()->Copy(URLForPath(src_dir_path),
- URLForPath(nonexisting_file_path),
- RecordStatusCallback());
+ URLForPath(nonexisting_file_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
}
@@ -532,16 +527,14 @@ TEST_F(FileSystemOperationTest, TestCopyFailureByQuota) {
test_helper_.storage_type(),
11);
- operation()->Truncate(URLForPath(src_file_path), 6,
- RecordStatusCallback());
+ operation()->Truncate(URLForPath(src_file_path), 6);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(src_file_path), &info));
EXPECT_EQ(6, info.size);
- operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path),
- RecordStatusCallback());
+ operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status());
EXPECT_FALSE(VirtualFileExists(dest_file_path));
@@ -553,8 +546,7 @@ TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndOverwrite) {
FilePath dest_dir_path(CreateVirtualTemporaryDir());
FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path));
- operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path),
- RecordStatusCallback());
+ operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualFileExists(dest_file_path));
@@ -567,8 +559,7 @@ TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndNew) {
FilePath dest_dir_path(CreateVirtualTemporaryDir());
FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile")));
- operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path),
- RecordStatusCallback());
+ operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualFileExists(dest_file_path));
@@ -579,8 +570,7 @@ TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) {
FilePath src_dir_path(CreateVirtualTemporaryDir());
FilePath dest_dir_path(CreateVirtualTemporaryDir());
- operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path),
- RecordStatusCallback());
+ operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
@@ -597,8 +587,7 @@ TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndNew) {
FilePath dest_child_dir_path(dest_parent_dir_path.
Append(FILE_PATH_LITERAL("NewDirectory")));
- operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_child_dir_path),
- RecordStatusCallback());
+ operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_child_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualDirectoryExists(dest_child_dir_path));
@@ -613,8 +602,7 @@ TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirRecursive) {
FilePath dest_dir_path(CreateVirtualTemporaryDir());
- operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path),
- RecordStatusCallback());
+ operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append(
@@ -629,8 +617,7 @@ TEST_F(FileSystemOperationTest, TestCreateFileFailure) {
// Already existing file and exclusive true.
FilePath dir_path(CreateVirtualTemporaryDir());
FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path));
- operation()->CreateFile(URLForPath(file_path), true,
- RecordStatusCallback());
+ operation()->CreateFile(URLForPath(file_path), true);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status());
}
@@ -639,8 +626,7 @@ TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileExists) {
// Already existing file and exclusive false.
FilePath dir_path(CreateVirtualTemporaryDir());
FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path));
- operation()->CreateFile(URLForPath(file_path), false,
- RecordStatusCallback());
+ operation()->CreateFile(URLForPath(file_path), false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualFileExists(file_path));
@@ -650,8 +636,7 @@ TEST_F(FileSystemOperationTest, TestCreateFileSuccessExclusive) {
// File doesn't exist but exclusive is true.
FilePath dir_path(CreateVirtualTemporaryDir());
FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist")));
- operation()->CreateFile(URLForPath(file_path), true,
- RecordStatusCallback());
+ operation()->CreateFile(URLForPath(file_path), true);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualFileExists(file_path));
@@ -661,8 +646,7 @@ TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileDoesntExist) {
// Non existing file.
FilePath dir_path(CreateVirtualTemporaryDir());
FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist")));
- operation()->CreateFile(URLForPath(file_path), false,
- RecordStatusCallback());
+ operation()->CreateFile(URLForPath(file_path), false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
}
@@ -674,8 +658,8 @@ TEST_F(FileSystemOperationTest,
FILE_PATH_LITERAL("DirDoesntExist")));
FilePath nonexisting_file_path(nonexisting_path.Append(
FILE_PATH_LITERAL("FileDoesntExist")));
- operation()->CreateDirectory(URLForPath(nonexisting_file_path), false, false,
- RecordStatusCallback());
+ operation()->CreateDirectory(
+ URLForPath(nonexisting_file_path), false, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
}
@@ -683,8 +667,7 @@ TEST_F(FileSystemOperationTest,
TEST_F(FileSystemOperationTest, TestCreateDirFailureDirExists) {
// Exclusive and dir existing at path.
FilePath src_dir_path(CreateVirtualTemporaryDir());
- operation()->CreateDirectory(URLForPath(src_dir_path), true, false,
- RecordStatusCallback());
+ operation()->CreateDirectory(URLForPath(src_dir_path), true, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status());
}
@@ -693,8 +676,7 @@ TEST_F(FileSystemOperationTest, TestCreateDirFailureFileExists) {
// Exclusive true and file existing at path.
FilePath dir_path(CreateVirtualTemporaryDir());
FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path));
- operation()->CreateDirectory(URLForPath(file_path), true, false,
- RecordStatusCallback());
+ operation()->CreateDirectory(URLForPath(file_path), true, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status());
}
@@ -702,16 +684,15 @@ TEST_F(FileSystemOperationTest, TestCreateDirFailureFileExists) {
TEST_F(FileSystemOperationTest, TestCreateDirSuccess) {
// Dir exists and exclusive is false.
FilePath dir_path(CreateVirtualTemporaryDir());
- operation()->CreateDirectory(URLForPath(dir_path), false, false,
- RecordStatusCallback());
+ operation()->CreateDirectory(URLForPath(dir_path), false, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
// Dir doesn't exist.
FilePath nonexisting_dir_path(FilePath(
FILE_PATH_LITERAL("nonexistingdir")));
- operation()->CreateDirectory(URLForPath(nonexisting_dir_path), false, false,
- RecordStatusCallback());
+ operation()->CreateDirectory(
+ URLForPath(nonexisting_dir_path), false, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualDirectoryExists(nonexisting_dir_path));
@@ -722,8 +703,8 @@ TEST_F(FileSystemOperationTest, TestCreateDirSuccessExclusive) {
FilePath nonexisting_dir_path(FilePath(
FILE_PATH_LITERAL("nonexistingdir")));
- operation()->CreateDirectory(URLForPath(nonexisting_dir_path), true, false,
- RecordStatusCallback());
+ operation()->CreateDirectory(
+ URLForPath(nonexisting_dir_path), true, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualDirectoryExists(nonexisting_dir_path));
@@ -732,19 +713,16 @@ TEST_F(FileSystemOperationTest, TestCreateDirSuccessExclusive) {
TEST_F(FileSystemOperationTest, TestExistsAndMetadataFailure) {
FilePath nonexisting_dir_path(FilePath(
FILE_PATH_LITERAL("nonexistingdir")));
- operation()->GetMetadata(URLForPath(nonexisting_dir_path),
- RecordMetadataCallback());
+ operation()->GetMetadata(URLForPath(nonexisting_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
- operation()->FileExists(URLForPath(nonexisting_dir_path),
- RecordStatusCallback());
+ operation()->FileExists(URLForPath(nonexisting_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
file_util::EnsureEndsWithSeparator(&nonexisting_dir_path);
- operation()->DirectoryExists(URLForPath(nonexisting_dir_path),
- RecordStatusCallback());
+ operation()->DirectoryExists(URLForPath(nonexisting_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
}
@@ -753,13 +731,12 @@ TEST_F(FileSystemOperationTest, TestExistsAndMetadataSuccess) {
FilePath dir_path(CreateVirtualTemporaryDir());
int read_access = 0;
- operation()->DirectoryExists(URLForPath(dir_path),
- RecordStatusCallback());
+ operation()->DirectoryExists(URLForPath(dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
++read_access;
- operation()->GetMetadata(URLForPath(dir_path), RecordMetadataCallback());
+ operation()->GetMetadata(URLForPath(dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(info().is_directory);
@@ -767,12 +744,12 @@ TEST_F(FileSystemOperationTest, TestExistsAndMetadataSuccess) {
++read_access;
FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path));
- operation()->FileExists(URLForPath(file_path), RecordStatusCallback());
+ operation()->FileExists(URLForPath(file_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
++read_access;
- operation()->GetMetadata(URLForPath(file_path), RecordMetadataCallback());
+ operation()->GetMetadata(URLForPath(file_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_FALSE(info().is_directory);
@@ -784,13 +761,13 @@ TEST_F(FileSystemOperationTest, TestExistsAndMetadataSuccess) {
TEST_F(FileSystemOperationTest, TestTypeMismatchErrors) {
FilePath dir_path(CreateVirtualTemporaryDir());
- operation()->FileExists(URLForPath(dir_path), RecordStatusCallback());
+ operation()->FileExists(URLForPath(dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status());
FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path));
ASSERT_FALSE(file_path.empty());
- operation()->DirectoryExists(URLForPath(file_path), RecordStatusCallback());
+ operation()->DirectoryExists(URLForPath(file_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status());
}
@@ -800,16 +777,14 @@ TEST_F(FileSystemOperationTest, TestReadDirFailure) {
FilePath nonexisting_dir_path(FilePath(
FILE_PATH_LITERAL("NonExistingDir")));
file_util::EnsureEndsWithSeparator(&nonexisting_dir_path);
- operation()->ReadDirectory(URLForPath(nonexisting_dir_path),
- RecordReadDirectoryCallback());
+ operation()->ReadDirectory(URLForPath(nonexisting_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
// File exists.
FilePath dir_path(CreateVirtualTemporaryDir());
FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path));
- operation()->ReadDirectory(URLForPath(file_path),
- RecordReadDirectoryCallback());
+ operation()->ReadDirectory(URLForPath(file_path));
MessageLoop::current()->RunAllPending();
// TODO(kkanetkar) crbug.com/54309 to change the error code.
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
@@ -825,10 +800,9 @@ TEST_F(FileSystemOperationTest, TestReadDirSuccess) {
FilePath child_dir_path(CreateVirtualTemporaryDirInDir(parent_dir_path));
ASSERT_FALSE(child_dir_path.empty());
- operation()->ReadDirectory(URLForPath(parent_dir_path),
- RecordReadDirectoryCallback());
+ operation()->ReadDirectory(URLForPath(parent_dir_path));
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(base::PLATFORM_FILE_OK, status());
+ EXPECT_EQ(kFileOperationStatusNotSet, status());
EXPECT_EQ(2u, entries().size());
for (size_t i = 0; i < entries().size(); ++i) {
@@ -849,8 +823,7 @@ TEST_F(FileSystemOperationTest, TestRemoveFailure) {
FILE_PATH_LITERAL("NonExistingDir")));
file_util::EnsureEndsWithSeparator(&nonexisting_path);
- operation()->Remove(URLForPath(nonexisting_path), false /* recursive */,
- RecordStatusCallback());
+ operation()->Remove(URLForPath(nonexisting_path), false /* recursive */);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
@@ -865,8 +838,7 @@ TEST_F(FileSystemOperationTest, TestRemoveFailure) {
FilePath child_dir_path(CreateVirtualTemporaryDirInDir(parent_dir_path));
ASSERT_FALSE(child_dir_path.empty());
- operation()->Remove(URLForPath(parent_dir_path), false /* recursive */,
- RecordStatusCallback());
+ operation()->Remove(URLForPath(parent_dir_path), false /* recursive */);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY,
status());
@@ -876,8 +848,7 @@ TEST_F(FileSystemOperationTest, TestRemoveSuccess) {
FilePath empty_dir_path(CreateVirtualTemporaryDir());
EXPECT_TRUE(VirtualDirectoryExists(empty_dir_path));
- operation()->Remove(URLForPath(empty_dir_path), false /* recursive */,
- RecordStatusCallback());
+ operation()->Remove(URLForPath(empty_dir_path), false /* recursive */);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_FALSE(VirtualDirectoryExists(empty_dir_path));
@@ -892,8 +863,7 @@ TEST_F(FileSystemOperationTest, TestRemoveSuccess) {
FilePath child_dir_path(CreateVirtualTemporaryDirInDir(parent_dir_path));
ASSERT_FALSE(child_dir_path.empty());
- operation()->Remove(URLForPath(parent_dir_path), true /* recursive */,
- RecordStatusCallback());
+ operation()->Remove(URLForPath(parent_dir_path), true /* recursive */);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_FALSE(VirtualDirectoryExists(parent_dir_path));
@@ -913,7 +883,7 @@ TEST_F(FileSystemOperationTest, TestTruncate) {
test_data, data_size));
// Check that its length is the size of the data written.
- operation()->GetMetadata(URLForPath(file_path), RecordMetadataCallback());
+ operation()->GetMetadata(URLForPath(file_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_FALSE(info().is_directory);
@@ -921,7 +891,7 @@ TEST_F(FileSystemOperationTest, TestTruncate) {
// Extend the file by truncating it.
int length = 17;
- operation()->Truncate(URLForPath(file_path), length, RecordStatusCallback());
+ operation()->Truncate(URLForPath(file_path), length);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
@@ -942,7 +912,7 @@ TEST_F(FileSystemOperationTest, TestTruncate) {
// Shorten the file by truncating it.
length = 3;
- operation()->Truncate(URLForPath(file_path), length, RecordStatusCallback());
+ operation()->Truncate(URLForPath(file_path), length);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
@@ -968,14 +938,14 @@ TEST_F(FileSystemOperationTest, TestTruncateFailureByQuota) {
test_helper_.storage_type(),
10);
- operation()->Truncate(URLForPath(file_path), 10, RecordStatusCallback());
+ operation()->Truncate(URLForPath(file_path), 10);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info));
EXPECT_EQ(10, info.size);
- operation()->Truncate(URLForPath(file_path), 11, RecordStatusCallback());
+ operation()->Truncate(URLForPath(file_path), 11);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status());
@@ -1001,9 +971,8 @@ TEST_F(FileSystemOperationTest, TestTouchFile) {
ASSERT_NE(last_modified, new_modified_time);
ASSERT_NE(last_accessed, new_accessed_time);
- operation()->TouchFile(
- URLForPath(file_path), new_accessed_time, new_modified_time,
- RecordStatusCallback());
+ operation()->TouchFile(URLForPath(file_path), new_accessed_time,
+ new_modified_time);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
diff --git a/webkit/fileapi/file_system_operation_write_unittest.cc b/webkit/fileapi/file_system_operation_write_unittest.cc
index 79fae3b..28d0298 100644
--- a/webkit/fileapi/file_system_operation_write_unittest.cc
+++ b/webkit/fileapi/file_system_operation_write_unittest.cc
@@ -11,7 +11,6 @@
#include <vector>
#include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
@@ -24,6 +23,7 @@
#include "webkit/blob/blob_data.h"
#include "webkit/blob/blob_storage_controller.h"
#include "webkit/blob/blob_url_request_job.h"
+#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_file_util.h"
#include "webkit/fileapi/file_system_operation.h"
@@ -65,9 +65,7 @@ class MockQuotaManager : public QuotaManager {
} // namespace (anonymous)
-class FileSystemOperationWriteTest
- : public testing::Test,
- public base::SupportsWeakPtr<FileSystemOperationWriteTest> {
+class FileSystemOperationWriteTest : public testing::Test {
public:
FileSystemOperationWriteTest()
: local_file_util_(new LocalFileUtil(QuotaFileUtil::CreateDefault())),
@@ -78,6 +76,13 @@ class FileSystemOperationWriteTest
FileSystemOperation* operation();
+ void set_failure_status(base::PlatformFileError status) {
+ EXPECT_FALSE(complete_);
+ EXPECT_EQ(status_, base::PLATFORM_FILE_OK);
+ EXPECT_NE(status, base::PLATFORM_FILE_OK);
+ complete_ = true;
+ status_ = status;
+ }
base::PlatformFileError status() const { return status_; }
void add_bytes_written(int64 bytes, bool complete) {
bytes_written_ += bytes;
@@ -95,25 +100,6 @@ class FileSystemOperationWriteTest
return test_helper_.GetURLForPath(path);
}
- // Callback function for recording test results.
- FileSystemOperationInterface::WriteCallback RecordWriteCallback() {
- return base::Bind(&FileSystemOperationWriteTest::DidWrite, AsWeakPtr());
- }
-
- void DidWrite(base::PlatformFileError status, int64 bytes, bool complete) {
- if (status == base::PLATFORM_FILE_OK) {
- add_bytes_written(bytes, complete);
- if (complete)
- MessageLoop::current()->Quit();
- } else {
- EXPECT_FALSE(complete_);
- EXPECT_EQ(status_, base::PLATFORM_FILE_OK);
- complete_ = true;
- status_ = status;
- MessageLoop::current()->Quit();
- }
- }
-
scoped_ptr<LocalFileUtil> local_file_util_;
scoped_refptr<MockQuotaManager> quota_manager_;
FileSystemTestOriginHelper test_helper_;
@@ -161,6 +147,45 @@ static net::URLRequestJob* BlobURLRequestJobFactory(net::URLRequest* request,
base::MessageLoopProxy::current());
}
+class MockDispatcher : public FileSystemCallbackDispatcher {
+ public:
+ MockDispatcher(FileSystemOperationWriteTest* test) : test_(test) { }
+
+ virtual void DidFail(base::PlatformFileError status) {
+ test_->set_failure_status(status);
+ MessageLoop::current()->Quit();
+ }
+
+ virtual void DidSucceed() {
+ ADD_FAILURE();
+ }
+
+ virtual void DidReadMetadata(
+ const base::PlatformFileInfo& info,
+ const FilePath& platform_path) {
+ ADD_FAILURE();
+ }
+
+ virtual void DidReadDirectory(
+ const std::vector<base::FileUtilProxy::Entry>& entries,
+ bool /* has_more */) {
+ ADD_FAILURE();
+ }
+
+ virtual void DidOpenFileSystem(const std::string&, const GURL&) {
+ ADD_FAILURE();
+ }
+
+ virtual void DidWrite(int64 bytes, bool complete) {
+ test_->add_bytes_written(bytes, complete);
+ if (complete)
+ MessageLoop::current()->Quit();
+ }
+
+ private:
+ FileSystemOperationWriteTest* test_;
+};
+
} // namespace (anonymous)
void FileSystemOperationWriteTest::SetUp() {
@@ -188,7 +213,7 @@ void FileSystemOperationWriteTest::TearDown() {
}
FileSystemOperation* FileSystemOperationWriteTest::operation() {
- return test_helper_.NewOperation();
+ return test_helper_.NewOperation(new MockDispatcher(this));
}
TEST_F(FileSystemOperationWriteTest, TestWriteSuccess) {
@@ -202,7 +227,7 @@ TEST_F(FileSystemOperationWriteTest, TestWriteSuccess) {
blob_url, blob_data);
operation()->Write(url_request_context, URLForPath(virtual_path_), blob_url,
- 0, RecordWriteCallback());
+ 0);
MessageLoop::current()->Run();
url_request_context->blob_storage_controller()->RemoveBlob(blob_url);
@@ -223,7 +248,7 @@ TEST_F(FileSystemOperationWriteTest, TestWriteZero) {
blob_url, blob_data);
operation()->Write(url_request_context, URLForPath(virtual_path_),
- blob_url, 0, RecordWriteCallback());
+ blob_url, 0);
MessageLoop::current()->Run();
url_request_context->blob_storage_controller()->RemoveBlob(blob_url);
@@ -238,7 +263,7 @@ TEST_F(FileSystemOperationWriteTest, TestWriteInvalidBlobUrl) {
new TestURLRequestContext());
operation()->Write(url_request_context, URLForPath(virtual_path_),
- GURL("blob:invalid"), 0, RecordWriteCallback());
+ GURL("blob:invalid"), 0);
MessageLoop::current()->Run();
EXPECT_EQ(0, bytes_written());
@@ -258,7 +283,7 @@ TEST_F(FileSystemOperationWriteTest, TestWriteInvalidFile) {
operation()->Write(url_request_context,
URLForPath(FilePath(FILE_PATH_LITERAL("nonexist"))),
- blob_url, 0, RecordWriteCallback());
+ blob_url, 0);
MessageLoop::current()->Run();
url_request_context->blob_storage_controller()->RemoveBlob(blob_url);
@@ -285,7 +310,7 @@ TEST_F(FileSystemOperationWriteTest, TestWriteDir) {
blob_url, blob_data);
operation()->Write(url_request_context, URLForPath(virtual_subdir_path),
- blob_url, 0, RecordWriteCallback());
+ blob_url, 0);
MessageLoop::current()->Run();
url_request_context->blob_storage_controller()->RemoveBlob(blob_url);
@@ -307,7 +332,7 @@ TEST_F(FileSystemOperationWriteTest, TestWriteFailureByQuota) {
quota_manager_->set_quota(10);
operation()->Write(url_request_context, URLForPath(virtual_path_), blob_url,
- 0, RecordWriteCallback());
+ 0);
MessageLoop::current()->Run();
url_request_context->blob_storage_controller()->RemoveBlob(blob_url);
diff --git a/webkit/fileapi/file_system_quota_unittest.cc b/webkit/fileapi/file_system_quota_unittest.cc
index bdc281a..4c1d259 100644
--- a/webkit/fileapi/file_system_quota_unittest.cc
+++ b/webkit/fileapi/file_system_quota_unittest.cc
@@ -11,11 +11,11 @@
#include "base/file_util.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "base/platform_file.h"
#include "base/scoped_temp_dir.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_operation.h"
#include "webkit/fileapi/file_system_test_helper.h"
#include "webkit/fileapi/file_system_usage_cache.h"
@@ -28,9 +28,7 @@ namespace fileapi {
const int kFileOperationStatusNotSet = 1;
-class FileSystemQuotaTest
- : public testing::Test,
- public base::SupportsWeakPtr<FileSystemQuotaTest> {
+class FileSystemQuotaTest : public testing::Test {
public:
FileSystemQuotaTest()
: local_file_util_(new LocalFileUtil(QuotaFileUtil::CreateDefault())),
@@ -42,6 +40,7 @@ class FileSystemQuotaTest
FileSystemOperation* operation();
+ void set_status(int status) { status_ = status; }
int status() const { return status_; }
quota::QuotaStatusCode quota_status() const { return quota_status_; }
int64 usage() { return usage_; }
@@ -117,15 +116,6 @@ class FileSystemQuotaTest
FilePath grandchild_file2_path_;
protected:
- // Callback for recording test results.
- FileSystemOperationInterface::StatusCallback RecordStatusCallback() {
- return base::Bind(&FileSystemQuotaTest::DidFinish, AsWeakPtr());
- }
-
- void DidFinish(base::PlatformFileError status) {
- status_ = status;
- }
-
FileSystemTestOriginHelper test_helper_;
ScopedTempDir work_dir_;
@@ -156,6 +146,50 @@ class FileSystemObfuscatedQuotaTest : public FileSystemQuotaTest {
scoped_refptr<FileSystemContext> file_system_context_;
};
+namespace {
+
+class MockDispatcher : public FileSystemCallbackDispatcher {
+ public:
+ explicit MockDispatcher(FileSystemQuotaTest* test) : test_(test) { }
+
+ virtual void DidFail(base::PlatformFileError status) {
+ test_->set_status(status);
+ }
+
+ virtual void DidSucceed() {
+ test_->set_status(base::PLATFORM_FILE_OK);
+ }
+
+ virtual void DidGetLocalPath(const FilePath& local_path) {
+ ADD_FAILURE();
+ }
+
+ virtual void DidReadMetadata(
+ const base::PlatformFileInfo& info,
+ const FilePath& platform_path) {
+ ADD_FAILURE();
+ }
+
+ virtual void DidReadDirectory(
+ const std::vector<base::FileUtilProxy::Entry>& entries,
+ bool /* has_more */) {
+ ADD_FAILURE();
+ }
+
+ virtual void DidOpenFileSystem(const std::string&, const GURL&) {
+ ADD_FAILURE();
+ }
+
+ virtual void DidWrite(int64 bytes, bool complete) {
+ ADD_FAILURE();
+ }
+
+ private:
+ FileSystemQuotaTest* test_;
+};
+
+} // namespace (anonymous)
+
void FileSystemQuotaTest::SetUp() {
ASSERT_TRUE(work_dir_.CreateUniqueTempDir());
FilePath filesystem_dir_path = work_dir_.path().AppendASCII("filesystem");
@@ -180,7 +214,7 @@ void FileSystemQuotaTest::TearDown() {
}
FileSystemOperation* FileSystemQuotaTest::operation() {
- return test_helper_.NewOperation();
+ return test_helper_.NewOperation(new MockDispatcher(this));
}
void FileSystemQuotaTest::OnGetUsageAndQuota(
@@ -205,14 +239,10 @@ TEST_F(FileSystemQuotaTest, TestMoveSuccessSrcDirRecursive) {
EXPECT_EQ(0, ActualSize());
- operation()->Truncate(URLForPath(child_file1_path_), 5000,
- RecordStatusCallback());
- operation()->Truncate(URLForPath(child_file2_path_), 400,
- RecordStatusCallback());
- operation()->Truncate(URLForPath(grandchild_file1_path_), 30,
- RecordStatusCallback());
- operation()->Truncate(URLForPath(grandchild_file2_path_), 2,
- RecordStatusCallback());
+ operation()->Truncate(URLForPath(child_file1_path_), 5000);
+ operation()->Truncate(URLForPath(child_file2_path_), 400);
+ operation()->Truncate(URLForPath(grandchild_file1_path_), 30);
+ operation()->Truncate(URLForPath(grandchild_file2_path_), 2);
MessageLoop::current()->RunAllPending();
const int64 all_file_size = 5000 + 400 + 30 + 2;
@@ -224,8 +254,7 @@ TEST_F(FileSystemQuotaTest, TestMoveSuccessSrcDirRecursive) {
EXPECT_EQ(all_file_size, usage());
ASSERT_LT(all_file_size, quota());
- operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path),
- RecordStatusCallback());
+ operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
@@ -251,14 +280,10 @@ TEST_F(FileSystemQuotaTest, TestCopySuccessSrcDirRecursive) {
EXPECT_EQ(0, ActualSize());
- operation()->Truncate(URLForPath(child_file1_path_), 8000,
- RecordStatusCallback());
- operation()->Truncate(URLForPath(child_file2_path_), 700,
- RecordStatusCallback());
- operation()->Truncate(URLForPath(grandchild_file1_path_), 60,
- RecordStatusCallback());
- operation()->Truncate(URLForPath(grandchild_file2_path_), 5,
- RecordStatusCallback());
+ operation()->Truncate(URLForPath(child_file1_path_), 8000);
+ operation()->Truncate(URLForPath(child_file2_path_), 700);
+ operation()->Truncate(URLForPath(grandchild_file1_path_), 60);
+ operation()->Truncate(URLForPath(grandchild_file2_path_), 5);
MessageLoop::current()->RunAllPending();
const int64 child_file_size = 8000 + 700;
@@ -272,8 +297,7 @@ TEST_F(FileSystemQuotaTest, TestCopySuccessSrcDirRecursive) {
EXPECT_EQ(all_file_size, usage());
ASSERT_LT(all_file_size, quota());
- operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir1_path),
- RecordStatusCallback());
+ operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir1_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
@@ -296,8 +320,7 @@ TEST_F(FileSystemQuotaTest, TestCopySuccessSrcDirRecursive) {
EXPECT_EQ(2 * all_file_size, usage());
ASSERT_LT(2 * all_file_size, quota());
- operation()->Copy(URLForPath(child_dir_path_), URLForPath(dest_dir2_path),
- RecordStatusCallback());
+ operation()->Copy(URLForPath(child_dir_path_), URLForPath(dest_dir2_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
diff --git a/webkit/fileapi/file_system_test_helper.cc b/webkit/fileapi/file_system_test_helper.cc
index 0d31f1d..4bb4011 100644
--- a/webkit/fileapi/file_system_test_helper.cc
+++ b/webkit/fileapi/file_system_test_helper.cc
@@ -8,6 +8,7 @@
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
#include "googleurl/src/gurl.h"
+#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_operation.h"
#include "webkit/fileapi/file_system_operation_context.h"
@@ -140,11 +141,14 @@ int64 FileSystemTestOriginHelper::ComputeCurrentOriginUsage() const {
return size;
}
-FileSystemOperation* FileSystemTestOriginHelper::NewOperation() {
+FileSystemOperation* FileSystemTestOriginHelper::NewOperation(
+ FileSystemCallbackDispatcher* callback_dispatcher) {
DCHECK(file_system_context_.get());
DCHECK(file_util_);
FileSystemOperation* operation =
- new FileSystemOperation(base::MessageLoopProxy::current(),
+ new FileSystemOperation(scoped_ptr<FileSystemCallbackDispatcher>(
+ callback_dispatcher),
+ base::MessageLoopProxy::current(),
file_system_context_.get());
operation->set_override_file_util(file_util_);
InitializeOperationContext(operation->file_system_operation_context());
diff --git a/webkit/fileapi/file_system_test_helper.h b/webkit/fileapi/file_system_test_helper.h
index 10ec99d..e70ae28 100644
--- a/webkit/fileapi/file_system_test_helper.h
+++ b/webkit/fileapi/file_system_test_helper.h
@@ -24,6 +24,7 @@ class FilePath;
namespace fileapi {
+class FileSystemCallbackDispatcher;
class FileSystemContext;
class FileSystemFileUtil;
class FileSystemOperation;
@@ -62,7 +63,8 @@ class FileSystemTestOriginHelper {
// This doesn't work with OFSFU.
int64 ComputeCurrentOriginUsage() const;
- FileSystemOperation* NewOperation();
+ FileSystemOperation* NewOperation(
+ FileSystemCallbackDispatcher* callback_dispatcher);
FileSystemOperationContext* NewOperationContext();
FileSystemContext* file_system_context() const {
diff --git a/webkit/fileapi/file_system_url_request_job.cc b/webkit/fileapi/file_system_url_request_job.cc
index b930c38..ef16482 100644
--- a/webkit/fileapi/file_system_url_request_job.cc
+++ b/webkit/fileapi/file_system_url_request_job.cc
@@ -22,6 +22,7 @@
#include "net/http/http_response_info.h"
#include "net/http/http_util.h"
#include "net/url_request/url_request.h"
+#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_operation.h"
#include "webkit/fileapi/file_system_util.h"
@@ -52,6 +53,60 @@ static net::HttpResponseHeaders* CreateHttpResponseHeaders() {
return headers;
}
+class FileSystemURLRequestJob::CallbackDispatcher
+ : public FileSystemCallbackDispatcher {
+ public:
+ // An instance of this class must be created by Create()
+ // (so that we do not leak ownerships).
+ static scoped_ptr<FileSystemCallbackDispatcher> Create(
+ FileSystemURLRequestJob* job) {
+ return scoped_ptr<FileSystemCallbackDispatcher>(
+ new CallbackDispatcher(job));
+ }
+
+ // fileapi::FileSystemCallbackDispatcher overrides.
+ virtual void DidSucceed() OVERRIDE {
+ NOTREACHED();
+ }
+
+ virtual void DidReadMetadata(const base::PlatformFileInfo& file_info,
+ const FilePath& platform_path) OVERRIDE {
+ job_->DidGetMetadata(file_info, platform_path);
+ }
+
+ virtual void DidReadDirectory(
+ const std::vector<base::FileUtilProxy::Entry>& entries,
+ bool has_more) OVERRIDE {
+ NOTREACHED();
+ }
+
+ virtual void DidWrite(int64 bytes, bool complete) OVERRIDE {
+ NOTREACHED();
+ }
+
+ virtual void DidOpenFileSystem(const std::string& name,
+ const GURL& root_path) OVERRIDE {
+ NOTREACHED();
+ }
+
+ virtual void DidFail(base::PlatformFileError error_code) OVERRIDE {
+ int rv = net::ERR_FILE_NOT_FOUND;
+ if (error_code == base::PLATFORM_FILE_ERROR_INVALID_URL)
+ rv = net::ERR_INVALID_URL;
+ job_->NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
+ }
+
+ private:
+ explicit CallbackDispatcher(FileSystemURLRequestJob* job) : job_(job) {
+ DCHECK(job_);
+ }
+
+ // TODO(adamk): Get rid of the need for refcounting here by
+ // allowing FileSystemOperations to be cancelled.
+ scoped_refptr<FileSystemURLRequestJob> job_;
+ DISALLOW_COPY_AND_ASSIGN(CallbackDispatcher);
+};
+
FileSystemURLRequestJob::FileSystemURLRequestJob(
URLRequest* request, FileSystemContext* file_system_context,
scoped_refptr<base::MessageLoopProxy> file_thread_proxy)
@@ -175,27 +230,19 @@ void FileSystemURLRequestJob::StartAsync() {
FileSystemOperationInterface* operation =
file_system_context_->CreateFileSystemOperation(
request_->url(),
+ CallbackDispatcher::Create(this),
file_thread_proxy_);
if (!operation) {
NotifyDone(URLRequestStatus(URLRequestStatus::FAILED,
net::ERR_INVALID_URL));
return;
}
- operation->GetMetadata(
- request_->url(),
- base::Bind(&FileSystemURLRequestJob::DidGetMetadata, this));
+ operation->GetMetadata(request_->url());
}
void FileSystemURLRequestJob::DidGetMetadata(
- base::PlatformFileError error_code,
const base::PlatformFileInfo& file_info,
const FilePath& platform_path) {
- if (error_code != base::PLATFORM_FILE_OK) {
- NotifyFailed(error_code == base::PLATFORM_FILE_ERROR_INVALID_URL ?
- net::ERR_INVALID_URL : net::ERR_FILE_NOT_FOUND);
- return;
- }
-
// We may have been orphaned...
if (!request_)
return;
diff --git a/webkit/fileapi/file_system_url_request_job.h b/webkit/fileapi/file_system_url_request_job.h
index e9adfd34..b980b56 100644
--- a/webkit/fileapi/file_system_url_request_job.h
+++ b/webkit/fileapi/file_system_url_request_job.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -55,8 +55,7 @@ class FileSystemURLRequestJob : public net::URLRequestJob {
virtual ~FileSystemURLRequestJob();
void StartAsync();
- void DidGetMetadata(base::PlatformFileError error_code,
- const base::PlatformFileInfo& file_info,
+ void DidGetMetadata(const base::PlatformFileInfo& file_info,
const FilePath& platform_path);
void DidOpen(base::PlatformFileError error_code,
base::PassPlatformFile file, bool created);
diff --git a/webkit/fileapi/file_writer_delegate_unittest.cc b/webkit/fileapi/file_writer_delegate_unittest.cc
index efde1e7..148c79b4 100644
--- a/webkit/fileapi/file_writer_delegate_unittest.cc
+++ b/webkit/fileapi/file_writer_delegate_unittest.cc
@@ -22,6 +22,7 @@
#include "net/url_request/url_request_job.h"
#include "net/url_request/url_request_status.h"
#include "testing/platform_test.h"
+#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_operation.h"
#include "webkit/fileapi/file_system_operation_context.h"
@@ -42,6 +43,13 @@ class Result {
bytes_written_(0),
complete_(false) {}
+ void set_failure_status(base::PlatformFileError status) {
+ EXPECT_FALSE(complete_);
+ EXPECT_EQ(status_, base::PLATFORM_FILE_OK);
+ EXPECT_NE(status, base::PLATFORM_FILE_OK);
+ complete_ = true;
+ status_ = status;
+ }
base::PlatformFileError status() const { return status_; }
void add_bytes_written(int64 bytes, bool complete) {
bytes_written_ += bytes;
@@ -51,20 +59,6 @@ class Result {
int64 bytes_written() const { return bytes_written_; }
bool complete() const { return complete_; }
- void DidWrite(base::PlatformFileError status, int64 bytes, bool complete) {
- if (status == base::PLATFORM_FILE_OK) {
- add_bytes_written(bytes, complete);
- if (complete)
- MessageLoop::current()->Quit();
- } else {
- EXPECT_FALSE(complete_);
- EXPECT_EQ(status_, base::PLATFORM_FILE_OK);
- complete_ = true;
- status_ = status;
- MessageLoop::current()->Quit();
- }
- }
-
private:
// For post-operation status.
base::PlatformFileError status_;
@@ -181,6 +175,45 @@ class FileWriterDelegateTestJob : public net::URLRequestJob {
int cursor_;
};
+class MockDispatcher : public FileSystemCallbackDispatcher {
+ public:
+ explicit MockDispatcher(Result* result) : result_(result) {}
+
+ virtual void DidFail(base::PlatformFileError status) {
+ result_->set_failure_status(status);
+ MessageLoop::current()->Quit();
+ }
+
+ virtual void DidSucceed() {
+ ADD_FAILURE();
+ }
+
+ virtual void DidReadMetadata(
+ const base::PlatformFileInfo& info,
+ const FilePath& platform_path) {
+ ADD_FAILURE();
+ }
+
+ virtual void DidReadDirectory(
+ const std::vector<base::FileUtilProxy::Entry>& entries,
+ bool /* has_more */) {
+ ADD_FAILURE();
+ }
+
+ virtual void DidOpenFileSystem(const std::string&, const GURL&) {
+ ADD_FAILURE();
+ }
+
+ virtual void DidWrite(int64 bytes, bool complete) {
+ result_->add_bytes_written(bytes, complete);
+ if (complete)
+ MessageLoop::current()->Quit();
+ }
+
+ private:
+ Result* result_;
+};
+
} // namespace (anonymous)
// static
@@ -208,9 +241,8 @@ void FileWriterDelegateTest::TearDown() {
FileSystemOperation* FileWriterDelegateTest::CreateNewOperation(
Result* result, int64 quota) {
- FileSystemOperation* operation = test_helper_.NewOperation();
- operation->set_write_callback(base::Bind(&Result::DidWrite,
- base::Unretained(result)));
+ FileSystemOperation* operation = test_helper_.NewOperation(
+ new MockDispatcher(result));
FileSystemOperationContext* context =
operation->file_system_operation_context();
context->set_allowed_bytes_growth(quota);
diff --git a/webkit/fileapi/sandbox_mount_point_provider.cc b/webkit/fileapi/sandbox_mount_point_provider.cc
index e79624e..1b2dc96 100644
--- a/webkit/fileapi/sandbox_mount_point_provider.cc
+++ b/webkit/fileapi/sandbox_mount_point_provider.cc
@@ -16,6 +16,7 @@
#include "base/metrics/histogram.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_util.h"
+#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_operation.h"
#include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/file_system_options.h"
@@ -415,9 +416,10 @@ SandboxMountPointProvider::CreateFileSystemOperation(
const GURL& origin_url,
FileSystemType file_system_type,
const FilePath& virtual_path,
+ scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
base::MessageLoopProxy* file_proxy,
FileSystemContext* context) const {
- return new FileSystemOperation(file_proxy, context);
+ return new FileSystemOperation(dispatcher.Pass(), file_proxy, context);
}
FilePath SandboxMountPointProvider::old_base_path() const {
diff --git a/webkit/fileapi/sandbox_mount_point_provider.h b/webkit/fileapi/sandbox_mount_point_provider.h
index a09488e..b00754d 100644
--- a/webkit/fileapi/sandbox_mount_point_provider.h
+++ b/webkit/fileapi/sandbox_mount_point_provider.h
@@ -89,6 +89,7 @@ class SandboxMountPointProvider
const GURL& origin_url,
FileSystemType file_system_type,
const FilePath& virtual_path,
+ scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
base::MessageLoopProxy* file_proxy,
FileSystemContext* context) const OVERRIDE;
diff --git a/webkit/tools/test_shell/simple_file_system.cc b/webkit/tools/test_shell/simple_file_system.cc
index 6a81e34..4dfb1ac 100644
--- a/webkit/tools/test_shell/simple_file_system.cc
+++ b/webkit/tools/test_shell/simple_file_system.cc
@@ -4,7 +4,6 @@
#include "webkit/tools/test_shell/simple_file_system.h"
-#include "base/bind.h"
#include "base/file_path.h"
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
@@ -19,6 +18,10 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
+#include "webkit/fileapi/file_system_callback_dispatcher.h"
+#include "webkit/fileapi/file_system_context.h"
+#include "webkit/fileapi/file_system_operation_interface.h"
+#include "webkit/fileapi/file_system_types.h"
#include "webkit/fileapi/mock_file_system_options.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/tools/test_shell/simple_file_writer.h"
@@ -37,9 +40,95 @@ using WebKit::WebString;
using WebKit::WebURL;
using WebKit::WebVector;
+using fileapi::FileSystemCallbackDispatcher;
using fileapi::FileSystemContext;
using fileapi::FileSystemOperationInterface;
+namespace {
+
+class SimpleFileSystemCallbackDispatcher
+ : public FileSystemCallbackDispatcher {
+ public:
+ // An instance of this class must be created by Create()
+ // (so that we do not leak ownerships).
+ static scoped_ptr<FileSystemCallbackDispatcher> Create(
+ const WeakPtr<SimpleFileSystem>& file_system,
+ WebFileSystemCallbacks* callbacks) {
+ return scoped_ptr<FileSystemCallbackDispatcher>(
+ new SimpleFileSystemCallbackDispatcher(file_system, callbacks));
+ }
+
+ ~SimpleFileSystemCallbackDispatcher() {
+ }
+
+ virtual void DidSucceed() {
+ DCHECK(file_system_);
+ callbacks_->didSucceed();
+ }
+
+ virtual void DidReadMetadata(const base::PlatformFileInfo& info,
+ const FilePath& platform_path) {
+ DCHECK(file_system_);
+ WebFileInfo web_file_info;
+ web_file_info.length = info.size;
+ web_file_info.modificationTime = info.last_modified.ToDoubleT();
+ web_file_info.type = info.is_directory ?
+ WebFileInfo::TypeDirectory : WebFileInfo::TypeFile;
+ web_file_info.platformPath =
+ webkit_glue::FilePathToWebString(platform_path);
+ callbacks_->didReadMetadata(web_file_info);
+ }
+
+ virtual void DidReadDirectory(
+ const std::vector<base::FileUtilProxy::Entry>& entries,
+ bool has_more) {
+ DCHECK(file_system_);
+ std::vector<WebFileSystemEntry> web_entries_vector;
+ for (std::vector<base::FileUtilProxy::Entry>::const_iterator it =
+ entries.begin(); it != entries.end(); ++it) {
+ WebFileSystemEntry entry;
+ entry.name = webkit_glue::FilePathStringToWebString(it->name);
+ entry.isDirectory = it->is_directory;
+ web_entries_vector.push_back(entry);
+ }
+ WebVector<WebKit::WebFileSystemEntry> web_entries =
+ web_entries_vector;
+ callbacks_->didReadDirectory(web_entries, has_more);
+ }
+
+ virtual void DidOpenFileSystem(
+ const std::string& name, const GURL& root) {
+ DCHECK(file_system_);
+ if (!root.is_valid())
+ callbacks_->didFail(WebKit::WebFileErrorSecurity);
+ else
+ callbacks_->didOpenFileSystem(WebString::fromUTF8(name), root);
+ }
+
+ virtual void DidFail(base::PlatformFileError error_code) {
+ DCHECK(file_system_);
+ callbacks_->didFail(
+ webkit_glue::PlatformFileErrorToWebFileError(error_code));
+ }
+
+ virtual void DidWrite(int64, bool) {
+ NOTREACHED();
+ }
+
+ private:
+ SimpleFileSystemCallbackDispatcher(
+ const WeakPtr<SimpleFileSystem>& file_system,
+ WebFileSystemCallbacks* callbacks)
+ : file_system_(file_system),
+ callbacks_(callbacks) {
+ }
+
+ WeakPtr<SimpleFileSystem> file_system_;
+ WebFileSystemCallbacks* callbacks_;
+};
+
+} // namespace
+
SimpleFileSystem::SimpleFileSystem() {
if (file_system_dir_.CreateUniqueTempDir()) {
file_system_context_ = new FileSystemContext(
@@ -83,64 +172,60 @@ void SimpleFileSystem::OpenFileSystem(
GURL origin_url(frame->document().securityOrigin().toString());
file_system_context_->OpenFileSystem(
- origin_url, type, create, OpenFileSystemHandler(callbacks));
+ origin_url, type, create,
+ SimpleFileSystemCallbackDispatcher::Create(AsWeakPtr(), callbacks));
}
void SimpleFileSystem::move(
const WebURL& src_path,
const WebURL& dest_path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(src_path)->Move(GURL(src_path), GURL(dest_path),
- FinishHandler(callbacks));
+ GetNewOperation(src_path, callbacks)->Move(GURL(src_path), GURL(dest_path));
}
void SimpleFileSystem::copy(
const WebURL& src_path, const WebURL& dest_path,
WebFileSystemCallbacks* callbacks) {
- GetNewOperation(src_path)->Copy(GURL(src_path), GURL(dest_path),
- FinishHandler(callbacks));
+ GetNewOperation(src_path, callbacks)->Copy(GURL(src_path), GURL(dest_path));
}
void SimpleFileSystem::remove(
const WebURL& path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(path)->Remove(path, false /* recursive */,
- FinishHandler(callbacks));
+ GetNewOperation(path, callbacks)->Remove(path, false /* recursive */);
}
void SimpleFileSystem::removeRecursively(
const WebURL& path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(path)->Remove(path, true /* recursive */,
- FinishHandler(callbacks));
+ GetNewOperation(path, callbacks)->Remove(path, true /* recursive */);
}
void SimpleFileSystem::readMetadata(
const WebURL& path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(path)->GetMetadata(path, GetMetadataHandler(callbacks));
+ GetNewOperation(path, callbacks)->GetMetadata(path);
}
void SimpleFileSystem::createFile(
const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(path)->CreateFile(path, exclusive, FinishHandler(callbacks));
+ GetNewOperation(path, callbacks)->CreateFile(path, exclusive);
}
void SimpleFileSystem::createDirectory(
const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(path)->CreateDirectory(path, exclusive, false,
- FinishHandler(callbacks));
+ GetNewOperation(path, callbacks)->CreateDirectory(path, exclusive, false);
}
void SimpleFileSystem::fileExists(
const WebURL& path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(path)->FileExists(path, FinishHandler(callbacks));
+ GetNewOperation(path, callbacks)->FileExists(path);
}
void SimpleFileSystem::directoryExists(
const WebURL& path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(path)->DirectoryExists(path, FinishHandler(callbacks));
+ GetNewOperation(path, callbacks)->DirectoryExists(path);
}
void SimpleFileSystem::readDirectory(
const WebURL& path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(path)->ReadDirectory(path, ReadDirectoryHandler(callbacks));
+ GetNewOperation(path, callbacks)->ReadDirectory(path);
}
WebFileWriter* SimpleFileSystem::createFileWriter(
@@ -149,93 +234,9 @@ WebFileWriter* SimpleFileSystem::createFileWriter(
}
FileSystemOperationInterface* SimpleFileSystem::GetNewOperation(
- const WebURL& url) {
+ const WebURL& url, WebFileSystemCallbacks* callbacks) {
return file_system_context_->CreateFileSystemOperation(
GURL(url),
+ SimpleFileSystemCallbackDispatcher::Create(AsWeakPtr(), callbacks),
base::MessageLoopProxy::current());
}
-
-FileSystemOperationInterface::StatusCallback
-SimpleFileSystem::FinishHandler(WebFileSystemCallbacks* callbacks) {
- return base::Bind(&SimpleFileSystem::DidFinish,
- AsWeakPtr(), base::Unretained(callbacks));
-}
-
-FileSystemOperationInterface::ReadDirectoryCallback
-SimpleFileSystem::ReadDirectoryHandler(WebFileSystemCallbacks* callbacks) {
- return base::Bind(&SimpleFileSystem::DidReadDirectory,
- AsWeakPtr(), base::Unretained(callbacks));
-}
-
-FileSystemOperationInterface::GetMetadataCallback
-SimpleFileSystem::GetMetadataHandler(WebFileSystemCallbacks* callbacks) {
- return base::Bind(&SimpleFileSystem::DidGetMetadata,
- AsWeakPtr(), base::Unretained(callbacks));
-}
-
-FileSystemContext::OpenFileSystemCallback
-SimpleFileSystem::OpenFileSystemHandler(WebFileSystemCallbacks* callbacks) {
- return base::Bind(&SimpleFileSystem::DidOpenFileSystem,
- AsWeakPtr(), base::Unretained(callbacks));
-}
-
-void SimpleFileSystem::DidFinish(WebFileSystemCallbacks* callbacks,
- base::PlatformFileError result) {
- if (result == base::PLATFORM_FILE_OK)
- callbacks->didSucceed();
- else
- callbacks->didFail(webkit_glue::PlatformFileErrorToWebFileError(result));
-}
-
-void SimpleFileSystem::DidGetMetadata(WebFileSystemCallbacks* callbacks,
- base::PlatformFileError result,
- const base::PlatformFileInfo& info,
- const FilePath& platform_path) {
- if (result == base::PLATFORM_FILE_OK) {
- WebFileInfo web_file_info;
- web_file_info.length = info.size;
- web_file_info.modificationTime = info.last_modified.ToDoubleT();
- web_file_info.type = info.is_directory ?
- WebFileInfo::TypeDirectory : WebFileInfo::TypeFile;
- web_file_info.platformPath =
- webkit_glue::FilePathToWebString(platform_path);
- callbacks->didReadMetadata(web_file_info);
- } else {
- callbacks->didFail(webkit_glue::PlatformFileErrorToWebFileError(result));
- }
-}
-
-void SimpleFileSystem::DidReadDirectory(
- WebFileSystemCallbacks* callbacks,
- base::PlatformFileError result,
- const std::vector<base::FileUtilProxy::Entry>& entries,
- bool has_more) {
- if (result == base::PLATFORM_FILE_OK) {
- std::vector<WebFileSystemEntry> web_entries_vector;
- for (std::vector<base::FileUtilProxy::Entry>::const_iterator it =
- entries.begin(); it != entries.end(); ++it) {
- WebFileSystemEntry entry;
- entry.name = webkit_glue::FilePathStringToWebString(it->name);
- entry.isDirectory = it->is_directory;
- web_entries_vector.push_back(entry);
- }
- WebVector<WebKit::WebFileSystemEntry> web_entries = web_entries_vector;
- callbacks->didReadDirectory(web_entries, has_more);
- } else {
- callbacks->didFail(webkit_glue::PlatformFileErrorToWebFileError(result));
- }
-}
-
-void SimpleFileSystem::DidOpenFileSystem(
- WebFileSystemCallbacks* callbacks,
- base::PlatformFileError result,
- const std::string& name, const GURL& root) {
- if (result == base::PLATFORM_FILE_OK) {
- if (!root.is_valid())
- callbacks->didFail(WebKit::WebFileErrorSecurity);
- else
- callbacks->didOpenFileSystem(WebString::fromUTF8(name), root);
- } else {
- callbacks->didFail(webkit_glue::PlatformFileErrorToWebFileError(result));
- }
-}
diff --git a/webkit/tools/test_shell/simple_file_system.h b/webkit/tools/test_shell/simple_file_system.h
index 81a61ab..82c2e01 100644
--- a/webkit/tools/test_shell/simple_file_system.h
+++ b/webkit/tools/test_shell/simple_file_system.h
@@ -10,8 +10,6 @@
#include "base/memory/weak_ptr.h"
#include "base/scoped_temp_dir.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSystem.h"
-#include "webkit/fileapi/file_system_context.h"
-#include "webkit/fileapi/file_system_operation_interface.h"
#include "webkit/fileapi/file_system_types.h"
#include <vector>
@@ -23,6 +21,7 @@ class WebURL;
namespace fileapi {
class FileSystemContext;
+class FileSystemOperationInterface;
}
class SimpleFileSystem
@@ -83,31 +82,7 @@ class SimpleFileSystem
private:
// Helpers.
fileapi::FileSystemOperationInterface* GetNewOperation(
- const WebKit::WebURL& path);
-
- // Callback Handlers
- fileapi::FileSystemOperationInterface::StatusCallback FinishHandler(
- WebKit::WebFileSystemCallbacks* callbacks);
- fileapi::FileSystemOperationInterface::GetMetadataCallback GetMetadataHandler(
- WebKit::WebFileSystemCallbacks* callbacks);
- fileapi::FileSystemOperationInterface::ReadDirectoryCallback
- ReadDirectoryHandler(WebKit::WebFileSystemCallbacks* callbacks);
- fileapi::FileSystemContext::OpenFileSystemCallback OpenFileSystemHandler(
- WebKit::WebFileSystemCallbacks* callbacks);
- void DidFinish(WebKit::WebFileSystemCallbacks* callbacks,
- base::PlatformFileError result);
- void DidGetMetadata(WebKit::WebFileSystemCallbacks* callbacks,
- base::PlatformFileError result,
- const base::PlatformFileInfo& info,
- const FilePath& platform_path);
- void DidReadDirectory(
- WebKit::WebFileSystemCallbacks* callbacks,
- base::PlatformFileError result,
- const std::vector<base::FileUtilProxy::Entry>& entries,
- bool has_more);
- void DidOpenFileSystem(WebKit::WebFileSystemCallbacks* callbacks,
- base::PlatformFileError result,
- const std::string& name, const GURL& root);
+ const WebKit::WebURL& path, WebKit::WebFileSystemCallbacks* callbacks);
// A temporary directory for FileSystem API.
ScopedTempDir file_system_dir_;
diff --git a/webkit/tools/test_shell/simple_file_writer.cc b/webkit/tools/test_shell/simple_file_writer.cc
index 251d8e9..cdd36b1 100644
--- a/webkit/tools/test_shell/simple_file_writer.cc
+++ b/webkit/tools/test_shell/simple_file_writer.cc
@@ -8,11 +8,13 @@
#include "base/logging.h"
#include "base/message_loop_proxy.h"
#include "net/url_request/url_request_context.h"
+#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_operation_interface.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
+using fileapi::FileSystemCallbackDispatcher;
using fileapi::FileSystemContext;
using fileapi::FileSystemOperationInterface;
using fileapi::WebFileWriterBase;
@@ -51,8 +53,7 @@ class SimpleFileWriter::IOThreadProxy
}
DCHECK(!operation_);
operation_ = GetNewOperation(path);
- operation_->Truncate(path, offset,
- base::Bind(&IOThreadProxy::DidFinish, this));
+ operation_->Truncate(path, offset);
}
void Write(const GURL& path, const GURL& blob_url, int64 offset) {
@@ -65,8 +66,7 @@ class SimpleFileWriter::IOThreadProxy
DCHECK(request_context_);
DCHECK(!operation_);
operation_ = GetNewOperation(path);
- operation_->Write(request_context_, path, blob_url, offset,
- base::Bind(&IOThreadProxy::DidWrite, this));
+ operation_->Write(request_context_, path, blob_url, offset);
}
void Cancel() {
@@ -77,45 +77,96 @@ class SimpleFileWriter::IOThreadProxy
return;
}
if (!operation_) {
- DidFailOnMainThread(base::PLATFORM_FILE_ERROR_INVALID_OPERATION);
+ DidFail(base::PLATFORM_FILE_ERROR_INVALID_OPERATION);
return;
}
- operation_->Cancel(base::Bind(&IOThreadProxy::DidFinish, this));
+ operation_->Cancel(CallbackDispatcher::Create(this));
}
private:
+ // Inner class to receive callbacks from FileSystemOperation.
+ class CallbackDispatcher : public FileSystemCallbackDispatcher {
+ public:
+ // An instance of this class must be created by Create()
+ // (so that we do not leak ownerships).
+ static scoped_ptr<FileSystemCallbackDispatcher> Create(
+ IOThreadProxy* proxy) {
+ return scoped_ptr<FileSystemCallbackDispatcher>(
+ new CallbackDispatcher(proxy));
+ }
+
+ ~CallbackDispatcher() {
+ proxy_->ClearOperation();
+ }
+
+ virtual void DidSucceed() {
+ proxy_->DidSucceed();
+ }
+
+ virtual void DidFail(base::PlatformFileError error_code) {
+ proxy_->DidFail(error_code);
+ }
+
+ virtual void DidWrite(int64 bytes, bool complete) {
+ proxy_->DidWrite(bytes, complete);
+ }
+
+ virtual void DidReadMetadata(
+ const base::PlatformFileInfo&,
+ const FilePath&) {
+ NOTREACHED();
+ }
+
+ virtual void DidReadDirectory(
+ const std::vector<base::FileUtilProxy::Entry>& entries,
+ bool has_more) {
+ NOTREACHED();
+ }
+
+ virtual void DidOpenFileSystem(
+ const std::string& name,
+ const GURL& root) {
+ NOTREACHED();
+ }
+
+ private:
+ explicit CallbackDispatcher(IOThreadProxy* proxy) : proxy_(proxy) {}
+ scoped_refptr<IOThreadProxy> proxy_;
+ };
+
FileSystemOperationInterface* GetNewOperation(const GURL& path) {
- return file_system_context_->CreateFileSystemOperation(path, io_thread_);
+ // The FileSystemOperation takes ownership of the CallbackDispatcher.
+ return file_system_context_->CreateFileSystemOperation(
+ path, CallbackDispatcher::Create(this), io_thread_);
}
- void DidSucceedOnMainThread() {
+ void DidSucceed() {
if (!main_thread_->BelongsToCurrentThread()) {
main_thread_->PostTask(
FROM_HERE,
- base::Bind(&IOThreadProxy::DidSucceedOnMainThread, this));
+ base::Bind(&IOThreadProxy::DidSucceed, this));
return;
}
if (simple_writer_)
simple_writer_->DidSucceed();
}
- void DidFailOnMainThread(base::PlatformFileError error_code) {
+ void DidFail(base::PlatformFileError error_code) {
if (!main_thread_->BelongsToCurrentThread()) {
main_thread_->PostTask(
FROM_HERE,
- base::Bind(&IOThreadProxy::DidFailOnMainThread, this, error_code));
+ base::Bind(&IOThreadProxy::DidFail, this, error_code));
return;
}
if (simple_writer_)
simple_writer_->DidFail(error_code);
}
- void DidWriteOnMainThread(int64 bytes, bool complete) {
+ void DidWrite(int64 bytes, bool complete) {
if (!main_thread_->BelongsToCurrentThread()) {
main_thread_->PostTask(
FROM_HERE,
- base::Bind(&IOThreadProxy::DidWriteOnMainThread,
- this, bytes, complete));
+ base::Bind(&IOThreadProxy::DidWrite, this, bytes, complete));
return;
}
if (simple_writer_)
@@ -127,25 +178,6 @@ class SimpleFileWriter::IOThreadProxy
operation_ = NULL;
}
- void DidFinish(base::PlatformFileError result) {
- if (result == base::PLATFORM_FILE_OK)
- DidSucceedOnMainThread();
- else
- DidFailOnMainThread(result);
- ClearOperation();
- }
-
- void DidWrite(base::PlatformFileError result, int64 bytes, bool complete) {
- if (result == base::PLATFORM_FILE_OK) {
- DidWriteOnMainThread(bytes, complete);
- if (complete)
- ClearOperation();
- } else {
- DidFailOnMainThread(result);
- ClearOperation();
- }
- }
-
scoped_refptr<base::MessageLoopProxy> io_thread_;
scoped_refptr<base::MessageLoopProxy> main_thread_;