Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Unified Diff: webkit/tools/test_shell/simple_file_writer.cc

Issue 9380040: Revert 121620 - Refactor FileSystemOperation to take callback for each method. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/tools/test_shell/simple_file_system.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/tools/test_shell/simple_file_writer.cc
===================================================================
--- webkit/tools/test_shell/simple_file_writer.cc (revision 121622)
+++ webkit/tools/test_shell/simple_file_writer.cc (working copy)
@@ -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 @@
}
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 @@
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 @@
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 @@
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_;
« no previous file with comments | « webkit/tools/test_shell/simple_file_system.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698