summaryrefslogtreecommitdiffstats
path: root/webkit/appcache
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-11 21:05:49 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-11 21:05:49 +0000
commit8336aaf477a8275edd9348c76a2a26c88b31bbe7 (patch)
tree9a177f94205de6259cf3d329c2b55ac217f8381b /webkit/appcache
parent947f374826592c6da1bfa620ebbe4e9aeb1bfe1a (diff)
downloadchromium_src-8336aaf477a8275edd9348c76a2a26c88b31bbe7.zip
chromium_src-8336aaf477a8275edd9348c76a2a26c88b31bbe7.tar.gz
chromium_src-8336aaf477a8275edd9348c76a2a26c88b31bbe7.tar.bz2
base::Bind: Convert most of webkit/appcache.
BUG=none TEST=none R=csilv@chromium.org Review URL: http://codereview.chromium.org/8515019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109696 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache')
-rw-r--r--webkit/appcache/appcache_request_handler_unittest.cc44
-rw-r--r--webkit/appcache/appcache_response_unittest.cc178
-rw-r--r--webkit/appcache/appcache_storage_impl_unittest.cc146
-rw-r--r--webkit/appcache/appcache_update_job_unittest.cc13
-rw-r--r--webkit/appcache/appcache_url_request_job_unittest.cc94
-rw-r--r--webkit/appcache/mock_appcache_storage.cc66
-rw-r--r--webkit/appcache/mock_appcache_storage.h9
7 files changed, 286 insertions, 264 deletions
diff --git a/webkit/appcache/appcache_request_handler_unittest.cc b/webkit/appcache/appcache_request_handler_unittest.cc
index a1dfa49..edbda46 100644
--- a/webkit/appcache/appcache_request_handler_unittest.cc
+++ b/webkit/appcache/appcache_request_handler_unittest.cc
@@ -6,7 +6,11 @@
#include <string>
#include <vector>
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/callback.h"
#include "base/message_loop.h"
+#include "base/task.h"
#include "base/threading/thread.h"
#include "base/synchronization/waitable_event.h"
#include "net/base/net_errors.h"
@@ -204,8 +208,10 @@ class AppCacheRequestHandlerTest : public testing::Test {
// We unwind the stack prior to finishing up to let stack
// based objects get deleted.
DCHECK(MessageLoop::current() == io_thread_->message_loop());
- MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &AppCacheRequestHandlerTest::TestFinishedUnwound));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&AppCacheRequestHandlerTest::TestFinishedUnwound,
+ base::Unretained(this)));
}
void TestFinishedUnwound() {
@@ -213,7 +219,7 @@ class AppCacheRequestHandlerTest : public testing::Test {
test_finished_event_->Signal();
}
- void PushNextTask(Task* task) {
+ void PushNextTask(const base::Closure& task) {
task_stack_.push(task);
}
@@ -230,8 +236,9 @@ class AppCacheRequestHandlerTest : public testing::Test {
// MainResource_Miss --------------------------------------------------
void MainResource_Miss() {
- PushNextTask(NewRunnableMethod(
- this, &AppCacheRequestHandlerTest::Verify_MainResource_Miss));
+ PushNextTask(
+ base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Miss,
+ base::Unretained(this)));
request_.reset(new MockURLRequest(GURL("http://blah/")));
handler_.reset(host_->CreateRequestHandler(request_.get(),
@@ -272,8 +279,9 @@ class AppCacheRequestHandlerTest : public testing::Test {
// MainResource_Hit --------------------------------------------------
void MainResource_Hit() {
- PushNextTask(NewRunnableMethod(
- this, &AppCacheRequestHandlerTest::Verify_MainResource_Hit));
+ PushNextTask(
+ base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Hit,
+ base::Unretained(this)));
request_.reset(new MockURLRequest(GURL("http://blah/")));
handler_.reset(host_->CreateRequestHandler(request_.get(),
@@ -317,8 +325,9 @@ class AppCacheRequestHandlerTest : public testing::Test {
// MainResource_Fallback --------------------------------------------------
void MainResource_Fallback() {
- PushNextTask(NewRunnableMethod(
- this, &AppCacheRequestHandlerTest::Verify_MainResource_Fallback));
+ PushNextTask(
+ base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Fallback,
+ base::Unretained(this)));
request_.reset(new MockURLRequest(GURL("http://blah/")));
handler_.reset(host_->CreateRequestHandler(request_.get(),
@@ -373,9 +382,9 @@ class AppCacheRequestHandlerTest : public testing::Test {
// MainResource_FallbackOverride --------------------------------------------
void MainResource_FallbackOverride() {
- PushNextTask(NewRunnableMethod(
- this,
- &AppCacheRequestHandlerTest::Verify_MainResource_FallbackOverride));
+ PushNextTask(base::Bind(
+ &AppCacheRequestHandlerTest::Verify_MainResource_FallbackOverride,
+ base::Unretained(this)));
request_.reset(new MockURLRequest(GURL("http://blah/fallback-override")));
handler_.reset(host_->CreateRequestHandler(request_.get(),
@@ -745,8 +754,9 @@ class AppCacheRequestHandlerTest : public testing::Test {
// MainResource_Blocked --------------------------------------------------
void MainResource_Blocked() {
- PushNextTask(NewRunnableMethod(
- this, &AppCacheRequestHandlerTest::Verify_MainResource_Blocked));
+ PushNextTask(
+ base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Blocked,
+ base::Unretained(this)));
request_.reset(new MockURLRequest(GURL("http://blah/")));
handler_.reset(host_->CreateRequestHandler(request_.get(),
@@ -801,7 +811,7 @@ class AppCacheRequestHandlerTest : public testing::Test {
// Data members --------------------------------------------------
scoped_ptr<base::WaitableEvent> test_finished_event_;
- std::stack<Task*> task_stack_;
+ std::stack<base::Closure> task_stack_;
scoped_ptr<MockAppCacheService> mock_service_;
scoped_ptr<AppCacheBackendImpl> backend_impl_;
scoped_ptr<MockFrontend> mock_frontend_;
@@ -895,7 +905,3 @@ TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) {
}
} // namespace appcache
-
-// AppCacheRequestHandlerTest is expected to always live longer than the
-// runnable methods. This lets us call NewRunnableMethod on its instances.
-DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheRequestHandlerTest);
diff --git a/webkit/appcache/appcache_response_unittest.cc b/webkit/appcache/appcache_response_unittest.cc
index ae75a4b..9b91712 100644
--- a/webkit/appcache/appcache_response_unittest.cc
+++ b/webkit/appcache/appcache_response_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,6 +6,9 @@
#include <string>
#include <utility>
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/pickle.h"
#include "base/threading/thread.h"
@@ -116,10 +119,9 @@ class AppCacheResponseTest : public testing::Test {
void TearDownTest() {
DCHECK(MessageLoop::current() == io_thread_->message_loop());
- while (!task_stack_.empty()) {
- delete task_stack_.top().first;
+ while (!task_stack_.empty())
task_stack_.pop();
- }
+
reader_.reset();
read_buffer_ = NULL;
read_info_buffer_ = NULL;
@@ -134,8 +136,9 @@ class AppCacheResponseTest : public testing::Test {
// We unwind the stack prior to finishing up to let stack
// based objects get deleted.
DCHECK(MessageLoop::current() == io_thread_->message_loop());
- MessageLoop::current()->PostTask(FROM_HERE,
- NewRunnableMethod(this, &AppCacheResponseTest::TestFinishedUnwound));
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&AppCacheResponseTest::TestFinishedUnwound,
+ base::Unretained(this)));
}
void TestFinishedUnwound() {
@@ -143,12 +146,12 @@ class AppCacheResponseTest : public testing::Test {
test_finished_event_->Signal();
}
- void PushNextTask(Task* task) {
- task_stack_.push(std::pair<Task*, bool>(task, false));
+ void PushNextTask(const base::Closure& task) {
+ task_stack_.push(std::pair<base::Closure, bool>(task, false));
}
- void PushNextTaskAsImmediate(Task* task) {
- task_stack_.push(std::pair<Task*, bool>(task, true));
+ void PushNextTaskAsImmediate(const base::Closure& task) {
+ task_stack_.push(std::pair<base::Closure, bool>(task, true));
}
void ScheduleNextTask() {
@@ -157,13 +160,13 @@ class AppCacheResponseTest : public testing::Test {
TestFinished();
return;
}
- scoped_ptr<Task> task(task_stack_.top().first);
+ base::Closure task = task_stack_.top().first;
bool immediate = task_stack_.top().second;
task_stack_.pop();
if (immediate)
- task->Run();
+ task.Run();
else
- MessageLoop::current()->PostTask(FROM_HERE, task.release());
+ MessageLoop::current()->PostTask(FROM_HERE, task);
}
// Wrappers to call AppCacheResponseReader/Writer Read and Write methods
@@ -183,9 +186,8 @@ class AppCacheResponseTest : public testing::Test {
IOBuffer* body, int body_len) {
DCHECK(body);
scoped_refptr<IOBuffer> body_ref(body);
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::WriteResponseBody,
- body_ref, body_len));
+ PushNextTask(base::Bind(&AppCacheResponseTest::WriteResponseBody,
+ base::Unretained(this), body_ref, body_len));
WriteResponseHead(head);
}
@@ -309,10 +311,10 @@ class AppCacheResponseTest : public testing::Test {
GURL(), 0, kNoSuchResponseId));
// Push tasks in reverse order
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::ReadNonExistentData));
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::ReadNonExistentInfo));
+ PushNextTask(base::Bind(&AppCacheResponseTest::ReadNonExistentData,
+ base::Unretained(this)));
+ PushNextTask(base::Bind(&AppCacheResponseTest::ReadNonExistentInfo,
+ base::Unretained(this)));
ScheduleNextTask();
}
@@ -334,8 +336,8 @@ class AppCacheResponseTest : public testing::Test {
// LoadResponseInfo_Miss ----------------------------------------------------
void LoadResponseInfo_Miss() {
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::LoadResponseInfo_Miss_Verify));
+ PushNextTask(base::Bind(&AppCacheResponseTest::LoadResponseInfo_Miss_Verify,
+ base::Unretained(this)));
service_->storage()->LoadResponseInfo(GURL(), 0, kNoSuchResponseId,
storage_delegate_.get());
}
@@ -353,8 +355,8 @@ class AppCacheResponseTest : public testing::Test {
// a. headers
// b. body
// 2. Use LoadResponseInfo to read the response headers back out
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::LoadResponseInfo_Hit_Step2));
+ PushNextTask(base::Bind(&AppCacheResponseTest::LoadResponseInfo_Hit_Step2,
+ base::Unretained(this)));
writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0));
written_response_id_ = writer_->response_id();
WriteBasicResponse();
@@ -362,8 +364,8 @@ class AppCacheResponseTest : public testing::Test {
void LoadResponseInfo_Hit_Step2() {
writer_.reset();
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::LoadResponseInfo_Hit_Verify));
+ PushNextTask(base::Bind(&AppCacheResponseTest::LoadResponseInfo_Hit_Verify,
+ base::Unretained(this)));
service_->storage()->LoadResponseInfo(GURL(), 0, written_response_id_,
storage_delegate_.get());
}
@@ -390,15 +392,14 @@ class AppCacheResponseTest : public testing::Test {
GetHttpResponseInfoSize(head) + kNumBlocks * kBlockSize;
// Push tasks in reverse order.
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::Verify_AmountWritten,
- expected_amount_written));
+ PushNextTask(base::Bind(&AppCacheResponseTest::Verify_AmountWritten,
+ base::Unretained(this), expected_amount_written));
for (int i = 0; i < kNumBlocks; ++i) {
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::WriteOneBlock, kNumBlocks - i));
+ PushNextTask(base::Bind(&AppCacheResponseTest::WriteOneBlock,
+ base::Unretained(this), kNumBlocks - i));
}
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::WriteResponseHead, head));
+ PushNextTask(base::Bind(&AppCacheResponseTest::WriteResponseHead,
+ base::Unretained(this), head));
writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0));
written_response_id_ = writer_->response_id();
@@ -424,22 +425,22 @@ class AppCacheResponseTest : public testing::Test {
// 6. Attempt to read beyond EOF of a range.
// Push tasks in reverse order
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::ReadRangeFullyBeyondEOF));
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::ReadRangePartiallyBeyondEOF));
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::ReadPastEOF));
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::ReadRange));
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::ReadPastEOF));
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::ReadAllAtOnce));
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::ReadInBlocks));
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::WriteOutBlocks));
+ PushNextTask(base::Bind(&AppCacheResponseTest::ReadRangeFullyBeyondEOF,
+ base::Unretained(this)));
+ PushNextTask(base::Bind(&AppCacheResponseTest::ReadRangePartiallyBeyondEOF,
+ base::Unretained(this)));
+ PushNextTask(base::Bind(&AppCacheResponseTest::ReadPastEOF,
+ base::Unretained(this)));
+ PushNextTask(base::Bind(&AppCacheResponseTest::ReadRange,
+ base::Unretained(this)));
+ PushNextTask(base::Bind(&AppCacheResponseTest::ReadPastEOF,
+ base::Unretained(this)));
+ PushNextTask(base::Bind(&AppCacheResponseTest::ReadAllAtOnce,
+ base::Unretained(this)));
+ PushNextTask(base::Bind(&AppCacheResponseTest::ReadInBlocks,
+ base::Unretained(this)));
+ PushNextTask(base::Bind(&AppCacheResponseTest::WriteOutBlocks,
+ base::Unretained(this)));
// Get them going.
ScheduleNextTask();
@@ -449,8 +450,8 @@ class AppCacheResponseTest : public testing::Test {
writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0));
written_response_id_ = writer_->response_id();
for (int i = 0; i < kNumBlocks; ++i) {
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::WriteOneBlock, kNumBlocks - i));
+ PushNextTask(base::Bind(&AppCacheResponseTest::WriteOneBlock,
+ base::Unretained(this), kNumBlocks - i));
}
ScheduleNextTask();
}
@@ -467,15 +468,15 @@ class AppCacheResponseTest : public testing::Test {
reader_.reset(service_->storage()->CreateResponseReader(
GURL(), 0, written_response_id_));
for (int i = 0; i < kNumBlocks; ++i) {
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::ReadOneBlock, kNumBlocks - i));
+ PushNextTask(base::Bind(&AppCacheResponseTest::ReadOneBlock,
+ base::Unretained(this), kNumBlocks - i));
}
ScheduleNextTask();
}
void ReadOneBlock(int block_number) {
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::VerifyOneBlock, block_number));
+ PushNextTask(base::Bind(&AppCacheResponseTest::VerifyOneBlock,
+ base::Unretained(this), block_number));
ReadResponseBody(new IOBuffer(kBlockSize), kBlockSize);
}
@@ -485,8 +486,8 @@ class AppCacheResponseTest : public testing::Test {
}
void ReadAllAtOnce() {
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::VerifyAllAtOnce));
+ PushNextTask(base::Bind(&AppCacheResponseTest::VerifyAllAtOnce,
+ base::Unretained(this)));
reader_.reset(service_->storage()->CreateResponseReader(
GURL(), 0, written_response_id_));
int big_size = kNumBlocks * kBlockSize;
@@ -509,8 +510,8 @@ class AppCacheResponseTest : public testing::Test {
}
void ReadRange() {
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::VerifyRange));
+ PushNextTask(base::Bind(&AppCacheResponseTest::VerifyRange,
+ base::Unretained(this)));
reader_.reset(service_->storage()->CreateResponseReader(
GURL(), 0, written_response_id_));
reader_->SetReadRange(kBlockSize, kBlockSize);
@@ -523,8 +524,8 @@ class AppCacheResponseTest : public testing::Test {
}
void ReadRangePartiallyBeyondEOF() {
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::VerifyRangeBeyondEOF));
+ PushNextTask(base::Bind(&AppCacheResponseTest::VerifyRangeBeyondEOF,
+ base::Unretained(this)));
reader_.reset(service_->storage()->CreateResponseReader(
GURL(), 0, written_response_id_));
reader_->SetReadRange(kBlockSize, kNumBlocks * kBlockSize);
@@ -553,10 +554,12 @@ class AppCacheResponseTest : public testing::Test {
// 2. Read and verify several blocks in similarly chaining reads.
// Push tasks in reverse order
- PushNextTaskAsImmediate(NewRunnableMethod(
- this, &AppCacheResponseTest::ReadInBlocksImmediately));
- PushNextTaskAsImmediate(NewRunnableMethod(
- this, &AppCacheResponseTest::WriteOutBlocksImmediately));
+ PushNextTaskAsImmediate(
+ base::Bind(&AppCacheResponseTest::ReadInBlocksImmediately,
+ base::Unretained(this)));
+ PushNextTaskAsImmediate(
+ base::Bind(&AppCacheResponseTest::WriteOutBlocksImmediately,
+ base::Unretained(this)));
// Get them going.
ScheduleNextTask();
@@ -566,8 +569,9 @@ class AppCacheResponseTest : public testing::Test {
writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0));
written_response_id_ = writer_->response_id();
for (int i = 0; i < kNumBlocks; ++i) {
- PushNextTaskAsImmediate(NewRunnableMethod(
- this, &AppCacheResponseTest::WriteOneBlock, kNumBlocks - i));
+ PushNextTaskAsImmediate(
+ base::Bind(&AppCacheResponseTest::WriteOneBlock,
+ base::Unretained(this), kNumBlocks - i));
}
ScheduleNextTask();
}
@@ -577,16 +581,17 @@ class AppCacheResponseTest : public testing::Test {
reader_.reset(service_->storage()->CreateResponseReader(
GURL(), 0, written_response_id_));
for (int i = 0; i < kNumBlocks; ++i) {
- PushNextTaskAsImmediate(NewRunnableMethod(
- this, &AppCacheResponseTest::ReadOneBlockImmediately,
+ PushNextTaskAsImmediate(
+ base::Bind(&AppCacheResponseTest::ReadOneBlockImmediately,
+ base::Unretained(this),
kNumBlocks - i));
}
ScheduleNextTask();
}
void ReadOneBlockImmediately(int block_number) {
- PushNextTaskAsImmediate(NewRunnableMethod(
- this, &AppCacheResponseTest::VerifyOneBlock, block_number));
+ PushNextTaskAsImmediate(base::Bind(&AppCacheResponseTest::VerifyOneBlock,
+ base::Unretained(this), block_number));
ReadResponseBody(new IOBuffer(kBlockSize), kBlockSize);
}
@@ -602,10 +607,10 @@ class AppCacheResponseTest : public testing::Test {
should_delete_writer_in_completion_callback_ = true;
writer_deletion_count_down_ = kNumBlocks;
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::ReadInBlocks));
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::WriteOutBlocks));
+ PushNextTask(base::Bind(&AppCacheResponseTest::ReadInBlocks,
+ base::Unretained(this)));
+ PushNextTask(base::Bind(&AppCacheResponseTest::WriteOutBlocks,
+ base::Unretained(this)));
ScheduleNextTask();
}
@@ -614,12 +619,12 @@ class AppCacheResponseTest : public testing::Test {
// 1. Write a few blocks normally.
// 2. Start a write, delete with it pending.
// 3. Start a read, delete with it pending.
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::ReadThenDelete));
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::WriteThenDelete));
- PushNextTask(NewRunnableMethod(
- this, &AppCacheResponseTest::WriteOutBlocks));
+ PushNextTask(base::Bind(&AppCacheResponseTest::ReadThenDelete,
+ base::Unretained(this)));
+ PushNextTask(base::Bind(&AppCacheResponseTest::WriteThenDelete,
+ base::Unretained(this)));
+ PushNextTask(base::Bind(&AppCacheResponseTest::WriteOutBlocks,
+ base::Unretained(this)));
ScheduleNextTask();
}
@@ -640,8 +645,9 @@ class AppCacheResponseTest : public testing::Test {
reader_.reset();
// Wait a moment to verify no callbacks.
- MessageLoop::current()->PostDelayedTask(FROM_HERE,
- NewRunnableMethod(this, &AppCacheResponseTest::VerifyNoCallbacks),
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE, base::Bind(&AppCacheResponseTest::VerifyNoCallbacks,
+ base::Unretained(this)),
10);
}
@@ -656,7 +662,7 @@ class AppCacheResponseTest : public testing::Test {
scoped_ptr<base::WaitableEvent> test_finished_event_;
scoped_ptr<MockStorageDelegate> storage_delegate_;
scoped_ptr<MockAppCacheService> service_;
- std::stack<std::pair<Task*, bool> > task_stack_;
+ std::stack<std::pair<base::Closure, bool> > task_stack_;
scoped_ptr<AppCacheResponseReader> reader_;
scoped_refptr<HttpResponseInfoIOBuffer> read_info_buffer_;
@@ -718,7 +724,3 @@ TEST_F(AppCacheResponseTest, DeleteWithIOPending) {
}
} // namespace appcache
-
-// AppCacheResponseTest is expected to always live longer than the
-// runnable methods. This lets us call NewRunnableMethod on its instances.
-DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheResponseTest);
diff --git a/webkit/appcache/appcache_storage_impl_unittest.cc b/webkit/appcache/appcache_storage_impl_unittest.cc
index 18de4a0..c0540af 100644
--- a/webkit/appcache/appcache_storage_impl_unittest.cc
+++ b/webkit/appcache/appcache_storage_impl_unittest.cc
@@ -4,6 +4,9 @@
#include <stack>
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/callback.h"
#include "base/message_loop.h"
#include "base/threading/thread.h"
#include "base/synchronization/waitable_event.h"
@@ -138,9 +141,9 @@ class AppCacheStorageImplTest : public testing::Test {
EXPECT_EQ(kOrigin, origin);
EXPECT_EQ(quota::kStorageTypeTemporary, type);
if (async_) {
- MessageLoop::current()->PostTask(FROM_HERE,
- NewRunnableMethod(this, &MockQuotaManager::CallCallback,
- callback));
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&MockQuotaManager::CallCallback,
+ base::Unretained(this), callback));
return;
}
CallCallback(callback);
@@ -214,8 +217,8 @@ class AppCacheStorageImplTest : public testing::Test {
// We also have to wait for InitTask completion call to be performed
// on the IO thread prior to running the test. Its guaranteed to be
// queued by this time.
- MessageLoop::current()->PostTask(FROM_HERE,
- NewRunnableFunction(&RunMethod, test_, method_));
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&RunMethod, test_, method_));
}
static void RunMethod(AppCacheStorageImplTest* test, Method method) {
@@ -280,8 +283,9 @@ class AppCacheStorageImplTest : public testing::Test {
// We unwind the stack prior to finishing up to let stack
// based objects get deleted.
DCHECK(MessageLoop::current() == io_thread->message_loop());
- MessageLoop::current()->PostTask(FROM_HERE,
- NewRunnableMethod(this, &AppCacheStorageImplTest::TestFinishedUnwound));
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&AppCacheStorageImplTest::TestFinishedUnwound,
+ base::Unretained(this)));
}
void TestFinishedUnwound() {
@@ -289,7 +293,7 @@ class AppCacheStorageImplTest : public testing::Test {
test_finished_event_->Signal();
}
- void PushNextTask(Task* task) {
+ void PushNextTask(const base::Closure& task) {
task_stack_.push(task);
}
@@ -310,9 +314,8 @@ class AppCacheStorageImplTest : public testing::Test {
// We pump a task thru the db thread to ensure any tasks previously
// scheduled on that thread have been performed prior to return.
base::WaitableEvent event(false, false);
- db_thread->message_loop()->PostTask(FROM_HERE,
- NewRunnableFunction(&AppCacheStorageImplTest::SignalEvent,
- &event));
+ db_thread->message_loop()->PostTask(
+ FROM_HERE, base::Bind(&AppCacheStorageImplTest::SignalEvent, &event));
event.Wait();
}
@@ -320,9 +323,9 @@ class AppCacheStorageImplTest : public testing::Test {
void LoadCache_Miss() {
// Attempt to load a cache that doesn't exist. Should
- // complete asyncly.
- PushNextTask(NewRunnableMethod(
- this, &AppCacheStorageImplTest::Verify_LoadCache_Miss));
+ // complete asynchronously.
+ PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_LoadCache_Miss,
+ base::Unretained(this)));
storage()->LoadCache(111, delegate());
EXPECT_NE(111, delegate()->loaded_cache_id_);
@@ -372,8 +375,8 @@ class AppCacheStorageImplTest : public testing::Test {
void CreateGroupInPopulatedOrigin() {
// Attempt to load a group that doesn't exist, one should
// be created for us, but not stored.
- PushNextTask(NewRunnableMethod(
- this, &AppCacheStorageImplTest::Verify_CreateGroup));
+ PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_CreateGroup,
+ base::Unretained(this)));
// Since the origin has groups, storage class will have to
// consult the database and completion will be async.
@@ -405,9 +408,9 @@ class AppCacheStorageImplTest : public testing::Test {
void LoadGroupAndCache_FarHit() {
// Attempt to load a cache that is not currently in use
// and does require loading from disk. This
- // load should complete asyncly.
- PushNextTask(NewRunnableMethod(
- this, &AppCacheStorageImplTest::Verify_LoadCache_Far_Hit));
+ // load should complete asynchronously.
+ PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_LoadCache_Far_Hit,
+ base::Unretained(this)));
// Setup some preconditions. Create a group and newest cache that
// appear to be "stored" and "not currently in use".
@@ -436,9 +439,9 @@ class AppCacheStorageImplTest : public testing::Test {
delegate()->loaded_cache_ = NULL;
EXPECT_FALSE(delegate()->loaded_group_);
- // Conduct the group load test, also complete asyncly.
- PushNextTask(NewRunnableMethod(
- this, &AppCacheStorageImplTest::Verify_LoadGroup_Far_Hit));
+ // Conduct the group load test, also complete asynchronously.
+ PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_LoadGroup_Far_Hit,
+ base::Unretained(this)));
storage()->LoadOrCreateGroup(kManifestUrl, delegate());
}
@@ -457,9 +460,9 @@ class AppCacheStorageImplTest : public testing::Test {
// StoreNewGroup --------------------------------------
void StoreNewGroup() {
- // Store a group and its newest cache. Should complete asyncly.
- PushNextTask(NewRunnableMethod(
- this, &AppCacheStorageImplTest::Verify_StoreNewGroup));
+ // Store a group and its newest cache. Should complete asynchronously.
+ PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_StoreNewGroup,
+ base::Unretained(this)));
// Setup some preconditions. Create a group and newest cache that
// appear to be "unstored".
@@ -471,7 +474,7 @@ class AppCacheStorageImplTest : public testing::Test {
// Hold a ref to the cache simulate the UpdateJob holding that ref,
// and hold a ref to the group to simulate the CacheHost holding that ref.
- // Have the quota manager retrun asyncly for this test.
+ // Have the quota manager retrun asynchronously for this test.
mock_quota_manager_proxy_->mock_manager_->async_ = true;
// Conduct the store test.
@@ -503,9 +506,9 @@ class AppCacheStorageImplTest : public testing::Test {
// StoreExistingGroup --------------------------------------
void StoreExistingGroup() {
- // Store a group and its newest cache. Should complete asyncly.
- PushNextTask(NewRunnableMethod(
- this, &AppCacheStorageImplTest::Verify_StoreExistingGroup));
+ // Store a group and its newest cache. Should complete asynchronously.
+ PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_StoreExistingGroup,
+ base::Unretained(this)));
// Setup some preconditions. Create a group and old complete cache
// that appear to be "stored"
@@ -563,9 +566,9 @@ class AppCacheStorageImplTest : public testing::Test {
cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::MASTER, 1, 100));
cache_->set_update_time(now);
- PushNextTask(NewRunnableMethod(
- this, &AppCacheStorageImplTest::Verify_StoreExistingGroupExistingCache,
- now));
+ PushNextTask(base::Bind(
+ &AppCacheStorageImplTest::Verify_StoreExistingGroupExistingCache,
+ base::Unretained(this), now));
// Conduct the test.
EXPECT_EQ(cache_, group_->newest_complete_cache());
@@ -609,9 +612,9 @@ class AppCacheStorageImplTest : public testing::Test {
// FailStoreGroup --------------------------------------
void FailStoreGroup() {
- // Store a group and its newest cache. Should complete asyncly.
- PushNextTask(NewRunnableMethod(
- this, &AppCacheStorageImplTest::Verify_FailStoreGroup));
+ // Store a group and its newest cache. Should complete asynchronously.
+ PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_FailStoreGroup,
+ base::Unretained(this)));
// Setup some preconditions. Create a group and newest cache that
// appear to be "unstored" and big enough to exceed the 5M limit.
@@ -648,9 +651,9 @@ class AppCacheStorageImplTest : public testing::Test {
// MakeGroupObsolete -------------------------------
void MakeGroupObsolete() {
- // Make a group obsolete, should complete asyncly.
- PushNextTask(NewRunnableMethod(
- this, &AppCacheStorageImplTest::Verify_MakeGroupObsolete));
+ // Make a group obsolete, should complete asynchronously.
+ PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_MakeGroupObsolete,
+ base::Unretained(this)));
// Setup some preconditions. Create a group and newest cache that
// appears to be "stored" and "currently in use".
@@ -738,7 +741,7 @@ class AppCacheStorageImplTest : public testing::Test {
EXPECT_TRUE(cache_->GetEntry(kEntryUrl)->IsExplicit());
// And the entry in storage should also be updated, but that
- // happens asyncly on the db thread.
+ // happens asynchronously on the db thread.
FlushDbThreadTasks();
AppCacheDatabase::EntryRecord entry_record2;
EXPECT_TRUE(database()->FindEntry(1, kEntryUrl, &entry_record2));
@@ -750,8 +753,9 @@ class AppCacheStorageImplTest : public testing::Test {
// MarkEntryAsForeignWithLoadInProgress -------------------------------
void MarkEntryAsForeignWithLoadInProgress() {
- PushNextTask(NewRunnableMethod(this,
- &AppCacheStorageImplTest::Verify_MarkEntryAsForeignWithLoadInProgress));
+ PushNextTask(base::Bind(
+ &AppCacheStorageImplTest::Verify_MarkEntryAsForeignWithLoadInProgress,
+ base::Unretained(this)));
// Setup some preconditions. Create a cache with an entry
// in storage, but not in the working set.
@@ -794,8 +798,8 @@ class AppCacheStorageImplTest : public testing::Test {
// FindNoMainResponse -------------------------------
void FindNoMainResponse() {
- PushNextTask(NewRunnableMethod(
- this, &AppCacheStorageImplTest::Verify_FindNoMainResponse));
+ PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_FindNoMainResponse,
+ base::Unretained(this)));
// Conduct the test.
storage()->FindResponseForMainRequest(kEntryUrl, GURL(), delegate());
@@ -825,8 +829,9 @@ class AppCacheStorageImplTest : public testing::Test {
}
void BasicFindMainResponse(bool drop_from_working_set) {
- PushNextTask(NewRunnableMethod(
- this, &AppCacheStorageImplTest::Verify_BasicFindMainResponse));
+ PushNextTask(base::Bind(
+ &AppCacheStorageImplTest::Verify_BasicFindMainResponse,
+ base::Unretained(this)));
// Setup some preconditions. Create a complete cache with an entry
// in storage.
@@ -874,8 +879,9 @@ class AppCacheStorageImplTest : public testing::Test {
}
void BasicFindMainFallbackResponse(bool drop_from_working_set) {
- PushNextTask(NewRunnableMethod(
- this, &AppCacheStorageImplTest::Verify_BasicFindMainFallbackResponse));
+ PushNextTask(base::Bind(
+ &AppCacheStorageImplTest::Verify_BasicFindMainFallbackResponse,
+ base::Unretained(this)));
// Setup some preconditions. Create a complete cache with a
// fallback namespace and entry.
@@ -932,8 +938,9 @@ class AppCacheStorageImplTest : public testing::Test {
// FindMainResponseWithMultipleHits -------------------------------
void FindMainResponseWithMultipleHits() {
- PushNextTask(NewRunnableMethod(this,
- &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits));
+ PushNextTask(base::Bind(
+ &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits,
+ base::Unretained(this)));
// Setup some preconditions, create a few caches with an identical set
// of entries and fallback namespaces. Only the last one remains in
@@ -1003,8 +1010,9 @@ class AppCacheStorageImplTest : public testing::Test {
// Conduct another test perferring kManifestUrl
delegate_.reset(new MockStorageDelegate(this));
- PushNextTask(NewRunnableMethod(this,
- &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits2));
+ PushNextTask(base::Bind(
+ &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits2,
+ base::Unretained(this)));
storage()->FindResponseForMainRequest(kEntryUrl, kManifestUrl, delegate());
EXPECT_NE(kEntryUrl, delegate()->found_url_);
}
@@ -1020,8 +1028,9 @@ class AppCacheStorageImplTest : public testing::Test {
// Conduct the another test perferring kManifestUrl2
delegate_.reset(new MockStorageDelegate(this));
- PushNextTask(NewRunnableMethod(this,
- &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits3));
+ PushNextTask(base::Bind(
+ &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits3,
+ base::Unretained(this)));
storage()->FindResponseForMainRequest(kEntryUrl, kManifestUrl2, delegate());
EXPECT_NE(kEntryUrl, delegate()->found_url_);
}
@@ -1037,8 +1046,9 @@ class AppCacheStorageImplTest : public testing::Test {
// Conduct another test with no preferred manifest that hits the fallback.
delegate_.reset(new MockStorageDelegate(this));
- PushNextTask(NewRunnableMethod(this,
- &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits4));
+ PushNextTask(base::Bind(
+ &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits4,
+ base::Unretained(this)));
storage()->FindResponseForMainRequest(
kFallbackTestUrl, GURL(), delegate());
EXPECT_NE(kFallbackTestUrl, delegate()->found_url_);
@@ -1057,8 +1067,9 @@ class AppCacheStorageImplTest : public testing::Test {
// Conduct another test preferring kManifestUrl2 that hits the fallback.
delegate_.reset(new MockStorageDelegate(this));
- PushNextTask(NewRunnableMethod(this,
- &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits5));
+ PushNextTask(base::Bind(
+ &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits5,
+ base::Unretained(this)));
storage()->FindResponseForMainRequest(
kFallbackTestUrl, kManifestUrl2, delegate());
EXPECT_NE(kFallbackTestUrl, delegate()->found_url_);
@@ -1129,9 +1140,8 @@ class AppCacheStorageImplTest : public testing::Test {
}
// We should not find anything for the foreign entry.
- PushNextTask(NewRunnableMethod(
- this, &AppCacheStorageImplTest::Verify_ExclusionNotFound,
- kEntryUrl, 1));
+ PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_ExclusionNotFound,
+ base::Unretained(this), kEntryUrl, 1));
storage()->FindResponseForMainRequest(kEntryUrl, GURL(), delegate());
}
@@ -1148,9 +1158,9 @@ class AppCacheStorageImplTest : public testing::Test {
if (phase == 1) {
// We should not find anything for the online namespace.
- PushNextTask(NewRunnableMethod(this,
- &AppCacheStorageImplTest::Verify_ExclusionNotFound,
- kOnlineNamespace, 2));
+ PushNextTask(
+ base::Bind(&AppCacheStorageImplTest::Verify_ExclusionNotFound,
+ base::Unretained(this), kOnlineNamespace, 2));
storage()->FindResponseForMainRequest(
kOnlineNamespace, GURL(), delegate());
return;
@@ -1158,9 +1168,9 @@ class AppCacheStorageImplTest : public testing::Test {
if (phase == 2) {
// We should not find anything for the online namespace nested within
// the fallback namespace.
- PushNextTask(NewRunnableMethod(this,
+ PushNextTask(base::Bind(
&AppCacheStorageImplTest::Verify_ExclusionNotFound,
- kOnlineNamespaceWithinFallback, 3));
+ base::Unretained(this), kOnlineNamespaceWithinFallback, 3));
storage()->FindResponseForMainRequest(
kOnlineNamespaceWithinFallback, GURL(), delegate());
return;
@@ -1227,7 +1237,7 @@ class AppCacheStorageImplTest : public testing::Test {
// Data members --------------------------------------------------
scoped_ptr<base::WaitableEvent> test_finished_event_;
- std::stack<Task*> task_stack_;
+ std::stack<base::Closure> task_stack_;
scoped_ptr<AppCacheService> service_;
scoped_ptr<MockStorageDelegate> delegate_;
scoped_refptr<MockQuotaManagerProxy> mock_quota_manager_proxy_;
@@ -1328,7 +1338,3 @@ TEST_F(AppCacheStorageImplTest, FindMainResponseExclusionsInWorkingSet) {
// That's all folks!
} // namespace appcache
-
-// AppCacheStorageImplTest is expected to always live longer than the
-// runnable methods. This lets us call NewRunnableMethod on its instances.
-DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheStorageImplTest);
diff --git a/webkit/appcache/appcache_update_job_unittest.cc b/webkit/appcache/appcache_update_job_unittest.cc
index 2f87651f..45eea63 100644
--- a/webkit/appcache/appcache_update_job_unittest.cc
+++ b/webkit/appcache/appcache_update_job_unittest.cc
@@ -4,6 +4,8 @@
#include "testing/gtest/include/gtest/gtest.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/stl_util.h"
#include "base/threading/thread.h"
#include "base/synchronization/waitable_event.h"
@@ -568,7 +570,7 @@ class AppCacheUpdateJobTest : public testing::Test,
void RunTestOnIOThread(Method method) {
event_.reset(new base::WaitableEvent(false, false));
io_thread_->message_loop()->PostTask(
- FROM_HERE, NewRunnableMethod(this, method));
+ FROM_HERE, base::Bind(method, base::Unretained(this)));
// Wait until task is done before exiting the test.
event_->Wait();
@@ -2819,8 +2821,9 @@ class AppCacheUpdateJobTest : public testing::Test,
void UpdateFinished() {
// We unwind the stack prior to finishing up to let stack-based objects
// get deleted.
- MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &AppCacheUpdateJobTest::UpdateFinishedUnwound));
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&AppCacheUpdateJobTest::UpdateFinishedUnwound,
+ base::Unretained(this)));
}
void UpdateFinishedUnwound() {
@@ -3451,7 +3454,3 @@ TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) {
}
} // namespace appcache
-
-// AppCacheUpdateJobTest is expected to always live longer than the
-// runnable methods. This lets us call NewRunnableMethod on its instances.
-DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheUpdateJobTest);
diff --git a/webkit/appcache/appcache_url_request_job_unittest.cc b/webkit/appcache/appcache_url_request_job_unittest.cc
index eadac53..aea70e7 100644
--- a/webkit/appcache/appcache_url_request_job_unittest.cc
+++ b/webkit/appcache/appcache_url_request_job_unittest.cc
@@ -5,6 +5,9 @@
#include <stack>
#include <utility>
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/pickle.h"
#include "base/synchronization/waitable_event.h"
@@ -212,10 +215,9 @@ class AppCacheURLRequestJobTest : public testing::Test {
url_request_delegate_.reset();
DCHECK(!mock_factory_job_);
- while (!task_stack_.empty()) {
- delete task_stack_.top().first;
+ while (!task_stack_.empty())
task_stack_.pop();
- }
+
reader_.reset();
read_buffer_ = NULL;
read_info_buffer_ = NULL;
@@ -231,8 +233,8 @@ class AppCacheURLRequestJobTest : public testing::Test {
// based objects get deleted.
DCHECK(MessageLoop::current() == io_thread_->message_loop());
MessageLoop::current()->PostTask(FROM_HERE,
- NewRunnableMethod(
- this, &AppCacheURLRequestJobTest::TestFinishedUnwound));
+ base::Bind(&AppCacheURLRequestJobTest::TestFinishedUnwound,
+ base::Unretained(this)));
}
void TestFinishedUnwound() {
@@ -240,12 +242,12 @@ class AppCacheURLRequestJobTest : public testing::Test {
test_finished_event_->Signal();
}
- void PushNextTask(Task* task) {
- task_stack_.push(std::pair<Task*, bool>(task, false));
+ void PushNextTask(const base::Closure& task) {
+ task_stack_.push(std::pair<base::Closure, bool>(task, false));
}
- void PushNextTaskAsImmediate(Task* task) {
- task_stack_.push(std::pair<Task*, bool>(task, true));
+ void PushNextTaskAsImmediate(const base::Closure& task) {
+ task_stack_.push(std::pair<base::Closure, bool>(task, true));
}
void ScheduleNextTask() {
@@ -254,13 +256,13 @@ class AppCacheURLRequestJobTest : public testing::Test {
TestFinished();
return;
}
- scoped_ptr<Task> task(task_stack_.top().first);
+ base::Closure task =task_stack_.top().first;
bool immediate = task_stack_.top().second;
task_stack_.pop();
if (immediate)
- task->Run();
+ task.Run();
else
- MessageLoop::current()->PostTask(FROM_HERE, task.release());
+ MessageLoop::current()->PostTask(FROM_HERE, task);
}
// Wrappers to call AppCacheResponseReader/Writer Read and Write methods
@@ -276,9 +278,8 @@ class AppCacheURLRequestJobTest : public testing::Test {
IOBuffer* body, int body_len) {
DCHECK(body);
scoped_refptr<IOBuffer> body_ref(body);
- PushNextTask(NewRunnableMethod(
- this, &AppCacheURLRequestJobTest::WriteResponseBody,
- body_ref, body_len));
+ PushNextTask(base::Bind(&AppCacheURLRequestJobTest::WriteResponseBody,
+ base::Unretained(this), body_ref, body_len));
WriteResponseHead(head);
}
@@ -456,8 +457,9 @@ class AppCacheURLRequestJobTest : public testing::Test {
void DeliverNetworkResponse() {
// This test has async steps.
- PushNextTask(NewRunnableMethod(
- this, &AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse));
+ PushNextTask(
+ base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse,
+ base::Unretained(this)));
AppCacheStorage* storage = service_->storage();
request_.reset(
@@ -488,8 +490,9 @@ class AppCacheURLRequestJobTest : public testing::Test {
void DeliverErrorResponse() {
// This test has async steps.
- PushNextTask(NewRunnableMethod(
- this, &AppCacheURLRequestJobTest::VerifyDeliverErrorResponse));
+ PushNextTask(
+ base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverErrorResponse,
+ base::Unretained(this)));
AppCacheStorage* storage = service_->storage();
request_.reset(
@@ -525,10 +528,12 @@ class AppCacheURLRequestJobTest : public testing::Test {
// 2. Use net::URLRequest to retrieve it.
// 3. Verify we received what we expected to receive.
- PushNextTask(NewRunnableMethod(
- this, &AppCacheURLRequestJobTest::VerifyDeliverSmallAppCachedResponse));
- PushNextTask(NewRunnableMethod(
- this, &AppCacheURLRequestJobTest::RequestAppCachedResource, false));
+ PushNextTask(base::Bind(
+ &AppCacheURLRequestJobTest::VerifyDeliverSmallAppCachedResponse,
+ base::Unretained(this)));
+ PushNextTask(
+ base::Bind(&AppCacheURLRequestJobTest::RequestAppCachedResource,
+ base::Unretained(this), false));
writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0));
written_response_id_ = writer_->response_id();
@@ -593,10 +598,12 @@ class AppCacheURLRequestJobTest : public testing::Test {
// 2. Use net::URLRequest to retrieve it.
// 3. Verify we received what we expected to receive.
- PushNextTask(NewRunnableMethod(
- this, &AppCacheURLRequestJobTest::VerifyDeliverLargeAppCachedResponse));
- PushNextTask(NewRunnableMethod(
- this, &AppCacheURLRequestJobTest::RequestAppCachedResource, true));
+ PushNextTask(base::Bind(
+ &AppCacheURLRequestJobTest::VerifyDeliverLargeAppCachedResponse,
+ base::Unretained(this)));
+ PushNextTask(base::Bind(
+ &AppCacheURLRequestJobTest::RequestAppCachedResource,
+ base::Unretained(this), true));
writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0));
written_response_id_ = writer_->response_id();
@@ -635,10 +642,11 @@ class AppCacheURLRequestJobTest : public testing::Test {
// 1. Write a small response to response storage.
// 2. Use net::URLRequest to retrieve it a subset using a range request
// 3. Verify we received what we expected to receive.
- PushNextTask(NewRunnableMethod(
- this, &AppCacheURLRequestJobTest::VerifyDeliverPartialResponse));
- PushNextTask(NewRunnableMethod(
- this, &AppCacheURLRequestJobTest::MakeRangeRequest));
+ PushNextTask(base::Bind(
+ &AppCacheURLRequestJobTest::VerifyDeliverPartialResponse,
+ base::Unretained(this)));
+ PushNextTask(base::Bind(
+ &AppCacheURLRequestJobTest::MakeRangeRequest, base::Unretained(this)));
writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0));
written_response_id_ = writer_->response_id();
WriteBasicResponse();
@@ -700,10 +708,11 @@ class AppCacheURLRequestJobTest : public testing::Test {
// 2. Use net::URLRequest to retrieve it.
// 3. Cancel the request after data starts coming in.
- PushNextTask(NewRunnableMethod(
- this, &AppCacheURLRequestJobTest::VerifyCancel));
- PushNextTask(NewRunnableMethod(
- this, &AppCacheURLRequestJobTest::RequestAppCachedResource, true));
+ PushNextTask(base::Bind(
+ &AppCacheURLRequestJobTest::VerifyCancel, base::Unretained(this)));
+ PushNextTask(base::Bind(
+ &AppCacheURLRequestJobTest::RequestAppCachedResource,
+ base::Unretained(this), true));
writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0));
written_response_id_ = writer_->response_id();
@@ -728,10 +737,11 @@ class AppCacheURLRequestJobTest : public testing::Test {
// 2. Use net::URLRequest to retrieve it.
// 3. Cancel the request after data starts coming in.
- PushNextTask(NewRunnableMethod(
- this, &AppCacheURLRequestJobTest::VerifyCancel));
- PushNextTask(NewRunnableMethod(
- this, &AppCacheURLRequestJobTest::RequestAppCachedResource, true));
+ PushNextTask(base::Bind(
+ &AppCacheURLRequestJobTest::VerifyCancel, base::Unretained(this)));
+ PushNextTask(base::Bind(
+ &AppCacheURLRequestJobTest::RequestAppCachedResource,
+ base::Unretained(this), true));
writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0));
written_response_id_ = writer_->response_id();
@@ -748,7 +758,7 @@ class AppCacheURLRequestJobTest : public testing::Test {
scoped_ptr<base::WaitableEvent> test_finished_event_;
scoped_ptr<MockStorageDelegate> storage_delegate_;
scoped_ptr<MockAppCacheService> service_;
- std::stack<std::pair<Task*, bool> > task_stack_;
+ std::stack<std::pair<base::Closure, bool> > task_stack_;
scoped_ptr<AppCacheResponseReader> reader_;
scoped_refptr<HttpResponseInfoIOBuffer> read_info_buffer_;
@@ -820,7 +830,3 @@ TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) {
}
} // namespace appcache
-
-// AppCacheURLRequestJobTest is expected to always live longer than the
-// runnable methods. This lets us call NewRunnableMethod on its instances.
-DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheURLRequestJobTest);
diff --git a/webkit/appcache/mock_appcache_storage.cc b/webkit/appcache/mock_appcache_storage.cc
index 8560074..4353390 100644
--- a/webkit/appcache/mock_appcache_storage.cc
+++ b/webkit/appcache/mock_appcache_storage.cc
@@ -4,6 +4,7 @@
#include "webkit/appcache/mock_appcache_storage.h"
+#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop.h"
@@ -28,7 +29,7 @@ namespace appcache {
MockAppCacheStorage::MockAppCacheStorage(AppCacheService* service)
: AppCacheStorage(service),
- ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
simulate_make_group_obsolete_failure_(false),
simulate_store_group_and_newest_cache_failure_(false),
simulate_find_main_resource_(false),
@@ -42,22 +43,23 @@ MockAppCacheStorage::MockAppCacheStorage(AppCacheService* service)
}
MockAppCacheStorage::~MockAppCacheStorage() {
- STLDeleteElements(&pending_tasks_);
}
void MockAppCacheStorage::GetAllInfo(Delegate* delegate) {
- ScheduleTask(method_factory_.NewRunnableMethod(
- &MockAppCacheStorage::ProcessGetAllInfo,
- make_scoped_refptr(GetOrCreateDelegateReference(delegate))));
+ ScheduleTask(
+ base::Bind(&MockAppCacheStorage::ProcessGetAllInfo,
+ weak_factory_.GetWeakPtr(),
+ make_scoped_refptr(GetOrCreateDelegateReference(delegate))));
}
void MockAppCacheStorage::LoadCache(int64 id, Delegate* delegate) {
DCHECK(delegate);
AppCache* cache = working_set_.GetCache(id);
if (ShouldCacheLoadAppearAsync(cache)) {
- ScheduleTask(method_factory_.NewRunnableMethod(
- &MockAppCacheStorage::ProcessLoadCache,
- id, make_scoped_refptr(GetOrCreateDelegateReference(delegate))));
+ ScheduleTask(
+ base::Bind(&MockAppCacheStorage::ProcessLoadCache,
+ weak_factory_.GetWeakPtr(), id,
+ make_scoped_refptr(GetOrCreateDelegateReference(delegate))));
return;
}
ProcessLoadCache(id, GetOrCreateDelegateReference(delegate));
@@ -68,10 +70,10 @@ void MockAppCacheStorage::LoadOrCreateGroup(
DCHECK(delegate);
AppCacheGroup* group = working_set_.GetGroup(manifest_url);
if (ShouldGroupLoadAppearAsync(group)) {
- ScheduleTask(method_factory_.NewRunnableMethod(
- &MockAppCacheStorage::ProcessLoadOrCreateGroup,
- manifest_url,
- make_scoped_refptr(GetOrCreateDelegateReference(delegate))));
+ ScheduleTask(
+ base::Bind(&MockAppCacheStorage::ProcessLoadOrCreateGroup,
+ weak_factory_.GetWeakPtr(), manifest_url,
+ make_scoped_refptr(GetOrCreateDelegateReference(delegate))));
return;
}
ProcessLoadOrCreateGroup(
@@ -83,11 +85,11 @@ void MockAppCacheStorage::StoreGroupAndNewestCache(
DCHECK(group && delegate && newest_cache);
// Always make this operation look async.
- ScheduleTask(method_factory_.NewRunnableMethod(
- &MockAppCacheStorage::ProcessStoreGroupAndNewestCache,
- make_scoped_refptr(group),
- make_scoped_refptr(newest_cache),
- make_scoped_refptr(GetOrCreateDelegateReference(delegate))));
+ ScheduleTask(
+ base::Bind(&MockAppCacheStorage::ProcessStoreGroupAndNewestCache,
+ weak_factory_.GetWeakPtr(), make_scoped_refptr(group),
+ make_scoped_refptr(newest_cache),
+ make_scoped_refptr(GetOrCreateDelegateReference(delegate))));
}
void MockAppCacheStorage::FindResponseForMainRequest(
@@ -97,10 +99,10 @@ void MockAppCacheStorage::FindResponseForMainRequest(
// Note: MockAppCacheStorage does not respect the preferred_manifest_url.
// Always make this operation look async.
- ScheduleTask(method_factory_.NewRunnableMethod(
- &MockAppCacheStorage::ProcessFindResponseForMainRequest,
- url,
- make_scoped_refptr(GetOrCreateDelegateReference(delegate))));
+ ScheduleTask(
+ base::Bind(&MockAppCacheStorage::ProcessFindResponseForMainRequest,
+ weak_factory_.GetWeakPtr(), url,
+ make_scoped_refptr(GetOrCreateDelegateReference(delegate))));
}
void MockAppCacheStorage::FindResponseForSubRequest(
@@ -140,10 +142,10 @@ void MockAppCacheStorage::MakeGroupObsolete(
DCHECK(group && delegate);
// Always make this method look async.
- ScheduleTask(method_factory_.NewRunnableMethod(
- &MockAppCacheStorage::ProcessMakeGroupObsolete,
- make_scoped_refptr(group),
- make_scoped_refptr(GetOrCreateDelegateReference(delegate))));
+ ScheduleTask(
+ base::Bind(&MockAppCacheStorage::ProcessMakeGroupObsolete,
+ weak_factory_.GetWeakPtr(), make_scoped_refptr(group),
+ make_scoped_refptr(GetOrCreateDelegateReference(delegate))));
}
AppCacheResponseReader* MockAppCacheStorage::CreateResponseReader(
@@ -405,19 +407,19 @@ void MockAppCacheStorage::ProcessMakeGroupObsolete(
delegate_ref->delegate->OnGroupMadeObsolete(group, true);
}
-void MockAppCacheStorage::ScheduleTask(Task* task) {
+void MockAppCacheStorage::ScheduleTask(const base::Closure& task) {
pending_tasks_.push_back(task);
- MessageLoop::current()->PostTask(FROM_HERE,
- method_factory_.NewRunnableMethod(
- &MockAppCacheStorage::RunOnePendingTask));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&MockAppCacheStorage::RunOnePendingTask,
+ weak_factory_.GetWeakPtr()));
}
void MockAppCacheStorage::RunOnePendingTask() {
DCHECK(!pending_tasks_.empty());
- Task* task = pending_tasks_.front();
+ base::Closure task = pending_tasks_.front();
pending_tasks_.pop_front();
- task->Run();
- delete task;
+ task.Run();
}
void MockAppCacheStorage::AddStoredCache(AppCache* cache) {
diff --git a/webkit/appcache/mock_appcache_storage.h b/webkit/appcache/mock_appcache_storage.h
index c6a49fac..c3b88b6 100644
--- a/webkit/appcache/mock_appcache_storage.h
+++ b/webkit/appcache/mock_appcache_storage.h
@@ -9,10 +9,11 @@
#include <map>
#include <vector>
+#include "base/callback.h"
#include "base/gtest_prod_util.h"
#include "base/hash_tables.h"
#include "base/memory/scoped_ptr.h"
-#include "base/task.h"
+#include "base/memory/weak_ptr.h"
#include "webkit/appcache/appcache.h"
#include "webkit/appcache/appcache_disk_cache.h"
#include "webkit/appcache/appcache_group.h"
@@ -76,7 +77,7 @@ class MockAppCacheStorage : public AppCacheStorage {
void ProcessFindResponseForMainRequest(
const GURL& url, scoped_refptr<DelegateReference> delegate_ref);
- void ScheduleTask(Task* task);
+ void ScheduleTask(const base::Closure& task);
void RunOnePendingTask();
void AddStoredCache(AppCache* cache);
@@ -168,8 +169,8 @@ class MockAppCacheStorage : public AppCacheStorage {
StoredGroupMap stored_groups_;
DoomedResponseIds doomed_response_ids_;
scoped_ptr<AppCacheDiskCache> disk_cache_;
- std::deque<Task*> pending_tasks_;
- ScopedRunnableMethodFactory<MockAppCacheStorage> method_factory_;
+ std::deque<base::Closure> pending_tasks_;
+ base::WeakPtrFactory<MockAppCacheStorage> weak_factory_;
bool simulate_make_group_obsolete_failure_;
bool simulate_store_group_and_newest_cache_failure_;