summaryrefslogtreecommitdiffstats
path: root/net/disk_cache
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-19 20:59:27 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-19 20:59:27 +0000
commit2a65aceb8e3ed63fecf62191ef6fb64d257bf484 (patch)
tree5f27b5c30f11f32cb8ca87126ef744d637c14590 /net/disk_cache
parenta18c4a5c9a056a2f49eccf360d141c215c85d053 (diff)
downloadchromium_src-2a65aceb8e3ed63fecf62191ef6fb64d257bf484.zip
chromium_src-2a65aceb8e3ed63fecf62191ef6fb64d257bf484.tar.gz
chromium_src-2a65aceb8e3ed63fecf62191ef6fb64d257bf484.tar.bz2
base::Bind: Convert most of disk_cache.
BUG=none TEST=none R=csilv Review URL: http://codereview.chromium.org/8963030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115019 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r--net/disk_cache/backend_impl.cc41
-rw-r--r--net/disk_cache/backend_impl.h17
-rw-r--r--net/disk_cache/backend_unittest.cc55
-rw-r--r--net/disk_cache/disk_cache.h23
-rw-r--r--net/disk_cache/disk_cache_perftest.cc38
-rw-r--r--net/disk_cache/disk_cache_test_base.cc44
-rw-r--r--net/disk_cache/entry_impl.cc72
-rw-r--r--net/disk_cache/entry_impl.h29
-rw-r--r--net/disk_cache/entry_unittest.cc289
-rw-r--r--net/disk_cache/in_flight_backend_io.cc103
-rw-r--r--net/disk_cache/in_flight_backend_io.h33
-rw-r--r--net/disk_cache/mem_backend_impl.cc6
-rw-r--r--net/disk_cache/mem_backend_impl.h9
-rw-r--r--net/disk_cache/mem_entry_impl.cc20
-rw-r--r--net/disk_cache/mem_entry_impl.h19
-rw-r--r--net/disk_cache/sparse_control.cc67
-rw-r--r--net/disk_cache/sparse_control.h11
-rw-r--r--net/disk_cache/stress_cache.cc14
18 files changed, 497 insertions, 393 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index 847ecac..17ccc5f 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -218,7 +218,7 @@ class CacheCreator {
net::CacheType type, uint32 flags,
base::MessageLoopProxy* thread, net::NetLog* net_log,
disk_cache::Backend** backend,
- net::OldCompletionCallback* callback)
+ const net::CompletionCallback& callback)
: path_(path),
force_(force),
retry_(false),
@@ -250,7 +250,7 @@ class CacheCreator {
uint32 flags_;
scoped_refptr<base::MessageLoopProxy> thread_;
disk_cache::Backend** backend_;
- net::OldCompletionCallback* callback_;
+ net::CompletionCallback callback_;
disk_cache::BackendImpl* cache_;
net::NetLog* net_log_;
@@ -277,7 +277,7 @@ void CacheCreator::DoCallback(int result) {
*backend_ = NULL;
delete cache_;
}
- callback_->Run(result);
+ callback_.Run(result);
delete this;
}
@@ -313,8 +313,8 @@ namespace disk_cache {
int CreateCacheBackend(net::CacheType type, const FilePath& path, int max_bytes,
bool force, base::MessageLoopProxy* thread,
net::NetLog* net_log, Backend** backend,
- OldCompletionCallback* callback) {
- DCHECK(callback);
+ const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
if (type == net::MEMORY_CACHE) {
*backend = MemBackendImpl::CreateBackend(max_bytes, net_log);
return *backend ? net::OK : net::ERR_FAILED;
@@ -434,11 +434,11 @@ int BackendImpl::CreateBackend(const FilePath& full_path, bool force,
int max_bytes, net::CacheType type,
uint32 flags, base::MessageLoopProxy* thread,
net::NetLog* net_log, Backend** backend,
- OldCompletionCallback* callback) {
- DCHECK(callback);
- CacheCreator* creator = new CacheCreator(full_path, force, max_bytes, type,
- flags, thread, net_log, backend,
- callback);
+ const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
+ CacheCreator* creator =
+ new CacheCreator(full_path, force, max_bytes, type, flags, thread,
+ net_log, backend, callback);
// This object will self-destroy when finished.
return creator->Run();
}
@@ -567,8 +567,8 @@ void BackendImpl::CleanupCache() {
// ------------------------------------------------------------------------
int BackendImpl::OpenPrevEntry(void** iter, Entry** prev_entry,
- OldCompletionCallback* callback) {
- DCHECK(callback);
+ const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
background_queue_.OpenPrevEntry(iter, prev_entry, callback);
return net::ERR_IO_PENDING;
}
@@ -1307,12 +1307,13 @@ void BackendImpl::ClearRefCountForTest() {
num_refs_ = 0;
}
-int BackendImpl::FlushQueueForTest(OldCompletionCallback* callback) {
+int BackendImpl::FlushQueueForTest(const net::CompletionCallback& callback) {
background_queue_.FlushQueue(callback);
return net::ERR_IO_PENDING;
}
-int BackendImpl::RunTaskForTest(Task* task, OldCompletionCallback* callback) {
+int BackendImpl::RunTaskForTest(Task* task,
+ const net::CompletionCallback& callback) {
background_queue_.RunTask(task, callback);
return net::ERR_IO_PENDING;
}
@@ -1369,15 +1370,15 @@ int32 BackendImpl::GetEntryCount() const {
}
int BackendImpl::OpenEntry(const std::string& key, Entry** entry,
- OldCompletionCallback* callback) {
- DCHECK(callback);
+ const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
background_queue_.OpenEntry(key, entry, callback);
return net::ERR_IO_PENDING;
}
int BackendImpl::CreateEntry(const std::string& key, Entry** entry,
- OldCompletionCallback* callback) {
- DCHECK(callback);
+ const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
background_queue_.CreateEntry(key, entry, callback);
return net::ERR_IO_PENDING;
}
@@ -1404,8 +1405,8 @@ int BackendImpl::DoomEntriesBetween(const base::Time initial_time,
}
int BackendImpl::DoomEntriesSince(const base::Time initial_time,
- OldCompletionCallback* callback) {
- DCHECK(callback);
+ const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
background_queue_.DoomEntriesSince(initial_time, callback);
return net::ERR_IO_PENDING;
}
diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h
index 6ef5906..b85c663d 100644
--- a/net/disk_cache/backend_impl.h
+++ b/net/disk_cache/backend_impl.h
@@ -56,7 +56,7 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend {
int max_bytes, net::CacheType type,
uint32 flags, base::MessageLoopProxy* thread,
net::NetLog* net_log, Backend** backend,
- OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
// Performs general initialization for this current instance of the cache.
int Init(const net::CompletionCallback& callback);
@@ -67,7 +67,7 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend {
// Same behavior as OpenNextEntry but walks the list from back to front.
int OpenPrevEntry(void** iter, Entry** prev_entry,
- OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
// Synchronous implementation of the asynchronous interface.
int SyncOpenEntry(const std::string& key, Entry** entry);
@@ -238,11 +238,11 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend {
void ClearRefCountForTest();
// Sends a dummy operation through the operation queue, for unit tests.
- int FlushQueueForTest(OldCompletionCallback* callback);
+ int FlushQueueForTest(const net::CompletionCallback& callback);
// Runs the provided task on the cache thread. The task will be automatically
// deleted after it runs.
- int RunTaskForTest(Task* task, OldCompletionCallback* callback);
+ int RunTaskForTest(Task* 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.
@@ -259,9 +259,9 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend {
// Backend implementation.
virtual int32 GetEntryCount() const OVERRIDE;
virtual int OpenEntry(const std::string& key, Entry** entry,
- OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int CreateEntry(const std::string& key, Entry** entry,
- OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int DoomEntry(const std::string& key,
const net::CompletionCallback& callback) OVERRIDE;
virtual int DoomAllEntries(const net::CompletionCallback& callback) OVERRIDE;
@@ -269,8 +269,9 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend {
const base::Time initial_time,
const base::Time end_time,
const net::CompletionCallback& callback) OVERRIDE;
- virtual int DoomEntriesSince(const base::Time initial_time,
- OldCompletionCallback* callback) OVERRIDE;
+ virtual int DoomEntriesSince(
+ const base::Time initial_time,
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int OpenNextEntry(void** iter, Entry** next_entry,
const net::CompletionCallback& callback) OVERRIDE;
virtual void EndEnumeration(void** iter) OVERRIDE;
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index c19ca68..9fa9f05 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -194,7 +194,7 @@ TEST_F(DiskCacheBackendTest, AppCacheKeying) {
}
TEST_F(DiskCacheTest, CreateBackend) {
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
{
ASSERT_TRUE(CleanupCacheDir());
@@ -205,8 +205,8 @@ TEST_F(DiskCacheTest, CreateBackend) {
// Test the private factory methods.
disk_cache::Backend* cache = NULL;
int rv = disk_cache::BackendImpl::CreateBackend(
- cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
- cache_thread.message_loop_proxy(), NULL, &cache, &cb);
+ cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
+ cache_thread.message_loop_proxy(), NULL, &cache, cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
ASSERT_TRUE(cache);
delete cache;
@@ -219,14 +219,14 @@ TEST_F(DiskCacheTest, CreateBackend) {
// Now test the public API.
rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, cache_path_, 0, false,
cache_thread.message_loop_proxy(),
- NULL, &cache, &cb);
+ NULL, &cache, cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
ASSERT_TRUE(cache);
delete cache;
cache = NULL;
rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, FilePath(), 0, false,
- NULL, NULL, &cache, &cb);
+ NULL, NULL, &cache, cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
ASSERT_TRUE(cache);
delete cache;
@@ -259,7 +259,7 @@ TEST_F(DiskCacheBackendTest, ExternalFiles) {
// Tests that we deal with file-level pending operations at destruction time.
TEST_F(DiskCacheTest, ShutdownWithPendingIO) {
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
{
ASSERT_TRUE(CleanupCacheDir());
@@ -271,12 +271,13 @@ TEST_F(DiskCacheTest, ShutdownWithPendingIO) {
int rv = disk_cache::BackendImpl::CreateBackend(
cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
base::MessageLoopProxy::current(), NULL,
- &cache, &cb);
+ &cache, cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
disk_cache::EntryImpl* entry;
- rv = cache->CreateEntry("some key",
- reinterpret_cast<disk_cache::Entry**>(&entry), &cb);
+ rv = cache->CreateEntry(
+ "some key", reinterpret_cast<disk_cache::Entry**>(&entry),
+ cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
const int kSize = 25000;
@@ -287,7 +288,7 @@ TEST_F(DiskCacheTest, ShutdownWithPendingIO) {
// We are using the current thread as the cache thread because we want to
// be able to call directly this method to make sure that the OS (instead
// of us switching thread) is returning IO pending.
- rv = entry->WriteDataImpl(0, i, buffer, kSize, &cb, false);
+ rv = entry->WriteDataImpl(0, i, buffer, kSize, cb.callback(), false);
if (rv == net::ERR_IO_PENDING)
break;
EXPECT_EQ(kSize, rv);
@@ -310,7 +311,7 @@ TEST_F(DiskCacheTest, ShutdownWithPendingIO) {
// Tests that we deal with background-thread pending operations.
TEST_F(DiskCacheTest, ShutdownWithPendingIO2) {
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
{
ASSERT_TRUE(CleanupCacheDir());
@@ -320,19 +321,19 @@ TEST_F(DiskCacheTest, ShutdownWithPendingIO2) {
disk_cache::Backend* cache;
int rv = disk_cache::BackendImpl::CreateBackend(
- cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
- cache_thread.message_loop_proxy(), NULL, &cache, &cb);
+ cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
+ cache_thread.message_loop_proxy(), NULL, &cache, cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
disk_cache::Entry* entry;
- rv = cache->CreateEntry("some key", &entry, &cb);
+ rv = cache->CreateEntry("some key", &entry, cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
const int kSize = 25000;
scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
CacheTestFillBuffer(buffer->data(), kSize, false);
- rv = entry->WriteData(0, 0, buffer, kSize, &cb, false);
+ rv = entry->WriteData(0, 0, buffer, kSize, cb.callback(), false);
EXPECT_EQ(net::ERR_IO_PENDING, rv);
entry->Close();
@@ -352,12 +353,12 @@ TEST_F(DiskCacheTest, TruncatedIndex) {
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0)));
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
disk_cache::Backend* backend = NULL;
int rv = disk_cache::BackendImpl::CreateBackend(
- cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNone,
- cache_thread.message_loop_proxy(), NULL, &backend, &cb);
+ cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNone,
+ cache_thread.message_loop_proxy(), NULL, &backend, cb.callback());
ASSERT_NE(net::OK, cb.GetResult(rv));
ASSERT_TRUE(backend == NULL);
@@ -1344,12 +1345,12 @@ TEST_F(DiskCacheTest, DeleteOld) {
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0)));
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
disk_cache::Backend* cache;
int rv = disk_cache::BackendImpl::CreateBackend(
cache_path_, true, 0, net::DISK_CACHE, disk_cache::kNoRandom,
- cache_thread.message_loop_proxy(), NULL, &cache, &cb);
+ cache_thread.message_loop_proxy(), NULL, &cache, cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
MessageLoopHelper helper;
@@ -2238,19 +2239,19 @@ TEST_F(DiskCacheTest, MultipleInstances) {
ScopedTestCache store3("cache_test3");
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
- base::Thread::Options(MessageLoop::TYPE_IO, 0)));
- TestOldCompletionCallback cb;
+ base::Thread::Options(MessageLoop::TYPE_IO, 0)));
+ net::TestCompletionCallback cb;
const int kNumberOfCaches = 2;
disk_cache::Backend* cache[kNumberOfCaches];
int rv = disk_cache::BackendImpl::CreateBackend(
- store1.path(), false, 0, net::DISK_CACHE, disk_cache::kNone,
- cache_thread.message_loop_proxy(), NULL, &cache[0], &cb);
+ store1.path(), false, 0, net::DISK_CACHE, disk_cache::kNone,
+ cache_thread.message_loop_proxy(), NULL, &cache[0], cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
rv = disk_cache::BackendImpl::CreateBackend(
- store2.path(), false, 0, net::MEDIA_CACHE, disk_cache::kNone,
- cache_thread.message_loop_proxy(), NULL, &cache[1], &cb);
+ store2.path(), false, 0, net::MEDIA_CACHE, disk_cache::kNone,
+ cache_thread.message_loop_proxy(), NULL, &cache[1], cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
ASSERT_TRUE(cache[0] != NULL && cache[1] != NULL);
@@ -2258,7 +2259,7 @@ TEST_F(DiskCacheTest, MultipleInstances) {
std::string key("the first key");
disk_cache::Entry* entry;
for (int i = 0; i < kNumberOfCaches; i++) {
- rv = cache[i]->CreateEntry(key, &entry, &cb);
+ rv = cache[i]->CreateEntry(key, &entry, cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
entry->Close();
}
diff --git a/net/disk_cache/disk_cache.h b/net/disk_cache/disk_cache.h
index 59231f6..7f4bf36 100644
--- a/net/disk_cache/disk_cache.h
+++ b/net/disk_cache/disk_cache.h
@@ -54,7 +54,7 @@ NET_EXPORT int CreateCacheBackend(net::CacheType type, const FilePath& path,
int max_bytes, bool force,
base::MessageLoopProxy* thread,
net::NetLog* net_log, Backend** backend,
- OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
// The root interface for a disk cache instance.
class NET_EXPORT Backend {
@@ -77,7 +77,7 @@ class NET_EXPORT Backend {
// will be invoked when the entry is available. The pointer to receive the
// |entry| must remain valid until the operation completes.
virtual int OpenEntry(const std::string& key, Entry** entry,
- OldCompletionCallback* callback) = 0;
+ const net::CompletionCallback& callback) = 0;
// Creates a new entry. Upon success, the out param holds a pointer to an
// Entry object representing the newly created disk cache entry. When the
@@ -86,7 +86,7 @@ class NET_EXPORT Backend {
// the |callback| will be invoked when the entry is available. The pointer to
// receive the |entry| must remain valid until the operation completes.
virtual int CreateEntry(const std::string& key, Entry** entry,
- OldCompletionCallback* callback) = 0;
+ const net::CompletionCallback& callback) = 0;
// Marks the entry, specified by the given key, for deletion. The return value
// is a net error code. If this method returns ERR_IO_PENDING, the |callback|
@@ -111,7 +111,7 @@ class NET_EXPORT Backend {
// value is a net error code. If this method returns ERR_IO_PENDING, the
// |callback| will be invoked when the operation completes.
virtual int DoomEntriesSince(const base::Time initial_time,
- OldCompletionCallback* callback) = 0;
+ const net::CompletionCallback& callback) = 0;
// Enumerates the cache. Initialize |iter| to NULL before calling this method
// the first time. That will cause the enumeration to start at the head of
@@ -178,7 +178,7 @@ class NET_EXPORT Entry {
// having to wait for all the callbacks, and still rely on the cleanup
// performed from the callback code.
virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
- OldCompletionCallback* completion_callback) = 0;
+ const net::CompletionCallback& callback) = 0;
// Copies cache data from the given buffer of length |buf_len|. If
// completion_callback is null, then this call blocks until the write
@@ -194,7 +194,7 @@ class NET_EXPORT Entry {
// If truncate is true, this call will truncate the stored data at the end of
// what we are writing here.
virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
- OldCompletionCallback* completion_callback,
+ const net::CompletionCallback& callback,
bool truncate) = 0;
// Sparse entries support:
@@ -242,7 +242,7 @@ class NET_EXPORT Entry {
// Behaves like ReadData() except that this method is used to access sparse
// entries.
virtual int ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
- OldCompletionCallback* completion_callback) = 0;
+ const net::CompletionCallback& callback) = 0;
// Behaves like WriteData() except that this method is used to access sparse
// entries. |truncate| is not part of this interface because a sparse entry
@@ -251,7 +251,7 @@ class NET_EXPORT Entry {
// that the content has changed), the whole entry should be doomed and
// re-created.
virtual int WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
- OldCompletionCallback* completion_callback) = 0;
+ const net::CompletionCallback& callback) = 0;
// Returns information about the currently stored portion of a sparse entry.
// |offset| and |len| describe a particular range that should be scanned to
@@ -263,13 +263,13 @@ class NET_EXPORT Entry {
// this method returns ERR_IO_PENDING, the |callback| will be invoked when the
// operation completes, and |start| must remain valid until that point.
virtual int GetAvailableRange(int64 offset, int len, int64* start,
- OldCompletionCallback* callback) = 0;
+ const net::CompletionCallback& callback) = 0;
// Returns true if this entry could be a sparse entry or false otherwise. This
// is a quick test that may return true even if the entry is not really
// sparse. This method doesn't modify the state of this entry (it will not
// create sparse tracking data). GetAvailableRange or ReadSparseData can be
- // used to perfom a definitive test of wether an existing entry is sparse or
+ // used to perform a definitive test of whether an existing entry is sparse or
// not, but that method may modify the current state of the entry (making it
// sparse, for instance). The purpose of this method is to test an existing
// entry, but without generating actual IO to perform a thorough check.
@@ -293,7 +293,8 @@ class NET_EXPORT Entry {
// Note that CancelSparseIO may have been called on another instance of this
// object that refers to the same physical disk entry.
// Note: This method is deprecated.
- virtual int ReadyForSparseIO(OldCompletionCallback* completion_callback) = 0;
+ virtual int ReadyForSparseIO(
+ const net::CompletionCallback& completion_callback) = 0;
protected:
virtual ~Entry() {}
diff --git a/net/disk_cache/disk_cache_perftest.cc b/net/disk_cache/disk_cache_perftest.cc
index 4115a15..be3cb0e 100644
--- a/net/disk_cache/disk_cache_perftest.cc
+++ b/net/disk_cache/disk_cache_perftest.cc
@@ -5,6 +5,7 @@
#include <string>
#include "base/basictypes.h"
+#include "base/bind.h"
#include "base/perftimer.h"
#include "base/string_util.h"
#include "base/threading/thread.h"
@@ -59,18 +60,21 @@ bool TimeWrite(int num_entries, disk_cache::Backend* cache,
entries->push_back(entry);
disk_cache::Entry* cache_entry;
- TestOldCompletionCallback cb;
- int rv = cache->CreateEntry(entry.key, &cache_entry, &cb);
+ net::TestCompletionCallback cb;
+ int rv = cache->CreateEntry(entry.key, &cache_entry, cb.callback());
if (net::OK != cb.GetResult(rv))
break;
- int ret = cache_entry->WriteData(0, 0, buffer1, kSize1, &callback, false);
+ int ret = cache_entry->WriteData(
+ 0, 0, buffer1, kSize1,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback), false);
if (net::ERR_IO_PENDING == ret)
expected++;
else if (kSize1 != ret)
break;
- ret = cache_entry->WriteData(1, 0, buffer2, entry.data_len, &callback,
- false);
+ ret = cache_entry->WriteData(
+ 1, 0, buffer2, entry.data_len,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback), false);
if (net::ERR_IO_PENDING == ret)
expected++;
else if (entry.data_len != ret)
@@ -105,17 +109,21 @@ bool TimeRead(int num_entries, disk_cache::Backend* cache,
for (int i = 0; i < num_entries; i++) {
disk_cache::Entry* cache_entry;
- TestOldCompletionCallback cb;
- int rv = cache->OpenEntry(entries[i].key, &cache_entry, &cb);
+ net::TestCompletionCallback cb;
+ int rv = cache->OpenEntry(entries[i].key, &cache_entry, cb.callback());
if (net::OK != cb.GetResult(rv))
break;
- int ret = cache_entry->ReadData(0, 0, buffer1, kSize1, &callback);
+ int ret = cache_entry->ReadData(
+ 0, 0, buffer1, kSize1,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback));
if (net::ERR_IO_PENDING == ret)
expected++;
else if (kSize1 != ret)
break;
- ret = cache_entry->ReadData(1, 0, buffer2, entries[i].data_len, &callback);
+ ret = cache_entry->ReadData(
+ 1, 0, buffer2, entries[i].data_len,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback));
if (net::ERR_IO_PENDING == ret)
expected++;
else if (entries[i].data_len != ret)
@@ -154,11 +162,11 @@ TEST_F(DiskCacheTest, CacheBackendPerformance) {
base::Thread::Options(MessageLoop::TYPE_IO, 0)));
ASSERT_TRUE(CleanupCacheDir());
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
disk_cache::Backend* cache;
int rv = disk_cache::CreateCacheBackend(
- net::DISK_CACHE, cache_path_, 0, false,
- cache_thread.message_loop_proxy(), NULL, &cache, &cb);
+ net::DISK_CACHE, cache_path_, 0, false,
+ cache_thread.message_loop_proxy(), NULL, &cache, cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
@@ -184,9 +192,9 @@ TEST_F(DiskCacheTest, CacheBackendPerformance) {
ASSERT_TRUE(file_util::EvictFileFromSystemCache(
cache_path_.AppendASCII("data_3")));
- rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, cache_path_, 0,
- false, cache_thread.message_loop_proxy(),
- NULL, &cache, &cb);
+ rv = disk_cache::CreateCacheBackend(
+ net::DISK_CACHE, cache_path_, 0, false, cache_thread.message_loop_proxy(),
+ NULL, &cache, cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
EXPECT_TRUE(TimeRead(num_entries, cache, entries, true));
diff --git a/net/disk_cache/disk_cache_test_base.cc b/net/disk_cache/disk_cache_test_base.cc
index 3182166..c70da92 100644
--- a/net/disk_cache/disk_cache_test_base.cc
+++ b/net/disk_cache/disk_cache_test_base.cc
@@ -79,8 +79,8 @@ void DiskCacheTestWithCache::InitCache() {
// We are expected to leak memory when simulating crashes.
void DiskCacheTestWithCache::SimulateCrash() {
ASSERT_TRUE(implementation_ && !memory_only_);
- TestOldCompletionCallback cb;
- int rv = cache_impl_->FlushQueueForTest(&cb);
+ net::TestCompletionCallback cb;
+ int rv = cache_impl_->FlushQueueForTest(cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
cache_impl_->ClearRefCountForTest();
@@ -106,15 +106,15 @@ void DiskCacheTestWithCache::SetMaxSize(int size) {
int DiskCacheTestWithCache::OpenEntry(const std::string& key,
disk_cache::Entry** entry) {
- TestOldCompletionCallback cb;
- int rv = cache_->OpenEntry(key, entry, &cb);
+ net::TestCompletionCallback cb;
+ int rv = cache_->OpenEntry(key, entry, cb.callback());
return cb.GetResult(rv);
}
int DiskCacheTestWithCache::CreateEntry(const std::string& key,
disk_cache::Entry** entry) {
- TestOldCompletionCallback cb;
- int rv = cache_->CreateEntry(key, entry, &cb);
+ net::TestCompletionCallback cb;
+ int rv = cache_->CreateEntry(key, entry, cb.callback());
return cb.GetResult(rv);
}
@@ -138,8 +138,8 @@ int DiskCacheTestWithCache::DoomEntriesBetween(const base::Time initial_time,
}
int DiskCacheTestWithCache::DoomEntriesSince(const base::Time initial_time) {
- TestOldCompletionCallback cb;
- int rv = cache_->DoomEntriesSince(initial_time, &cb);
+ net::TestCompletionCallback cb;
+ int rv = cache_->DoomEntriesSince(initial_time, cb.callback());
return cb.GetResult(rv);
}
@@ -154,8 +154,8 @@ void DiskCacheTestWithCache::FlushQueueForTest() {
if (memory_only_ || !cache_impl_)
return;
- TestOldCompletionCallback cb;
- int rv = cache_impl_->FlushQueueForTest(&cb);
+ net::TestCompletionCallback cb;
+ int rv = cache_impl_->FlushQueueForTest(cb.callback());
EXPECT_EQ(net::OK, cb.GetResult(rv));
}
@@ -166,39 +166,39 @@ void DiskCacheTestWithCache::RunTaskForTest(Task* task) {
return;
}
- TestOldCompletionCallback cb;
- int rv = cache_impl_->RunTaskForTest(task, &cb);
+ net::TestCompletionCallback cb;
+ int rv = cache_impl_->RunTaskForTest(task, cb.callback());
EXPECT_EQ(net::OK, cb.GetResult(rv));
}
int DiskCacheTestWithCache::ReadData(disk_cache::Entry* entry, int index,
int offset, net::IOBuffer* buf, int len) {
- TestOldCompletionCallback cb;
- int rv = entry->ReadData(index, offset, buf, len, &cb);
+ net::TestCompletionCallback cb;
+ int rv = entry->ReadData(index, offset, buf, len, cb.callback());
return cb.GetResult(rv);
}
int DiskCacheTestWithCache::WriteData(disk_cache::Entry* entry, int index,
int offset, net::IOBuffer* buf, int len,
bool truncate) {
- TestOldCompletionCallback cb;
- int rv = entry->WriteData(index, offset, buf, len, &cb, truncate);
+ net::TestCompletionCallback cb;
+ int rv = entry->WriteData(index, offset, buf, len, cb.callback(), truncate);
return cb.GetResult(rv);
}
int DiskCacheTestWithCache::ReadSparseData(disk_cache::Entry* entry,
int64 offset, net::IOBuffer* buf,
int len) {
- TestOldCompletionCallback cb;
- int rv = entry->ReadSparseData(offset, buf, len, &cb);
+ net::TestCompletionCallback cb;
+ int rv = entry->ReadSparseData(offset, buf, len, cb.callback());
return cb.GetResult(rv);
}
int DiskCacheTestWithCache::WriteSparseData(disk_cache::Entry* entry,
int64 offset,
net::IOBuffer* buf, int len) {
- TestOldCompletionCallback cb;
- int rv = entry->WriteSparseData(offset, buf, len, &cb);
+ net::TestCompletionCallback cb;
+ int rv = entry->WriteSparseData(offset, buf, len, cb.callback());
return cb.GetResult(rv);
}
@@ -277,10 +277,10 @@ void DiskCacheTestWithCache::InitDiskCache() {
use_current_thread_ ? base::MessageLoopProxy::current() :
cache_thread_.message_loop_proxy();
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
int rv = disk_cache::BackendImpl::CreateBackend(
cache_path_, force_creation_, size_, type_,
- disk_cache::kNoRandom, thread, NULL, &cache_, &cb);
+ disk_cache::kNoRandom, thread, NULL, &cache_, cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
}
diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc
index b0226a7..ad745a7 100644
--- a/net/disk_cache/entry_impl.cc
+++ b/net/disk_cache/entry_impl.cc
@@ -33,7 +33,7 @@ class SyncCallback: public disk_cache::FileIOCallback {
// |end_event_type| is the event type to log on completion. Logs nothing on
// discard, or when the NetLog is not set to log all events.
SyncCallback(disk_cache::EntryImpl* entry, net::IOBuffer* buffer,
- net::OldCompletionCallback* callback,
+ const net::CompletionCallback& callback,
net::NetLog::EventType end_event_type)
: entry_(entry), callback_(callback), buf_(buffer),
start_(TimeTicks::Now()), end_event_type_(end_event_type) {
@@ -47,7 +47,7 @@ class SyncCallback: public disk_cache::FileIOCallback {
private:
disk_cache::EntryImpl* entry_;
- net::OldCompletionCallback* callback_;
+ net::CompletionCallback callback_;
scoped_refptr<net::IOBuffer> buf_;
TimeTicks start_;
const net::NetLog::EventType end_event_type_;
@@ -57,7 +57,7 @@ class SyncCallback: public disk_cache::FileIOCallback {
void SyncCallback::OnFileIOComplete(int bytes_copied) {
entry_->DecrementIoCount();
- if (callback_) {
+ if (!callback_.is_null()) {
if (entry_->net_log().IsLoggingAllEvents()) {
entry_->net_log().EndEvent(
end_event_type_,
@@ -65,14 +65,14 @@ void SyncCallback::OnFileIOComplete(int bytes_copied) {
new disk_cache::ReadWriteCompleteParameters(bytes_copied)));
}
entry_->ReportIOTime(disk_cache::EntryImpl::kAsyncIO, start_);
- callback_->Run(bytes_copied);
+ callback_.Run(bytes_copied);
}
entry_->Release();
delete this;
}
void SyncCallback::Discard() {
- callback_ = NULL;
+ callback_.Reset();
buf_ = NULL;
OnFileIOComplete(0);
}
@@ -308,8 +308,9 @@ void EntryImpl::DoomImpl() {
backend_->InternalDoomEntry(this);
}
-int EntryImpl::ReadDataImpl(int index, int offset, net::IOBuffer* buf,
- int buf_len, OldCompletionCallback* callback) {
+int EntryImpl::ReadDataImpl(
+ int index, int offset, net::IOBuffer* buf, int buf_len,
+ const net::CompletionCallback& callback) {
if (net_log_.IsLoggingAllEvents()) {
net_log_.BeginEvent(
net::NetLog::TYPE_ENTRY_READ_DATA,
@@ -327,9 +328,9 @@ int EntryImpl::ReadDataImpl(int index, int offset, net::IOBuffer* buf,
return result;
}
-int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf,
- int buf_len, OldCompletionCallback* callback,
- bool truncate) {
+int EntryImpl::WriteDataImpl(
+ int index, int offset, net::IOBuffer* buf, int buf_len,
+ const net::CompletionCallback& callback, bool truncate) {
if (net_log_.IsLoggingAllEvents()) {
net_log_.BeginEvent(
net::NetLog::TYPE_ENTRY_WRITE_DATA,
@@ -349,7 +350,7 @@ int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf,
}
int EntryImpl::ReadSparseDataImpl(int64 offset, net::IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
DCHECK(node_.Data()->dirty || read_only_);
int result = InitSparseData();
if (net::OK != result)
@@ -362,8 +363,9 @@ int EntryImpl::ReadSparseDataImpl(int64 offset, net::IOBuffer* buf, int buf_len,
return result;
}
-int EntryImpl::WriteSparseDataImpl(int64 offset, net::IOBuffer* buf,
- int buf_len, OldCompletionCallback* callback) {
+int EntryImpl::WriteSparseDataImpl(
+ int64 offset, net::IOBuffer* buf, int buf_len,
+ const net::CompletionCallback& callback) {
DCHECK(node_.Data()->dirty || read_only_);
int result = InitSparseData();
if (net::OK != result)
@@ -391,7 +393,7 @@ void EntryImpl::CancelSparseIOImpl() {
sparse_->CancelIO();
}
-int EntryImpl::ReadyForSparseIOImpl(OldCompletionCallback* callback) {
+int EntryImpl::ReadyForSparseIOImpl(const net::CompletionCallback& callback) {
DCHECK(sparse_.get());
return sparse_->ReadyToUse(callback);
}
@@ -798,8 +800,8 @@ int32 EntryImpl::GetDataSize(int index) const {
}
int EntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) {
- if (!callback)
+ const net::CompletionCallback& callback) {
+ if (callback.is_null())
return ReadDataImpl(index, offset, buf, buf_len, callback);
DCHECK(node_.Data()->dirty || read_only_);
@@ -818,9 +820,10 @@ int EntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
return net::ERR_IO_PENDING;
}
-int EntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback, bool truncate) {
- if (!callback)
+int EntryImpl::WriteData(
+ int index, int offset, net::IOBuffer* buf, int buf_len,
+ const net::CompletionCallback& callback, bool truncate) {
+ if (callback.is_null())
return WriteDataImpl(index, offset, buf, buf_len, callback, truncate);
DCHECK(node_.Data()->dirty || read_only_);
@@ -836,8 +839,8 @@ int EntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
}
int EntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) {
- if (!callback)
+ const net::CompletionCallback& callback) {
+ if (callback.is_null())
return ReadSparseDataImpl(offset, buf, buf_len, callback);
backend_->background_queue()->ReadSparseData(this, offset, buf, buf_len,
@@ -846,8 +849,8 @@ int EntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
}
int EntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) {
- if (!callback)
+ const net::CompletionCallback& callback) {
+ if (callback.is_null())
return WriteSparseDataImpl(offset, buf, buf_len, callback);
backend_->background_queue()->WriteSparseData(this, offset, buf, buf_len,
@@ -856,7 +859,7 @@ int EntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
}
int EntryImpl::GetAvailableRange(int64 offset, int len, int64* start,
- OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
backend_->background_queue()->GetAvailableRange(this, offset, len, start,
callback);
return net::ERR_IO_PENDING;
@@ -875,7 +878,7 @@ void EntryImpl::CancelSparseIO() {
backend_->background_queue()->CancelSparseIO(this);
}
-int EntryImpl::ReadyForSparseIO(net::OldCompletionCallback* callback) {
+int EntryImpl::ReadyForSparseIO(const net::CompletionCallback& callback) {
if (!sparse_.get())
return net::OK;
@@ -938,8 +941,9 @@ EntryImpl::~EntryImpl() {
// ------------------------------------------------------------------------
-int EntryImpl::InternalReadData(int index, int offset, net::IOBuffer* buf,
- int buf_len, OldCompletionCallback* callback) {
+int EntryImpl::InternalReadData(
+ int index, int offset, net::IOBuffer* buf, int buf_len,
+ const net::CompletionCallback& callback) {
DCHECK(node_.Data()->dirty || read_only_);
DVLOG(2) << "Read from " << index << " at " << offset << " : " << buf_len;
if (index < 0 || index >= kNumStreams)
@@ -993,7 +997,7 @@ int EntryImpl::InternalReadData(int index, int offset, net::IOBuffer* buf,
}
SyncCallback* io_callback = NULL;
- if (callback) {
+ if (!callback.is_null()) {
io_callback = new SyncCallback(this, buf, callback,
net::NetLog::TYPE_ENTRY_READ_DATA);
}
@@ -1015,12 +1019,12 @@ int EntryImpl::InternalReadData(int index, int offset, net::IOBuffer* buf,
ReportIOTime(kReadAsync1, start_async);
ReportIOTime(kRead, start);
- return (completed || !callback) ? buf_len : net::ERR_IO_PENDING;
+ return (completed || callback.is_null()) ? buf_len : net::ERR_IO_PENDING;
}
-int EntryImpl::InternalWriteData(int index, int offset, net::IOBuffer* buf,
- int buf_len, OldCompletionCallback* callback,
- bool truncate) {
+int EntryImpl::InternalWriteData(
+ int index, int offset, net::IOBuffer* buf, int buf_len,
+ const net::CompletionCallback& callback, bool truncate) {
DCHECK(node_.Data()->dirty || read_only_);
DVLOG(2) << "Write to " << index << " at " << offset << " : " << buf_len;
if (index < 0 || index >= kNumStreams)
@@ -1093,7 +1097,7 @@ int EntryImpl::InternalWriteData(int index, int offset, net::IOBuffer* buf,
return 0;
SyncCallback* io_callback = NULL;
- if (callback) {
+ if (!callback.is_null()) {
io_callback = new SyncCallback(this, buf, callback,
net::NetLog::TYPE_ENTRY_WRITE_DATA);
}
@@ -1115,7 +1119,7 @@ int EntryImpl::InternalWriteData(int index, int offset, net::IOBuffer* buf,
ReportIOTime(kWriteAsync1, start_async);
ReportIOTime(kWrite, start);
- return (completed || !callback) ? buf_len : net::ERR_IO_PENDING;
+ return (completed || callback.is_null()) ? buf_len : net::ERR_IO_PENDING;
}
// ------------------------------------------------------------------------
diff --git a/net/disk_cache/entry_impl.h b/net/disk_cache/entry_impl.h
index 62ec9d7..3083b23 100644
--- a/net/disk_cache/entry_impl.h
+++ b/net/disk_cache/entry_impl.h
@@ -40,16 +40,16 @@ class NET_EXPORT_PRIVATE EntryImpl
// Background implementation of the Entry interface.
void DoomImpl();
int ReadDataImpl(int index, int offset, net::IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
int WriteDataImpl(int index, int offset, net::IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback, bool truncate);
+ const net::CompletionCallback& callback, bool truncate);
int ReadSparseDataImpl(int64 offset, net::IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
int WriteSparseDataImpl(int64 offset, net::IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
int GetAvailableRangeImpl(int64 offset, int len, int64* start);
void CancelSparseIOImpl();
- int ReadyForSparseIOImpl(OldCompletionCallback* callback);
+ int ReadyForSparseIOImpl(const net::CompletionCallback& callback);
inline CacheEntryBlock* entry() {
return &entry_;
@@ -148,22 +148,23 @@ class NET_EXPORT_PRIVATE EntryImpl
virtual int32 GetDataSize(int index) const OVERRIDE;
virtual int ReadData(
int index, int offset, net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* completion_callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* completion_callback,
+ const net::CompletionCallback& callback,
bool truncate) OVERRIDE;
virtual int ReadSparseData(
int64 offset, net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* completion_callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int WriteSparseData(
int64 offset, net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* completion_callback) OVERRIDE;
- virtual int GetAvailableRange(int64 offset, int len, int64* start,
- OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
+ virtual int GetAvailableRange(
+ int64 offset, int len, int64* start,
+ const net::CompletionCallback& callback) OVERRIDE;
virtual bool CouldBeSparse() const OVERRIDE;
virtual void CancelSparseIO() OVERRIDE;
virtual int ReadyForSparseIO(
- net::OldCompletionCallback* completion_callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
private:
enum {
@@ -176,9 +177,9 @@ class NET_EXPORT_PRIVATE EntryImpl
// Do all the work for ReadDataImpl and WriteDataImpl. Implemented as
// separate functions to make logging of results simpler.
int InternalReadData(int index, int offset, net::IOBuffer* buf,
- int buf_len, OldCompletionCallback* callback);
+ int buf_len, const net::CompletionCallback& callback);
int InternalWriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback, bool truncate);
+ const net::CompletionCallback& callback, bool truncate);
// Initializes the storage for an internal or external data block.
bool CreateDataBlock(int index, int size);
diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc
index ef8ad89..cf9e6cd 100644
--- a/net/disk_cache/entry_unittest.cc
+++ b/net/disk_cache/entry_unittest.cc
@@ -3,10 +3,12 @@
// found in the LICENSE file.
#include "base/basictypes.h"
+#include "base/bind.h"
#include "base/file_util.h"
#include "base/threading/platform_thread.h"
#include "base/timer.h"
#include "base/string_util.h"
+#include "net/base/completion_callback.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
@@ -77,11 +79,14 @@ void DiskCacheEntryTest::InternalSyncIOBackground(disk_cache::Entry* entry) {
const int kSize1 = 10;
scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1));
CacheTestFillBuffer(buffer1->data(), kSize1, false);
- EXPECT_EQ(0, entry->ReadData(0, 0, buffer1, kSize1, NULL));
+ EXPECT_EQ(0, entry->ReadData(
+ 0, 0, buffer1, kSize1, net::CompletionCallback()));
base::strlcpy(buffer1->data(), "the data", kSize1);
- EXPECT_EQ(10, entry->WriteData(0, 0, buffer1, kSize1, NULL, false));
+ EXPECT_EQ(10, entry->WriteData(
+ 0, 0, buffer1, kSize1, net::CompletionCallback(), false));
memset(buffer1->data(), 0, kSize1);
- EXPECT_EQ(10, entry->ReadData(0, 0, buffer1, kSize1, NULL));
+ EXPECT_EQ(10, entry->ReadData(
+ 0, 0, buffer1, kSize1, net::CompletionCallback()));
EXPECT_STREQ("the data", buffer1->data());
const int kSize2 = 5000;
@@ -91,23 +96,33 @@ void DiskCacheEntryTest::InternalSyncIOBackground(disk_cache::Entry* entry) {
memset(buffer3->data(), 0, kSize3);
CacheTestFillBuffer(buffer2->data(), kSize2, false);
base::strlcpy(buffer2->data(), "The really big data goes here", kSize2);
- EXPECT_EQ(5000, entry->WriteData(1, 1500, buffer2, kSize2, NULL, false));
+ EXPECT_EQ(5000, entry->WriteData(
+ 1, 1500, buffer2, kSize2, net::CompletionCallback(), false));
memset(buffer2->data(), 0, kSize2);
- EXPECT_EQ(4989, entry->ReadData(1, 1511, buffer2, kSize2, NULL));
+ EXPECT_EQ(4989, entry->ReadData(
+ 1, 1511, buffer2, kSize2, net::CompletionCallback()));
EXPECT_STREQ("big data goes here", buffer2->data());
- EXPECT_EQ(5000, entry->ReadData(1, 0, buffer2, kSize2, NULL));
+ EXPECT_EQ(5000, entry->ReadData(
+ 1, 0, buffer2, kSize2, net::CompletionCallback()));
EXPECT_EQ(0, memcmp(buffer2->data(), buffer3->data(), 1500));
- EXPECT_EQ(1500, entry->ReadData(1, 5000, buffer2, kSize2, NULL));
-
- EXPECT_EQ(0, entry->ReadData(1, 6500, buffer2, kSize2, NULL));
- EXPECT_EQ(6500, entry->ReadData(1, 0, buffer3, kSize3, NULL));
- EXPECT_EQ(8192, entry->WriteData(1, 0, buffer3, 8192, NULL, false));
- EXPECT_EQ(8192, entry->ReadData(1, 0, buffer3, kSize3, NULL));
+ EXPECT_EQ(1500, entry->ReadData(
+ 1, 5000, buffer2, kSize2, net::CompletionCallback()));
+
+ EXPECT_EQ(0, entry->ReadData(
+ 1, 6500, buffer2, kSize2, net::CompletionCallback()));
+ EXPECT_EQ(6500, entry->ReadData(
+ 1, 0, buffer3, kSize3, net::CompletionCallback()));
+ EXPECT_EQ(8192, entry->WriteData(
+ 1, 0, buffer3, 8192, net::CompletionCallback(), false));
+ EXPECT_EQ(8192, entry->ReadData(
+ 1, 0, buffer3, kSize3, net::CompletionCallback()));
EXPECT_EQ(8192, entry->GetDataSize(1));
// We need to delete the memory buffer on this thread.
- EXPECT_EQ(0, entry->WriteData(0, 0, NULL, 0, NULL, true));
- EXPECT_EQ(0, entry->WriteData(1, 0, NULL, 0, NULL, true));
+ EXPECT_EQ(0, entry->WriteData(
+ 0, 0, NULL, 0, net::CompletionCallback(), true));
+ EXPECT_EQ(0, entry->WriteData(
+ 1, 0, NULL, 0, net::CompletionCallback(), true));
}
// We need to support synchronous IO even though it is not a supported operation
@@ -181,17 +196,23 @@ void DiskCacheEntryTest::InternalAsyncIO() {
CacheTestFillBuffer(buffer2->data(), kSize2, false);
CacheTestFillBuffer(buffer3->data(), kSize3, false);
- EXPECT_EQ(0, entry->ReadData(0, 15 * 1024, buffer1, kSize1, &callback1));
+ EXPECT_EQ(0, entry->ReadData(
+ 0, 15 * 1024, buffer1, kSize1,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback1)));
base::strlcpy(buffer1->data(), "the data", kSize1);
int expected = 0;
- int ret = entry->WriteData(0, 0, buffer1, kSize1, &callback2, false);
+ int ret = entry->WriteData(
+ 0, 0, buffer1, kSize1,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback2), false);
EXPECT_TRUE(10 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
memset(buffer2->data(), 0, kSize2);
- ret = entry->ReadData(0, 0, buffer2, kSize1, &callback3);
+ ret = entry->ReadData(
+ 0, 0, buffer2, kSize1,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback3));
EXPECT_TRUE(10 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
@@ -200,21 +221,27 @@ void DiskCacheEntryTest::InternalAsyncIO() {
EXPECT_STREQ("the data", buffer2->data());
base::strlcpy(buffer2->data(), "The really big data goes here", kSize2);
- ret = entry->WriteData(1, 1500, buffer2, kSize2, &callback4, true);
+ ret = entry->WriteData(
+ 1, 1500, buffer2, kSize2,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback4), true);
EXPECT_TRUE(5000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
memset(buffer3->data(), 0, kSize3);
- ret = entry->ReadData(1, 1511, buffer3, kSize2, &callback5);
+ ret = entry->ReadData(
+ 1, 1511, buffer3, kSize2,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback5));
EXPECT_TRUE(4989 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
EXPECT_STREQ("big data goes here", buffer3->data());
- ret = entry->ReadData(1, 0, buffer2, kSize2, &callback6);
+ ret = entry->ReadData(
+ 1, 0, buffer2, kSize2,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback6));
EXPECT_TRUE(5000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
@@ -223,35 +250,47 @@ void DiskCacheEntryTest::InternalAsyncIO() {
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
EXPECT_EQ(0, memcmp(buffer2->data(), buffer3->data(), 1500));
- ret = entry->ReadData(1, 5000, buffer2, kSize2, &callback7);
+ ret = entry->ReadData(
+ 1, 5000, buffer2, kSize2,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback7));
EXPECT_TRUE(1500 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
- ret = entry->ReadData(1, 0, buffer3, kSize3, &callback9);
+ ret = entry->ReadData(
+ 1, 0, buffer3, kSize3,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback9));
EXPECT_TRUE(6500 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
- ret = entry->WriteData(1, 0, buffer3, 8192, &callback10, true);
+ ret = entry->WriteData(
+ 1, 0, buffer3, 8192,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback10), true);
EXPECT_TRUE(8192 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
- ret = entry->ReadData(1, 0, buffer3, kSize3, &callback11);
+ ret = entry->ReadData(
+ 1, 0, buffer3, kSize3,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback11));
EXPECT_TRUE(8192 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
EXPECT_EQ(8192, entry->GetDataSize(1));
- ret = entry->ReadData(0, 0, buffer1, kSize1, &callback12);
+ ret = entry->ReadData(
+ 0, 0, buffer1, kSize1,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback12));
EXPECT_TRUE(10 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
- ret = entry->ReadData(1, 0, buffer2, kSize2, &callback13);
+ ret = entry->ReadData(
+ 1, 0, buffer2, kSize2,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback13));
EXPECT_TRUE(5000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
@@ -297,28 +336,39 @@ void DiskCacheEntryTest::ExternalSyncIOBackground(disk_cache::Entry* entry) {
CacheTestFillBuffer(buffer1->data(), kSize1, false);
CacheTestFillBuffer(buffer2->data(), kSize2, false);
base::strlcpy(buffer1->data(), "the data", kSize1);
- EXPECT_EQ(17000, entry->WriteData(0, 0, buffer1, kSize1, NULL, false));
+ EXPECT_EQ(17000, entry->WriteData(
+ 0, 0, buffer1, kSize1, net::CompletionCallback(), false));
memset(buffer1->data(), 0, kSize1);
- EXPECT_EQ(17000, entry->ReadData(0, 0, buffer1, kSize1, NULL));
+ EXPECT_EQ(17000, entry->ReadData(
+ 0, 0, buffer1, kSize1, net::CompletionCallback()));
EXPECT_STREQ("the data", buffer1->data());
base::strlcpy(buffer2->data(), "The really big data goes here", kSize2);
- EXPECT_EQ(25000, entry->WriteData(1, 10000, buffer2, kSize2, NULL, false));
+ EXPECT_EQ(25000, entry->WriteData(
+ 1, 10000, buffer2, kSize2, net::CompletionCallback(), false));
memset(buffer2->data(), 0, kSize2);
- EXPECT_EQ(24989, entry->ReadData(1, 10011, buffer2, kSize2, NULL));
+ EXPECT_EQ(24989, entry->ReadData(
+ 1, 10011, buffer2, kSize2, net::CompletionCallback()));
EXPECT_STREQ("big data goes here", buffer2->data());
- EXPECT_EQ(25000, entry->ReadData(1, 0, buffer2, kSize2, NULL));
+ EXPECT_EQ(25000, entry->ReadData(
+ 1, 0, buffer2, kSize2, net::CompletionCallback()));
EXPECT_EQ(0, memcmp(buffer2->data(), buffer2->data(), 10000));
- EXPECT_EQ(5000, entry->ReadData(1, 30000, buffer2, kSize2, NULL));
-
- EXPECT_EQ(0, entry->ReadData(1, 35000, buffer2, kSize2, NULL));
- EXPECT_EQ(17000, entry->ReadData(1, 0, buffer1, kSize1, NULL));
- EXPECT_EQ(17000, entry->WriteData(1, 20000, buffer1, kSize1, NULL, false));
+ EXPECT_EQ(5000, entry->ReadData(
+ 1, 30000, buffer2, kSize2, net::CompletionCallback()));
+
+ EXPECT_EQ(0, entry->ReadData(
+ 1, 35000, buffer2, kSize2, net::CompletionCallback()));
+ EXPECT_EQ(17000, entry->ReadData(
+ 1, 0, buffer1, kSize1, net::CompletionCallback()));
+ EXPECT_EQ(17000, entry->WriteData(
+ 1, 20000, buffer1, kSize1, net::CompletionCallback(), false));
EXPECT_EQ(37000, entry->GetDataSize(1));
// We need to delete the memory buffer on this thread.
- EXPECT_EQ(0, entry->WriteData(0, 0, NULL, 0, NULL, true));
- EXPECT_EQ(0, entry->WriteData(1, 0, NULL, 0, NULL, true));
+ EXPECT_EQ(0, entry->WriteData(
+ 0, 0, NULL, 0, net::CompletionCallback(), true));
+ EXPECT_EQ(0, entry->WriteData(
+ 1, 0, NULL, 0, net::CompletionCallback(), true));
}
void DiskCacheEntryTest::ExternalSyncIO() {
@@ -381,7 +431,9 @@ void DiskCacheEntryTest::ExternalAsyncIO() {
CacheTestFillBuffer(buffer2->data(), kSize2, false);
CacheTestFillBuffer(buffer3->data(), kSize3, false);
base::strlcpy(buffer1->data(), "the data", kSize1);
- int ret = entry->WriteData(0, 0, buffer1, kSize1, &callback1, false);
+ int ret = entry->WriteData(
+ 0, 0, buffer1, kSize1,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback1), false);
EXPECT_TRUE(17000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
@@ -389,7 +441,9 @@ void DiskCacheEntryTest::ExternalAsyncIO() {
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
memset(buffer2->data(), 0, kSize1);
- ret = entry->ReadData(0, 0, buffer2, kSize1, &callback2);
+ ret = entry->ReadData(
+ 0, 0, buffer2, kSize1,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback2));
EXPECT_TRUE(17000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
@@ -398,7 +452,9 @@ void DiskCacheEntryTest::ExternalAsyncIO() {
EXPECT_STREQ("the data", buffer1->data());
base::strlcpy(buffer2->data(), "The really big data goes here", kSize2);
- ret = entry->WriteData(1, 10000, buffer2, kSize2, &callback3, false);
+ ret = entry->WriteData(
+ 1, 10000, buffer2, kSize2,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback3), false);
EXPECT_TRUE(25000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
@@ -406,31 +462,43 @@ void DiskCacheEntryTest::ExternalAsyncIO() {
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
memset(buffer3->data(), 0, kSize3);
- ret = entry->ReadData(1, 10011, buffer3, kSize3, &callback4);
+ ret = entry->ReadData(
+ 1, 10011, buffer3, kSize3,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback4));
EXPECT_TRUE(24989 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
EXPECT_STREQ("big data goes here", buffer3->data());
- ret = entry->ReadData(1, 0, buffer2, kSize2, &callback5);
+ ret = entry->ReadData(
+ 1, 0, buffer2, kSize2,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback5));
EXPECT_TRUE(25000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
EXPECT_EQ(0, memcmp(buffer2->data(), buffer2->data(), 10000));
- ret = entry->ReadData(1, 30000, buffer2, kSize2, &callback6);
+ ret = entry->ReadData(
+ 1, 30000, buffer2, kSize2,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback6));
EXPECT_TRUE(5000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
- EXPECT_EQ(0, entry->ReadData(1, 35000, buffer2, kSize2, &callback7));
- ret = entry->ReadData(1, 0, buffer1, kSize1, &callback8);
+ EXPECT_EQ(0, entry->ReadData(
+ 1, 35000, buffer2, kSize2,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback7)));
+ ret = entry->ReadData(
+ 1, 0, buffer1, kSize1,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback8));
EXPECT_TRUE(17000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
- ret = entry->WriteData(1, 20000, buffer1, kSize1, &callback9, false);
+ ret = entry->WriteData(
+ 1, 20000, buffer1, kSize1,
+ base::Bind(&net::OldCompletionCallbackAdapter, &callback9), false);
EXPECT_TRUE(17000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
expected++;
@@ -1150,9 +1218,9 @@ TEST_F(DiskCacheEntryTest, ReadWriteDestroyBuffer) {
scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
CacheTestFillBuffer(buffer->data(), kSize, false);
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
EXPECT_EQ(net::ERR_IO_PENDING,
- entry->WriteData(0, 0, buffer, kSize, &cb, false));
+ entry->WriteData(0, 0, buffer, kSize, cb.callback(), false));
// Release our reference to the buffer.
buffer = NULL;
@@ -1162,7 +1230,8 @@ TEST_F(DiskCacheEntryTest, ReadWriteDestroyBuffer) {
buffer = new net::IOBuffer(kSize);
CacheTestFillBuffer(buffer->data(), kSize, false);
- EXPECT_EQ(net::ERR_IO_PENDING, entry->ReadData(0, 0, buffer, kSize, &cb));
+ EXPECT_EQ(net::ERR_IO_PENDING,
+ entry->ReadData(0, 0, buffer, kSize, cb.callback()));
buffer = NULL;
EXPECT_EQ(kSize, cb.WaitForResult());
@@ -1290,10 +1359,12 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyEnumerationWithSparseEntries) {
ASSERT_EQ(net::OK, CreateEntry(key, &parent_entry));
// Writes to the parent entry.
- EXPECT_EQ(kSize, parent_entry->WriteSparseData(0, buf, kSize, NULL));
+ EXPECT_EQ(kSize, parent_entry->WriteSparseData(0, buf, kSize,
+ net::CompletionCallback()));
// This write creates a child entry and writes to it.
- EXPECT_EQ(kSize, parent_entry->WriteSparseData(8192, buf, kSize, NULL));
+ EXPECT_EQ(kSize, parent_entry->WriteSparseData(8192, buf, kSize,
+ net::CompletionCallback()));
parent_entry->Close();
@@ -1315,16 +1386,16 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyEnumerationWithSparseEntries) {
// Writes |buf_1| to offset and reads it back as |buf_2|.
void VerifySparseIO(disk_cache::Entry* entry, int64 offset,
net::IOBuffer* buf_1, int size, net::IOBuffer* buf_2) {
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
memset(buf_2->data(), 0, size);
- int ret = entry->ReadSparseData(offset, buf_2, size, &cb);
+ int ret = entry->ReadSparseData(offset, buf_2, size, cb.callback());
EXPECT_EQ(0, cb.GetResult(ret));
- ret = entry->WriteSparseData(offset, buf_1, size, &cb);
+ ret = entry->WriteSparseData(offset, buf_1, size, cb.callback());
EXPECT_EQ(size, cb.GetResult(ret));
- ret = entry->ReadSparseData(offset, buf_2, size, &cb);
+ ret = entry->ReadSparseData(offset, buf_2, size, cb.callback());
EXPECT_EQ(size, cb.GetResult(ret));
EXPECT_EQ(0, memcmp(buf_1->data(), buf_2->data(), size));
@@ -1334,13 +1405,12 @@ void VerifySparseIO(disk_cache::Entry* entry, int64 offset,
// same as the content of the provided |buffer|.
void VerifyContentSparseIO(disk_cache::Entry* entry, int64 offset, char* buffer,
int size) {
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
scoped_refptr<net::IOBuffer> buf_1(new net::IOBuffer(size));
memset(buf_1->data(), 0, size);
- int ret = entry->ReadSparseData(offset, buf_1, size, &cb);
+ int ret = entry->ReadSparseData(offset, buf_1, size, cb.callback());
EXPECT_EQ(size, cb.GetResult(ret));
-
EXPECT_EQ(0, memcmp(buf_1->data(), buffer, size));
}
@@ -1431,36 +1501,39 @@ void DiskCacheEntryTest::GetAvailableRange() {
// We stop at the first empty block.
int64 start;
- TestOldCompletionCallback cb;
- int rv = entry->GetAvailableRange(0x20F0000, kSize * 2, &start, &cb);
+ net::TestCompletionCallback cb;
+ int rv = entry->GetAvailableRange(
+ 0x20F0000, kSize * 2, &start, cb.callback());
EXPECT_EQ(kSize, cb.GetResult(rv));
EXPECT_EQ(0x20F0000, start);
start = 0;
- rv = entry->GetAvailableRange(0, kSize, &start, &cb);
+ rv = entry->GetAvailableRange(0, kSize, &start, cb.callback());
EXPECT_EQ(0, cb.GetResult(rv));
- rv = entry->GetAvailableRange(0x20F0000 - kSize, kSize, &start, &cb);
+ rv = entry->GetAvailableRange(
+ 0x20F0000 - kSize, kSize, &start, cb.callback());
EXPECT_EQ(0, cb.GetResult(rv));
- rv = entry->GetAvailableRange(0, 0x2100000, &start, &cb);
+ rv = entry->GetAvailableRange(0, 0x2100000, &start, cb.callback());
EXPECT_EQ(kSize, cb.GetResult(rv));
EXPECT_EQ(0x20F0000, start);
// We should be able to Read based on the results of GetAvailableRange.
start = -1;
- rv = entry->GetAvailableRange(0x2100000, kSize, &start, &cb);
+ rv = entry->GetAvailableRange(0x2100000, kSize, &start, cb.callback());
EXPECT_EQ(0, cb.GetResult(rv));
- rv = entry->ReadSparseData(start, buf, kSize, &cb);
+ rv = entry->ReadSparseData(start, buf, kSize, cb.callback());
EXPECT_EQ(0, cb.GetResult(rv));
start = 0;
- rv = entry->GetAvailableRange(0x20F2000, kSize, &start, &cb);
+ rv = entry->GetAvailableRange(0x20F2000, kSize, &start, cb.callback());
EXPECT_EQ(0x2000, cb.GetResult(rv));
EXPECT_EQ(0x20F2000, start);
EXPECT_EQ(0x2000, ReadSparseData(entry, start, buf, kSize));
// Make sure that we respect the |len| argument.
start = 0;
- rv = entry->GetAvailableRange(0x20F0001 - kSize, kSize, &start, &cb);
+ rv = entry->GetAvailableRange(
+ 0x20F0001 - kSize, kSize, &start, cb.callback());
EXPECT_EQ(1, cb.GetResult(rv));
EXPECT_EQ(0x20F0000, start);
@@ -1569,45 +1642,49 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyMisalignedGetAvailableRange) {
ASSERT_EQ(net::OK, CreateEntry(key, &entry));
// Writes in the middle of an entry.
- EXPECT_EQ(1024, entry->WriteSparseData(0, buf, 1024, NULL));
- EXPECT_EQ(1024, entry->WriteSparseData(5120, buf, 1024, NULL));
- EXPECT_EQ(1024, entry->WriteSparseData(10000, buf, 1024, NULL));
+ EXPECT_EQ(1024, entry->WriteSparseData(
+ 0, buf, 1024, net::CompletionCallback()));
+ EXPECT_EQ(1024, entry->WriteSparseData(
+ 5120, buf, 1024, net::CompletionCallback()));
+ EXPECT_EQ(1024, entry->WriteSparseData(
+ 10000, buf, 1024, net::CompletionCallback()));
// Writes in the middle of an entry and spans 2 child entries.
- EXPECT_EQ(8192, entry->WriteSparseData(50000, buf, 8192, NULL));
+ EXPECT_EQ(8192, entry->WriteSparseData(
+ 50000, buf, 8192, net::CompletionCallback()));
int64 start;
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
// Test that we stop at a discontinuous child at the second block.
- int rv = entry->GetAvailableRange(0, 10000, &start, &cb);
+ int rv = entry->GetAvailableRange(0, 10000, &start, cb.callback());
EXPECT_EQ(1024, cb.GetResult(rv));
EXPECT_EQ(0, start);
// Test that number of bytes is reported correctly when we start from the
// middle of a filled region.
- rv = entry->GetAvailableRange(512, 10000, &start, &cb);
+ rv = entry->GetAvailableRange(512, 10000, &start, cb.callback());
EXPECT_EQ(512, cb.GetResult(rv));
EXPECT_EQ(512, start);
// Test that we found bytes in the child of next block.
- rv = entry->GetAvailableRange(1024, 10000, &start, &cb);
+ rv = entry->GetAvailableRange(1024, 10000, &start, cb.callback());
EXPECT_EQ(1024, cb.GetResult(rv));
EXPECT_EQ(5120, start);
// Test that the desired length is respected. It starts within a filled
// region.
- rv = entry->GetAvailableRange(5500, 512, &start, &cb);
+ rv = entry->GetAvailableRange(5500, 512, &start, cb.callback());
EXPECT_EQ(512, cb.GetResult(rv));
EXPECT_EQ(5500, start);
// Test that the desired length is respected. It starts before a filled
// region.
- rv = entry->GetAvailableRange(5000, 620, &start, &cb);
+ rv = entry->GetAvailableRange(5000, 620, &start, cb.callback());
EXPECT_EQ(500, cb.GetResult(rv));
EXPECT_EQ(5120, start);
// Test that multiple blocks are scanned.
- rv = entry->GetAvailableRange(40000, 20000, &start, &cb);
+ rv = entry->GetAvailableRange(40000, 20000, &start, cb.callback());
EXPECT_EQ(8192, cb.GetResult(rv));
EXPECT_EQ(50000, start);
@@ -1672,10 +1749,14 @@ void DiskCacheEntryTest::DoomSparseEntry() {
int64 offset = 1024;
// Write to a bunch of ranges.
for (int i = 0; i < 12; i++) {
- EXPECT_EQ(kSize, entry1->WriteSparseData(offset, buf, kSize, NULL));
+ EXPECT_EQ(kSize, entry1->WriteSparseData(offset, buf, kSize,
+ net::CompletionCallback()));
// Keep the second map under the default size.
- if (i < 9)
- EXPECT_EQ(kSize, entry2->WriteSparseData(offset, buf, kSize, NULL));
+ if (i < 9) {
+ EXPECT_EQ(kSize, entry2->WriteSparseData(offset, buf, kSize,
+ net::CompletionCallback()));
+ }
+
offset *= 4;
}
@@ -1768,7 +1849,8 @@ TEST_F(DiskCacheEntryTest, DoomSparseEntry2) {
int64 offset = 1024;
// Write to a bunch of ranges.
for (int i = 0; i < 12; i++) {
- EXPECT_EQ(kSize, entry->WriteSparseData(offset, buf, kSize, NULL));
+ EXPECT_EQ(kSize, entry->WriteSparseData(offset, buf, kSize,
+ net::CompletionCallback()));
offset *= 4;
}
EXPECT_EQ(9, cache_->GetEntryCount());
@@ -1819,20 +1901,20 @@ void DiskCacheEntryTest::PartialSparseEntry() {
int rv;
int64 start;
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
if (memory_only_) {
- rv = entry->GetAvailableRange(0, 600, &start, &cb);
+ rv = entry->GetAvailableRange(0, 600, &start, cb.callback());
EXPECT_EQ(100, cb.GetResult(rv));
EXPECT_EQ(500, start);
} else {
- rv = entry->GetAvailableRange(0, 2048, &start, &cb);
+ rv = entry->GetAvailableRange(0, 2048, &start, cb.callback());
EXPECT_EQ(1024, cb.GetResult(rv));
EXPECT_EQ(1024, start);
}
- rv = entry->GetAvailableRange(kSize, kSize, &start, &cb);
+ rv = entry->GetAvailableRange(kSize, kSize, &start, cb.callback());
EXPECT_EQ(500, cb.GetResult(rv));
EXPECT_EQ(kSize, start);
- rv = entry->GetAvailableRange(20 * 1024, 10000, &start, &cb);
+ rv = entry->GetAvailableRange(20 * 1024, 10000, &start, cb.callback());
EXPECT_EQ(3616, cb.GetResult(rv));
EXPECT_EQ(20 * 1024, start);
@@ -1840,24 +1922,24 @@ void DiskCacheEntryTest::PartialSparseEntry() {
// 2. Query within a filled 1KB block.
// 3. Query beyond a filled 1KB block.
if (memory_only_) {
- rv = entry->GetAvailableRange(19400, kSize, &start, &cb);
+ rv = entry->GetAvailableRange(19400, kSize, &start, cb.callback());
EXPECT_EQ(3496, cb.GetResult(rv));
EXPECT_EQ(20000, start);
} else {
- rv = entry->GetAvailableRange(19400, kSize, &start, &cb);
+ rv = entry->GetAvailableRange(19400, kSize, &start, cb.callback());
EXPECT_EQ(3016, cb.GetResult(rv));
EXPECT_EQ(20480, start);
}
- rv = entry->GetAvailableRange(3073, kSize, &start, &cb);
+ rv = entry->GetAvailableRange(3073, kSize, &start, cb.callback());
EXPECT_EQ(1523, cb.GetResult(rv));
EXPECT_EQ(3073, start);
- rv = entry->GetAvailableRange(4600, kSize, &start, &cb);
+ rv = entry->GetAvailableRange(4600, kSize, &start, cb.callback());
EXPECT_EQ(0, cb.GetResult(rv));
EXPECT_EQ(4600, start);
// Now make another write and verify that there is no hole in between.
EXPECT_EQ(kSize, WriteSparseData(entry, 500 + kSize, buf1, kSize));
- rv = entry->GetAvailableRange(1024, 10000, &start, &cb);
+ rv = entry->GetAvailableRange(1024, 10000, &start, cb.callback());
EXPECT_EQ(7 * 1024 + 500, cb.GetResult(rv));
EXPECT_EQ(1024, start);
EXPECT_EQ(kSize, ReadSparseData(entry, kSize, buf2, kSize));
@@ -1941,12 +2023,13 @@ TEST_F(DiskCacheEntryTest, CancelSparseIO) {
CacheTestFillBuffer(buf->data(), kSize, false);
// This will open and write two "real" entries.
- TestOldCompletionCallback cb1, cb2, cb3, cb4, cb5;
- int rv = entry->WriteSparseData(1024 * 1024 - 4096, buf, kSize, &cb1);
+ net::TestCompletionCallback cb1, cb2, cb3, cb4, cb5;
+ int rv = entry->WriteSparseData(
+ 1024 * 1024 - 4096, buf, kSize, cb1.callback());
EXPECT_EQ(net::ERR_IO_PENDING, rv);
int64 offset = 0;
- rv = entry->GetAvailableRange(offset, kSize, &offset, &cb5);
+ rv = entry->GetAvailableRange(offset, kSize, &offset, cb5.callback());
rv = cb5.GetResult(rv);
if (!cb1.have_result()) {
// We may or may not have finished writing to the entry. If we have not,
@@ -1956,16 +2039,18 @@ TEST_F(DiskCacheEntryTest, CancelSparseIO) {
// We cancel the pending operation, and register multiple notifications.
entry->CancelSparseIO();
- EXPECT_EQ(net::ERR_IO_PENDING, entry->ReadyForSparseIO(&cb2));
- EXPECT_EQ(net::ERR_IO_PENDING, entry->ReadyForSparseIO(&cb3));
+ EXPECT_EQ(net::ERR_IO_PENDING, entry->ReadyForSparseIO(cb2.callback()));
+ EXPECT_EQ(net::ERR_IO_PENDING, entry->ReadyForSparseIO(cb3.callback()));
entry->CancelSparseIO(); // Should be a no op at this point.
- EXPECT_EQ(net::ERR_IO_PENDING, entry->ReadyForSparseIO(&cb4));
+ EXPECT_EQ(net::ERR_IO_PENDING, entry->ReadyForSparseIO(cb4.callback()));
if (!cb1.have_result()) {
EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED,
- entry->ReadSparseData(offset, buf, kSize, NULL));
+ entry->ReadSparseData(offset, buf, kSize,
+ net::CompletionCallback()));
EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED,
- entry->WriteSparseData(offset, buf, kSize, NULL));
+ entry->WriteSparseData(offset, buf, kSize,
+ net::CompletionCallback()));
}
// Now see if we receive all notifications. Note that we should not be able
@@ -1976,7 +2061,7 @@ TEST_F(DiskCacheEntryTest, CancelSparseIO) {
EXPECT_EQ(net::OK, cb3.WaitForResult());
EXPECT_EQ(net::OK, cb4.WaitForResult());
- rv = entry->GetAvailableRange(offset, kSize, &offset, &cb5);
+ rv = entry->GetAvailableRange(offset, kSize, &offset, cb5.callback());
EXPECT_EQ(0, cb5.GetResult(rv));
entry->Close();
}
diff --git a/net/disk_cache/in_flight_backend_io.cc b/net/disk_cache/in_flight_backend_io.cc
index 30a5500..8a0e930 100644
--- a/net/disk_cache/in_flight_backend_io.cc
+++ b/net/disk_cache/in_flight_backend_io.cc
@@ -5,6 +5,7 @@
#include "net/disk_cache/in_flight_backend_io.h"
#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "net/base/net_errors.h"
@@ -15,25 +16,11 @@
namespace disk_cache {
BackendIO::BackendIO(InFlightIO* controller, BackendImpl* backend,
- net::OldCompletionCallback* callback)
- : BackgroundIO(controller),
- backend_(backend),
- old_callback_(callback),
- operation_(OP_NONE),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- my_callback_(this, &BackendIO::OnIOComplete)) {
- start_time_ = base::TimeTicks::Now();
-}
-
-BackendIO::BackendIO(InFlightIO* controller, BackendImpl* backend,
const net::CompletionCallback& callback)
: BackgroundIO(controller),
backend_(backend),
- old_callback_(NULL),
callback_(callback),
- operation_(OP_NONE),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- my_callback_(this, &BackendIO::OnIOComplete)) {
+ operation_(OP_NONE) {
start_time_ = base::TimeTicks::Now();
}
@@ -270,20 +257,25 @@ void BackendIO::ExecuteBackendOperation() {
void BackendIO::ExecuteEntryOperation() {
switch (operation_) {
case OP_READ:
- result_ = entry_->ReadDataImpl(index_, offset_, buf_, buf_len_,
- &my_callback_);
+ result_ = entry_->ReadDataImpl(
+ index_, offset_, buf_, buf_len_,
+ base::Bind(&BackendIO::OnIOComplete, base::Unretained(this)));
break;
case OP_WRITE:
- result_ = entry_->WriteDataImpl(index_, offset_, buf_, buf_len_,
- &my_callback_, truncate_);
+ result_ = entry_->WriteDataImpl(
+ index_, offset_, buf_, buf_len_,
+ base::Bind(&BackendIO::OnIOComplete, base::Unretained(this)),
+ truncate_);
break;
case OP_READ_SPARSE:
- result_ = entry_->ReadSparseDataImpl(offset64_, buf_, buf_len_,
- &my_callback_);
+ result_ = entry_->ReadSparseDataImpl(
+ offset64_, buf_, buf_len_,
+ base::Bind(&BackendIO::OnIOComplete, base::Unretained(this)));
break;
case OP_WRITE_SPARSE:
- result_ = entry_->WriteSparseDataImpl(offset64_, buf_, buf_len_,
- &my_callback_);
+ result_ = entry_->WriteSparseDataImpl(
+ offset64_, buf_, buf_len_,
+ base::Bind(&BackendIO::OnIOComplete, base::Unretained(this)));
break;
case OP_GET_RANGE:
result_ = entry_->GetAvailableRangeImpl(offset64_, buf_len_, start_);
@@ -293,7 +285,8 @@ void BackendIO::ExecuteEntryOperation() {
result_ = net::OK;
break;
case OP_IS_READY:
- result_ = entry_->ReadyForSparseIOImpl(&my_callback_);
+ result_ = entry_->ReadyForSparseIOImpl(
+ base::Bind(&BackendIO::OnIOComplete, base::Unretained(this)));
break;
default:
NOTREACHED() << "Invalid Operation";
@@ -303,8 +296,6 @@ void BackendIO::ExecuteEntryOperation() {
controller_->OnIOComplete(this);
}
-// ---------------------------------------------------------------------------
-
InFlightBackendIO::InFlightBackendIO(BackendImpl* backend,
base::MessageLoopProxy* background_thread)
: backend_(backend),
@@ -321,14 +312,14 @@ void InFlightBackendIO::Init(const net::CompletionCallback& callback) {
}
void InFlightBackendIO::OpenEntry(const std::string& key, Entry** entry,
- OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
operation->OpenEntry(key, entry);
PostOperation(operation);
}
void InFlightBackendIO::CreateEntry(const std::string& key, Entry** entry,
- OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
operation->CreateEntry(key, entry);
PostOperation(operation);
@@ -356,8 +347,8 @@ void InFlightBackendIO::DoomEntriesBetween(const base::Time initial_time,
PostOperation(operation);
}
-void InFlightBackendIO::DoomEntriesSince(const base::Time initial_time,
- OldCompletionCallback* callback) {
+void InFlightBackendIO::DoomEntriesSince(
+ const base::Time initial_time, const net::CompletionCallback& callback) {
scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
operation->DoomEntriesSince(initial_time);
PostOperation(operation);
@@ -371,43 +362,48 @@ void InFlightBackendIO::OpenNextEntry(void** iter, Entry** next_entry,
}
void InFlightBackendIO::OpenPrevEntry(void** iter, Entry** prev_entry,
- OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
operation->OpenPrevEntry(iter, prev_entry);
PostOperation(operation);
}
void InFlightBackendIO::EndEnumeration(void* iterator) {
- scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, NULL));
+ scoped_refptr<BackendIO> operation(
+ new BackendIO(this, backend_, net::CompletionCallback()));
operation->EndEnumeration(iterator);
PostOperation(operation);
}
void InFlightBackendIO::OnExternalCacheHit(const std::string& key) {
- scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, NULL));
+ scoped_refptr<BackendIO> operation(
+ new BackendIO(this, backend_, net::CompletionCallback()));
operation->OnExternalCacheHit(key);
PostOperation(operation);
}
void InFlightBackendIO::CloseEntryImpl(EntryImpl* entry) {
- scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, NULL));
+ scoped_refptr<BackendIO> operation(
+ new BackendIO(this, backend_, net::CompletionCallback()));
operation->CloseEntryImpl(entry);
PostOperation(operation);
}
void InFlightBackendIO::DoomEntryImpl(EntryImpl* entry) {
- scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, NULL));
+ scoped_refptr<BackendIO> operation(
+ new BackendIO(this, backend_, net::CompletionCallback()));
operation->DoomEntryImpl(entry);
PostOperation(operation);
}
-void InFlightBackendIO::FlushQueue(net::OldCompletionCallback* callback) {
+void InFlightBackendIO::FlushQueue(const net::CompletionCallback& callback) {
scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
operation->FlushQueue();
PostOperation(operation);
}
-void InFlightBackendIO::RunTask(Task* task, net::OldCompletionCallback* callback) {
+void InFlightBackendIO::RunTask(
+ Task* task, const net::CompletionCallback& callback) {
scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
operation->RunTask(task);
PostOperation(operation);
@@ -415,7 +411,7 @@ void InFlightBackendIO::RunTask(Task* task, net::OldCompletionCallback* callback
void InFlightBackendIO::ReadData(EntryImpl* entry, int index, int offset,
net::IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
operation->ReadData(entry, index, offset, buf, buf_len);
PostOperation(operation);
@@ -424,44 +420,45 @@ void InFlightBackendIO::ReadData(EntryImpl* entry, int index, int offset,
void InFlightBackendIO::WriteData(EntryImpl* entry, int index, int offset,
net::IOBuffer* buf, int buf_len,
bool truncate,
- OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
operation->WriteData(entry, index, offset, buf, buf_len, truncate);
PostOperation(operation);
}
-void InFlightBackendIO::ReadSparseData(EntryImpl* entry, int64 offset,
- net::IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback) {
+void InFlightBackendIO::ReadSparseData(
+ EntryImpl* entry, int64 offset, net::IOBuffer* buf, int buf_len,
+ const net::CompletionCallback& callback) {
scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
operation->ReadSparseData(entry, offset, buf, buf_len);
PostOperation(operation);
}
-void InFlightBackendIO::WriteSparseData(EntryImpl* entry, int64 offset,
- net::IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback) {
+void InFlightBackendIO::WriteSparseData(
+ EntryImpl* entry, int64 offset, net::IOBuffer* buf, int buf_len,
+ const net::CompletionCallback& callback) {
scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
operation->WriteSparseData(entry, offset, buf, buf_len);
PostOperation(operation);
}
-void InFlightBackendIO::GetAvailableRange(EntryImpl* entry, int64 offset,
- int len, int64* start,
- OldCompletionCallback* callback) {
+void InFlightBackendIO::GetAvailableRange(
+ EntryImpl* entry, int64 offset, int len, int64* start,
+ const net::CompletionCallback& callback) {
scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
operation->GetAvailableRange(entry, offset, len, start);
PostOperation(operation);
}
void InFlightBackendIO::CancelSparseIO(EntryImpl* entry) {
- scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, NULL));
+ scoped_refptr<BackendIO> operation(
+ new BackendIO(this, backend_, net::CompletionCallback()));
operation->CancelSparseIO(entry);
PostOperation(operation);
}
-void InFlightBackendIO::ReadyForSparseIO(EntryImpl* entry,
- OldCompletionCallback* callback) {
+void InFlightBackendIO::ReadyForSparseIO(
+ EntryImpl* entry, const net::CompletionCallback& callback) {
scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
operation->ReadyForSparseIO(entry);
PostOperation(operation);
@@ -479,9 +476,7 @@ void InFlightBackendIO::OnOperationComplete(BackgroundIO* operation,
CACHE_UMA(TIMES, "TotalIOTime", 0, op->ElapsedTime());
}
- if (op->old_callback() && (!cancel || op->IsEntryOperation()))
- op->old_callback()->Run(op->result());
- else if (!op->callback().is_null() && (!cancel || op->IsEntryOperation()))
+ if (!op->callback().is_null() && (!cancel || op->IsEntryOperation()))
op->callback().Run(op->result());
}
diff --git a/net/disk_cache/in_flight_backend_io.h b/net/disk_cache/in_flight_backend_io.h
index c3a52d5..a23c955 100644
--- a/net/disk_cache/in_flight_backend_io.h
+++ b/net/disk_cache/in_flight_backend_io.h
@@ -26,8 +26,6 @@ class EntryImpl;
class BackendIO : public BackgroundIO {
public:
BackendIO(InFlightIO* controller, BackendImpl* backend,
- net::OldCompletionCallback* callback);
- BackendIO(InFlightIO* controller, BackendImpl* backend,
const net::CompletionCallback& callback);
// Runs the actual operation on the background thread.
@@ -39,7 +37,6 @@ class BackendIO : public BackgroundIO {
// Returns true if this operation is directed to an entry (vs. the backend).
bool IsEntryOperation();
- net::OldCompletionCallback* old_callback() const { return old_callback_; }
net::CompletionCallback callback() const { return callback_; }
// Grabs an extra reference of entry_.
@@ -116,10 +113,8 @@ class BackendIO : public BackgroundIO {
void ExecuteEntryOperation();
BackendImpl* backend_;
- net::OldCompletionCallback* old_callback_;
net::CompletionCallback callback_;
Operation operation_;
- net::OldCompletionCallbackImpl<BackendIO> my_callback_;
// The arguments of all the operations we proxy:
std::string key_;
@@ -152,9 +147,9 @@ class InFlightBackendIO : public InFlightIO {
// Proxied operations.
void Init(const net::CompletionCallback& callback);
void OpenEntry(const std::string& key, Entry** entry,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
void CreateEntry(const std::string& key, Entry** entry,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
void DoomEntry(const std::string& key,
const net::CompletionCallback& callback);
void DoomAllEntries(const net::CompletionCallback& callback);
@@ -162,29 +157,31 @@ class InFlightBackendIO : public InFlightIO {
const base::Time end_time,
const net::CompletionCallback& callback);
void DoomEntriesSince(const base::Time initial_time,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
void OpenNextEntry(void** iter, Entry** next_entry,
const net::CompletionCallback& callback);
void OpenPrevEntry(void** iter, Entry** prev_entry,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
void EndEnumeration(void* iterator);
void OnExternalCacheHit(const std::string& key);
void CloseEntryImpl(EntryImpl* entry);
void DoomEntryImpl(EntryImpl* entry);
- void FlushQueue(net::OldCompletionCallback* callback);
- void RunTask(Task* task, net::OldCompletionCallback* callback);
+ void FlushQueue(const net::CompletionCallback& callback);
+ void RunTask(Task* task, const net::CompletionCallback& callback);
void ReadData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf,
- int buf_len, net::OldCompletionCallback* callback);
- void WriteData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf,
- int buf_len, bool truncate, net::OldCompletionCallback* callback);
+ int buf_len, const net::CompletionCallback& callback);
+ void WriteData(
+ EntryImpl* entry, int index, int offset, net::IOBuffer* buf,
+ int buf_len, bool truncate, const net::CompletionCallback& callback);
void ReadSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf,
- int buf_len, net::OldCompletionCallback* callback);
+ int buf_len, const net::CompletionCallback& callback);
void WriteSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf,
- int buf_len, net::OldCompletionCallback* callback);
+ int buf_len, const net::CompletionCallback& callback);
void GetAvailableRange(EntryImpl* entry, int64 offset, int len, int64* start,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
void CancelSparseIO(EntryImpl* entry);
- void ReadyForSparseIO(EntryImpl* entry, net::OldCompletionCallback* callback);
+ void ReadyForSparseIO(EntryImpl* entry,
+ const net::CompletionCallback& callback);
// Blocks until all operations are cancelled or completed.
void WaitForPendingIO();
diff --git a/net/disk_cache/mem_backend_impl.cc b/net/disk_cache/mem_backend_impl.cc
index 89b5825..37c3b2f 100644
--- a/net/disk_cache/mem_backend_impl.cc
+++ b/net/disk_cache/mem_backend_impl.cc
@@ -129,7 +129,7 @@ int32 MemBackendImpl::GetEntryCount() const {
}
int MemBackendImpl::OpenEntry(const std::string& key, Entry** entry,
- OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
if (OpenEntry(key, entry))
return net::OK;
@@ -137,7 +137,7 @@ int MemBackendImpl::OpenEntry(const std::string& key, Entry** entry,
}
int MemBackendImpl::CreateEntry(const std::string& key, Entry** entry,
- OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
if (CreateEntry(key, entry))
return net::OK;
@@ -169,7 +169,7 @@ int MemBackendImpl::DoomEntriesBetween(
}
int MemBackendImpl::DoomEntriesSince(const base::Time initial_time,
- OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
if (DoomEntriesSince(initial_time))
return net::OK;
diff --git a/net/disk_cache/mem_backend_impl.h b/net/disk_cache/mem_backend_impl.h
index 1b799f4..94308e9 100644
--- a/net/disk_cache/mem_backend_impl.h
+++ b/net/disk_cache/mem_backend_impl.h
@@ -65,9 +65,9 @@ class NET_EXPORT_PRIVATE MemBackendImpl : public Backend {
// Backend interface.
virtual int32 GetEntryCount() const OVERRIDE;
virtual int OpenEntry(const std::string& key, Entry** entry,
- OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int CreateEntry(const std::string& key, Entry** entry,
- OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int DoomEntry(const std::string& key,
const net::CompletionCallback& callback) OVERRIDE;
virtual int DoomAllEntries(const net::CompletionCallback& callback) OVERRIDE;
@@ -75,8 +75,9 @@ class NET_EXPORT_PRIVATE MemBackendImpl : public Backend {
const base::Time initial_time,
const base::Time end_time,
const net::CompletionCallback& callback) OVERRIDE;
- virtual int DoomEntriesSince(const base::Time initial_time,
- OldCompletionCallback* callback) OVERRIDE;
+ virtual int DoomEntriesSince(
+ const base::Time initial_time,
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int OpenNextEntry(void** iter, Entry** next_entry,
const net::CompletionCallback& callback) OVERRIDE;
virtual void EndEnumeration(void** iter) OVERRIDE;
diff --git a/net/disk_cache/mem_entry_impl.cc b/net/disk_cache/mem_entry_impl.cc
index 677cd6a..de6329b 100644
--- a/net/disk_cache/mem_entry_impl.cc
+++ b/net/disk_cache/mem_entry_impl.cc
@@ -167,7 +167,7 @@ int32 MemEntryImpl::GetDataSize(int index) const {
}
int MemEntryImpl::ReadData(int index, int offset, net::IOBuffer* buf,
- int buf_len, net::OldCompletionCallback* completion_callback) {
+ int buf_len, const net::CompletionCallback& callback) {
if (net_log_.IsLoggingAllEvents()) {
net_log_.BeginEvent(
net::NetLog::TYPE_ENTRY_READ_DATA,
@@ -186,7 +186,7 @@ int MemEntryImpl::ReadData(int index, int offset, net::IOBuffer* buf,
}
int MemEntryImpl::WriteData(int index, int offset, net::IOBuffer* buf,
- int buf_len, net::OldCompletionCallback* completion_callback, bool truncate) {
+ int buf_len, const net::CompletionCallback& callback, bool truncate) {
if (net_log_.IsLoggingAllEvents()) {
net_log_.BeginEvent(
net::NetLog::TYPE_ENTRY_WRITE_DATA,
@@ -205,7 +205,7 @@ int MemEntryImpl::WriteData(int index, int offset, net::IOBuffer* buf,
}
int MemEntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* completion_callback) {
+ const net::CompletionCallback& callback) {
if (net_log_.IsLoggingAllEvents()) {
net_log_.BeginEvent(
net::NetLog::TYPE_SPARSE_READ,
@@ -219,7 +219,7 @@ int MemEntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
}
int MemEntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* completion_callback) {
+ const net::CompletionCallback& callback) {
if (net_log_.IsLoggingAllEvents()) {
net_log_.BeginEvent(net::NetLog::TYPE_SPARSE_WRITE,
make_scoped_refptr(
@@ -232,7 +232,7 @@ int MemEntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
}
int MemEntryImpl::GetAvailableRange(int64 offset, int len, int64* start,
- OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
if (net_log_.IsLoggingAllEvents()) {
net_log_.BeginEvent(
net::NetLog::TYPE_SPARSE_GET_RANGE,
@@ -254,8 +254,7 @@ bool MemEntryImpl::CouldBeSparse() const {
return (children_.get() != NULL);
}
-int MemEntryImpl::ReadyForSparseIO(
- net::OldCompletionCallback* completion_callback) {
+int MemEntryImpl::ReadyForSparseIO(const net::CompletionCallback& callback) {
return net::OK;
}
@@ -369,8 +368,9 @@ int MemEntryImpl::InternalReadSparseData(int64 offset, net::IOBuffer* buf,
child->net_log().source(),
io_buf->BytesRemaining())));
}
- int ret = child->ReadData(kSparseData, child_offset, io_buf,
- io_buf->BytesRemaining(), NULL);
+ int ret = child->ReadData(
+ kSparseData, child_offset, io_buf, io_buf->BytesRemaining(),
+ net::CompletionCallback());
if (net_log_.IsLoggingAllEvents()) {
net_log_.EndEventWithNetErrorCode(
net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, ret);
@@ -433,7 +433,7 @@ int MemEntryImpl::InternalWriteSparseData(int64 offset, net::IOBuffer* buf,
// TODO(hclam): if there is data in the entry and this write is not
// continuous we may want to discard this write.
int ret = child->WriteData(kSparseData, child_offset, io_buf, write_len,
- NULL, true);
+ net::CompletionCallback(), true);
if (net_log_.IsLoggingAllEvents()) {
net_log_.EndEventWithNetErrorCode(
net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, ret);
diff --git a/net/disk_cache/mem_entry_impl.h b/net/disk_cache/mem_entry_impl.h
index cf305ba..7e188a5 100644
--- a/net/disk_cache/mem_entry_impl.h
+++ b/net/disk_cache/mem_entry_impl.h
@@ -100,22 +100,23 @@ class MemEntryImpl : public Entry {
virtual int32 GetDataSize(int index) const OVERRIDE;
virtual int ReadData(
int index, int offset, net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* completion_callback) OVERRIDE;
- virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* completion_callback,
- bool truncate) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
+ virtual int WriteData(
+ int index, int offset, net::IOBuffer* buf, int buf_len,
+ const net::CompletionCallback& callback, bool truncate) OVERRIDE;
virtual int ReadSparseData(
int64 offset, net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* completion_callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int WriteSparseData(
int64 offset, net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* completion_callback) OVERRIDE;
- virtual int GetAvailableRange(int64 offset, int len, int64* start,
- OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
+ virtual int GetAvailableRange(
+ int64 offset, int len, int64* start,
+ const net::CompletionCallback& callback) OVERRIDE;
virtual bool CouldBeSparse() const OVERRIDE;
virtual void CancelSparseIO() OVERRIDE {}
virtual int ReadyForSparseIO(
- net::OldCompletionCallback* completion_callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
private:
typedef base::hash_map<int, MemEntryImpl*> EntryMap;
diff --git a/net/disk_cache/sparse_control.cc b/net/disk_cache/sparse_control.cc
index b5d1744..ee558ba 100644
--- a/net/disk_cache/sparse_control.cc
+++ b/net/disk_cache/sparse_control.cc
@@ -189,10 +189,7 @@ SparseControl::SparseControl(EntryImpl* entry)
child_(NULL),
operation_(kNoOperation),
init_(false),
- child_map_(child_data_.bitmap, kNumSparseBits, kNumSparseBits / 32),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- child_callback_(this, &SparseControl::OnChildIOCompleted)),
- user_callback_(NULL) {
+ child_map_(child_data_.bitmap, kNumSparseBits, kNumSparseBits / 32) {
}
SparseControl::~SparseControl() {
@@ -233,8 +230,9 @@ bool SparseControl::CouldBeSparse() const {
return (entry_->GetDataSize(kSparseIndex) != 0);
}
-int SparseControl::StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf,
- int buf_len, net::OldCompletionCallback* callback) {
+int SparseControl::StartIO(
+ SparseOperation op, int64 offset, net::IOBuffer* buf, int buf_len,
+ const net::CompletionCallback& callback) {
DCHECK(init_);
// We don't support simultaneous IO for sparse data.
if (operation_ != kNoOperation)
@@ -248,7 +246,7 @@ int SparseControl::StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf,
return net::ERR_CACHE_OPERATION_NOT_SUPPORTED;
DCHECK(!user_buf_);
- DCHECK(!user_callback_);
+ DCHECK(user_callback_.is_null());
if (!buf && (op == kReadOperation || op == kWriteOperation))
return 0;
@@ -276,7 +274,7 @@ int SparseControl::StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf,
// Everything was done synchronously.
operation_ = kNoOperation;
user_buf_ = NULL;
- user_callback_ = NULL;
+ user_callback_.Reset();
return result_;
}
@@ -292,7 +290,8 @@ int SparseControl::GetAvailableRange(int64 offset, int len, int64* start) {
DCHECK(start);
range_found_ = false;
- int result = StartIO(kGetRangeOperation, offset, NULL, len, NULL);
+ int result = StartIO(
+ kGetRangeOperation, offset, NULL, len, net::CompletionCallback());
if (range_found_) {
*start = offset_;
return result;
@@ -309,7 +308,7 @@ void SparseControl::CancelIO() {
abort_ = true;
}
-int SparseControl::ReadyToUse(net::OldCompletionCallback* completion_callback) {
+int SparseControl::ReadyToUse(const net::CompletionCallback& callback) {
if (!abort_)
return net::OK;
@@ -317,7 +316,7 @@ int SparseControl::ReadyToUse(net::OldCompletionCallback* completion_callback) {
// one extra reference due to the pending IO operation itself, but we'll
// release that one before invoking user_callback_.
entry_->AddRef(); // Balanced in DoAbortCallbacks.
- abort_callbacks_.push_back(completion_callback);
+ abort_callbacks_.push_back(callback);
return net::ERR_IO_PENDING;
}
@@ -371,8 +370,9 @@ int SparseControl::CreateSparseEntry() {
scoped_refptr<net::IOBuffer> buf(
new net::WrappedIOBuffer(reinterpret_cast<char*>(&sparse_header_)));
- int rv = entry_->WriteData(kSparseIndex, 0, buf, sizeof(sparse_header_), NULL,
- false);
+ int rv = entry_->WriteData(
+ kSparseIndex, 0, buf, sizeof(sparse_header_), net::CompletionCallback(),
+ false);
if (rv != sizeof(sparse_header_)) {
DLOG(ERROR) << "Unable to save sparse_header_";
return net::ERR_CACHE_OPERATION_NOT_SUPPORTED;
@@ -402,7 +402,8 @@ int SparseControl::OpenSparseEntry(int data_len) {
new net::WrappedIOBuffer(reinterpret_cast<char*>(&sparse_header_)));
// Read header.
- int rv = entry_->ReadData(kSparseIndex, 0, buf, sizeof(sparse_header_), NULL);
+ int rv = entry_->ReadData(
+ kSparseIndex, 0, buf, sizeof(sparse_header_), net::CompletionCallback());
if (rv != static_cast<int>(sizeof(sparse_header_)))
return net::ERR_CACHE_READ_FAILURE;
@@ -416,7 +417,7 @@ int SparseControl::OpenSparseEntry(int data_len) {
// Read the actual bitmap.
buf = new net::IOBuffer(map_len);
rv = entry_->ReadData(kSparseIndex, sizeof(sparse_header_), buf, map_len,
- NULL);
+ net::CompletionCallback());
if (rv != map_len)
return net::ERR_CACHE_READ_FAILURE;
@@ -455,7 +456,8 @@ bool SparseControl::OpenChild() {
new net::WrappedIOBuffer(reinterpret_cast<char*>(&child_data_)));
// Read signature.
- int rv = child_->ReadData(kSparseIndex, 0, buf, sizeof(child_data_), NULL);
+ int rv = child_->ReadData(
+ kSparseIndex, 0, buf, sizeof(child_data_), net::CompletionCallback());
if (rv != sizeof(child_data_))
return KillChildAndContinue(key, true); // This is a fatal failure.
@@ -478,8 +480,9 @@ void SparseControl::CloseChild() {
new net::WrappedIOBuffer(reinterpret_cast<char*>(&child_data_)));
// Save the allocation bitmap before closing the child entry.
- int rv = child_->WriteData(kSparseIndex, 0, buf, sizeof(child_data_),
- NULL, false);
+ int rv = child_->WriteData(
+ kSparseIndex, 0, buf, sizeof(child_data_), net::CompletionCallback(),
+ false);
if (rv != sizeof(child_data_))
DLOG(ERROR) << "Failed to save child data";
child_->Release();
@@ -545,8 +548,9 @@ void SparseControl::WriteSparseData() {
reinterpret_cast<const char*>(children_map_.GetMap())));
int len = children_map_.ArraySize() * 4;
- int rv = entry_->WriteData(kSparseIndex, sizeof(sparse_header_), buf, len,
- NULL, false);
+ int rv = entry_->WriteData(
+ kSparseIndex, sizeof(sparse_header_), buf, len, net::CompletionCallback(),
+ false);
if (rv != len) {
DLOG(ERROR) << "Unable to save sparse map";
}
@@ -649,8 +653,9 @@ void SparseControl::InitChildData() {
scoped_refptr<net::WrappedIOBuffer> buf(
new net::WrappedIOBuffer(reinterpret_cast<char*>(&child_data_)));
- int rv = child_->WriteData(kSparseIndex, 0, buf, sizeof(child_data_),
- NULL, false);
+ int rv = child_->WriteData(
+ kSparseIndex, 0, buf, sizeof(child_data_), net::CompletionCallback(),
+ false);
if (rv != sizeof(child_data_))
DLOG(ERROR) << "Failed to save child data";
SetChildBit(true);
@@ -691,7 +696,11 @@ bool SparseControl::DoChildIO() {
// We have more work to do. Let's not trigger a callback to the caller.
finished_ = false;
- net::OldCompletionCallback* callback = user_callback_ ? &child_callback_ : NULL;
+ net::CompletionCallback callback;
+ if (!user_callback_.is_null()) {
+ callback =
+ base::Bind(&SparseControl::OnChildIOCompleted, base::Unretained(this));
+ }
int rv = 0;
switch (operation_) {
@@ -836,27 +845,27 @@ void SparseControl::OnChildIOCompleted(int result) {
}
void SparseControl::DoUserCallback() {
- DCHECK(user_callback_);
- net::OldCompletionCallback* c = user_callback_;
- user_callback_ = NULL;
+ DCHECK(!user_callback_.is_null());
+ net::CompletionCallback cb = user_callback_;
+ user_callback_.Reset();
user_buf_ = NULL;
pending_ = false;
operation_ = kNoOperation;
int rv = result_;
entry_->Release(); // Don't touch object after this line.
- c->Run(rv);
+ cb.Run(rv);
}
void SparseControl::DoAbortCallbacks() {
for (size_t i = 0; i < abort_callbacks_.size(); i++) {
// Releasing all references to entry_ may result in the destruction of this
// object so we should not be touching it after the last Release().
- net::OldCompletionCallback* c = abort_callbacks_[i];
+ net::CompletionCallback cb = abort_callbacks_[i];
if (i == abort_callbacks_.size() - 1)
abort_callbacks_.clear();
entry_->Release(); // Don't touch object after this line.
- c->Run(net::OK);
+ cb.Run(net::OK);
}
}
diff --git a/net/disk_cache/sparse_control.h b/net/disk_cache/sparse_control.h
index 98829bd..be6ca13 100644
--- a/net/disk_cache/sparse_control.h
+++ b/net/disk_cache/sparse_control.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009-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.
@@ -59,7 +59,7 @@ class SparseControl {
// WriteSparseData for details about the arguments. The return value is the
// number of bytes read or written, or a net error code.
int StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf,
- int buf_len, net::OldCompletionCallback* callback);
+ int buf_len, const net::CompletionCallback& callback);
// Implements Entry::GetAvailableRange().
int GetAvailableRange(int64 offset, int len, int64* start);
@@ -70,7 +70,7 @@ class SparseControl {
// Returns OK if the entry can be used for new IO or ERR_IO_PENDING if we are
// busy. If the entry is busy, we'll invoke the callback when we are ready
// again. See disk_cache::Entry::ReadyToUse() for more info.
- int ReadyToUse(net::OldCompletionCallback* completion_callback);
+ int ReadyToUse(const net::CompletionCallback& completion_callback);
// Deletes the children entries of |entry|.
static void DeleteChildren(EntryImpl* entry);
@@ -159,9 +159,8 @@ class SparseControl {
SparseData child_data_; // Parent and allocation map of child_.
Bitmap child_map_; // The allocation map as a bitmap.
- net::OldCompletionCallbackImpl<SparseControl> child_callback_;
- net::OldCompletionCallback* user_callback_;
- std::vector<net::OldCompletionCallback*> abort_callbacks_;
+ net::CompletionCallback user_callback_;
+ std::vector<net::CompletionCallback> abort_callbacks_;
int64 offset_; // Current sparse offset.
scoped_refptr<net::DrainableIOBuffer> user_buf_;
int buf_len_; // Bytes to read or write.
diff --git a/net/disk_cache/stress_cache.cc b/net/disk_cache/stress_cache.cc
index 52abb16..1a394c1 100644
--- a/net/disk_cache/stress_cache.cc
+++ b/net/disk_cache/stress_cache.cc
@@ -154,18 +154,18 @@ void StressTheCache(int iteration) {
if (entries[slot])
entries[slot]->Close();
- TestOldCompletionCallback old_cb;
- rv = cache->OpenEntry(keys[key], &entries[slot], &old_cb);
- if (old_cb.GetResult(rv) != net::OK) {
- rv = cache->CreateEntry(keys[key], &entries[slot], &old_cb);
- CHECK_EQ(net::OK, old_cb.GetResult(rv));
+ net::TestCompletionCallback cb;
+ rv = cache->OpenEntry(keys[key], &entries[slot], cb.callback());
+ if (cb.GetResult(rv) != net::OK) {
+ rv = cache->CreateEntry(keys[key], &entries[slot], cb.callback());
+ CHECK_EQ(net::OK, cb.GetResult(rv));
}
base::snprintf(buffer->data(), kSize,
"i: %d iter: %d, size: %d, truncate: %d ", i, iteration,
size, truncate ? 1 : 0);
- rv = entries[slot]->WriteData(0, 0, buffer, size, &old_cb, truncate);
- CHECK_EQ(size, old_cb.GetResult(rv));
+ rv = entries[slot]->WriteData(0, 0, buffer, size, cb.callback(), truncate);
+ CHECK_EQ(size, cb.GetResult(rv));
if (rand() % 100 > 80) {
key = rand() % kNumKeys;