Index: webkit/plugins/ppapi/quota_file_io.cc |
diff --git a/webkit/plugins/ppapi/quota_file_io.cc b/webkit/plugins/ppapi/quota_file_io.cc |
index 4a26f676bd7a943e6655d0f53b264e486d19b1b4..65b105b32f8f3bb31c964d2844388c2cbbfcff8b 100644 |
--- a/webkit/plugins/ppapi/quota_file_io.cc |
+++ b/webkit/plugins/ppapi/quota_file_io.cc |
@@ -14,6 +14,7 @@ |
#include "webkit/plugins/ppapi/resource_helper.h" |
#include "webkit/plugins/ppapi/resource_tracker.h" |
+using base::FileUtilProxy; |
using base::PlatformFile; |
using base::PlatformFileError; |
using quota::StorageType; |
@@ -63,7 +64,7 @@ class QuotaFileIO::WriteOperation : public PendingOperationBase { |
int64_t offset, |
const char* buffer, |
int32_t bytes_to_write, |
- WriteCallback* callback) |
+ const WriteCallback& callback) |
: PendingOperationBase(quota_io, is_will_operation), |
offset_(offset), |
bytes_to_write_(bytes_to_write), |
@@ -71,8 +72,7 @@ class QuotaFileIO::WriteOperation : public PendingOperationBase { |
finished_(false), |
status_(base::PLATFORM_FILE_OK), |
bytes_written_(0), |
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
- runnable_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
+ weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
if (!is_will_operation) { |
// TODO(kinuko): check the API convention if we really need to keep a |
// copy of the buffer during the async write operations. |
@@ -100,10 +100,11 @@ class QuotaFileIO::WriteOperation : public PendingOperationBase { |
return; |
} |
- if (!base::FileUtilProxy::Write( |
+ if (!FileUtilProxy::Write( |
plugin_delegate->GetFileThreadMessageLoopProxy(), |
quota_io_->file_, offset_, buffer_.get(), bytes_to_write_, |
- callback_factory_.NewCallback(&WriteOperation::DidFinish))) { |
+ base::Bind(&WriteOperation::DidFinish, |
+ weak_ptr_factory_.GetWeakPtr()))) { |
DidFail(base::PLATFORM_FILE_ERROR_FAILED); |
return; |
} |
@@ -117,8 +118,9 @@ class QuotaFileIO::WriteOperation : public PendingOperationBase { |
virtual void WillRunCallback() { |
base::MessageLoopProxy::current()->PostTask( |
- FROM_HERE, runnable_factory_.NewRunnableMethod( |
- &WriteOperation::RunCallback)); |
+ FROM_HERE, |
+ base::Bind(&WriteOperation::RunCallback, |
+ weak_ptr_factory_.GetWeakPtr())); |
} |
private: |
@@ -133,21 +135,18 @@ class QuotaFileIO::WriteOperation : public PendingOperationBase { |
} |
virtual void RunCallback() { |
- DCHECK(callback_.get()); |
- callback_->Run(status_, bytes_written_); |
- callback_.reset(); |
- delete this; |
+ DCHECK(!callback_.is_null()); |
+ callback_.Run(status_, bytes_written_); |
} |
const int64_t offset_; |
scoped_array<char> buffer_; |
const int32_t bytes_to_write_; |
- scoped_ptr<WriteCallback> callback_; |
+ WriteCallback callback_; |
bool finished_; |
PlatformFileError status_; |
int64_t bytes_written_; |
- base::ScopedCallbackFactory<WriteOperation> callback_factory_; |
- ScopedRunnableMethodFactory<WriteOperation> runnable_factory_; |
+ base::WeakPtrFactory<WriteOperation> weak_ptr_factory_; |
}; |
class QuotaFileIO::SetLengthOperation : public PendingOperationBase { |
@@ -155,11 +154,11 @@ class QuotaFileIO::SetLengthOperation : public PendingOperationBase { |
SetLengthOperation(QuotaFileIO* quota_io, |
bool is_will_operation, |
int64_t length, |
- StatusCallback* callback) |
+ const StatusCallback& callback) |
: PendingOperationBase(quota_io, is_will_operation), |
length_(length), |
callback_(callback), |
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} |
+ weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} |
virtual ~SetLengthOperation() {} |
@@ -180,10 +179,13 @@ class QuotaFileIO::SetLengthOperation : public PendingOperationBase { |
return; |
} |
- if (!base::FileUtilProxy::Truncate( |
+ if (!FileUtilProxy::PostFileTaskAndReplyStatus<bool, PlatformFileError>( |
plugin_delegate->GetFileThreadMessageLoopProxy(), |
- quota_io_->file_, length_, |
- callback_factory_.NewCallback(&SetLengthOperation::DidFinish))) { |
+ FROM_HERE, |
+ base::Bind(&base::TruncatePlatformFile, |
+ quota_io_->file_, length_), |
+ base::Bind(&SetLengthOperation::DidFinish, |
+ weak_ptr_factory_.GetWeakPtr()))) { |
DidFail(base::PLATFORM_FILE_ERROR_FAILED); |
return; |
} |
@@ -196,15 +198,13 @@ class QuotaFileIO::SetLengthOperation : public PendingOperationBase { |
private: |
void DidFinish(PlatformFileError status) { |
quota_io_->DidSetLength(status, length_); |
- DCHECK(callback_.get()); |
- callback_->Run(status); |
- callback_.reset(); |
- delete this; |
+ DCHECK(!callback_.is_null()); |
+ callback_.Run(status); |
} |
int64_t length_; |
- scoped_ptr<StatusCallback> callback_; |
- base::ScopedCallbackFactory<SetLengthOperation> callback_factory_; |
+ StatusCallback callback_; |
+ base::WeakPtrFactory<SetLengthOperation> weak_ptr_factory_; |
}; |
// QuotaFileIO -------------------------------------------------------------- |
@@ -224,7 +224,6 @@ QuotaFileIO::QuotaFileIO( |
outstanding_errors_(0), |
max_written_offset_(0), |
inflight_operations_(0), |
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
DCHECK_NE(base::kInvalidPlatformFileValue, file_); |
DCHECK_NE(quota::kStorageTypeUnknown, storage_type_); |
@@ -240,9 +239,8 @@ QuotaFileIO::~QuotaFileIO() { |
bool QuotaFileIO::Write( |
int64_t offset, const char* buffer, int32_t bytes_to_write, |
- WriteCallback* callback) { |
+ const WriteCallback& callback) { |
if (bytes_to_write <= 0) { |
- delete callback; |
return false; |
} |
WriteOperation* op = new WriteOperation( |
@@ -250,7 +248,7 @@ bool QuotaFileIO::Write( |
return RegisterOperationForQuotaChecks(op); |
} |
-bool QuotaFileIO::SetLength(int64_t length, StatusCallback* callback) { |
+bool QuotaFileIO::SetLength(int64_t length, const StatusCallback& callback) { |
DCHECK(pending_operations_.empty()); |
SetLengthOperation* op = new SetLengthOperation( |
this, false, length, callback); |
@@ -258,13 +256,14 @@ bool QuotaFileIO::SetLength(int64_t length, StatusCallback* callback) { |
} |
bool QuotaFileIO::WillWrite( |
- int64_t offset, int32_t bytes_to_write, WriteCallback* callback) { |
+ int64_t offset, int32_t bytes_to_write, const WriteCallback& callback) { |
WriteOperation* op = new WriteOperation( |
this, true, offset, NULL, bytes_to_write, callback); |
return RegisterOperationForQuotaChecks(op); |
} |
-bool QuotaFileIO::WillSetLength(int64_t length, StatusCallback* callback) { |
+bool QuotaFileIO::WillSetLength( |
+ int64_t length, const StatusCallback& callback) { |
DCHECK(pending_operations_.empty()); |
SetLengthOperation* op = new SetLengthOperation(this, true, length, callback); |
return RegisterOperationForQuotaChecks(op); |
@@ -292,10 +291,10 @@ bool QuotaFileIO::RegisterOperationForQuotaChecks( |
// Query the file size. |
++outstanding_quota_queries_; |
- if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( |
+ if (!FileUtilProxy::GetFileInfoFromPlatformFile( |
plugin_delegate->GetFileThreadMessageLoopProxy(), file_, |
- callback_factory_.NewCallback( |
- &QuotaFileIO::DidQueryInfoForQuota))) { |
+ base::Bind(&QuotaFileIO::DidQueryInfoForQuota, |
+ weak_ptr_factory_.GetWeakPtr()))) { |
// This makes the call fail synchronously; we do not fire the callback |
// here but just delete the operation and return false. |
return false; |