Commit e29f9339 authored by michaeln@google.com's avatar michaeln@google.com

base::Bind: Cleanups in webkit/appcache

Review URL: http://codereview.chromium.org/8399019

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107812 0039d316-1c4b-4281-b951-d872f2087c98
parent 11b63ca1
......@@ -4,6 +4,7 @@
#include "webkit/appcache/appcache_response.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/pickle.h"
......@@ -75,7 +76,7 @@ AppCacheResponseIO::AppCacheResponseIO(
int64 response_id, int64 group_id, AppCacheDiskCacheInterface* disk_cache)
: response_id_(response_id), group_id_(group_id), disk_cache_(disk_cache),
entry_(NULL), buffer_len_(0), user_callback_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
ALLOW_THIS_IN_INITIALIZER_LIST(raw_callback_(
new net::CancelableOldCompletionCallback<AppCacheResponseIO>(
this, &AppCacheResponseIO::OnRawIOComplete))) {
......@@ -88,9 +89,9 @@ AppCacheResponseIO::~AppCacheResponseIO() {
}
void AppCacheResponseIO::ScheduleIOOldCompletionCallback(int result) {
MessageLoop::current()->PostTask(FROM_HERE,
method_factory_.NewRunnableMethod(
&AppCacheResponseIO::OnIOComplete, result));
MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(&AppCacheResponseIO::OnIOComplete,
weak_factory_.GetWeakPtr(), result));
}
void AppCacheResponseIO::InvokeUserOldCompletionCallback(int result) {
......
......@@ -8,7 +8,7 @@
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/task.h"
#include "base/memory/weak_ptr.h"
#include "googleurl/src/gurl.h"
#include "net/base/completion_callback.h"
#include "net/http/http_response_info.h"
......@@ -100,8 +100,6 @@ class APPCACHE_EXPORT AppCacheResponseIO {
int64 response_id() const { return response_id_; }
protected:
friend class ScopedRunnableMethodFactory<AppCacheResponseIO>;
template <class T>
class EntryCallback : public net::CancelableOldCompletionCallback<T> {
public:
......@@ -137,7 +135,7 @@ class APPCACHE_EXPORT AppCacheResponseIO {
scoped_refptr<net::IOBuffer> buffer_;
int buffer_len_;
net::OldCompletionCallback* user_callback_;
ScopedRunnableMethodFactory<AppCacheResponseIO> method_factory_;
base::WeakPtrFactory<AppCacheResponseIO> weak_factory_;
private:
void OnRawIOComplete(int result);
......
......@@ -4,6 +4,7 @@
#include "webkit/appcache/appcache_service.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/stl_util.h"
......@@ -49,13 +50,13 @@ class AppCacheService::AsyncHelper
if (callback_) {
// Defer to guarentee async completion.
MessageLoop::current()->PostTask(
FROM_HERE,
NewRunnableFunction(&DeferredCallCallback, callback_, rv));
FROM_HERE, base::Bind(&DeferredCallCallback, callback_, rv));
}
callback_ = NULL;
}
static void DeferredCallCallback(net::OldCompletionCallback* callback, int rv) {
static void DeferredCallCallback(net::OldCompletionCallback* callback,
int rv) {
callback->Run(rv);
}
......
......@@ -4,6 +4,7 @@
#include <string>
#include "base/bind.h"
#include "base/message_loop.h"
#include "base/pickle.h"
#include "net/base/completion_callback.h"
......@@ -65,9 +66,10 @@ class MockResponseReader : public AppCacheResponseReader {
private:
void ScheduleUserCallback(int result) {
MessageLoop::current()->PostTask(FROM_HERE,
method_factory_.NewRunnableMethod(
&MockResponseReader::InvokeUserOldCompletionCallback, result));
MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&MockResponseReader::InvokeUserOldCompletionCallback,
weak_factory_.GetWeakPtr(), result));
}
scoped_ptr<net::HttpResponseInfo> info_;
......
......@@ -30,7 +30,7 @@ AppCacheURLRequestJob::AppCacheURLRequestJob(
cache_entry_not_found_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_(
this, &AppCacheURLRequestJob::OnReadComplete)),
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
DCHECK(storage_);
}
......@@ -73,8 +73,8 @@ void AppCacheURLRequestJob::MaybeBeginDelivery() {
// callbacks happen as they would for network requests.
MessageLoop::current()->PostTask(
FROM_HERE,
method_factory_.NewRunnableMethod(
&AppCacheURLRequestJob::BeginDelivery));
base::Bind(&AppCacheURLRequestJob::BeginDelivery,
weak_factory_.GetWeakPtr()));
}
}
......@@ -220,7 +220,7 @@ void AppCacheURLRequestJob::Kill() {
storage_ = NULL;
}
net::URLRequestJob::Kill();
method_factory_.RevokeAll();
weak_factory_.InvalidateWeakPtrs();
}
}
......
......@@ -7,7 +7,7 @@
#include <string>
#include "base/task.h"
#include "base/memory/weak_ptr.h"
#include "net/http/http_byte_range.h"
#include "net/url_request/url_request_job.h"
#include "webkit/appcache/appcache_entry.h"
......@@ -137,7 +137,7 @@ class APPCACHE_EXPORT AppCacheURLRequestJob : public net::URLRequestJob,
scoped_ptr<net::HttpResponseInfo> range_response_info_;
scoped_ptr<AppCacheResponseReader> reader_;
net::OldCompletionCallbackImpl<AppCacheURLRequestJob> read_callback_;
ScopedRunnableMethodFactory<AppCacheURLRequestJob> method_factory_;
base::WeakPtrFactory<AppCacheURLRequestJob> weak_factory_;
};
} // namespace appcache
......
......@@ -4,6 +4,7 @@
#include "webkit/appcache/mock_appcache_service.h"
#include "base/bind.h"
#include "base/message_loop.h"
namespace appcache {
......@@ -17,7 +18,7 @@ void MockAppCacheService::DeleteAppCachesForOrigin(
++delete_called_count_;
MessageLoop::current()->PostTask(
FROM_HERE,
NewRunnableFunction(&DeferredCallCallback, callback,
base::Bind(&DeferredCallCallback, callback,
mock_delete_appcaches_for_origin_result_));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment