summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-21 17:51:30 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-21 17:51:30 +0000
commit5030416098386143fa314dbfe14fa46acdd34198 (patch)
treeacc367f84f0ad0ae20d5ed1d09278fdaa48733ca /webkit
parent61af32de2587714e5df7b1892365a9106b273204 (diff)
downloadchromium_src-5030416098386143fa314dbfe14fa46acdd34198.zip
chromium_src-5030416098386143fa314dbfe14fa46acdd34198.tar.gz
chromium_src-5030416098386143fa314dbfe14fa46acdd34198.tar.bz2
base::Bind: Convert most of webkit/appcache.
BUG=none TEST=none R=csilv Review URL: http://codereview.chromium.org/8991001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115353 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/appcache/appcache_disk_cache.cc60
-rw-r--r--webkit/appcache/appcache_disk_cache.h32
-rw-r--r--webkit/appcache/appcache_request_handler_unittest.cc27
-rw-r--r--webkit/appcache/appcache_response.cc91
-rw-r--r--webkit/appcache/appcache_response.h20
-rw-r--r--webkit/appcache/appcache_response_unittest.cc42
-rw-r--r--webkit/appcache/appcache_service.cc25
-rw-r--r--webkit/appcache/appcache_service_unittest.cc8
-rw-r--r--webkit/appcache/appcache_storage.cc10
-rw-r--r--webkit/appcache/appcache_storage.h1
-rw-r--r--webkit/appcache/appcache_storage_impl.cc16
-rw-r--r--webkit/appcache/appcache_storage_impl.h4
-rw-r--r--webkit/appcache/appcache_update_job.cc51
-rw-r--r--webkit/appcache/appcache_update_job.h5
-rw-r--r--webkit/appcache/appcache_update_job_unittest.cc61
-rw-r--r--webkit/appcache/appcache_url_request_job.cc8
-rw-r--r--webkit/appcache/appcache_url_request_job.h1
-rw-r--r--webkit/appcache/appcache_url_request_job_unittest.cc26
-rw-r--r--webkit/appcache/mock_appcache_storage.h2
-rw-r--r--webkit/appcache/view_appcache_internals_job.cc9
-rw-r--r--webkit/fileapi/file_system_dir_url_request_job_unittest.cc12
-rw-r--r--webkit/fileapi/file_system_url_request_job_unittest.cc12
-rw-r--r--webkit/fileapi/webfilewriter_base_unittest.cc2
-rw-r--r--webkit/support/test_webmessageportchannel.cc6
24 files changed, 267 insertions, 264 deletions
diff --git a/webkit/appcache/appcache_disk_cache.cc b/webkit/appcache/appcache_disk_cache.cc
index 4c7d794..7cdc4ae 100644
--- a/webkit/appcache/appcache_disk_cache.cc
+++ b/webkit/appcache/appcache_disk_cache.cc
@@ -59,30 +59,28 @@ class AppCacheDiskCache::EntryImpl : public Entry {
class AppCacheDiskCache::ActiveCall {
public:
explicit ActiveCall(AppCacheDiskCache* owner)
- : entry_(NULL), callback_(NULL), owner_(owner), entry_ptr_(NULL),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- async_completion_(this, &ActiveCall::OnAsyncCompletion)) {
+ : entry_(NULL),
+ owner_(owner),
+ entry_ptr_(NULL) {
}
int CreateEntry(int64 key, Entry** entry,
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
int rv = owner_->disk_cache()->CreateEntry(
base::Int64ToString(key), &entry_ptr_,
- base::Bind(&ActiveCall::OnAsyncCompletion,
- base::Unretained(this)));
+ base::Bind(&ActiveCall::OnAsyncCompletion, base::Unretained(this)));
return HandleImmediateReturnValue(rv, entry, callback);
}
int OpenEntry(int64 key, Entry** entry,
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
int rv = owner_->disk_cache()->OpenEntry(
base::Int64ToString(key), &entry_ptr_,
- base::Bind(&ActiveCall::OnAsyncCompletion,
- base::Unretained(this)));
+ base::Bind(&ActiveCall::OnAsyncCompletion, base::Unretained(this)));
return HandleImmediateReturnValue(rv, entry, callback);
}
- int DoomEntry(int64 key, net::OldCompletionCallback* callback) {
+ int DoomEntry(int64 key, const net::CompletionCallback& callback) {
int rv = owner_->disk_cache()->DoomEntry(
base::Int64ToString(key),
base::Bind(&ActiveCall::OnAsyncCompletion, base::Unretained(this)));
@@ -91,7 +89,7 @@ class AppCacheDiskCache::ActiveCall {
private:
int HandleImmediateReturnValue(int rv, Entry** entry,
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
if (rv == net::ERR_IO_PENDING) {
// OnAsyncCompletion will be called later.
callback_ = callback;
@@ -109,20 +107,19 @@ class AppCacheDiskCache::ActiveCall {
owner_->RemoveActiveCall(this);
if (rv == net::OK && entry_)
*entry_ = new EntryImpl(entry_ptr_);
- callback_->Run(rv);
- callback_ = NULL;
+ callback_.Run(rv);
+ callback_.Reset();
delete this;
}
Entry** entry_;
- net::OldCompletionCallback* callback_;
+ net::CompletionCallback callback_;
AppCacheDiskCache* owner_;
disk_cache::Entry* entry_ptr_;
- net::OldCompletionCallbackImpl<ActiveCall> async_completion_;
};
AppCacheDiskCache::AppCacheDiskCache()
- : is_disabled_(false), init_callback_(NULL) {
+ : is_disabled_(false) {
}
AppCacheDiskCache::~AppCacheDiskCache() {
@@ -137,13 +134,14 @@ AppCacheDiskCache::~AppCacheDiskCache() {
int AppCacheDiskCache::InitWithDiskBackend(
const FilePath& disk_cache_directory, int disk_cache_size, bool force,
- base::MessageLoopProxy* cache_thread, net::OldCompletionCallback* callback) {
+ base::MessageLoopProxy* cache_thread,
+ const net::CompletionCallback& callback) {
return Init(net::APP_CACHE, disk_cache_directory,
disk_cache_size, force, cache_thread, callback);
}
int AppCacheDiskCache::InitWithMemBackend(
- int mem_cache_size, net::OldCompletionCallback* callback) {
+ int mem_cache_size, const net::CompletionCallback& callback) {
return Init(net::MEMORY_CACHE, FilePath(), mem_cache_size, false, NULL,
callback);
}
@@ -162,8 +160,9 @@ void AppCacheDiskCache::Disable() {
}
int AppCacheDiskCache::CreateEntry(int64 key, Entry** entry,
- net::OldCompletionCallback* callback) {
- DCHECK(entry && callback);
+ const net::CompletionCallback& callback) {
+ DCHECK(entry);
+ DCHECK(!callback.is_null());
if (is_disabled_)
return net::ERR_ABORTED;
@@ -179,8 +178,9 @@ int AppCacheDiskCache::CreateEntry(int64 key, Entry** entry,
}
int AppCacheDiskCache::OpenEntry(int64 key, Entry** entry,
- net::OldCompletionCallback* callback) {
- DCHECK(entry && callback);
+ const net::CompletionCallback& callback) {
+ DCHECK(entry);
+ DCHECK(!callback.is_null());
if (is_disabled_)
return net::ERR_ABORTED;
@@ -196,8 +196,8 @@ int AppCacheDiskCache::OpenEntry(int64 key, Entry** entry,
}
int AppCacheDiskCache::DoomEntry(int64 key,
- net::OldCompletionCallback* callback) {
- DCHECK(callback);
+ const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
if (is_disabled_)
return net::ERR_ABORTED;
@@ -212,11 +212,13 @@ int AppCacheDiskCache::DoomEntry(int64 key,
return (new ActiveCall(this))->DoomEntry(key, callback);
}
+AppCacheDiskCache::PendingCall::~PendingCall() {}
+
int AppCacheDiskCache::Init(net::CacheType cache_type,
const FilePath& cache_directory,
int cache_size, bool force,
base::MessageLoopProxy* cache_thread,
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
DCHECK(!is_initializing() && !disk_cache_.get());
is_disabled_ = false;
create_backend_callback_ = new CreateBackendCallback(
@@ -241,9 +243,9 @@ void AppCacheDiskCache::OnCreateBackendComplete(int rv) {
create_backend_callback_ = NULL;
// Invoke our clients callback function.
- if (init_callback_) {
- init_callback_->Run(rv);
- init_callback_ = NULL;
+ if (!init_callback_.is_null()) {
+ init_callback_.Run(rv);
+ init_callback_.Reset();
}
// Service pending calls that were queued up while we were initailizating.
@@ -265,7 +267,7 @@ void AppCacheDiskCache::OnCreateBackendComplete(int rv) {
break;
}
if (rv != net::ERR_IO_PENDING)
- iter->callback->Run(rv);
+ iter->callback.Run(rv);
}
pending_calls_.clear();
}
diff --git a/webkit/appcache/appcache_disk_cache.h b/webkit/appcache/appcache_disk_cache.h
index f5259c2..069127c 100644
--- a/webkit/appcache/appcache_disk_cache.h
+++ b/webkit/appcache/appcache_disk_cache.h
@@ -27,22 +27,22 @@ class APPCACHE_EXPORT AppCacheDiskCache
int InitWithDiskBackend(const FilePath& disk_cache_directory,
int disk_cache_size, bool force,
base::MessageLoopProxy* cache_thread,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
// Initializes the object to use memory only storage.
// This is used for Chrome's incognito browsing.
int InitWithMemBackend(int disk_cache_size,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
void Disable();
bool is_disabled() const { return is_disabled_; }
virtual int CreateEntry(int64 key, Entry** entry,
- net::OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int OpenEntry(int64 key, Entry** entry,
- net::OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int DoomEntry(int64 key,
- net::OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
private:
class EntryImpl;
@@ -76,13 +76,23 @@ class APPCACHE_EXPORT AppCacheDiskCache
PendingCallType call_type;
int64 key;
Entry** entry;
- net::OldCompletionCallback* callback;
+ net::CompletionCallback callback;
PendingCall()
- : call_type(CREATE), key(0), entry(NULL), callback(NULL) {}
+ : call_type(CREATE),
+ key(0),
+ entry(NULL) {
+ }
+
PendingCall(PendingCallType call_type, int64 key,
- Entry** entry, net::OldCompletionCallback* callback)
- : call_type(call_type), key(key), entry(entry), callback(callback) {}
+ Entry** entry, const net::CompletionCallback& callback)
+ : call_type(call_type),
+ key(key),
+ entry(entry),
+ callback(callback) {
+ }
+
+ ~PendingCall();
};
typedef std::vector<PendingCall> PendingCalls;
@@ -95,13 +105,13 @@ class APPCACHE_EXPORT AppCacheDiskCache
disk_cache::Backend* disk_cache() { return disk_cache_.get(); }
int Init(net::CacheType cache_type, const FilePath& directory,
int cache_size, bool force, base::MessageLoopProxy* cache_thread,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
void OnCreateBackendComplete(int rv);
void AddActiveCall(ActiveCall* call) { active_calls_.insert(call); }
void RemoveActiveCall(ActiveCall* call) { active_calls_.erase(call); }
bool is_disabled_;
- net::OldCompletionCallback* init_callback_;
+ net::CompletionCallback init_callback_;
scoped_refptr<CreateBackendCallback> create_backend_callback_;
PendingCalls pending_calls_;
ActiveCalls active_calls_;
diff --git a/webkit/appcache/appcache_request_handler_unittest.cc b/webkit/appcache/appcache_request_handler_unittest.cc
index edbda46..c576133 100644
--- a/webkit/appcache/appcache_request_handler_unittest.cc
+++ b/webkit/appcache/appcache_request_handler_unittest.cc
@@ -55,24 +55,13 @@ class AppCacheRequestHandlerTest : public testing::Test {
virtual void OnContentBlocked(int host_id, const GURL& manifest_url) {}
};
- // Helper class run a test on our io_thread. The io_thread
- // is spun up once and reused for all tests.
+ // Helper callback to run a test on our io_thread. The io_thread is spun up
+ // once and reused for all tests.
template <class Method>
- class WrapperTask : public Task {
- public:
- WrapperTask(AppCacheRequestHandlerTest* test, Method method)
- : test_(test), method_(method) {
- }
-
- virtual void Run() {
- test_->SetUpTest();
- (test_->*method_)();
- }
-
- private:
- AppCacheRequestHandlerTest* test_;
- Method method_;
- };
+ void MethodWrapper(Method method) {
+ SetUpTest();
+ (this->*method)();
+ }
// Subclasses to simulate particular responses so test cases can
// exercise fallback code paths.
@@ -168,7 +157,9 @@ class AppCacheRequestHandlerTest : public testing::Test {
void RunTestOnIOThread(Method method) {
test_finished_event_ .reset(new base::WaitableEvent(false, false));
io_thread_->message_loop()->PostTask(
- FROM_HERE, new WrapperTask<Method>(this, method));
+ FROM_HERE,
+ base::Bind(&AppCacheRequestHandlerTest::MethodWrapper<Method>,
+ base::Unretained(this), method));
test_finished_event_->Wait();
}
diff --git a/webkit/appcache/appcache_response.cc b/webkit/appcache/appcache_response.cc
index 60be758..05fdbf6 100644
--- a/webkit/appcache/appcache_response.cc
+++ b/webkit/appcache/appcache_response.cc
@@ -9,6 +9,7 @@
#include "base/message_loop.h"
#include "base/pickle.h"
#include "base/string_util.h"
+#include "net/base/completion_callback.h"
#include "net/base/net_errors.h"
#include "net/base/io_buffer.h"
#include "webkit/appcache/appcache_service.h"
@@ -74,8 +75,11 @@ HttpResponseInfoIOBuffer::~HttpResponseInfoIOBuffer() {}
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),
+ : response_id_(response_id),
+ group_id_(group_id),
+ disk_cache_(disk_cache),
+ entry_(NULL),
+ buffer_len_(0),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
}
@@ -95,9 +99,9 @@ void AppCacheResponseIO::InvokeUserOldCompletionCallback(int result) {
// so the caller can schedule additional operations in the callback.
buffer_ = NULL;
info_buffer_ = NULL;
- net::OldCompletionCallback* temp_user_callback = user_callback_;
- user_callback_ = NULL;
- temp_user_callback->Run(result);
+ net::CompletionCallback cb = callback_;
+ callback_.Reset();
+ cb.Run(result);
}
void AppCacheResponseIO::ReadRaw(int index, int offset,
@@ -143,13 +147,16 @@ AppCacheResponseReader::~AppCacheResponseReader() {
}
void AppCacheResponseReader::ReadInfo(HttpResponseInfoIOBuffer* info_buf,
- net::OldCompletionCallback* callback) {
- DCHECK(callback && !IsReadPending());
- DCHECK(info_buf && !info_buf->http_info.get());
- DCHECK(!buffer_.get() && !info_buffer_.get());
+ const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
+ DCHECK(!IsReadPending());
+ DCHECK(info_buf);
+ DCHECK(!info_buf->http_info.get());
+ DCHECK(!buffer_.get());
+ DCHECK(!info_buffer_.get());
info_buffer_ = info_buf;
- user_callback_ = callback; // cleared on completion
+ callback_ = callback; // cleared on completion
OpenEntryIfNeededAndContinue();
}
@@ -170,14 +177,17 @@ void AppCacheResponseReader::ContinueReadInfo() {
}
void AppCacheResponseReader::ReadData(net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) {
- DCHECK(callback && !IsReadPending());
- DCHECK(buf && (buf_len >= 0));
- DCHECK(!buffer_.get() && !info_buffer_.get());
+ const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
+ DCHECK(!IsReadPending());
+ DCHECK(buf);
+ DCHECK(buf_len >= 0);
+ DCHECK(!buffer_.get());
+ DCHECK(!info_buffer_.get());
buffer_ = buf;
buffer_len_ = buf_len;
- user_callback_ = callback; // cleared on completion
+ callback_ = callback; // cleared on completion
OpenEntryIfNeededAndContinue();
}
@@ -237,8 +247,9 @@ void AppCacheResponseReader::OpenEntryIfNeededAndContinue() {
} else {
open_callback_ = new EntryCallback<AppCacheResponseReader>(
this, &AppCacheResponseReader::OnOpenEntryComplete);
- rv = disk_cache_->OpenEntry(response_id_, &open_callback_->entry_ptr_,
- open_callback_.get());
+ rv = disk_cache_->OpenEntry(
+ response_id_, &open_callback_->entry_ptr_,
+ base::Bind(&net::OldCompletionCallbackAdapter, open_callback_));
}
if (rv != net::ERR_IO_PENDING)
@@ -276,15 +287,19 @@ AppCacheResponseWriter::~AppCacheResponseWriter() {
create_callback_.release()->Cancel();
}
-void AppCacheResponseWriter::WriteInfo(HttpResponseInfoIOBuffer* info_buf,
- net::OldCompletionCallback* callback) {
- DCHECK(callback && !IsWritePending());
- DCHECK(info_buf && info_buf->http_info.get());
- DCHECK(!buffer_.get() && !info_buffer_.get());
+void AppCacheResponseWriter::WriteInfo(
+ HttpResponseInfoIOBuffer* info_buf,
+ const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
+ DCHECK(!IsWritePending());
+ DCHECK(info_buf);
+ DCHECK(info_buf->http_info.get());
+ DCHECK(!buffer_.get());
+ DCHECK(!info_buffer_.get());
DCHECK(info_buf->http_info->headers);
info_buffer_ = info_buf;
- user_callback_ = callback; // cleared on completion
+ callback_ = callback; // cleared on completion
CreateEntryIfNeededAndContinue();
}
@@ -303,15 +318,18 @@ void AppCacheResponseWriter::ContinueWriteInfo() {
WriteRaw(kResponseInfoIndex, 0, buffer_, write_amount_);
}
-void AppCacheResponseWriter::WriteData(net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) {
- DCHECK(callback && !IsWritePending());
- DCHECK(buf && (buf_len >= 0));
- DCHECK(!buffer_.get() && !info_buffer_.get());
+void AppCacheResponseWriter::WriteData(
+ net::IOBuffer* buf, int buf_len, const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
+ DCHECK(!IsWritePending());
+ DCHECK(buf);
+ DCHECK(buf_len >= 0);
+ DCHECK(!buffer_.get());
+ DCHECK(!info_buffer_.get());
buffer_ = buf;
write_amount_ = buf_len;
- user_callback_ = callback; // cleared on completion
+ callback_ = callback; // cleared on completion
CreateEntryIfNeededAndContinue();
}
@@ -346,8 +364,9 @@ void AppCacheResponseWriter::CreateEntryIfNeededAndContinue() {
creation_phase_ = INITIAL_ATTEMPT;
create_callback_ = new EntryCallback<AppCacheResponseWriter>(
this, &AppCacheResponseWriter::OnCreateEntryComplete);
- rv = disk_cache_->CreateEntry(response_id_, &create_callback_->entry_ptr_,
- create_callback_.get());
+ rv = disk_cache_->CreateEntry(
+ response_id_, &create_callback_->entry_ptr_,
+ base::Bind(&net::OldCompletionCallbackAdapter, create_callback_));
}
if (rv != net::ERR_IO_PENDING)
OnCreateEntryComplete(rv);
@@ -360,15 +379,18 @@ void AppCacheResponseWriter::OnCreateEntryComplete(int rv) {
if (rv != net::OK) {
// We may try to overwrite existing entries.
creation_phase_ = DOOM_EXISTING;
- rv = disk_cache_->DoomEntry(response_id_, create_callback_.get());
+ rv = disk_cache_->DoomEntry(
+ response_id_, base::Bind(&net::OldCompletionCallbackAdapter,
+ create_callback_));
if (rv != net::ERR_IO_PENDING)
OnCreateEntryComplete(rv);
return;
}
} else if (creation_phase_ == DOOM_EXISTING) {
creation_phase_ = SECOND_ATTEMPT;
- rv = disk_cache_->CreateEntry(response_id_, &create_callback_->entry_ptr_,
- create_callback_.get());
+ rv = disk_cache_->CreateEntry(
+ response_id_, &create_callback_->entry_ptr_,
+ base::Bind(&net::OldCompletionCallbackAdapter, create_callback_));
if (rv != net::ERR_IO_PENDING)
OnCreateEntryComplete(rv);
return;
@@ -389,4 +411,3 @@ void AppCacheResponseWriter::OnCreateEntryComplete(int rv) {
}
} // namespace appcache
-
diff --git a/webkit/appcache/appcache_response.h b/webkit/appcache/appcache_response.h
index 4a538ee..b7d8a7d 100644
--- a/webkit/appcache/appcache_response.h
+++ b/webkit/appcache/appcache_response.h
@@ -67,7 +67,7 @@ struct APPCACHE_EXPORT HttpResponseInfoIOBuffer
virtual ~HttpResponseInfoIOBuffer();
};
-// Low level storage api used by the response reader and writer.
+// Low level storage API used by the response reader and writer.
class APPCACHE_EXPORT AppCacheDiskCacheInterface {
public:
class Entry {
@@ -83,10 +83,10 @@ class APPCACHE_EXPORT AppCacheDiskCacheInterface {
};
virtual int CreateEntry(int64 key, Entry** entry,
- net::OldCompletionCallback* callback) = 0;
+ const net::CompletionCallback& callback) = 0;
virtual int OpenEntry(int64 key, Entry** entry,
- net::OldCompletionCallback* callback) = 0;
- virtual int DoomEntry(int64 key, net::OldCompletionCallback* callback) = 0;
+ const net::CompletionCallback& callback) = 0;
+ virtual int DoomEntry(int64 key, const net::CompletionCallback& callback) = 0;
protected:
friend class base::RefCounted<AppCacheDiskCacheInterface>;
@@ -121,7 +121,7 @@ class APPCACHE_EXPORT AppCacheResponseIO {
virtual void OnIOComplete(int result) = 0;
- bool IsIOPending() { return user_callback_ ? true : false; }
+ bool IsIOPending() { return !callback_.is_null(); }
void ScheduleIOOldCompletionCallback(int result);
void InvokeUserOldCompletionCallback(int result);
void ReadRaw(int index, int offset, net::IOBuffer* buf, int buf_len);
@@ -134,7 +134,7 @@ class APPCACHE_EXPORT AppCacheResponseIO {
scoped_refptr<HttpResponseInfoIOBuffer> info_buffer_;
scoped_refptr<net::IOBuffer> buffer_;
int buffer_len_;
- net::OldCompletionCallback* user_callback_;
+ net::CompletionCallback callback_;
base::WeakPtrFactory<AppCacheResponseIO> weak_factory_;
private:
@@ -160,7 +160,7 @@ class APPCACHE_EXPORT AppCacheResponseReader : public AppCacheResponseIO {
// Should only be called where there is no Read operation in progress.
// (virtual for testing)
virtual void ReadInfo(HttpResponseInfoIOBuffer* info_buf,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
// Reads data from storage. Always returns the result of the read
// asynchronously through the 'callback'. Returns the number of bytes read
@@ -171,7 +171,7 @@ class APPCACHE_EXPORT AppCacheResponseReader : public AppCacheResponseIO {
// Should only be called where there is no Read operation in progress.
// (virtual for testing)
virtual void ReadData(net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
// Returns true if there is a read operation, for data or info, pending.
bool IsReadPending() { return IsIOPending(); }
@@ -218,7 +218,7 @@ class APPCACHE_EXPORT AppCacheResponseWriter : public AppCacheResponseIO {
// required parameter. The contents of 'info_buf' are not modified.
// Should only be called where there is no Write operation in progress.
void WriteInfo(HttpResponseInfoIOBuffer* info_buf,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
// Writes data to storage. Always returns the result of the write
// asynchronously through the 'callback'. Returns the number of bytes written
@@ -229,7 +229,7 @@ class APPCACHE_EXPORT AppCacheResponseWriter : public AppCacheResponseIO {
// The contents of 'buf' are not modified.
// Should only be called where there is no Write operation in progress.
void WriteData(net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
// Returns true if there is a write pending.
bool IsWritePending() { return IsIOPending(); }
diff --git a/webkit/appcache/appcache_response_unittest.cc b/webkit/appcache/appcache_response_unittest.cc
index 9b91712..4a4ac28 100644
--- a/webkit/appcache/appcache_response_unittest.cc
+++ b/webkit/appcache/appcache_response_unittest.cc
@@ -82,16 +82,7 @@ class AppCacheResponseTest : public testing::Test {
io_thread_.reset(NULL);
}
- AppCacheResponseTest()
- : ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_(
- this, &AppCacheResponseTest::OnReadComplete)),
- ALLOW_THIS_IN_INITIALIZER_LIST(read_info_callback_(
- this, &AppCacheResponseTest::OnReadInfoComplete)),
- ALLOW_THIS_IN_INITIALIZER_LIST(write_callback_(
- this, &AppCacheResponseTest::OnWriteComplete)),
- ALLOW_THIS_IN_INITIALIZER_LIST(write_info_callback_(
- this, &AppCacheResponseTest::OnWriteInfoComplete)) {
- }
+ AppCacheResponseTest() {}
template <class Method>
void RunTestOnIOThread(Method method) {
@@ -195,7 +186,10 @@ class AppCacheResponseTest : public testing::Test {
EXPECT_FALSE(writer_->IsWritePending());
expected_write_result_ = GetHttpResponseInfoSize(head);
write_info_buffer_ = new HttpResponseInfoIOBuffer(head);
- writer_->WriteInfo(write_info_buffer_, &write_info_callback_);
+ writer_->WriteInfo(
+ write_info_buffer_,
+ base::Bind(&AppCacheResponseTest::OnWriteInfoComplete,
+ base::Unretained(this)));
}
void WriteResponseBody(scoped_refptr<IOBuffer> io_buffer, int buf_len) {
@@ -203,7 +197,9 @@ class AppCacheResponseTest : public testing::Test {
write_buffer_ = io_buffer;
expected_write_result_ = buf_len;
writer_->WriteData(
- write_buffer_, buf_len, &write_callback_);
+ write_buffer_, buf_len,
+ base::Bind(&AppCacheResponseTest::OnWriteComplete,
+ base::Unretained(this)));
}
void ReadResponseBody(scoped_refptr<IOBuffer> io_buffer, int buf_len) {
@@ -211,7 +207,9 @@ class AppCacheResponseTest : public testing::Test {
read_buffer_ = io_buffer;
expected_read_result_ = buf_len;
reader_->ReadData(
- read_buffer_, buf_len, &read_callback_);
+ read_buffer_, buf_len,
+ base::Bind(&AppCacheResponseTest::OnReadComplete,
+ base::Unretained(this)));
}
// AppCacheResponseReader / Writer completion callbacks
@@ -321,7 +319,10 @@ class AppCacheResponseTest : public testing::Test {
void ReadNonExistentInfo() {
EXPECT_FALSE(reader_->IsReadPending());
read_info_buffer_ = new HttpResponseInfoIOBuffer();
- reader_->ReadInfo(read_info_buffer_, &read_info_callback_);
+ reader_->ReadInfo(
+ read_info_buffer_,
+ base::Bind(&AppCacheResponseTest::OnReadInfoComplete,
+ base::Unretained(this)));
EXPECT_TRUE(reader_->IsReadPending());
expected_read_result_ = net::ERR_CACHE_MISS;
}
@@ -329,7 +330,10 @@ class AppCacheResponseTest : public testing::Test {
void ReadNonExistentData() {
EXPECT_FALSE(reader_->IsReadPending());
read_buffer_ = new IOBuffer(kBlockSize);
- reader_->ReadData(read_buffer_, kBlockSize, &read_callback_);
+ reader_->ReadData(
+ read_buffer_, kBlockSize,
+ base::Bind(&AppCacheResponseTest::OnReadComplete,
+ base::Unretained(this)));
EXPECT_TRUE(reader_->IsReadPending());
expected_read_result_ = net::ERR_CACHE_MISS;
}
@@ -506,7 +510,9 @@ class AppCacheResponseTest : public testing::Test {
read_buffer_ = new IOBuffer(kBlockSize);
expected_read_result_ = 0;
reader_->ReadData(
- read_buffer_, kBlockSize, &read_callback_);
+ read_buffer_, kBlockSize,
+ base::Bind(&AppCacheResponseTest::OnReadComplete,
+ base::Unretained(this)));
}
void ReadRange() {
@@ -668,8 +674,6 @@ class AppCacheResponseTest : public testing::Test {
scoped_refptr<HttpResponseInfoIOBuffer> read_info_buffer_;
scoped_refptr<IOBuffer> read_buffer_;
int expected_read_result_;
- net::OldCompletionCallbackImpl<AppCacheResponseTest> read_callback_;
- net::OldCompletionCallbackImpl<AppCacheResponseTest> read_info_callback_;
bool should_delete_reader_in_completion_callback_;
int reader_deletion_count_down_;
bool read_callback_was_called_;
@@ -679,8 +683,6 @@ class AppCacheResponseTest : public testing::Test {
scoped_refptr<HttpResponseInfoIOBuffer> write_info_buffer_;
scoped_refptr<IOBuffer> write_buffer_;
int expected_write_result_;
- net::OldCompletionCallbackImpl<AppCacheResponseTest> write_callback_;
- net::OldCompletionCallbackImpl<AppCacheResponseTest> write_info_callback_;
bool should_delete_writer_in_completion_callback_;
int writer_deletion_count_down_;
bool write_callback_was_called_;
diff --git a/webkit/appcache/appcache_service.cc b/webkit/appcache/appcache_service.cc
index 3d4a318..79ee7ac 100644
--- a/webkit/appcache/appcache_service.cc
+++ b/webkit/appcache/appcache_service.cc
@@ -5,6 +5,7 @@
#include "webkit/appcache/appcache_service.h"
#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/stl_util.h"
@@ -345,11 +346,7 @@ class AppCacheService::CheckResponseHelper : AsyncHelper {
kIOBufferSize(32 * 1024),
expected_total_size_(0),
amount_headers_read_(0),
- amount_data_read_(0),
- ALLOW_THIS_IN_INITIALIZER_LIST(read_info_callback_(
- this, &CheckResponseHelper::OnReadInfoComplete)),
- ALLOW_THIS_IN_INITIALIZER_LIST(read_data_callback_(
- this, &CheckResponseHelper::OnReadDataComplete)) {
+ amount_data_read_(0) {
}
virtual void Start() {
@@ -382,8 +379,6 @@ class AppCacheService::CheckResponseHelper : AsyncHelper {
int64 expected_total_size_;
int amount_headers_read_;
int amount_data_read_;
- net::OldCompletionCallbackImpl<CheckResponseHelper> read_info_callback_;
- net::OldCompletionCallbackImpl<CheckResponseHelper> read_data_callback_;
DISALLOW_COPY_AND_ASSIGN(CheckResponseHelper);
};
@@ -418,7 +413,9 @@ void AppCacheService::CheckResponseHelper::OnGroupLoaded(
response_reader_.reset(service_->storage()->CreateResponseReader(
manifest_url_, group->group_id(), response_id_));
info_buffer_ = new HttpResponseInfoIOBuffer();
- response_reader_->ReadInfo(info_buffer_, &read_info_callback_);
+ response_reader_->ReadInfo(
+ info_buffer_, base::Bind(&CheckResponseHelper::OnReadInfoComplete,
+ base::Unretained(this)));
}
void AppCacheService::CheckResponseHelper::OnReadInfoComplete(int result) {
@@ -433,16 +430,20 @@ void AppCacheService::CheckResponseHelper::OnReadInfoComplete(int result) {
// Start reading the data.
data_buffer_ = new net::IOBuffer(kIOBufferSize);
- response_reader_->ReadData(data_buffer_, kIOBufferSize,
- &read_data_callback_);
+ response_reader_->ReadData(
+ data_buffer_, kIOBufferSize,
+ base::Bind(&CheckResponseHelper::OnReadDataComplete,
+ base::Unretained(this)));
}
void AppCacheService::CheckResponseHelper::OnReadDataComplete(int result) {
if (result > 0) {
// Keep reading until we've read thru everything or failed to read.
amount_data_read_ += result;
- response_reader_->ReadData(data_buffer_, kIOBufferSize,
- &read_data_callback_);
+ response_reader_->ReadData(
+ data_buffer_, kIOBufferSize,
+ base::Bind(&CheckResponseHelper::OnReadDataComplete,
+ base::Unretained(this)));
return;
}
diff --git a/webkit/appcache/appcache_service_unittest.cc b/webkit/appcache/appcache_service_unittest.cc
index 1a58964..9bc74e5 100644
--- a/webkit/appcache/appcache_service_unittest.cc
+++ b/webkit/appcache/appcache_service_unittest.cc
@@ -40,9 +40,9 @@ class MockResponseReader : public AppCacheResponseReader {
data_(data), data_size_(data_size) {
}
virtual void ReadInfo(HttpResponseInfoIOBuffer* info_buf,
- net::OldCompletionCallback* callback) OVERRIDE {
+ const net::CompletionCallback& callback) OVERRIDE {
info_buffer_ = info_buf;
- user_callback_ = callback; // Cleared on completion.
+ callback_ = callback; // Cleared on completion.
int rv = info_.get() ? info_size_ : net::ERR_FAILED;
info_buffer_->http_info.reset(info_.release());
@@ -50,10 +50,10 @@ class MockResponseReader : public AppCacheResponseReader {
ScheduleUserCallback(rv);
}
virtual void ReadData(net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) OVERRIDE {
+ const net::CompletionCallback& callback) OVERRIDE {
buffer_ = buf;
buffer_len_ = buf_len;
- user_callback_ = callback; // Cleared on completion.
+ callback_ = callback; // Cleared on completion.
if (!data_) {
ScheduleUserCallback(net::ERR_CACHE_READ_FAILURE);
diff --git a/webkit/appcache/appcache_storage.cc b/webkit/appcache/appcache_storage.cc
index 7247c40..8d0b08b 100644
--- a/webkit/appcache/appcache_storage.cc
+++ b/webkit/appcache/appcache_storage.cc
@@ -4,6 +4,8 @@
#include "webkit/appcache/appcache_storage.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/stl_util.h"
#include "webkit/appcache/appcache_response.h"
#include "webkit/appcache/appcache_service.h"
@@ -46,9 +48,7 @@ AppCacheStorage::ResponseInfoLoadTask::ResponseInfoLoadTask(
manifest_url_(manifest_url),
group_id_(group_id),
response_id_(response_id),
- info_buffer_(new HttpResponseInfoIOBuffer),
- ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_(
- this, &ResponseInfoLoadTask::OnReadComplete)) {
+ info_buffer_(new HttpResponseInfoIOBuffer) {
storage_->pending_info_loads_.insert(
PendingResponseInfoLoads::value_type(response_id, this));
}
@@ -61,7 +61,9 @@ void AppCacheStorage::ResponseInfoLoadTask::StartIfNeeded() {
return;
reader_.reset(
storage_->CreateResponseReader(manifest_url_, group_id_, response_id_));
- reader_->ReadInfo(info_buffer_, &read_callback_);
+ reader_->ReadInfo(
+ info_buffer_, base::Bind(&ResponseInfoLoadTask::OnReadComplete,
+ base::Unretained(this)));
}
void AppCacheStorage::ResponseInfoLoadTask::OnReadComplete(int result) {
diff --git a/webkit/appcache/appcache_storage.h b/webkit/appcache/appcache_storage.h
index 7aab17f..4d30ce3 100644
--- a/webkit/appcache/appcache_storage.h
+++ b/webkit/appcache/appcache_storage.h
@@ -254,7 +254,6 @@ class APPCACHE_EXPORT AppCacheStorage {
scoped_ptr<AppCacheResponseReader> reader_;
DelegateReferenceVector delegates_;
scoped_refptr<HttpResponseInfoIOBuffer> info_buffer_;
- net::OldCompletionCallbackImpl<ResponseInfoLoadTask> read_callback_;
};
typedef std::map<int64, ResponseInfoLoadTask*> PendingResponseInfoLoads;
diff --git a/webkit/appcache/appcache_storage_impl.cc b/webkit/appcache/appcache_storage_impl.cc
index b374093..e2a0b26 100644
--- a/webkit/appcache/appcache_storage_impl.cc
+++ b/webkit/appcache/appcache_storage_impl.cc
@@ -1208,10 +1208,6 @@ AppCacheStorageImpl::AppCacheStorageImpl(AppCacheService* service)
is_response_deletion_scheduled_(false),
did_start_deleting_responses_(false),
last_deletable_response_rowid_(0),
- ALLOW_THIS_IN_INITIALIZER_LIST(doom_callback_(
- this, &AppCacheStorageImpl::OnDeletedOneResponse)),
- ALLOW_THIS_IN_INITIALIZER_LIST(init_callback_(
- this, &AppCacheStorageImpl::OnDiskCacheInitialized)),
database_(NULL), is_disabled_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
}
@@ -1596,7 +1592,9 @@ void AppCacheStorageImpl::DeleteOneResponse() {
// TODO(michaeln): add group_id to DoomEntry args
int64 id = deletable_response_ids_.front();
- int rv = disk_cache_->DoomEntry(id, &doom_callback_);
+ int rv = disk_cache_->DoomEntry(
+ id, base::Bind(&AppCacheStorageImpl::OnDeletedOneResponse,
+ base::Unretained(this)));
if (rv != net::ERR_IO_PENDING)
OnDeletedOneResponse(rv);
}
@@ -1682,11 +1680,15 @@ AppCacheDiskCache* AppCacheStorageImpl::disk_cache() {
disk_cache_.reset(new AppCacheDiskCache);
if (is_incognito_) {
rv = disk_cache_->InitWithMemBackend(
- kMaxMemDiskCacheSize, &init_callback_);
+ kMaxMemDiskCacheSize,
+ base::Bind(&AppCacheStorageImpl::OnDiskCacheInitialized,
+ base::Unretained(this)));
} else {
rv = disk_cache_->InitWithDiskBackend(
cache_directory_.Append(kDiskCacheDirectoryName),
- kMaxDiskCacheSize, false, cache_thread_, &init_callback_);
+ kMaxDiskCacheSize, false, cache_thread_,
+ base::Bind(&AppCacheStorageImpl::OnDiskCacheInitialized,
+ base::Unretained(this)));
}
// We should not keep this reference around.
diff --git a/webkit/appcache/appcache_storage_impl.h b/webkit/appcache/appcache_storage_impl.h
index f54295a..db87bbf 100644
--- a/webkit/appcache/appcache_storage_impl.h
+++ b/webkit/appcache/appcache_storage_impl.h
@@ -154,10 +154,6 @@ class AppCacheStorageImpl : public AppCacheStorage {
bool did_start_deleting_responses_;
int64 last_deletable_response_rowid_;
- // AppCacheDiskCache async callbacks
- net::OldCompletionCallbackImpl<AppCacheStorageImpl> doom_callback_;
- net::OldCompletionCallbackImpl<AppCacheStorageImpl> init_callback_;
-
// Created on the IO thread, but only used on the DB thread.
AppCacheDatabase* database_;
diff --git a/webkit/appcache/appcache_update_job.cc b/webkit/appcache/appcache_update_job.cc
index 572ba75..31dc325 100644
--- a/webkit/appcache/appcache_update_job.cc
+++ b/webkit/appcache/appcache_update_job.cc
@@ -4,6 +4,8 @@
#include "webkit/appcache/appcache_update_job.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/compiler_specific.h"
#include "base/message_loop.h"
#include "base/string_util.h"
@@ -89,12 +91,13 @@ AppCacheUpdateJob::UrlToFetch::~UrlToFetch() {
// data out to the disk cache.
AppCacheUpdateJob::URLFetcher::URLFetcher(
const GURL& url, FetchType fetch_type, AppCacheUpdateJob* job)
- : url_(url), job_(job), fetch_type_(fetch_type), retry_503_attempts_(0),
+ : url_(url),
+ job_(job),
+ fetch_type_(fetch_type),
+ retry_503_attempts_(0),
buffer_(new net::IOBuffer(kBufferSize)),
ALLOW_THIS_IN_INITIALIZER_LIST(
- request_(new net::URLRequest(url, this))),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- write_callback_(this, &URLFetcher::OnWriteComplete)) {
+ request_(new net::URLRequest(url, this))) {
}
AppCacheUpdateJob::URLFetcher::~URLFetcher() {
@@ -147,7 +150,9 @@ void AppCacheUpdateJob::URLFetcher::OnResponseStarted(
scoped_refptr<HttpResponseInfoIOBuffer> io_buffer(
new HttpResponseInfoIOBuffer(
new net::HttpResponseInfo(request->response_info())));
- response_writer_->WriteInfo(io_buffer, &write_callback_);
+ response_writer_->WriteInfo(
+ io_buffer,
+ base::Bind(&URLFetcher::OnWriteComplete, base::Unretained(this)));
} else {
ReadResponseData();
}
@@ -236,7 +241,9 @@ bool AppCacheUpdateJob::URLFetcher::ConsumeResponseData(int bytes_read) {
case URL_FETCH:
case MASTER_ENTRY_FETCH:
DCHECK(response_writer_.get());
- response_writer_->WriteData(buffer_, bytes_read, &write_callback_);
+ response_writer_->WriteData(
+ buffer_, bytes_read,
+ base::Bind(&URLFetcher::OnWriteComplete, base::Unretained(this)));
return false; // wait for async write completion to continue reading
default:
NOTREACHED();
@@ -293,13 +300,7 @@ AppCacheUpdateJob::AppCacheUpdateJob(AppCacheService* service,
master_entries_completed_(0),
url_fetches_completed_(0),
manifest_fetcher_(NULL),
- stored_state_(UNSTORED),
- ALLOW_THIS_IN_INITIALIZER_LIST(manifest_info_write_callback_(
- this, &AppCacheUpdateJob::OnManifestInfoWriteComplete)),
- ALLOW_THIS_IN_INITIALIZER_LIST(manifest_data_write_callback_(
- this, &AppCacheUpdateJob::OnManifestDataWriteComplete)),
- ALLOW_THIS_IN_INITIALIZER_LIST(manifest_data_read_callback_(
- this, &AppCacheUpdateJob::OnManifestDataReadComplete)) {
+ stored_state_(UNSTORED) {
DCHECK(group_);
manifest_url_ = group_->manifest_url();
}
@@ -701,8 +702,10 @@ void AppCacheUpdateJob::HandleManifestRefetchCompleted(
manifest_response_writer_.reset(CreateResponseWriter());
scoped_refptr<HttpResponseInfoIOBuffer> io_buffer(
new HttpResponseInfoIOBuffer(manifest_response_info_.release()));
- manifest_response_writer_->WriteInfo(io_buffer,
- &manifest_info_write_callback_);
+ manifest_response_writer_->WriteInfo(
+ io_buffer,
+ base::Bind(&AppCacheUpdateJob::OnManifestInfoWriteComplete,
+ base::Unretained(this)));
}
} else {
VLOG(1) << "Request status: " << request->status().status()
@@ -717,8 +720,10 @@ void AppCacheUpdateJob::OnManifestInfoWriteComplete(int result) {
if (result > 0) {
scoped_refptr<net::StringIOBuffer> io_buffer(
new net::StringIOBuffer(manifest_data_));
- manifest_response_writer_->WriteData(io_buffer, manifest_data_.length(),
- &manifest_data_write_callback_);
+ manifest_response_writer_->WriteData(
+ io_buffer, manifest_data_.length(),
+ base::Bind(&AppCacheUpdateJob::OnManifestDataWriteComplete,
+ base::Unretained(this)));
} else {
HandleCacheFailure("Failed to write the manifest headers to storage");
}
@@ -845,15 +850,19 @@ void AppCacheUpdateJob::CheckIfManifestChanged() {
group_->group_id(),
entry->response_id()));
read_manifest_buffer_ = new net::IOBuffer(kBufferSize);
- manifest_response_reader_->ReadData(read_manifest_buffer_, kBufferSize,
- &manifest_data_read_callback_); // async read
+ manifest_response_reader_->ReadData(
+ read_manifest_buffer_, kBufferSize,
+ base::Bind(&AppCacheUpdateJob::OnManifestDataReadComplete,
+ base::Unretained(this))); // async read
}
void AppCacheUpdateJob::OnManifestDataReadComplete(int result) {
if (result > 0) {
loaded_manifest_data_.append(read_manifest_buffer_->data(), result);
- manifest_response_reader_->ReadData(read_manifest_buffer_, kBufferSize,
- &manifest_data_read_callback_); // read more
+ manifest_response_reader_->ReadData(
+ read_manifest_buffer_, kBufferSize,
+ base::Bind(&AppCacheUpdateJob::OnManifestDataReadComplete,
+ base::Unretained(this))); // read more
} else {
read_manifest_buffer_ = NULL;
manifest_response_reader_.reset();
diff --git a/webkit/appcache/appcache_update_job.h b/webkit/appcache/appcache_update_job.h
index cb19b24..0f3905e 100644
--- a/webkit/appcache/appcache_update_job.h
+++ b/webkit/appcache/appcache_update_job.h
@@ -144,7 +144,6 @@ class APPCACHE_EXPORT AppCacheUpdateJob : public AppCacheStorage::Delegate,
scoped_refptr<net::HttpResponseHeaders> existing_response_headers_;
std::string manifest_data_;
scoped_ptr<AppCacheResponseWriter> response_writer_;
- net::OldCompletionCallbackImpl<URLFetcher> write_callback_;
}; // class URLFetcher
AppCacheResponseWriter* CreateResponseWriter();
@@ -305,10 +304,6 @@ class APPCACHE_EXPORT AppCacheUpdateJob : public AppCacheStorage::Delegate,
// Whether we've stored the resulting group/cache yet.
StoredState stored_state_;
- net::OldCompletionCallbackImpl<AppCacheUpdateJob> manifest_info_write_callback_;
- net::OldCompletionCallbackImpl<AppCacheUpdateJob> manifest_data_write_callback_;
- net::OldCompletionCallbackImpl<AppCacheUpdateJob> manifest_data_read_callback_;
-
FRIEND_TEST_ALL_PREFIXES(AppCacheGroupTest, QueueUpdate);
DISALLOW_COPY_AND_ASSIGN(AppCacheUpdateJob);
diff --git a/webkit/appcache/appcache_update_job_unittest.cc b/webkit/appcache/appcache_update_job_unittest.cc
index 47b1d42..1d6a4ec 100644
--- a/webkit/appcache/appcache_update_job_unittest.cc
+++ b/webkit/appcache/appcache_update_job_unittest.cc
@@ -978,18 +978,16 @@ class AppCacheUpdateJobTest : public testing::Test,
const std::string seed_data(kManifest1Contents);
scoped_refptr<net::StringIOBuffer> io_buffer(
new net::StringIOBuffer(seed_data));
- write_callback_.reset(
- new net::OldCompletionCallbackImpl<AppCacheUpdateJobTest>(this,
- &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData));
- response_writer_->WriteData(io_buffer, seed_data.length(),
- write_callback_.get());
+ response_writer_->WriteData(
+ io_buffer, seed_data.length(),
+ base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
+ base::Unretained(this)));
// Start update after data write completes asynchronously.
}
void StartUpdateAfterSeedingStorageData(int result) {
ASSERT_GT(result, 0);
- write_callback_.reset();
response_writer_.reset();
AppCacheUpdateJob* update = group_->update_job_;
@@ -1104,11 +1102,10 @@ class AppCacheUpdateJobTest : public testing::Test,
const std::string seed_data("different");
scoped_refptr<net::StringIOBuffer> io_buffer(
new net::StringIOBuffer(seed_data));
- write_callback_.reset(
- new net::OldCompletionCallbackImpl<AppCacheUpdateJobTest>(this,
- &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData));
- response_writer_->WriteData(io_buffer, seed_data.length(),
- write_callback_.get());
+ response_writer_->WriteData(
+ io_buffer, seed_data.length(),
+ base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
+ base::Unretained(this)));
// Start update after data write completes asynchronously.
}
@@ -1167,10 +1164,10 @@ class AppCacheUpdateJobTest : public testing::Test,
response_info->headers = headers; // adds ref to headers
scoped_refptr<HttpResponseInfoIOBuffer> io_buffer(
new HttpResponseInfoIOBuffer(response_info)); // adds ref to info
- write_callback_.reset(
- new net::OldCompletionCallbackImpl<AppCacheUpdateJobTest>(this,
- &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData));
- response_writer_->WriteInfo(io_buffer, write_callback_.get());
+ response_writer_->WriteInfo(
+ io_buffer,
+ base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
+ base::Unretained(this)));
// Start update after data write completes asynchronously.
}
@@ -1226,10 +1223,10 @@ class AppCacheUpdateJobTest : public testing::Test,
response_info->headers = headers; // adds ref to headers
scoped_refptr<HttpResponseInfoIOBuffer> io_buffer(
new HttpResponseInfoIOBuffer(response_info)); // adds ref to info
- write_callback_.reset(
- new net::OldCompletionCallbackImpl<AppCacheUpdateJobTest>(this,
- &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData));
- response_writer_->WriteInfo(io_buffer, write_callback_.get());
+ response_writer_->WriteInfo(
+ io_buffer,
+ base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
+ base::Unretained(this)));
// Start update after data write completes asynchronously.
}
@@ -1285,10 +1282,10 @@ class AppCacheUpdateJobTest : public testing::Test,
response_info->headers = headers; // adds ref to headers
scoped_refptr<HttpResponseInfoIOBuffer> io_buffer(
new HttpResponseInfoIOBuffer(response_info)); // adds ref to info
- write_callback_.reset(
- new net::OldCompletionCallbackImpl<AppCacheUpdateJobTest>(this,
- &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData));
- response_writer_->WriteInfo(io_buffer, write_callback_.get());
+ response_writer_->WriteInfo(
+ io_buffer,
+ base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
+ base::Unretained(this)));
// Start update after data write completes asynchronously.
}
@@ -2666,10 +2663,10 @@ class AppCacheUpdateJobTest : public testing::Test,
response_info->headers = headers; // adds ref to headers
scoped_refptr<HttpResponseInfoIOBuffer> io_buffer(
new HttpResponseInfoIOBuffer(response_info)); // adds ref to info
- write_callback_.reset(
- new net::OldCompletionCallbackImpl<AppCacheUpdateJobTest>(this,
- &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData));
- response_writer_->WriteInfo(io_buffer, write_callback_.get());
+ response_writer_->WriteInfo(
+ io_buffer,
+ base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
+ base::Unretained(this)));
// Start update after data write completes asynchronously.
}
@@ -2725,10 +2722,10 @@ class AppCacheUpdateJobTest : public testing::Test,
response_info->headers = headers; // adds ref to headers
scoped_refptr<HttpResponseInfoIOBuffer> io_buffer(
new HttpResponseInfoIOBuffer(response_info)); // adds ref to info
- write_callback_.reset(
- new net::OldCompletionCallbackImpl<AppCacheUpdateJobTest>(this,
- &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData));
- response_writer_->WriteInfo(io_buffer, write_callback_.get());
+ response_writer_->WriteInfo(
+ io_buffer,
+ base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
+ base::Unretained(this)));
// Start update after data write completes asynchronously.
}
@@ -3230,8 +3227,6 @@ class AppCacheUpdateJobTest : public testing::Test,
scoped_ptr<base::WaitableEvent> event_;
scoped_ptr<AppCacheResponseWriter> response_writer_;
- scoped_ptr<net::OldCompletionCallbackImpl<AppCacheUpdateJobTest> >
- write_callback_;
// Hosts used by an async test that need to live until update job finishes.
// Otherwise, test can put host on the stack instead of here.
diff --git a/webkit/appcache/appcache_url_request_job.cc b/webkit/appcache/appcache_url_request_job.cc
index 2d9b828..7d17909 100644
--- a/webkit/appcache/appcache_url_request_job.cc
+++ b/webkit/appcache/appcache_url_request_job.cc
@@ -6,6 +6,8 @@
#include "webkit/appcache/appcache_url_request_job.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/compiler_specific.h"
#include "base/message_loop.h"
#include "base/string_util.h"
@@ -28,8 +30,6 @@ AppCacheURLRequestJob::AppCacheURLRequestJob(
delivery_type_(AWAITING_DELIVERY_ORDERS),
group_id_(0), cache_id_(kNoCacheId), is_fallback_(false),
cache_entry_not_found_(false),
- ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_(
- this, &AppCacheURLRequestJob::OnReadComplete)),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
DCHECK(storage_);
}
@@ -268,7 +268,9 @@ bool AppCacheURLRequestJob::ReadRawData(net::IOBuffer* buf, int buf_size,
DCHECK_NE(buf_size, 0);
DCHECK(bytes_read);
DCHECK(!reader_->IsReadPending());
- reader_->ReadData(buf, buf_size, &read_callback_);
+ reader_->ReadData(
+ buf, buf_size, base::Bind(&AppCacheURLRequestJob::OnReadComplete,
+ base::Unretained(this)));
SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0));
return false;
}
diff --git a/webkit/appcache/appcache_url_request_job.h b/webkit/appcache/appcache_url_request_job.h
index 271a777..25b0cf6 100644
--- a/webkit/appcache/appcache_url_request_job.h
+++ b/webkit/appcache/appcache_url_request_job.h
@@ -139,7 +139,6 @@ class APPCACHE_EXPORT AppCacheURLRequestJob : public net::URLRequestJob,
net::HttpByteRange range_requested_;
scoped_ptr<net::HttpResponseInfo> range_response_info_;
scoped_ptr<AppCacheResponseReader> reader_;
- net::OldCompletionCallbackImpl<AppCacheURLRequestJob> read_callback_;
base::WeakPtrFactory<AppCacheURLRequestJob> weak_factory_;
};
diff --git a/webkit/appcache/appcache_url_request_job_unittest.cc b/webkit/appcache/appcache_url_request_job_unittest.cc
index aea70e7..a7ff8b0 100644
--- a/webkit/appcache/appcache_url_request_job_unittest.cc
+++ b/webkit/appcache/appcache_url_request_job_unittest.cc
@@ -169,14 +169,8 @@ class AppCacheURLRequestJobTest : public testing::Test {
}
AppCacheURLRequestJobTest()
- : ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_(
- this, &AppCacheURLRequestJobTest::OnReadComplete)),
- ALLOW_THIS_IN_INITIALIZER_LIST(read_info_callback_(
- this, &AppCacheURLRequestJobTest::OnReadInfoComplete)),
- ALLOW_THIS_IN_INITIALIZER_LIST(write_callback_(
- this, &AppCacheURLRequestJobTest::OnWriteComplete)),
- ALLOW_THIS_IN_INITIALIZER_LIST(write_info_callback_(
- this, &AppCacheURLRequestJobTest::OnWriteInfoComplete)) {
+ : ALLOW_THIS_IN_INITIALIZER_LIST(read_info_callback_(
+ this, &AppCacheURLRequestJobTest::OnReadInfoComplete)) {
}
template <class Method>
@@ -287,7 +281,10 @@ class AppCacheURLRequestJobTest : public testing::Test {
EXPECT_FALSE(writer_->IsWritePending());
expected_write_result_ = GetHttpResponseInfoSize(head);
write_info_buffer_ = new HttpResponseInfoIOBuffer(head);
- writer_->WriteInfo(write_info_buffer_, &write_info_callback_);
+ writer_->WriteInfo(
+ write_info_buffer_,
+ base::Bind(&AppCacheURLRequestJobTest::OnWriteInfoComplete,
+ base::Unretained(this)));
}
void WriteResponseBody(scoped_refptr<IOBuffer> io_buffer, int buf_len) {
@@ -295,7 +292,9 @@ class AppCacheURLRequestJobTest : public testing::Test {
write_buffer_ = io_buffer;
expected_write_result_ = buf_len;
writer_->WriteData(
- write_buffer_, buf_len, &write_callback_);
+ write_buffer_, buf_len,
+ base::Bind(&AppCacheURLRequestJobTest::OnWriteComplete,
+ base::Unretained(this)));
}
void ReadResponseBody(scoped_refptr<IOBuffer> io_buffer, int buf_len) {
@@ -303,7 +302,9 @@ class AppCacheURLRequestJobTest : public testing::Test {
read_buffer_ = io_buffer;
expected_read_result_ = buf_len;
reader_->ReadData(
- read_buffer_, buf_len, &read_callback_);
+ read_buffer_, buf_len,
+ base::Bind(&AppCacheURLRequestJobTest::OnReadComplete,
+ base::Unretained(this)));
}
// AppCacheResponseReader / Writer completion callbacks
@@ -764,7 +765,6 @@ class AppCacheURLRequestJobTest : public testing::Test {
scoped_refptr<HttpResponseInfoIOBuffer> read_info_buffer_;
scoped_refptr<IOBuffer> read_buffer_;
int expected_read_result_;
- net::OldCompletionCallbackImpl<AppCacheURLRequestJobTest> read_callback_;
net::OldCompletionCallbackImpl<AppCacheURLRequestJobTest> read_info_callback_;
bool should_delete_reader_in_completion_callback_;
int reader_deletion_count_down_;
@@ -775,8 +775,6 @@ class AppCacheURLRequestJobTest : public testing::Test {
scoped_refptr<HttpResponseInfoIOBuffer> write_info_buffer_;
scoped_refptr<IOBuffer> write_buffer_;
int expected_write_result_;
- net::OldCompletionCallbackImpl<AppCacheURLRequestJobTest> write_callback_;
- net::OldCompletionCallbackImpl<AppCacheURLRequestJobTest> write_info_callback_;
bool should_delete_writer_in_completion_callback_;
int writer_deletion_count_down_;
bool write_callback_was_called_;
diff --git a/webkit/appcache/mock_appcache_storage.h b/webkit/appcache/mock_appcache_storage.h
index 424a0f9..94f30dd 100644
--- a/webkit/appcache/mock_appcache_storage.h
+++ b/webkit/appcache/mock_appcache_storage.h
@@ -115,7 +115,7 @@ class MockAppCacheStorage : public AppCacheStorage {
if (!disk_cache_.get()) {
const int kMaxCacheSize = 10 * 1024 * 1024;
disk_cache_.reset(new AppCacheDiskCache);
- disk_cache_->InitWithMemBackend(kMaxCacheSize, NULL);
+ disk_cache_->InitWithMemBackend(kMaxCacheSize, net::CompletionCallback());
}
return disk_cache_.get();
}
diff --git a/webkit/appcache/view_appcache_internals_job.cc b/webkit/appcache/view_appcache_internals_job.cc
index 3d51b4c..2d0d27c 100644
--- a/webkit/appcache/view_appcache_internals_job.cc
+++ b/webkit/appcache/view_appcache_internals_job.cc
@@ -505,9 +505,8 @@ class ViewEntryJob : public BaseInternalsJob,
int64 response_id, int64 group_id)
: BaseInternalsJob(request, service),
manifest_url_(manifest_url), entry_url_(entry_url),
- response_id_(response_id), group_id_(group_id), amount_read_(0),
- ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_(
- this, &ViewEntryJob::OnReadComplete)) {}
+ response_id_(response_id), group_id_(group_id), amount_read_(0) {
+ }
virtual void Start() {
DCHECK(request_);
@@ -566,7 +565,8 @@ class ViewEntryJob : public BaseInternalsJob,
reader_.reset(appcache_service_->storage()->CreateResponseReader(
manifest_url_, group_id_, response_id_));
reader_->ReadData(
- response_data_, amount_to_read, &read_callback_);
+ response_data_, amount_to_read,
+ base::Bind(&ViewEntryJob::OnReadComplete, base::Unretained(this)));
}
void OnReadComplete(int result) {
@@ -585,7 +585,6 @@ class ViewEntryJob : public BaseInternalsJob,
scoped_refptr<net::IOBuffer> response_data_;
int amount_read_;
scoped_ptr<AppCacheResponseReader> reader_;
- net::OldCompletionCallbackImpl<ViewEntryJob> read_callback_;
};
} // namespace
diff --git a/webkit/fileapi/file_system_dir_url_request_job_unittest.cc b/webkit/fileapi/file_system_dir_url_request_job_unittest.cc
index fb52cd2..e7871c8 100644
--- a/webkit/fileapi/file_system_dir_url_request_job_unittest.cc
+++ b/webkit/fileapi/file_system_dir_url_request_job_unittest.cc
@@ -281,21 +281,11 @@ TEST_F(FileSystemDirURLRequestJobTest, NoSuchDirectory) {
EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error());
}
-class QuitNowTask : public Task {
- public:
- virtual void Run() {
- MessageLoop::current()->QuitNow();
- }
-};
-
TEST_F(FileSystemDirURLRequestJobTest, Cancel) {
CreateDirectory("foo");
TestRequestNoRun(CreateFileSystemURL("foo/"));
// Run StartAsync() and only StartAsync().
- MessageLoop::current()->PostTask(FROM_HERE, new QuitNowTask);
- MessageLoop::current()->Run();
-
- request_.reset();
+ MessageLoop::current()->DeleteSoon(FROM_HERE, request_.release());
MessageLoop::current()->RunAllPending();
// If we get here, success! we didn't crash!
}
diff --git a/webkit/fileapi/file_system_url_request_job_unittest.cc b/webkit/fileapi/file_system_url_request_job_unittest.cc
index bd0ada8..10f4d0c 100644
--- a/webkit/fileapi/file_system_url_request_job_unittest.cc
+++ b/webkit/fileapi/file_system_url_request_job_unittest.cc
@@ -335,22 +335,12 @@ TEST_F(FileSystemURLRequestJobTest, NoSuchFile) {
EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error());
}
-class QuitNowTask : public Task {
- public:
- virtual void Run() {
- MessageLoop::current()->QuitNow();
- }
-};
-
TEST_F(FileSystemURLRequestJobTest, Cancel) {
WriteFile("file1.dat", kTestFileData, arraysize(kTestFileData) - 1);
TestRequestNoRun(CreateFileSystemURL("file1.dat"));
// Run StartAsync() and only StartAsync().
- MessageLoop::current()->PostTask(FROM_HERE, new QuitNowTask);
- MessageLoop::current()->Run();
-
- request_.reset();
+ MessageLoop::current()->DeleteSoon(FROM_HERE, request_.release());
MessageLoop::current()->RunAllPending();
// If we get here, success! we didn't crash!
}
diff --git a/webkit/fileapi/webfilewriter_base_unittest.cc b/webkit/fileapi/webfilewriter_base_unittest.cc
index 088493e..b2c1041 100644
--- a/webkit/fileapi/webfilewriter_base_unittest.cc
+++ b/webkit/fileapi/webfilewriter_base_unittest.cc
@@ -385,7 +385,7 @@ TEST_F(FileWriterTest, CancelFailedTruncate) {
EXPECT_EQ(0, received_did_write_count_);
}
-TEST_F(FileWriterTest, DeleteInOldCompletionCallbacks) {
+TEST_F(FileWriterTest, DeleteInCompletionCallbacks) {
delete_in_client_callback_ = true;
writer()->write(kBasicFileWrite_Offset, GURL("blob://bloburl/"));
EXPECT_FALSE(testable_writer_.get());
diff --git a/webkit/support/test_webmessageportchannel.cc b/webkit/support/test_webmessageportchannel.cc
index 8460460..98fae47 100644
--- a/webkit/support/test_webmessageportchannel.cc
+++ b/webkit/support/test_webmessageportchannel.cc
@@ -4,6 +4,7 @@
#include "webkit/support/test_webmessageportchannel.h"
+#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/task.h"
@@ -66,9 +67,8 @@ void TestWebMessagePortChannel::postMessage(const WebString& data,
return;
MessageLoop::current()->PostTask(
FROM_HERE,
- NewRunnableMethod(remote_.get(),
- &TestWebMessagePortChannel::queueMessage,
- new Message(data, ports)));
+ base::Bind(&TestWebMessagePortChannel::queueMessage, remote_.get(),
+ new Message(data, ports)));
}
bool TestWebMessagePortChannel::tryGetMessage(WebString* data,