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 @@ ...@@ -4,6 +4,7 @@
#include "webkit/appcache/appcache_response.h" #include "webkit/appcache/appcache_response.h"
#include "base/bind.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/pickle.h" #include "base/pickle.h"
...@@ -75,7 +76,7 @@ AppCacheResponseIO::AppCacheResponseIO( ...@@ -75,7 +76,7 @@ AppCacheResponseIO::AppCacheResponseIO(
int64 response_id, int64 group_id, AppCacheDiskCacheInterface* disk_cache) int64 response_id, int64 group_id, AppCacheDiskCacheInterface* disk_cache)
: response_id_(response_id), group_id_(group_id), disk_cache_(disk_cache), : response_id_(response_id), group_id_(group_id), disk_cache_(disk_cache),
entry_(NULL), buffer_len_(0), user_callback_(NULL), 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_( ALLOW_THIS_IN_INITIALIZER_LIST(raw_callback_(
new net::CancelableOldCompletionCallback<AppCacheResponseIO>( new net::CancelableOldCompletionCallback<AppCacheResponseIO>(
this, &AppCacheResponseIO::OnRawIOComplete))) { this, &AppCacheResponseIO::OnRawIOComplete))) {
...@@ -88,9 +89,9 @@ AppCacheResponseIO::~AppCacheResponseIO() { ...@@ -88,9 +89,9 @@ AppCacheResponseIO::~AppCacheResponseIO() {
} }
void AppCacheResponseIO::ScheduleIOOldCompletionCallback(int result) { void AppCacheResponseIO::ScheduleIOOldCompletionCallback(int result) {
MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::current()->PostTask(
method_factory_.NewRunnableMethod( FROM_HERE, base::Bind(&AppCacheResponseIO::OnIOComplete,
&AppCacheResponseIO::OnIOComplete, result)); weak_factory_.GetWeakPtr(), result));
} }
void AppCacheResponseIO::InvokeUserOldCompletionCallback(int result) { void AppCacheResponseIO::InvokeUserOldCompletionCallback(int result) {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/task.h" #include "base/memory/weak_ptr.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
#include "net/base/completion_callback.h" #include "net/base/completion_callback.h"
#include "net/http/http_response_info.h" #include "net/http/http_response_info.h"
...@@ -100,8 +100,6 @@ class APPCACHE_EXPORT AppCacheResponseIO { ...@@ -100,8 +100,6 @@ class APPCACHE_EXPORT AppCacheResponseIO {
int64 response_id() const { return response_id_; } int64 response_id() const { return response_id_; }
protected: protected:
friend class ScopedRunnableMethodFactory<AppCacheResponseIO>;
template <class T> template <class T>
class EntryCallback : public net::CancelableOldCompletionCallback<T> { class EntryCallback : public net::CancelableOldCompletionCallback<T> {
public: public:
...@@ -137,7 +135,7 @@ class APPCACHE_EXPORT AppCacheResponseIO { ...@@ -137,7 +135,7 @@ class APPCACHE_EXPORT AppCacheResponseIO {
scoped_refptr<net::IOBuffer> buffer_; scoped_refptr<net::IOBuffer> buffer_;
int buffer_len_; int buffer_len_;
net::OldCompletionCallback* user_callback_; net::OldCompletionCallback* user_callback_;
ScopedRunnableMethodFactory<AppCacheResponseIO> method_factory_; base::WeakPtrFactory<AppCacheResponseIO> weak_factory_;
private: private:
void OnRawIOComplete(int result); void OnRawIOComplete(int result);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "webkit/appcache/appcache_service.h" #include "webkit/appcache/appcache_service.h"
#include "base/bind.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/stl_util.h" #include "base/stl_util.h"
...@@ -49,13 +50,13 @@ class AppCacheService::AsyncHelper ...@@ -49,13 +50,13 @@ class AppCacheService::AsyncHelper
if (callback_) { if (callback_) {
// Defer to guarentee async completion. // Defer to guarentee async completion.
MessageLoop::current()->PostTask( MessageLoop::current()->PostTask(
FROM_HERE, FROM_HERE, base::Bind(&DeferredCallCallback, callback_, rv));
NewRunnableFunction(&DeferredCallCallback, callback_, rv));
} }
callback_ = NULL; callback_ = NULL;
} }
static void DeferredCallCallback(net::OldCompletionCallback* callback, int rv) { static void DeferredCallCallback(net::OldCompletionCallback* callback,
int rv) {
callback->Run(rv); callback->Run(rv);
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <string> #include <string>
#include "base/bind.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/pickle.h" #include "base/pickle.h"
#include "net/base/completion_callback.h" #include "net/base/completion_callback.h"
...@@ -65,9 +66,10 @@ class MockResponseReader : public AppCacheResponseReader { ...@@ -65,9 +66,10 @@ class MockResponseReader : public AppCacheResponseReader {
private: private:
void ScheduleUserCallback(int result) { void ScheduleUserCallback(int result) {
MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::current()->PostTask(
method_factory_.NewRunnableMethod( FROM_HERE,
&MockResponseReader::InvokeUserOldCompletionCallback, result)); base::Bind(&MockResponseReader::InvokeUserOldCompletionCallback,
weak_factory_.GetWeakPtr(), result));
} }
scoped_ptr<net::HttpResponseInfo> info_; scoped_ptr<net::HttpResponseInfo> info_;
......
...@@ -30,7 +30,7 @@ AppCacheURLRequestJob::AppCacheURLRequestJob( ...@@ -30,7 +30,7 @@ AppCacheURLRequestJob::AppCacheURLRequestJob(
cache_entry_not_found_(false), cache_entry_not_found_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_( ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_(
this, &AppCacheURLRequestJob::OnReadComplete)), this, &AppCacheURLRequestJob::OnReadComplete)),
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
DCHECK(storage_); DCHECK(storage_);
} }
...@@ -73,8 +73,8 @@ void AppCacheURLRequestJob::MaybeBeginDelivery() { ...@@ -73,8 +73,8 @@ void AppCacheURLRequestJob::MaybeBeginDelivery() {
// callbacks happen as they would for network requests. // callbacks happen as they would for network requests.
MessageLoop::current()->PostTask( MessageLoop::current()->PostTask(
FROM_HERE, FROM_HERE,
method_factory_.NewRunnableMethod( base::Bind(&AppCacheURLRequestJob::BeginDelivery,
&AppCacheURLRequestJob::BeginDelivery)); weak_factory_.GetWeakPtr()));
} }
} }
...@@ -220,7 +220,7 @@ void AppCacheURLRequestJob::Kill() { ...@@ -220,7 +220,7 @@ void AppCacheURLRequestJob::Kill() {
storage_ = NULL; storage_ = NULL;
} }
net::URLRequestJob::Kill(); net::URLRequestJob::Kill();
method_factory_.RevokeAll(); weak_factory_.InvalidateWeakPtrs();
} }
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <string> #include <string>
#include "base/task.h" #include "base/memory/weak_ptr.h"
#include "net/http/http_byte_range.h" #include "net/http/http_byte_range.h"
#include "net/url_request/url_request_job.h" #include "net/url_request/url_request_job.h"
#include "webkit/appcache/appcache_entry.h" #include "webkit/appcache/appcache_entry.h"
...@@ -137,7 +137,7 @@ class APPCACHE_EXPORT AppCacheURLRequestJob : public net::URLRequestJob, ...@@ -137,7 +137,7 @@ class APPCACHE_EXPORT AppCacheURLRequestJob : public net::URLRequestJob,
scoped_ptr<net::HttpResponseInfo> range_response_info_; scoped_ptr<net::HttpResponseInfo> range_response_info_;
scoped_ptr<AppCacheResponseReader> reader_; scoped_ptr<AppCacheResponseReader> reader_;
net::OldCompletionCallbackImpl<AppCacheURLRequestJob> read_callback_; net::OldCompletionCallbackImpl<AppCacheURLRequestJob> read_callback_;
ScopedRunnableMethodFactory<AppCacheURLRequestJob> method_factory_; base::WeakPtrFactory<AppCacheURLRequestJob> weak_factory_;
}; };
} // namespace appcache } // namespace appcache
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "webkit/appcache/mock_appcache_service.h" #include "webkit/appcache/mock_appcache_service.h"
#include "base/bind.h"
#include "base/message_loop.h" #include "base/message_loop.h"
namespace appcache { namespace appcache {
...@@ -17,8 +18,8 @@ void MockAppCacheService::DeleteAppCachesForOrigin( ...@@ -17,8 +18,8 @@ void MockAppCacheService::DeleteAppCachesForOrigin(
++delete_called_count_; ++delete_called_count_;
MessageLoop::current()->PostTask( MessageLoop::current()->PostTask(
FROM_HERE, FROM_HERE,
NewRunnableFunction(&DeferredCallCallback, callback, base::Bind(&DeferredCallCallback, callback,
mock_delete_appcaches_for_origin_result_)); mock_delete_appcaches_for_origin_result_));
} }
} // namespace appcache } // namespace appcache
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