| Index: content/common/fileapi/webfilewriter_impl.cc
|
| diff --git a/content/common/fileapi/webfilewriter_impl.cc b/content/common/fileapi/webfilewriter_impl.cc
|
| index ac685e1b78fbb7358aead0a4b94da71286b435da..117e28820c189bd0eabbf8154873feb3ab541347 100644
|
| --- a/content/common/fileapi/webfilewriter_impl.cc
|
| +++ b/content/common/fileapi/webfilewriter_impl.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "content/common/fileapi/webfilewriter_impl.h"
|
|
|
| +#include "base/bind.h"
|
| #include "content/common/child_thread.h"
|
| #include "content/common/fileapi/file_system_dispatcher.h"
|
|
|
| @@ -15,47 +16,46 @@ inline FileSystemDispatcher* GetFileSystemDispatcher() {
|
| }
|
| }
|
|
|
| -class WebFileWriterImpl::CallbackDispatcher
|
| - : public fileapi::FileSystemCallbackDispatcher {
|
| +class WebFileWriterImpl::CallbackDispatcher {
|
| public:
|
| - explicit CallbackDispatcher(
|
| - const base::WeakPtr<WebFileWriterImpl>& writer) : writer_(writer) {
|
| - }
|
| - virtual ~CallbackDispatcher() {
|
| - }
|
| - virtual void DidReadMetadata(
|
| - const base::PlatformFileInfo&,
|
| - const base::FilePath&) OVERRIDE {
|
| - NOTREACHED();
|
| - }
|
| - virtual void DidCreateSnapshotFile(
|
| - const base::PlatformFileInfo&,
|
| - const base::FilePath&) OVERRIDE {
|
| - NOTREACHED();
|
| - }
|
| - virtual void DidReadDirectory(
|
| - const std::vector<base::FileUtilProxy::Entry>& entries,
|
| - bool has_more) OVERRIDE {
|
| - NOTREACHED();
|
| + ~CallbackDispatcher() {}
|
| +
|
| + static FileSystemDispatcher::StatusCallback GetStatusCallback(
|
| + const base::WeakPtr<WebFileWriterImpl>& writer) {
|
| + CallbackDispatcher* dispatcher = new CallbackDispatcher(writer);
|
| + return base::Bind(&CallbackDispatcher::DidFinish, base::Owned(dispatcher));
|
| }
|
| - virtual void DidOpenFileSystem(const std::string& name,
|
| - const GURL& root) OVERRIDE {
|
| - NOTREACHED();
|
| +
|
| + static FileSystemDispatcher::WriteCallback GetWriteCallback(
|
| + const base::WeakPtr<WebFileWriterImpl>& writer) {
|
| + CallbackDispatcher* dispatcher = new CallbackDispatcher(writer);
|
| + return base::Bind(&CallbackDispatcher::DidWrite, base::Owned(dispatcher));
|
| }
|
| - virtual void DidSucceed() OVERRIDE {
|
| - if (writer_)
|
| +
|
| + void DidFinish(base::PlatformFileError error_code) {
|
| + if (!writer_)
|
| + return;
|
| + if (error_code == base::PLATFORM_FILE_OK)
|
| writer_->DidSucceed();
|
| - }
|
| - virtual void DidFail(base::PlatformFileError error_code) OVERRIDE {
|
| - if (writer_)
|
| + else
|
| writer_->DidFail(error_code);
|
| }
|
| - virtual void DidWrite(int64 bytes, bool complete) OVERRIDE {
|
| - if (writer_)
|
| +
|
| + void DidWrite(base::PlatformFileError error_code,
|
| + int64 bytes, bool complete) {
|
| + if (!writer_)
|
| + return;
|
| + if (error_code == base::PLATFORM_FILE_OK)
|
| writer_->DidWrite(bytes, complete);
|
| + else
|
| + writer_->DidFail(error_code);
|
| }
|
|
|
| private:
|
| + explicit CallbackDispatcher(
|
| + const base::WeakPtr<WebFileWriterImpl>& writer) : writer_(writer) {
|
| + }
|
| +
|
| base::WeakPtr<WebFileWriterImpl> writer_;
|
| };
|
|
|
| @@ -70,20 +70,22 @@ WebFileWriterImpl::~WebFileWriterImpl() {
|
|
|
| void WebFileWriterImpl::DoTruncate(const GURL& path, int64 offset) {
|
| // The FileSystemDispatcher takes ownership of the CallbackDispatcher.
|
| - GetFileSystemDispatcher()->Truncate(path, offset, &request_id_,
|
| - new CallbackDispatcher(AsWeakPtr()));
|
| + GetFileSystemDispatcher()->Truncate(
|
| + path, offset, &request_id_,
|
| + CallbackDispatcher::GetStatusCallback(AsWeakPtr()));
|
| }
|
|
|
| void WebFileWriterImpl::DoWrite(
|
| const GURL& path, const GURL& blob_url, int64 offset) {
|
| GetFileSystemDispatcher()->Write(
|
| path, blob_url, offset, &request_id_,
|
| - new CallbackDispatcher(AsWeakPtr()));
|
| + CallbackDispatcher::GetWriteCallback(AsWeakPtr()));
|
| }
|
|
|
| void WebFileWriterImpl::DoCancel() {
|
| - GetFileSystemDispatcher()->Cancel(request_id_,
|
| - new CallbackDispatcher(AsWeakPtr()));
|
| + GetFileSystemDispatcher()->Cancel(
|
| + request_id_,
|
| + CallbackDispatcher::GetStatusCallback(AsWeakPtr()));
|
| }
|
|
|
| } // namespace content
|
|
|