Index: webkit/fileapi/file_system_operation.cc |
diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc |
index 7d2dcb0e615a3a60654316ecf9c4441a3d6393ec..1cd5e5d8668703b738f2ae97ea355d46bc76fa32 100644 |
--- a/webkit/fileapi/file_system_operation.cc |
+++ b/webkit/fileapi/file_system_operation.cc |
@@ -4,6 +4,7 @@ |
#include "webkit/fileapi/file_system_operation.h" |
+#include "base/bind.h" |
#include "base/time.h" |
#include "base/utf_string_conversions.h" |
#include "net/base/escape.h" |
@@ -64,6 +65,7 @@ FileSystemOperation::FileSystemOperation( |
: proxy_(proxy), |
dispatcher_(dispatcher), |
file_system_operation_context_(file_system_context, file_util), |
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
DCHECK(dispatcher); |
#ifndef NDEBUG |
@@ -120,8 +122,10 @@ void FileSystemOperation::CreateFile(const GURL& path, |
file_system_operation_context_.set_src_file_util(file_util); |
exclusive_ = exclusive; |
- GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( |
- &FileSystemOperation::DelayedCreateFileForQuota)); |
+ GetUsageAndQuotaThenCallback( |
+ origin_url, |
+ base::Bind(&FileSystemOperation::DelayedCreateFileForQuota, |
+ weak_factory_.GetWeakPtr())); |
} |
void FileSystemOperation::DelayedCreateFileForQuota( |
@@ -165,8 +169,10 @@ void FileSystemOperation::CreateDirectory(const GURL& path, |
exclusive_ = exclusive; |
recursive_ = recursive; |
- GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( |
- &FileSystemOperation::DelayedCreateDirectoryForQuota)); |
+ GetUsageAndQuotaThenCallback( |
+ origin_url, |
+ base::Bind(&FileSystemOperation::DelayedCreateDirectoryForQuota, |
+ weak_factory_.GetWeakPtr())); |
} |
void FileSystemOperation::DelayedCreateDirectoryForQuota( |
@@ -217,8 +223,10 @@ void FileSystemOperation::Copy(const GURL& src_path, |
if (!file_system_operation_context_.dest_file_util()) |
file_system_operation_context_.set_dest_file_util(dest_file_util); |
- GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback( |
- &FileSystemOperation::DelayedCopyForQuota)); |
+ GetUsageAndQuotaThenCallback( |
+ dest_origin_url, |
+ base::Bind(&FileSystemOperation::DelayedCopyForQuota, |
+ weak_factory_.GetWeakPtr())); |
} |
void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, |
@@ -268,8 +276,10 @@ void FileSystemOperation::Move(const GURL& src_path, |
if (!file_system_operation_context_.dest_file_util()) |
file_system_operation_context_.set_dest_file_util(dest_file_util); |
- GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback( |
- &FileSystemOperation::DelayedMoveForQuota)); |
+ GetUsageAndQuotaThenCallback( |
+ dest_origin_url, |
+ base::Bind(&FileSystemOperation::DelayedMoveForQuota, |
+ weak_factory_.GetWeakPtr())); |
} |
void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, |
@@ -442,8 +452,10 @@ void FileSystemOperation::Write( |
new net::URLRequest(blob_url, file_writer_delegate_.get())); |
blob_request_->set_context(url_request_context); |
- GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( |
- &FileSystemOperation::DelayedWriteForQuota)); |
+ GetUsageAndQuotaThenCallback( |
+ origin_url, |
+ base::Bind(&FileSystemOperation::DelayedWriteForQuota, |
+ weak_factory_.GetWeakPtr())); |
} |
void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, |
@@ -484,8 +496,10 @@ void FileSystemOperation::Truncate(const GURL& path, int64 length) { |
file_system_operation_context_.set_src_file_util(file_util); |
length_ = length; |
- GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( |
- &FileSystemOperation::DelayedTruncateForQuota)); |
+ GetUsageAndQuotaThenCallback( |
+ origin_url, |
+ base::Bind(&FileSystemOperation::DelayedTruncateForQuota, |
+ weak_factory_.GetWeakPtr())); |
} |
void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, |
@@ -574,8 +588,10 @@ void FileSystemOperation::OpenFile(const GURL& path, |
file_system_operation_context_.set_src_file_util(file_util); |
file_flags_ = file_flags; |
- GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( |
- &FileSystemOperation::DelayedOpenFileForQuota)); |
+ GetUsageAndQuotaThenCallback( |
+ origin_url, |
+ base::Bind(&FileSystemOperation::DelayedOpenFileForQuota, |
+ weak_factory_.GetWeakPtr())); |
} |
void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status, |
@@ -631,7 +647,7 @@ void FileSystemOperation::Cancel(FileSystemOperation* cancel_operation_ptr) { |
void FileSystemOperation::GetUsageAndQuotaThenCallback( |
const GURL& origin_url, |
- quota::QuotaManager::GetUsageAndQuotaCallback* callback) { |
+ quota::QuotaManager::GetUsageAndQuotaCallback callback) { |
quota::QuotaManagerProxy* quota_manager_proxy = |
file_system_context()->quota_manager_proxy(); |
if (!quota_manager_proxy || |
@@ -639,8 +655,7 @@ void FileSystemOperation::GetUsageAndQuotaThenCallback( |
file_system_operation_context_.src_type())) { |
// If we don't have the quota manager or the requested filesystem type |
// does not support quota, we should be able to let it go. |
- callback->Run(quota::kQuotaStatusOk, 0, kint64max); |
- delete callback; |
+ callback.Run(quota::kQuotaStatusOk, 0, kint64max); |
return; |
} |
DCHECK(quota_manager_proxy); |