summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-17 18:40:30 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-17 18:40:30 +0000
commit30c1eea51e20355f11cc37b1bf82ac11644ab2b8 (patch)
treeb031284a67e6d1618427301c83cd2ff6106b645e /webkit
parent35d5280876154e0dab2f472314e49dce2ced217b (diff)
downloadchromium_src-30c1eea51e20355f11cc37b1bf82ac11644ab2b8.zip
chromium_src-30c1eea51e20355f11cc37b1bf82ac11644ab2b8.tar.gz
chromium_src-30c1eea51e20355f11cc37b1bf82ac11644ab2b8.tar.bz2
base::Bind: Convert FileUtilProxy::CreateOrOpenCallback.
BUG=none TEST=none R=csilv@chromium.org Review URL: http://codereview.chromium.org/8311010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105860 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/blob/blob_url_request_job.cc6
-rw-r--r--webkit/blob/blob_url_request_job.h2
-rw-r--r--webkit/fileapi/file_system_file_util_proxy.cc13
-rw-r--r--webkit/fileapi/file_system_file_util_proxy.h2
-rw-r--r--webkit/fileapi/file_system_operation.cc22
-rw-r--r--webkit/fileapi/file_system_operation.h2
-rw-r--r--webkit/fileapi/file_system_url_request_job.cc7
-rw-r--r--webkit/fileapi/file_system_url_request_job.h4
-rw-r--r--webkit/fileapi/file_system_url_request_job_unittest.cc1
9 files changed, 31 insertions, 28 deletions
diff --git a/webkit/blob/blob_url_request_job.cc b/webkit/blob/blob_url_request_job.cc
index a02096f..d70536a 100644
--- a/webkit/blob/blob_url_request_job.cc
+++ b/webkit/blob/blob_url_request_job.cc
@@ -52,7 +52,8 @@ BlobURLRequestJob::BlobURLRequestJob(
BlobData* blob_data,
base::MessageLoopProxy* file_thread_proxy)
: net::URLRequestJob(request),
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
blob_data_(blob_data),
file_thread_proxy_(file_thread_proxy),
item_index_(0),
@@ -111,6 +112,7 @@ void BlobURLRequestJob::Kill() {
net::URLRequestJob::Kill();
callback_factory_.RevokeAll();
+ weak_factory_.InvalidateWeakPtrs();
method_factory_.RevokeAll();
}
@@ -316,7 +318,7 @@ bool BlobURLRequestJob::DispatchReadFile(const BlobData::Item& item) {
base::FileUtilProxy::CreateOrOpen(
file_thread_proxy_, item.file_path(), kFileOpenFlags,
- callback_factory_.NewCallback(&BlobURLRequestJob::DidOpen));
+ base::Bind(&BlobURLRequestJob::DidOpen, weak_factory_.GetWeakPtr()));
SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0));
return false;
}
diff --git a/webkit/blob/blob_url_request_job.h b/webkit/blob/blob_url_request_job.h
index ff563b86..160dfac 100644
--- a/webkit/blob/blob_url_request_job.h
+++ b/webkit/blob/blob_url_request_job.h
@@ -8,6 +8,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_callback_factory.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/platform_file.h"
#include "base/task.h"
#include "net/http/http_byte_range.h"
@@ -69,6 +70,7 @@ class BlobURLRequestJob : public net::URLRequestJob {
void DidRead(int result);
base::ScopedCallbackFactory<BlobURLRequestJob> callback_factory_;
+ base::WeakPtrFactory<BlobURLRequestJob> weak_factory_;
scoped_refptr<BlobData> blob_data_;
scoped_refptr<base::MessageLoopProxy> file_thread_proxy_;
std::vector<int64> item_length_list_;
diff --git a/webkit/fileapi/file_system_file_util_proxy.cc b/webkit/fileapi/file_system_file_util_proxy.cc
index 1906258..1372657 100644
--- a/webkit/fileapi/file_system_file_util_proxy.cc
+++ b/webkit/fileapi/file_system_file_util_proxy.cc
@@ -79,7 +79,7 @@ class RelayCreateOrOpen : public MessageLoopRelay {
scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
const FilePath& file_path,
int file_flags,
- fileapi::FileSystemFileUtilProxy::CreateOrOpenCallback* callback)
+ const fileapi::FileSystemFileUtilProxy::CreateOrOpenCallback& callback)
: MessageLoopRelay(context),
message_loop_proxy_(message_loop_proxy),
file_path_(file_path),
@@ -87,7 +87,7 @@ class RelayCreateOrOpen : public MessageLoopRelay {
callback_(callback),
file_handle_(base::kInvalidPlatformFileValue),
created_(false) {
- DCHECK(callback);
+ DCHECK_EQ(false, callback.is_null());
}
protected:
@@ -103,16 +103,15 @@ class RelayCreateOrOpen : public MessageLoopRelay {
}
virtual void RunCallback() {
- callback_->Run(error_code(), base::PassPlatformFile(&file_handle_),
- created_);
- delete callback_;
+ callback_.Run(error_code(), base::PassPlatformFile(&file_handle_),
+ created_);
}
private:
scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
FilePath file_path_;
int file_flags_;
- fileapi::FileSystemFileUtilProxy::CreateOrOpenCallback* callback_;
+ fileapi::FileSystemFileUtilProxy::CreateOrOpenCallback callback_;
base::PlatformFile file_handle_;
bool created_;
};
@@ -432,7 +431,7 @@ bool FileSystemFileUtilProxy::CreateOrOpen(
const FileSystemOperationContext& context,
scoped_refptr<MessageLoopProxy> message_loop_proxy,
const FilePath& file_path, int file_flags,
- CreateOrOpenCallback* callback) {
+ const CreateOrOpenCallback& callback) {
return Start(FROM_HERE, message_loop_proxy, new RelayCreateOrOpen(context,
message_loop_proxy, file_path, file_flags, callback));
}
diff --git a/webkit/fileapi/file_system_file_util_proxy.h b/webkit/fileapi/file_system_file_util_proxy.h
index e376314..e05b81a 100644
--- a/webkit/fileapi/file_system_file_util_proxy.h
+++ b/webkit/fileapi/file_system_file_util_proxy.h
@@ -54,7 +54,7 @@ class FileSystemFileUtilProxy {
scoped_refptr<MessageLoopProxy> message_loop_proxy,
const FilePath& file_path,
int file_flags,
- CreateOrOpenCallback* callback);
+ const CreateOrOpenCallback& callback);
// Close the given file handle.
static bool Close(const FileSystemOperationContext& context,
diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc
index a02e2a7..93bd3ae 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,7 +65,8 @@ FileSystemOperation::FileSystemOperation(
: proxy_(proxy),
dispatcher_(dispatcher),
file_system_operation_context_(file_system_context, file_util),
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
DCHECK(dispatcher);
#ifndef NDEBUG
pending_operation_ = kOperationNone;
@@ -179,10 +181,7 @@ void FileSystemOperation::DelayedCreateDirectoryForQuota(
file_system_operation_context_.src_type()));
FileSystemFileUtilProxy::CreateDirectory(
- file_system_operation_context_,
- proxy_,
- src_virtual_path_,
- exclusive_,
+ file_system_operation_context_, proxy_, src_virtual_path_, exclusive_,
recursive_,
callback_factory_.NewCallback(
&FileSystemOperation::DidFinishFileOperation));
@@ -461,8 +460,8 @@ void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status,
src_virtual_path_,
base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE |
base::PLATFORM_FILE_ASYNC,
- callback_factory_.NewCallback(
- &FileSystemOperation::OnFileOpenedForWrite));
+ base::Bind(&FileSystemOperation::OnFileOpenedForWrite,
+ weak_factory_.GetWeakPtr()));
}
void FileSystemOperation::Truncate(const GURL& path, int64 length) {
@@ -588,12 +587,9 @@ void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status,
file_system_operation_context_.src_type()));
FileSystemFileUtilProxy::CreateOrOpen(
- file_system_operation_context_,
- proxy_,
- src_virtual_path_,
- file_flags_,
- callback_factory_.NewCallback(
- &FileSystemOperation::DidOpenFile));
+ file_system_operation_context_, proxy_, src_virtual_path_, file_flags_,
+ base::Bind(&FileSystemOperation::DidOpenFile,
+ weak_factory_.GetWeakPtr()));
}
// We can only get here on a write or truncate that's not yet completed.
diff --git a/webkit/fileapi/file_system_operation.h b/webkit/fileapi/file_system_operation.h
index b38633a..5876692 100644
--- a/webkit/fileapi/file_system_operation.h
+++ b/webkit/fileapi/file_system_operation.h
@@ -13,6 +13,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_callback_factory.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/message_loop_proxy.h"
#include "base/platform_file.h"
#include "base/process.h"
@@ -241,6 +242,7 @@ class FileSystemOperation {
FileSystemOperationContext file_system_operation_context_;
base::ScopedCallbackFactory<FileSystemOperation> callback_factory_;
+ base::WeakPtrFactory<FileSystemOperation> weak_factory_;
scoped_ptr<ScopedQuotaUtilHelper> quota_util_helper_;
diff --git a/webkit/fileapi/file_system_url_request_job.cc b/webkit/fileapi/file_system_url_request_job.cc
index 8cdf9d4..8c28ded 100644
--- a/webkit/fileapi/file_system_url_request_job.cc
+++ b/webkit/fileapi/file_system_url_request_job.cc
@@ -107,7 +107,7 @@ FileSystemURLRequestJob::FileSystemURLRequestJob(
file_system_context_(file_system_context),
file_thread_proxy_(file_thread_proxy),
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
- ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
stream_(NULL),
is_directory_(false),
remaining_bytes_(0) {
@@ -133,7 +133,7 @@ void FileSystemURLRequestJob::Kill() {
}
URLRequestJob::Kill();
method_factory_.RevokeAll();
- callback_factory_.RevokeAll();
+ weak_factory_.InvalidateWeakPtrs();
}
bool FileSystemURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size,
@@ -239,7 +239,8 @@ void FileSystemURLRequestJob::DidGetMetadata(
if (!is_directory_) {
base::FileUtilProxy::CreateOrOpen(
file_thread_proxy_, platform_path, kFileFlags,
- callback_factory_.NewCallback(&FileSystemURLRequestJob::DidOpen));
+ base::Bind(&FileSystemURLRequestJob::DidOpen,
+ weak_factory_.GetWeakPtr()));
} else {
NotifyHeadersComplete();
}
diff --git a/webkit/fileapi/file_system_url_request_job.h b/webkit/fileapi/file_system_url_request_job.h
index 1c66708..945e257 100644
--- a/webkit/fileapi/file_system_url_request_job.h
+++ b/webkit/fileapi/file_system_url_request_job.h
@@ -8,8 +8,8 @@
#include <string>
-#include "base/memory/scoped_callback_factory.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/message_loop_proxy.h"
#include "base/platform_file.h"
#include "base/task.h"
@@ -62,7 +62,7 @@ class FileSystemURLRequestJob : public net::URLRequestJob {
FileSystemContext* file_system_context_;
scoped_refptr<base::MessageLoopProxy> file_thread_proxy_;
ScopedRunnableMethodFactory<FileSystemURLRequestJob> method_factory_;
- base::ScopedCallbackFactory<FileSystemURLRequestJob> callback_factory_;
+ base::WeakPtrFactory<FileSystemURLRequestJob> weak_factory_;
scoped_ptr<net::FileStream> stream_;
bool is_directory_;
scoped_ptr<net::HttpResponseInfo> response_info_;
diff --git a/webkit/fileapi/file_system_url_request_job_unittest.cc b/webkit/fileapi/file_system_url_request_job_unittest.cc
index 0070033..33e0e7c 100644
--- a/webkit/fileapi/file_system_url_request_job_unittest.cc
+++ b/webkit/fileapi/file_system_url_request_job_unittest.cc
@@ -17,6 +17,7 @@
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/format_macros.h"
+#include "base/memory/scoped_callback_factory.h"
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
#include "base/platform_file.h"