diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-20 22:03:43 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-20 22:03:43 +0000 |
commit | 9e629ab7f5050ea6de068c2cf2d5099d6ce2d41a (patch) | |
tree | a3966fb64e445ab48ac995f50b4a6f7dd562ecc5 /webkit/fileapi/file_writer_delegate.cc | |
parent | 1dd1c7d6265f69a5c0aea599e3fed3d6e4e8cc41 (diff) | |
download | chromium_src-9e629ab7f5050ea6de068c2cf2d5099d6ce2d41a.zip chromium_src-9e629ab7f5050ea6de068c2cf2d5099d6ce2d41a.tar.gz chromium_src-9e629ab7f5050ea6de068c2cf2d5099d6ce2d41a.tar.bz2 |
base::Bind: Final cleanup in webkit/fileapi.
BUG=none
TEST=none
R=csilv@chromium.org
Review URL: http://codereview.chromium.org/8353023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106600 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/file_writer_delegate.cc')
-rw-r--r-- | webkit/fileapi/file_writer_delegate.cc | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/webkit/fileapi/file_writer_delegate.cc b/webkit/fileapi/file_writer_delegate.cc index 4c4ab24..4bd1fc3 100644 --- a/webkit/fileapi/file_writer_delegate.cc +++ b/webkit/fileapi/file_writer_delegate.cc @@ -5,6 +5,7 @@ #include "webkit/fileapi/file_writer_delegate.h" #include "base/bind.h" +#include "base/callback.h" #include "base/file_util_proxy.h" #include "base/message_loop.h" #include "base/threading/thread_restrictions.h" @@ -22,37 +23,37 @@ static const int kReadBufSize = 32768; namespace { -typedef Callback2<base::PlatformFileError /* error code */, - const base::PlatformFileInfo& /* file_info */ - >::Type InitializeTaskCallback; +typedef base::Callback<void(base::PlatformFileError /* error code */, + const base::PlatformFileInfo& /* file_info */)> + InitializeTaskCallback; class InitializeTask : public base::RefCountedThreadSafe<InitializeTask> { public: InitializeTask( base::PlatformFile file, FileSystemOperationContext* context, - InitializeTaskCallback* callback) + const InitializeTaskCallback& callback) : origin_message_loop_proxy_( base::MessageLoopProxy::current()), error_code_(base::PLATFORM_FILE_OK), file_(file), context_(*context), callback_(callback) { - DCHECK(callback); + DCHECK_EQ(false, callback.is_null()); } bool Start(scoped_refptr<base::MessageLoopProxy> message_loop_proxy, const tracked_objects::Location& from_here) { - return message_loop_proxy->PostTask(from_here, NewRunnableMethod(this, - &InitializeTask::ProcessOnTargetThread)); + return message_loop_proxy->PostTask( + from_here, + base::Bind(&InitializeTask::ProcessOnTargetThread, this)); } private: friend class base::RefCountedThreadSafe<InitializeTask>; void RunCallback() { - callback_->Run(error_code_, file_info_); - delete callback_; + callback_.Run(error_code_, file_info_); } void ProcessOnTargetThread() { @@ -66,8 +67,9 @@ class InitializeTask : public base::RefCountedThreadSafe<InitializeTask> { } if (!base::GetPlatformFileInfo(file_, &file_info_)) error_code_ = base::PLATFORM_FILE_ERROR_FAILED; - origin_message_loop_proxy_->PostTask(FROM_HERE, NewRunnableMethod(this, - &InitializeTask::RunCallback)); + origin_message_loop_proxy_->PostTask( + FROM_HERE, + base::Bind(&InitializeTask::RunCallback, this)); } scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; @@ -75,7 +77,7 @@ class InitializeTask : public base::RefCountedThreadSafe<InitializeTask> { base::PlatformFile file_; FileSystemOperationContext context_; - InitializeTaskCallback* callback_; + InitializeTaskCallback callback_; base::PlatformFileInfo file_info_; }; @@ -95,8 +97,7 @@ FileWriterDelegate::FileWriterDelegate( total_bytes_written_(0), allowed_bytes_to_write_(0), io_buffer_(new net::IOBufferWithSize(kReadBufSize)), - method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), - callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { } FileWriterDelegate::~FileWriterDelegate() { @@ -131,8 +132,8 @@ void FileWriterDelegate::Start(base::PlatformFile file, scoped_refptr<InitializeTask> relay = new InitializeTask( file_, file_system_operation_context(), - callback_factory_.NewCallback( - &FileWriterDelegate::OnGetFileInfoAndCallStartUpdate)); + base::Bind(&FileWriterDelegate::OnGetFileInfoAndCallStartUpdate, + weak_factory_.GetWeakPtr())); relay->Start(proxy_, FROM_HERE); } @@ -196,8 +197,8 @@ void FileWriterDelegate::Read() { if (request_->Read(io_buffer_.get(), io_buffer_->size(), &bytes_read_)) { MessageLoop::current()->PostTask( FROM_HERE, - method_factory_.NewRunnableMethod( - &FileWriterDelegate::OnDataReceived, bytes_read_)); + base::Bind(&FileWriterDelegate::OnDataReceived, + weak_factory_.GetWeakPtr(), bytes_read_)); } else if (!request_->status().is_io_pending()) { OnError(base::PLATFORM_FILE_ERROR_FAILED); } @@ -239,8 +240,8 @@ void FileWriterDelegate::Write() { if (write_response > 0) MessageLoop::current()->PostTask( FROM_HERE, - method_factory_.NewRunnableMethod( - &FileWriterDelegate::OnDataWritten, write_response)); + base::Bind(&FileWriterDelegate::OnDataWritten, + weak_factory_.GetWeakPtr(), write_response)); else if (net::ERR_IO_PENDING != write_response) OnError(base::PLATFORM_FILE_ERROR_FAILED); } |