summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/disk_cache/backend_impl.cc2
-rw-r--r--net/disk_cache/backend_impl.h3
-rw-r--r--net/disk_cache/disk_cache_test_base.cc36
-rw-r--r--net/disk_cache/disk_cache_test_base.h2
-rw-r--r--net/disk_cache/entry_unittest.cc44
-rw-r--r--net/disk_cache/in_flight_backend_io.cc7
-rw-r--r--net/disk_cache/in_flight_backend_io.h7
7 files changed, 29 insertions, 72 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index 17ccc5f..5e652d7 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -1312,7 +1312,7 @@ int BackendImpl::FlushQueueForTest(const net::CompletionCallback& callback) {
return net::ERR_IO_PENDING;
}
-int BackendImpl::RunTaskForTest(Task* task,
+int BackendImpl::RunTaskForTest(const base::Closure& task,
const net::CompletionCallback& callback) {
background_queue_.RunTask(task, callback);
return net::ERR_IO_PENDING;
diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h
index b85c663d..53c8893 100644
--- a/net/disk_cache/backend_impl.h
+++ b/net/disk_cache/backend_impl.h
@@ -242,7 +242,8 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend {
// Runs the provided task on the cache thread. The task will be automatically
// deleted after it runs.
- int RunTaskForTest(Task* task, const net::CompletionCallback& callback);
+ int RunTaskForTest(const base::Closure& task,
+ const net::CompletionCallback& callback);
// Trims an entry (all if |empty| is true) from the list of deleted
// entries. This method should be called directly on the cache thread.
diff --git a/net/disk_cache/disk_cache_test_base.cc b/net/disk_cache/disk_cache_test_base.cc
index c70da92..a2bf2a2 100644
--- a/net/disk_cache/disk_cache_test_base.cc
+++ b/net/disk_cache/disk_cache_test_base.cc
@@ -159,15 +159,14 @@ void DiskCacheTestWithCache::FlushQueueForTest() {
EXPECT_EQ(net::OK, cb.GetResult(rv));
}
-void DiskCacheTestWithCache::RunTaskForTest(Task* task) {
+void DiskCacheTestWithCache::RunTaskForTest(const base::Closure& closure) {
if (memory_only_ || !cache_impl_) {
- task->Run();
- delete task;
+ closure.Run();
return;
}
net::TestCompletionCallback cb;
- int rv = cache_impl_->RunTaskForTest(task, cb.callback());
+ int rv = cache_impl_->RunTaskForTest(closure, cb.callback());
EXPECT_EQ(net::OK, cb.GetResult(rv));
}
@@ -202,33 +201,16 @@ int DiskCacheTestWithCache::WriteSparseData(disk_cache::Entry* entry,
return cb.GetResult(rv);
}
-// Simple task to run part of a test from the cache thread.
-class TrimTask : public Task {
- public:
- TrimTask(disk_cache::BackendImpl* backend, bool deleted, bool empty)
- : backend_(backend),
- deleted_(deleted),
- empty_(empty) {}
-
- virtual void Run() {
- if (deleted_)
- backend_->TrimDeletedListForTest(empty_);
- else
- backend_->TrimForTest(empty_);
- }
-
- protected:
- disk_cache::BackendImpl* backend_;
- bool deleted_;
- bool empty_;
-};
-
void DiskCacheTestWithCache::TrimForTest(bool empty) {
- RunTaskForTest(new TrimTask(cache_impl_, false, empty));
+ RunTaskForTest(base::Bind(&disk_cache::BackendImpl::TrimForTest,
+ base::Unretained(cache_impl_),
+ empty));
}
void DiskCacheTestWithCache::TrimDeletedListForTest(bool empty) {
- RunTaskForTest(new TrimTask(cache_impl_, true, empty));
+ RunTaskForTest(base::Bind(&disk_cache::BackendImpl::TrimDeletedListForTest,
+ base::Unretained(cache_impl_),
+ empty));
}
void DiskCacheTestWithCache::TearDown() {
diff --git a/net/disk_cache/disk_cache_test_base.h b/net/disk_cache/disk_cache_test_base.h
index 4e1fb12..ed3d8bd 100644
--- a/net/disk_cache/disk_cache_test_base.h
+++ b/net/disk_cache/disk_cache_test_base.h
@@ -112,7 +112,7 @@ class DiskCacheTestWithCache : public DiskCacheTest {
int DoomEntriesSince(const base::Time initial_time);
int OpenNextEntry(void** iter, disk_cache::Entry** next_entry);
void FlushQueueForTest();
- void RunTaskForTest(Task* task);
+ void RunTaskForTest(const base::Closure& closure);
int ReadData(disk_cache::Entry* entry, int index, int offset,
net::IOBuffer* buf, int len);
int WriteData(disk_cache::Entry* entry, int index, int offset,
diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc
index cf9e6cd..f81e9d4 100644
--- a/net/disk_cache/entry_unittest.cc
+++ b/net/disk_cache/entry_unittest.cc
@@ -53,27 +53,6 @@ class DiskCacheEntryTest : public DiskCacheTestWithCache {
void PartialSparseEntry();
};
-// Simple task to run part of a test from the cache thread.
-class SyncIOTask : public Task {
- public:
- SyncIOTask(DiskCacheEntryTest* test, disk_cache::Entry* entry)
- : test_(test), entry_(entry) {}
-
- protected:
- DiskCacheEntryTest* test_;
- disk_cache::Entry* entry_;
-};
-
-class InternalSyncIOTask : public SyncIOTask {
- public:
- InternalSyncIOTask(DiskCacheEntryTest* test, disk_cache::Entry* entry)
- : SyncIOTask(test, entry) {}
-
- virtual void Run() {
- test_->InternalSyncIOBackground(entry_);
- }
-};
-
// This part of the test runs on the background thread.
void DiskCacheEntryTest::InternalSyncIOBackground(disk_cache::Entry* entry) {
const int kSize1 = 10;
@@ -134,8 +113,11 @@ void DiskCacheEntryTest::InternalSyncIO() {
ASSERT_EQ(net::OK, CreateEntry("the first key", &entry));
ASSERT_TRUE(NULL != entry);
- // The bulk of the test runs from within the task, on the cache thread.
- RunTaskForTest(new InternalSyncIOTask(this, entry));
+ // The bulk of the test runs from within the callback, on the cache thread.
+ RunTaskForTest(base::Bind(&DiskCacheEntryTest::InternalSyncIOBackground,
+ base::Unretained(this),
+ entry));
+
entry->Doom();
entry->Close();
@@ -317,16 +299,6 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyInternalAsyncIO) {
InternalAsyncIO();
}
-class ExternalSyncIOTask : public SyncIOTask {
- public:
- ExternalSyncIOTask(DiskCacheEntryTest* test, disk_cache::Entry* entry)
- : SyncIOTask(test, entry) {}
-
- virtual void Run() {
- test_->ExternalSyncIOBackground(entry_);
- }
-};
-
// This part of the test runs on the background thread.
void DiskCacheEntryTest::ExternalSyncIOBackground(disk_cache::Entry* entry) {
const int kSize1 = 17000;
@@ -375,8 +347,10 @@ void DiskCacheEntryTest::ExternalSyncIO() {
disk_cache::Entry* entry;
ASSERT_EQ(net::OK, CreateEntry("the first key", &entry));
- // The bulk of the test runs from within the task, on the cache thread.
- RunTaskForTest(new ExternalSyncIOTask(this, entry));
+ // The bulk of the test runs from within the callback, on the cache thread.
+ RunTaskForTest(base::Bind(&DiskCacheEntryTest::ExternalSyncIOBackground,
+ base::Unretained(this),
+ entry));
entry->Doom();
entry->Close();
diff --git a/net/disk_cache/in_flight_backend_io.cc b/net/disk_cache/in_flight_backend_io.cc
index 8a0e930..345b0e2 100644
--- a/net/disk_cache/in_flight_backend_io.cc
+++ b/net/disk_cache/in_flight_backend_io.cc
@@ -126,7 +126,7 @@ void BackendIO::FlushQueue() {
operation_ = OP_FLUSH_QUEUE;
}
-void BackendIO::RunTask(Task* task) {
+void BackendIO::RunTask(const base::Closure& task) {
operation_ = OP_RUN_TASK;
task_ = task;
}
@@ -241,8 +241,7 @@ void BackendIO::ExecuteBackendOperation() {
result_ = net::OK;
break;
case OP_RUN_TASK:
- task_->Run();
- delete task_;
+ task_.Run();
result_ = net::OK;
break;
default:
@@ -403,7 +402,7 @@ void InFlightBackendIO::FlushQueue(const net::CompletionCallback& callback) {
}
void InFlightBackendIO::RunTask(
- Task* task, const net::CompletionCallback& callback) {
+ const base::Closure& task, const net::CompletionCallback& callback) {
scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
operation->RunTask(task);
PostOperation(operation);
diff --git a/net/disk_cache/in_flight_backend_io.h b/net/disk_cache/in_flight_backend_io.h
index a23c955..4e6f904 100644
--- a/net/disk_cache/in_flight_backend_io.h
+++ b/net/disk_cache/in_flight_backend_io.h
@@ -61,7 +61,7 @@ class BackendIO : public BackgroundIO {
void CloseEntryImpl(EntryImpl* entry);
void DoomEntryImpl(EntryImpl* entry);
void FlushQueue(); // Dummy operation.
- void RunTask(Task* task);
+ void RunTask(const base::Closure& task);
void ReadData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf,
int buf_len);
void WriteData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf,
@@ -132,7 +132,7 @@ class BackendIO : public BackgroundIO {
int64 offset64_;
int64* start_;
base::TimeTicks start_time_;
- Task* task_;
+ base::Closure task_;
DISALLOW_COPY_AND_ASSIGN(BackendIO);
};
@@ -167,7 +167,8 @@ class InFlightBackendIO : public InFlightIO {
void CloseEntryImpl(EntryImpl* entry);
void DoomEntryImpl(EntryImpl* entry);
void FlushQueue(const net::CompletionCallback& callback);
- void RunTask(Task* task, const net::CompletionCallback& callback);
+ void RunTask(const base::Closure& task,
+ const net::CompletionCallback& callback);
void ReadData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf,
int buf_len, const net::CompletionCallback& callback);
void WriteData(