summaryrefslogtreecommitdiffstats
path: root/net
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
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')
-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
-rw-r--r--net/http/disk_cache_based_ssl_host_info.cc36
-rw-r--r--net/http/disk_cache_based_ssl_host_info.h2
-rw-r--r--net/http/http_cache.cc73
-rw-r--r--net/http/http_cache.h9
-rw-r--r--net/http/http_cache_transaction.cc52
-rw-r--r--net/http/http_cache_transaction.h8
-rw-r--r--net/http/http_cache_unittest.cc60
-rw-r--r--net/http/mock_http_cache.cc115
-rw-r--r--net/http/mock_http_cache.h46
-rw-r--r--net/http/partial_data.cc25
-rw-r--r--net/http/partial_data.h6
-rw-r--r--net/tools/crash_cache/crash_cache.cc52
-rw-r--r--net/tools/dump_cache/cache_dumper.cc10
-rw-r--r--net/tools/dump_cache/cache_dumper.h14
-rw-r--r--net/tools/dump_cache/upgrade.cc43
-rw-r--r--net/url_request/view_cache_helper.cc18
-rw-r--r--net/url_request/view_cache_helper.h1
-rw-r--r--net/url_request/view_cache_helper_unittest.cc26
36 files changed, 831 insertions, 655 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;
diff --git a/net/http/disk_cache_based_ssl_host_info.cc b/net/http/disk_cache_based_ssl_host_info.cc
index 003618e..46a557f 100644
--- a/net/http/disk_cache_based_ssl_host_info.cc
+++ b/net/http/disk_cache_based_ssl_host_info.cc
@@ -4,8 +4,10 @@
#include "net/http/disk_cache_based_ssl_host_info.h"
+#include "base/bind.h"
#include "base/callback.h"
#include "base/logging.h"
+#include "net/base/completion_callback.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/http/http_cache.h"
@@ -39,8 +41,8 @@ DiskCacheBasedSSLHostInfo::DiskCacheBasedSSLHostInfo(
CertVerifier* cert_verifier,
HttpCache* http_cache)
: SSLHostInfo(hostname, ssl_config, cert_verifier),
- weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
- callback_(new CallbackImpl(weak_ptr_factory_.GetWeakPtr(),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
+ callback_(new CallbackImpl(weak_factory_.GetWeakPtr(),
&DiskCacheBasedSSLHostInfo::OnIOComplete)),
state_(GET_BACKEND),
ready_(false),
@@ -205,12 +207,16 @@ int DiskCacheBasedSSLHostInfo::DoCreateOrOpenComplete(int rv) {
int DiskCacheBasedSSLHostInfo::DoGetBackend() {
state_ = GET_BACKEND_COMPLETE;
- return http_cache_->GetBackend(callback_->backend_pointer(), callback_);
+ return http_cache_->GetBackend(
+ callback_->backend_pointer(),
+ base::Bind(&net::OldCompletionCallbackAdapter, callback_));
}
int DiskCacheBasedSSLHostInfo::DoOpen() {
state_ = OPEN_COMPLETE;
- return backend_->OpenEntry(key(), callback_->entry_pointer(), callback_);
+ return backend_->OpenEntry(
+ key(), callback_->entry_pointer(),
+ base::Bind(&net::OldCompletionCallbackAdapter, callback_));
}
int DiskCacheBasedSSLHostInfo::DoRead() {
@@ -222,8 +228,9 @@ int DiskCacheBasedSSLHostInfo::DoRead() {
read_buffer_ = new IOBuffer(size);
state_ = READ_COMPLETE;
- return entry_->ReadData(0 /* index */, 0 /* offset */, read_buffer_,
- size, callback_);
+ return entry_->ReadData(
+ 0 /* index */, 0 /* offset */, read_buffer_, size,
+ base::Bind(&net::OldCompletionCallbackAdapter, callback_));
}
int DiskCacheBasedSSLHostInfo::DoWrite() {
@@ -231,17 +238,24 @@ int DiskCacheBasedSSLHostInfo::DoWrite() {
memcpy(write_buffer_->data(), new_data_.data(), new_data_.size());
state_ = WRITE_COMPLETE;
- return entry_->WriteData(0 /* index */, 0 /* offset */, write_buffer_,
- new_data_.size(), callback_, true /* truncate */);
+ return entry_->WriteData(
+ 0 /* index */, 0 /* offset */, write_buffer_, new_data_.size(),
+ base::Bind(&net::OldCompletionCallbackAdapter, callback_),
+ true /* truncate */);
}
int DiskCacheBasedSSLHostInfo::DoCreateOrOpen() {
DCHECK(entry_ == NULL);
state_ = CREATE_OR_OPEN_COMPLETE;
- if (found_entry_)
- return backend_->OpenEntry(key(), callback_->entry_pointer(), callback_);
+ if (found_entry_) {
+ return backend_->OpenEntry(
+ key(), callback_->entry_pointer(),
+ base::Bind(&net::OldCompletionCallbackAdapter, callback_));
+ }
- return backend_->CreateEntry(key(), callback_->entry_pointer(), callback_);
+ return backend_->CreateEntry(
+ key(), callback_->entry_pointer(),
+ base::Bind(&net::OldCompletionCallbackAdapter, callback_));
}
int DiskCacheBasedSSLHostInfo::DoWaitForDataReadyDone() {
diff --git a/net/http/disk_cache_based_ssl_host_info.h b/net/http/disk_cache_based_ssl_host_info.h
index 2339ae9..5fd2be80 100644
--- a/net/http/disk_cache_based_ssl_host_info.h
+++ b/net/http/disk_cache_based_ssl_host_info.h
@@ -105,7 +105,7 @@ class NET_EXPORT_PRIVATE DiskCacheBasedSSLHostInfo
// IsCallbackPending returns true if we have a pending callback.
bool IsCallbackPending() const;
- base::WeakPtrFactory<DiskCacheBasedSSLHostInfo> weak_ptr_factory_;
+ base::WeakPtrFactory<DiskCacheBasedSSLHostInfo> weak_factory_;
CallbackImpl* callback_;
State state_;
bool ready_;
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc
index 8ee0ac6..1dcb368 100644
--- a/net/http/http_cache.cc
+++ b/net/http/http_cache.cc
@@ -13,6 +13,7 @@
#endif
#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/format_macros.h"
#include "base/location.h"
@@ -89,9 +90,9 @@ HttpCache::BackendFactory* HttpCache::DefaultBackend::InMemory(int max_bytes) {
return new DefaultBackend(MEMORY_CACHE, FilePath(), max_bytes, NULL);
}
-int HttpCache::DefaultBackend::CreateBackend(NetLog* net_log,
- disk_cache::Backend** backend,
- OldCompletionCallback* callback) {
+int HttpCache::DefaultBackend::CreateBackend(
+ NetLog* net_log, disk_cache::Backend** backend,
+ const CompletionCallback& callback) {
DCHECK_GE(max_bytes_, 0);
return disk_cache::CreateCacheBackend(type_, path_, max_bytes_, true,
thread_, net_log, backend, callback);
@@ -143,11 +144,16 @@ enum WorkItemOperation {
class HttpCache::WorkItem {
public:
WorkItem(WorkItemOperation operation, Transaction* trans, ActiveEntry** entry)
- : operation_(operation), trans_(trans), entry_(entry), callback_(NULL),
+ : operation_(operation),
+ trans_(trans),
+ entry_(entry),
backend_(NULL) {}
WorkItem(WorkItemOperation operation, Transaction* trans,
- OldCompletionCallback* cb, disk_cache::Backend** backend)
- : operation_(operation), trans_(trans), entry_(NULL), callback_(cb),
+ const net::CompletionCallback& cb, disk_cache::Backend** backend)
+ : operation_(operation),
+ trans_(trans),
+ entry_(NULL),
+ callback_(cb),
backend_(backend) {}
~WorkItem() {}
@@ -165,8 +171,8 @@ class HttpCache::WorkItem {
bool DoCallback(int result, disk_cache::Backend* backend) {
if (backend_)
*backend_ = backend;
- if (callback_) {
- callback_->Run(result);
+ if (!callback_.is_null()) {
+ callback_.Run(result);
return true;
}
return false;
@@ -175,15 +181,15 @@ class HttpCache::WorkItem {
WorkItemOperation operation() { return operation_; }
void ClearTransaction() { trans_ = NULL; }
void ClearEntry() { entry_ = NULL; }
- void ClearCallback() { callback_ = NULL; }
+ void ClearCallback() { callback_.Reset(); }
bool Matches(Transaction* trans) const { return trans == trans_; }
- bool IsValid() const { return trans_ || entry_ || callback_; }
+ bool IsValid() const { return trans_ || entry_ || !callback_.is_null(); }
private:
WorkItemOperation operation_;
Transaction* trans_;
ActiveEntry** entry_;
- OldCompletionCallback* callback_; // User callback.
+ net::CompletionCallback callback_; // User callback.
disk_cache::Backend** backend_;
};
@@ -279,7 +285,9 @@ void HttpCache::MetadataWriter::VerifyResponse(int result) {
if (response_info->response_time != expected_response_time_)
return SelfDestroy();
- result = transaction_->WriteMetadata(buf_, buf_len_, &callback_);
+ result = transaction_->WriteMetadata(
+ buf_, buf_len_,
+ base::Bind(&MetadataWriter::OnIOComplete, base::Unretained(this)));
if (result != ERR_IO_PENDING)
SelfDestroy();
}
@@ -422,8 +430,8 @@ HttpCache::~HttpCache() {
}
int HttpCache::GetBackend(disk_cache::Backend** backend,
- OldCompletionCallback* callback) {
- DCHECK(callback != NULL);
+ const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
if (disk_cache_.get()) {
*backend = disk_cache_.get();
@@ -452,8 +460,10 @@ void HttpCache::WriteMetadata(const GURL& url,
return;
// Do lazy initialization of disk cache if needed.
- if (!disk_cache_.get())
- CreateBackend(NULL, NULL); // We don't care about the result.
+ if (!disk_cache_.get()) {
+ // We don't care about the result.
+ CreateBackend(NULL, net::CompletionCallback());
+ }
HttpCache::Transaction* trans = new HttpCache::Transaction(this);
MetadataWriter* writer = new MetadataWriter(trans);
@@ -492,8 +502,10 @@ void HttpCache::OnExternalCacheHit(const GURL& url,
int HttpCache::CreateTransaction(scoped_ptr<HttpTransaction>* trans) {
// Do lazy initialization of disk cache if needed.
- if (!disk_cache_.get())
- CreateBackend(NULL, NULL); // We don't care about the result.
+ if (!disk_cache_.get()) {
+ // We don't care about the result.
+ CreateBackend(NULL, net::CompletionCallback());
+ }
trans->reset(new HttpCache::Transaction(this));
return OK;
@@ -512,7 +524,7 @@ HttpNetworkSession* HttpCache::GetSession() {
//-----------------------------------------------------------------------------
int HttpCache::CreateBackend(disk_cache::Backend** backend,
- OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
if (!backend_factory_.get())
return ERR_FAILED;
@@ -525,7 +537,7 @@ int HttpCache::CreateBackend(disk_cache::Backend** backend,
// entry, so we use an empty key for it.
PendingOp* pending_op = GetPendingOp("");
if (pending_op->writer) {
- if (callback)
+ if (!callback.is_null())
pending_op->pending_queue.push_back(item.release());
return ERR_IO_PENDING;
}
@@ -536,8 +548,9 @@ int HttpCache::CreateBackend(disk_cache::Backend** backend,
BackendCallback* my_callback = new BackendCallback(this, pending_op);
pending_op->callback = my_callback;
- int rv = backend_factory_->CreateBackend(net_log_, &pending_op->backend,
- my_callback);
+ int rv = backend_factory_->CreateBackend(
+ net_log_, &pending_op->backend,
+ base::Bind(&net::OldCompletionCallbackAdapter, my_callback));
if (rv != ERR_IO_PENDING) {
pending_op->writer->ClearCallback();
my_callback->Run(rv);
@@ -553,7 +566,8 @@ int HttpCache::GetBackendForTransaction(Transaction* trans) {
if (!building_backend_)
return ERR_FAILED;
- WorkItem* item = new WorkItem(WI_CREATE_BACKEND, trans, NULL, NULL);
+ WorkItem* item = new WorkItem(
+ WI_CREATE_BACKEND, trans, net::CompletionCallback(), NULL);
PendingOp* pending_op = GetPendingOp("");
DCHECK(pending_op->writer);
pending_op->pending_queue.push_back(item);
@@ -762,7 +776,9 @@ int HttpCache::OpenEntry(const std::string& key, ActiveEntry** entry,
BackendCallback* my_callback = new BackendCallback(this, pending_op);
pending_op->callback = my_callback;
- int rv = disk_cache_->OpenEntry(key, &(pending_op->disk_entry), my_callback);
+ int rv = disk_cache_->OpenEntry(
+ key, &(pending_op->disk_entry),
+ base::Bind(&net::OldCompletionCallbackAdapter, my_callback));
if (rv != ERR_IO_PENDING) {
item->ClearTransaction();
my_callback->Run(rv);
@@ -788,8 +804,9 @@ int HttpCache::CreateEntry(const std::string& key, ActiveEntry** entry,
BackendCallback* my_callback = new BackendCallback(this, pending_op);
pending_op->callback = my_callback;
- int rv = disk_cache_->CreateEntry(key, &(pending_op->disk_entry),
- my_callback);
+ int rv = disk_cache_->CreateEntry(
+ key, &(pending_op->disk_entry),
+ base::Bind(&net::OldCompletionCallbackAdapter, my_callback));
if (rv != ERR_IO_PENDING) {
item->ClearTransaction();
my_callback->Run(rv);
@@ -1018,7 +1035,7 @@ void HttpCache::OnProcessPendingQueue(ActiveEntry* entry) {
entry->will_process_pending_queue = false;
DCHECK(!entry->writer);
- // If no one is interested in this entry, then we can de-activate it.
+ // If no one is interested in this entry, then we can deactivate it.
if (entry->pending_queue.empty()) {
if (entry->readers.empty())
DestroyEntry(entry);
@@ -1104,7 +1121,7 @@ void HttpCache::OnIOComplete(int result, PendingOp* pending_op) {
if (item->operation() == WI_CREATE_ENTRY) {
if (result == OK) {
- // A second Create request, but the first request succeded.
+ // A second Create request, but the first request succeeded.
item->NotifyTransaction(ERR_CACHE_CREATE_FAILURE, NULL);
} else {
if (op != WI_CREATE_ENTRY) {
diff --git a/net/http/http_cache.h b/net/http/http_cache.h
index 00d5b98..9d1b9aa 100644
--- a/net/http/http_cache.h
+++ b/net/http/http_cache.h
@@ -89,7 +89,7 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory,
// |callback| because the object can be deleted from within the callback.
virtual int CreateBackend(NetLog* net_log,
disk_cache::Backend** backend,
- OldCompletionCallback* callback) = 0;
+ const CompletionCallback& callback) = 0;
};
// A default backend factory for the common use cases.
@@ -108,7 +108,7 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory,
// BackendFactory implementation.
virtual int CreateBackend(NetLog* net_log,
disk_cache::Backend** backend,
- OldCompletionCallback* callback) OVERRIDE;
+ const CompletionCallback& callback) OVERRIDE;
private:
CacheType type_;
@@ -156,7 +156,8 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory,
// a network error code, and it could be ERR_IO_PENDING, in which case the
// |callback| will be notified when the operation completes. The pointer that
// receives the |backend| must remain valid until the operation completes.
- int GetBackend(disk_cache::Backend** backend, OldCompletionCallback* callback);
+ int GetBackend(disk_cache::Backend** backend,
+ const net::CompletionCallback& callback);
// Returns the current backend (can be NULL).
disk_cache::Backend* GetCurrentBackend() const;
@@ -242,7 +243,7 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory,
// Creates the |backend| object and notifies the |callback| when the operation
// completes. Returns an error code.
int CreateBackend(disk_cache::Backend** backend,
- OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
// Makes sure that the backend creation is complete before allowing the
// provided transaction to use the object. Returns an error code. |trans|
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc
index a17e890..13ce79c 100644
--- a/net/http/http_cache_transaction.cc
+++ b/net/http/http_cache_transaction.cc
@@ -12,6 +12,7 @@
#include <string>
+#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/field_trial.h"
@@ -19,6 +20,7 @@
#include "base/string_util.h"
#include "base/time.h"
#include "net/base/cert_status_flags.h"
+#include "net/base/completion_callback.h"
#include "net/base/io_buffer.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
@@ -167,10 +169,10 @@ HttpCache::Transaction::~Transaction() {
}
int HttpCache::Transaction::WriteMetadata(IOBuffer* buf, int buf_len,
- OldCompletionCallback* callback) {
+ const CompletionCallback& callback) {
DCHECK(buf);
DCHECK_GT(buf_len, 0);
- DCHECK(callback);
+ DCHECK(!callback.is_null());
if (!cache_ || !entry_)
return ERR_UNEXPECTED;
@@ -1111,7 +1113,9 @@ int HttpCache::Transaction::DoTruncateCachedData() {
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, NULL);
// Truncate the stream.
- return WriteToEntry(kResponseContentIndex, 0, NULL, 0, cache_callback_);
+ return WriteToEntry(
+ kResponseContentIndex, 0, NULL, 0,
+ base::Bind(&net::OldCompletionCallbackAdapter, cache_callback_));
}
int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) {
@@ -1134,7 +1138,9 @@ int HttpCache::Transaction::DoTruncateCachedMetadata() {
if (net_log_.IsLoggingAllEvents())
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, NULL);
- return WriteToEntry(kMetadataIndex, 0, NULL, 0, cache_callback_);
+ return WriteToEntry(
+ kMetadataIndex, 0, NULL, 0,
+ base::Bind(&net::OldCompletionCallbackAdapter, cache_callback_));
}
int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) {
@@ -1186,8 +1192,9 @@ int HttpCache::Transaction::DoCacheReadResponse() {
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL);
cache_callback_->AddRef(); // Balanced in DoCacheReadResponseComplete.
- return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_,
- io_buf_len_, cache_callback_);
+ return entry_->disk_entry->ReadData(
+ kResponseInfoIndex, 0, read_buf_, io_buf_len_,
+ base::Bind(&net::OldCompletionCallbackAdapter, cache_callback_));
}
int HttpCache::Transaction::DoCacheReadResponseComplete(int result) {
@@ -1278,9 +1285,9 @@ int HttpCache::Transaction::DoCacheReadMetadata() {
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL);
cache_callback_->AddRef(); // Balanced in DoCacheReadMetadataComplete.
- return entry_->disk_entry->ReadData(kMetadataIndex, 0, response_.metadata,
- response_.metadata->size(),
- cache_callback_);
+ return entry_->disk_entry->ReadData(
+ kMetadataIndex, 0, response_.metadata, response_.metadata->size(),
+ base::Bind(&net::OldCompletionCallbackAdapter, cache_callback_));
}
int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) {
@@ -1299,7 +1306,8 @@ int HttpCache::Transaction::DoCacheQueryData() {
// Balanced in DoCacheQueryDataComplete.
cache_callback_->AddRef();
- return entry_->disk_entry->ReadyForSparseIO(cache_callback_);
+ return entry_->disk_entry->ReadyForSparseIO(
+ base::Bind(&net::OldCompletionCallbackAdapter, cache_callback_));
}
int HttpCache::Transaction::DoCacheQueryDataComplete(int result) {
@@ -1320,12 +1328,14 @@ int HttpCache::Transaction::DoCacheReadData() {
if (net_log_.IsLoggingAllEvents())
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA, NULL);
if (partial_.get()) {
- return partial_->CacheRead(entry_->disk_entry, read_buf_, io_buf_len_,
- cache_callback_);
+ return partial_->CacheRead(
+ entry_->disk_entry, read_buf_, io_buf_len_,
+ base::Bind(&net::OldCompletionCallbackAdapter, cache_callback_));
}
- return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_,
- read_buf_, io_buf_len_, cache_callback_);
+ return entry_->disk_entry->ReadData(
+ kResponseContentIndex, read_offset_, read_buf_, io_buf_len_,
+ base::Bind(&net::OldCompletionCallbackAdapter, cache_callback_));
}
int HttpCache::Transaction::DoCacheReadDataComplete(int result) {
@@ -1357,7 +1367,9 @@ int HttpCache::Transaction::DoCacheWriteData(int num_bytes) {
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, NULL);
cache_callback_->AddRef(); // Balanced in DoCacheWriteDataComplete.
- return AppendResponseDataToEntry(read_buf_, num_bytes, cache_callback_);
+ return AppendResponseDataToEntry(
+ read_buf_, num_bytes,
+ base::Bind(&net::OldCompletionCallbackAdapter, cache_callback_));
}
int HttpCache::Transaction::DoCacheWriteDataComplete(int result) {
@@ -1932,7 +1944,7 @@ int HttpCache::Transaction::ReadFromEntry(IOBuffer* data, int data_len) {
int HttpCache::Transaction::WriteToEntry(int index, int offset,
IOBuffer* data, int data_len,
- OldCompletionCallback* callback) {
+ const CompletionCallback& callback) {
if (!entry_)
return data_len;
@@ -1983,12 +1995,14 @@ int HttpCache::Transaction::WriteResponseInfoToEntry(bool truncated) {
// destructor of this object so cache_callback_ may be currently in use.
write_headers_callback_->AddRef();
io_buf_len_ = data->pickle()->size();
- return entry_->disk_entry->WriteData(kResponseInfoIndex, 0, data, io_buf_len_,
- write_headers_callback_, true);
+ return entry_->disk_entry->WriteData(
+ kResponseInfoIndex, 0, data, io_buf_len_,
+ base::Bind(&net::OldCompletionCallbackAdapter, write_headers_callback_),
+ true);
}
int HttpCache::Transaction::AppendResponseDataToEntry(
- IOBuffer* data, int data_len, OldCompletionCallback* callback) {
+ IOBuffer* data, int data_len, const CompletionCallback& callback) {
if (!entry_ || !data_len)
return data_len;
diff --git a/net/http/http_cache_transaction.h b/net/http/http_cache_transaction.h
index b6c11c7..f60a445 100644
--- a/net/http/http_cache_transaction.h
+++ b/net/http/http_cache_transaction.h
@@ -68,7 +68,7 @@ class HttpCache::Transaction : public HttpTransaction {
// Returns the number of bytes actually written, or a net error code. If the
// operation cannot complete immediately, returns ERR_IO_PENDING, grabs a
// reference to the buffer (until completion), and notifies the caller using
- // the provided |callback| when the operatiopn finishes.
+ // the provided |callback| when the operation finishes.
//
// The first time this method is called for a given transaction, previous
// meta-data will be overwritten with the provided data, and subsequent
@@ -80,7 +80,7 @@ class HttpCache::Transaction : public HttpTransaction {
// method.
int WriteMetadata(IOBuffer* buf,
int buf_len,
- OldCompletionCallback* callback);
+ const CompletionCallback& callback);
// This transaction is being deleted and we are not done writing to the cache.
// We need to indicate that the response data was truncated. Returns true on
@@ -291,7 +291,7 @@ class HttpCache::Transaction : public HttpTransaction {
// cache entry is destroyed. Future calls to this function will just do
// nothing without side-effect. Returns a network error code.
int WriteToEntry(int index, int offset, IOBuffer* data, int data_len,
- OldCompletionCallback* callback);
+ const CompletionCallback& callback);
// Called to write response_ to the cache entry. |truncated| indicates if the
// entry should be marked as incomplete.
@@ -300,7 +300,7 @@ class HttpCache::Transaction : public HttpTransaction {
// Called to append response data to the cache entry. Returns a network error
// code.
int AppendResponseDataToEntry(IOBuffer* data, int data_len,
- OldCompletionCallback* callback);
+ const CompletionCallback& callback);
// Called when we are done writing to the cache entry.
void DoneWritingToEntry(bool success);
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index 0c0ff6f..2ffa866 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -5,6 +5,7 @@
#include "net/http/http_cache.h"
#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/memory/scoped_vector.h"
#include "base/message_loop.h"
#include "base/string_util.h"
@@ -32,18 +33,27 @@ using base::Time;
namespace {
-class DeleteCacheOldCompletionCallback : public TestOldCompletionCallback {
+class DeleteCacheCompletionCallback : public TestCompletionCallbackBase {
public:
- explicit DeleteCacheOldCompletionCallback(MockHttpCache* cache)
- : cache_(cache) {}
+ explicit DeleteCacheCompletionCallback(MockHttpCache* cache)
+ : cache_(cache),
+ ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
+ base::Bind(&DeleteCacheCompletionCallback::OnComplete,
+ base::Unretained(this)))) {
+ }
+
+ const net::CompletionCallback& callback() const { return callback_; }
- virtual void RunWithParams(const Tuple1<int>& params) {
+ private:
+ void OnComplete(int result) {
delete cache_;
- TestOldCompletionCallback::RunWithParams(params);
+ SetResult(result);
}
- private:
MockHttpCache* cache_;
+ net::CompletionCallback callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(DeleteCacheCompletionCallback);
};
//-----------------------------------------------------------------------------
@@ -344,8 +354,8 @@ void CreateTruncatedEntry(std::string raw_headers, MockHttpCache* cache) {
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(100));
int len = static_cast<int>(base::strlcpy(buf->data(),
"rg: 00-09 rg: 10-19 ", 100));
- TestOldCompletionCallback cb;
- int rv = entry->WriteData(1, 0, buf, len, &cb, true);
+ net::TestCompletionCallback cb;
+ int rv = entry->WriteData(1, 0, buf, len, cb.callback(), true);
EXPECT_EQ(len, cb.GetResult(rv));
entry->Close();
}
@@ -395,9 +405,9 @@ TEST(HttpCache, GetBackend) {
MockHttpCache cache(net::HttpCache::DefaultBackend::InMemory(0));
disk_cache::Backend* backend;
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
// This will lazily initialize the backend.
- int rv = cache.http_cache()->GetBackend(&backend, &cb);
+ int rv = cache.http_cache()->GetBackend(&backend, cb.callback());
EXPECT_EQ(net::OK, cb.GetResult(rv));
}
@@ -1449,14 +1459,14 @@ TEST(HttpCache, DeleteCacheWaitingForBackend) {
// We cannot call FinishCreation because the factory itself will go away with
// the cache, so grab the callback and attempt to use it.
- net::OldCompletionCallback* callback = factory->callback();
+ net::CompletionCallback callback = factory->callback();
disk_cache::Backend** backend = factory->backend();
cache.reset();
MessageLoop::current()->RunAllPending();
*backend = NULL;
- callback->Run(net::ERR_ABORTED);
+ callback.Run(net::ERR_ABORTED);
}
// Tests that we can delete the cache while creating the backend, from within
@@ -1465,9 +1475,9 @@ TEST(HttpCache, DeleteCacheWaitingForBackend2) {
MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
MockHttpCache* cache = new MockHttpCache(factory);
- DeleteCacheOldCompletionCallback cb(cache);
+ DeleteCacheCompletionCallback cb(cache);
disk_cache::Backend* backend;
- int rv = cache->http_cache()->GetBackend(&backend, &cb);
+ int rv = cache->http_cache()->GetBackend(&backend, cb.callback());
EXPECT_EQ(net::ERR_IO_PENDING, rv);
// Now let's queue a regular transaction
@@ -1480,8 +1490,8 @@ TEST(HttpCache, DeleteCacheWaitingForBackend2) {
c->trans->Start(&request, &c->callback, net::BoundNetLog());
// And another direct backend request.
- TestOldCompletionCallback cb2;
- rv = cache->http_cache()->GetBackend(&backend, &cb2);
+ net::TestCompletionCallback cb2;
+ rv = cache->http_cache()->GetBackend(&backend, cb2.callback());
EXPECT_EQ(net::ERR_IO_PENDING, rv);
// Just to make sure that everything is still pending.
@@ -2814,8 +2824,8 @@ TEST(HttpCache, GET_Previous206_NotSparse) {
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500));
int len = static_cast<int>(base::strlcpy(buf->data(),
kRangeGET_TransactionOK.data, 500));
- TestOldCompletionCallback cb;
- int rv = entry->WriteData(1, 0, buf, len, &cb, true);
+ net::TestCompletionCallback cb;
+ int rv = entry->WriteData(1, 0, buf, len, cb.callback(), true);
EXPECT_EQ(len, cb.GetResult(rv));
entry->Close();
@@ -2858,8 +2868,8 @@ TEST(HttpCache, RangeGET_Previous206_NotSparse_2) {
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500));
int len = static_cast<int>(base::strlcpy(buf->data(),
kRangeGET_TransactionOK.data, 500));
- TestOldCompletionCallback cb;
- int rv = entry->WriteData(1, 0, buf, len, &cb, true);
+ net::TestCompletionCallback cb;
+ int rv = entry->WriteData(1, 0, buf, len, cb.callback(), true);
EXPECT_EQ(len, cb.GetResult(rv));
entry->Close();
@@ -2900,8 +2910,8 @@ TEST(HttpCache, GET_Previous206_NotValidation) {
scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(500));
int len = static_cast<int>(base::strlcpy(buf->data(),
kRangeGET_TransactionOK.data, 500));
- TestOldCompletionCallback cb;
- int rv = entry->WriteData(1, 0, buf, len, &cb, true);
+ net::TestCompletionCallback cb;
+ int rv = entry->WriteData(1, 0, buf, len, cb.callback(), true);
EXPECT_EQ(len, cb.GetResult(rv));
entry->Close();
@@ -3298,8 +3308,8 @@ TEST(HttpCache, RangeGET_InvalidResponse3) {
ASSERT_TRUE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &en));
int64 cached_start = 0;
- TestOldCompletionCallback cb;
- int rv = en->GetAvailableRange(40, 20, &cached_start, &cb);
+ net::TestCompletionCallback cb;
+ int rv = en->GetAvailableRange(40, 20, &cached_start, cb.callback());
EXPECT_EQ(10, cb.GetResult(rv));
EXPECT_EQ(50, cached_start);
en->Close();
@@ -4616,7 +4626,7 @@ TEST(HttpCache, StopCachingTruncatedEntry) {
RemoveMockTransaction(&kRangeGET_TransactionOK);
}
-// Tests that we detect truncated rersources from the net when there is
+// Tests that we detect truncated resources from the net when there is
// a Content-Length header.
TEST(HttpCache, TruncatedByContentLength) {
MockHttpCache cache;
diff --git a/net/http/mock_http_cache.cc b/net/http/mock_http_cache.cc
index 5145e66..ed8976f 100644
--- a/net/http/mock_http_cache.cc
+++ b/net/http/mock_http_cache.cc
@@ -46,7 +46,7 @@ void CallbackForwader(const net::CompletionCallback& callback, int result) {
struct MockDiskEntry::CallbackInfo {
scoped_refptr<MockDiskEntry> entry;
- net::OldCompletionCallback* callback;
+ net::CompletionCallback callback;
int result;
};
@@ -88,10 +88,11 @@ int32 MockDiskEntry::GetDataSize(int index) const {
return static_cast<int32>(data_[index].size());
}
-int MockDiskEntry::ReadData(int index, int offset, net::IOBuffer* buf,
- int buf_len, net::OldCompletionCallback* callback) {
+int MockDiskEntry::ReadData(
+ int index, int offset, net::IOBuffer* buf, int buf_len,
+ const net::CompletionCallback& callback) {
DCHECK(index >= 0 && index < kNumCacheEntryDataIndices);
- DCHECK(callback);
+ DCHECK(!callback.is_null());
if (fail_requests_)
return net::ERR_CACHE_READ_FAILURE;
@@ -111,11 +112,11 @@ int MockDiskEntry::ReadData(int index, int offset, net::IOBuffer* buf,
return net::ERR_IO_PENDING;
}
-int MockDiskEntry::WriteData(int index, int offset, net::IOBuffer* buf,
- int buf_len, net::OldCompletionCallback* callback,
- bool truncate) {
+int MockDiskEntry::WriteData(
+ int index, int offset, net::IOBuffer* buf, int buf_len,
+ const net::CompletionCallback& callback, bool truncate) {
DCHECK(index >= 0 && index < kNumCacheEntryDataIndices);
- DCHECK(callback);
+ DCHECK(!callback.is_null());
DCHECK(truncate);
if (fail_requests_) {
@@ -138,8 +139,8 @@ int MockDiskEntry::WriteData(int index, int offset, net::IOBuffer* buf,
}
int MockDiskEntry::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) {
- DCHECK(callback);
+ const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
if (!sparse_ || busy_)
return net::ERR_CACHE_OPERATION_NOT_SUPPORTED;
if (offset < 0)
@@ -168,8 +169,8 @@ int MockDiskEntry::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
int MockDiskEntry::WriteSparseData(int64 offset, net::IOBuffer* buf,
int buf_len,
- net::OldCompletionCallback* callback) {
- DCHECK(callback);
+ const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
if (busy_)
return net::ERR_CACHE_OPERATION_NOT_SUPPORTED;
if (!sparse_) {
@@ -200,8 +201,8 @@ int MockDiskEntry::WriteSparseData(int64 offset, net::IOBuffer* buf,
}
int MockDiskEntry::GetAvailableRange(int64 offset, int len, int64* start,
- net::OldCompletionCallback* callback) {
- DCHECK(callback);
+ const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
if (!sparse_ || busy_)
return net::ERR_CACHE_OPERATION_NOT_SUPPORTED;
if (offset < 0)
@@ -245,16 +246,16 @@ void MockDiskEntry::CancelSparseIO() {
cancel_ = true;
}
-int MockDiskEntry::ReadyForSparseIO(net::OldCompletionCallback* callback) {
+int MockDiskEntry::ReadyForSparseIO(const net::CompletionCallback& callback) {
if (!cancel_)
return net::OK;
cancel_ = false;
- DCHECK(callback);
+ DCHECK(!callback.is_null());
if (MockHttpCache::GetTestMode(test_mode_) & TEST_MODE_SYNC_CACHE_READ)
return net::OK;
- // The pending operation is already in the message loop (and hopefuly
+ // The pending operation is already in the message loop (and hopefully
// already in the second pass). Just notify the caller that it finished.
CallbackLater(callback, 0);
return net::ERR_IO_PENDING;
@@ -269,7 +270,7 @@ void MockDiskEntry::IgnoreCallbacks(bool value) {
return;
ignore_callbacks_ = value;
if (!value)
- StoreAndDeliverCallbacks(false, NULL, NULL, 0);
+ StoreAndDeliverCallbacks(false, NULL, net::CompletionCallback(), 0);
}
MockDiskEntry::~MockDiskEntry() {
@@ -278,7 +279,7 @@ MockDiskEntry::~MockDiskEntry() {
// Unlike the callbacks for MockHttpTransaction, we want this one to run even
// if the consumer called Close on the MockDiskEntry. We achieve that by
// leveraging the fact that this class is reference counted.
-void MockDiskEntry::CallbackLater(net::OldCompletionCallback* callback,
+void MockDiskEntry::CallbackLater(const net::CompletionCallback& callback,
int result) {
if (ignore_callbacks_)
return StoreAndDeliverCallbacks(true, this, callback, result);
@@ -286,7 +287,8 @@ void MockDiskEntry::CallbackLater(net::OldCompletionCallback* callback,
&MockDiskEntry::RunCallback, this, callback, result));
}
-void MockDiskEntry::RunCallback(net::OldCompletionCallback* callback, int result) {
+void MockDiskEntry::RunCallback(
+ const net::CompletionCallback& callback, int result) {
if (busy_) {
// This is kind of hacky, but controlling the behavior of just this entry
// from a test is sort of complicated. What we really want to do is
@@ -295,22 +297,22 @@ void MockDiskEntry::RunCallback(net::OldCompletionCallback* callback, int result
// this operation (already posted to the message loop)... and without
// just delaying for n mS (which may cause trouble with slow bots). So
// we re-post this operation (all async sparse IO operations will take two
- // trips trhough the message loop instead of one).
+ // trips through the message loop instead of one).
if (!delayed_) {
delayed_ = true;
return CallbackLater(callback, result);
}
}
busy_ = false;
- callback->Run(result);
+ callback.Run(result);
}
// When |store| is true, stores the callback to be delivered later; otherwise
// delivers any callback previously stored.
// Static.
-void MockDiskEntry::StoreAndDeliverCallbacks(bool store, MockDiskEntry* entry,
- net::OldCompletionCallback* callback,
- int result) {
+void MockDiskEntry::StoreAndDeliverCallbacks(
+ bool store, MockDiskEntry* entry, const net::CompletionCallback& callback,
+ int result) {
static std::vector<CallbackInfo> callback_list;
if (store) {
CallbackInfo c = {entry, callback, result};
@@ -344,8 +346,8 @@ int32 MockDiskCache::GetEntryCount() const {
}
int MockDiskCache::OpenEntry(const std::string& key, disk_cache::Entry** entry,
- net::OldCompletionCallback* callback) {
- DCHECK(callback);
+ const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
if (fail_requests_)
return net::ERR_CACHE_OPEN_FAILURE;
@@ -370,15 +372,14 @@ int MockDiskCache::OpenEntry(const std::string& key, disk_cache::Entry** entry,
if (GetTestModeForEntry(key) & TEST_MODE_SYNC_CACHE_START)
return net::OK;
- CallbackLater(
- base::Bind(&net::OldCompletionCallbackAdapter, callback), net::OK);
+ CallbackLater(callback, net::OK);
return net::ERR_IO_PENDING;
}
int MockDiskCache::CreateEntry(const std::string& key,
disk_cache::Entry** entry,
- net::OldCompletionCallback* callback) {
- DCHECK(callback);
+ const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
if (fail_requests_)
return net::ERR_CACHE_CREATE_FAILURE;
@@ -410,8 +411,7 @@ int MockDiskCache::CreateEntry(const std::string& key,
if (GetTestModeForEntry(key) & TEST_MODE_SYNC_CACHE_START)
return net::OK;
- CallbackLater(
- base::Bind(&net::OldCompletionCallbackAdapter, callback), net::OK);
+ CallbackLater(callback, net::OK);
return net::ERR_IO_PENDING;
}
@@ -442,7 +442,7 @@ int MockDiskCache::DoomEntriesBetween(const base::Time initial_time,
}
int MockDiskCache::DoomEntriesSince(const base::Time initial_time,
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
return net::ERR_NOT_IMPLEMENTED;
}
@@ -478,7 +478,7 @@ void MockDiskCache::CallbackLater(const net::CompletionCallback& callback,
int MockBackendFactory::CreateBackend(net::NetLog* net_log,
disk_cache::Backend** backend,
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
*backend = new MockDiskCache();
return net::OK;
}
@@ -494,9 +494,9 @@ MockHttpCache::MockHttpCache(net::HttpCache::BackendFactory* disk_cache_factory)
}
MockDiskCache* MockHttpCache::disk_cache() {
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
disk_cache::Backend* backend;
- int rv = http_cache_.GetBackend(&backend, &cb);
+ int rv = http_cache_.GetBackend(&backend, cb.callback());
rv = cb.GetResult(rv);
return (rv == net::OK) ? static_cast<MockDiskCache*>(backend) : NULL;
}
@@ -506,9 +506,9 @@ bool MockHttpCache::ReadResponseInfo(disk_cache::Entry* disk_entry,
bool* response_truncated) {
int size = disk_entry->GetDataSize(0);
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(size));
- int rv = disk_entry->ReadData(0, 0, buffer, size, &cb);
+ int rv = disk_entry->ReadData(0, 0, buffer, size, cb.callback());
rv = cb.GetResult(rv);
EXPECT_EQ(size, rv);
@@ -524,28 +524,28 @@ bool MockHttpCache::WriteResponseInfo(
response_info->Persist(
&pickle, skip_transient_headers, response_truncated);
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
scoped_refptr<net::WrappedIOBuffer> data(new net::WrappedIOBuffer(
reinterpret_cast<const char*>(pickle.data())));
int len = static_cast<int>(pickle.size());
- int rv = disk_entry->WriteData(0, 0, data, len, &cb, true);
+ int rv = disk_entry->WriteData(0, 0, data, len, cb.callback(), true);
rv = cb.GetResult(rv);
return (rv == len);
}
bool MockHttpCache::OpenBackendEntry(const std::string& key,
disk_cache::Entry** entry) {
- TestOldCompletionCallback cb;
- int rv = disk_cache()->OpenEntry(key, entry, &cb);
+ net::TestCompletionCallback cb;
+ int rv = disk_cache()->OpenEntry(key, entry, cb.callback());
return (cb.GetResult(rv) == net::OK);
}
bool MockHttpCache::CreateBackendEntry(const std::string& key,
disk_cache::Entry** entry,
net::NetLog* net_log) {
- TestOldCompletionCallback cb;
- int rv = disk_cache()->CreateEntry(key, entry, &cb);
+ net::TestCompletionCallback cb;
+ int rv = disk_cache()->CreateEntry(key, entry, cb.callback());
return (cb.GetResult(rv) == net::OK);
}
@@ -566,15 +566,15 @@ void MockHttpCache::SetTestMode(int test_mode) {
int MockDiskCacheNoCB::CreateEntry(const std::string& key,
disk_cache::Entry** entry,
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
return net::ERR_IO_PENDING;
}
//-----------------------------------------------------------------------------
-int MockBackendNoCbFactory::CreateBackend(net::NetLog* net_log,
- disk_cache::Backend** backend,
- net::OldCompletionCallback* callback) {
+int MockBackendNoCbFactory::CreateBackend(
+ net::NetLog* net_log, disk_cache::Backend** backend,
+ const net::CompletionCallback& callback) {
*backend = new MockDiskCacheNoCB();
return net::OK;
}
@@ -582,12 +582,17 @@ int MockBackendNoCbFactory::CreateBackend(net::NetLog* net_log,
//-----------------------------------------------------------------------------
MockBlockingBackendFactory::MockBlockingBackendFactory()
- : backend_(NULL), callback_(NULL), block_(true), fail_(false) {
+ : backend_(NULL),
+ block_(true),
+ fail_(false) {
+}
+
+MockBlockingBackendFactory::~MockBlockingBackendFactory() {
}
int MockBlockingBackendFactory::CreateBackend(
net::NetLog* net_log, disk_cache::Backend** backend,
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
if (!block_) {
if (!fail_)
*backend = new MockDiskCache();
@@ -601,11 +606,11 @@ int MockBlockingBackendFactory::CreateBackend(
void MockBlockingBackendFactory::FinishCreation() {
block_ = false;
- if (callback_) {
+ if (!callback_.is_null()) {
if (!fail_)
*backend_ = new MockDiskCache();
- net::OldCompletionCallback* cb = callback_;
- callback_ = NULL;
- cb->Run(Result()); // This object can be deleted here.
+ net::CompletionCallback cb = callback_;
+ callback_.Reset();
+ cb.Run(Result()); // This object can be deleted here.
}
}
diff --git a/net/http/mock_http_cache.h b/net/http/mock_http_cache.h
index d934e49..8cddc05 100644
--- a/net/http/mock_http_cache.h
+++ b/net/http/mock_http_cache.h
@@ -34,20 +34,22 @@ class MockDiskEntry : public disk_cache::Entry,
virtual base::Time GetLastModified() const OVERRIDE;
virtual int32 GetDataSize(int index) const OVERRIDE;
virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback,
+ const net::CompletionCallback& callback,
bool truncate) OVERRIDE;
virtual int ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) OVERRIDE;
- virtual int WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) OVERRIDE;
- virtual int GetAvailableRange(int64 offset, int len, int64* start,
- net::OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
+ virtual int WriteSparseData(
+ int64 offset, net::IOBuffer* buf, int buf_len,
+ 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& completion_callback) OVERRIDE;
// Fail most subsequent requests.
void set_fail_requests() { fail_requests_ = true; }
@@ -66,14 +68,14 @@ class MockDiskEntry : public disk_cache::Entry,
// Unlike the callbacks for MockHttpTransaction, we want this one to run even
// if the consumer called Close on the MockDiskEntry. We achieve that by
// leveraging the fact that this class is reference counted.
- void CallbackLater(net::OldCompletionCallback* callback, int result);
+ void CallbackLater(const net::CompletionCallback& callback, int result);
- void RunCallback(net::OldCompletionCallback* callback, int result);
+ void RunCallback(const net::CompletionCallback& callback, int result);
// When |store| is true, stores the callback to be delivered later; otherwise
// delivers any callback previously stored.
static void StoreAndDeliverCallbacks(bool store, MockDiskEntry* entry,
- net::OldCompletionCallback* callback,
+ const net::CompletionCallback& callback,
int result);
static const int kNumCacheEntryDataIndices = 3;
@@ -97,9 +99,9 @@ class MockDiskCache : public disk_cache::Backend {
virtual int32 GetEntryCount() const OVERRIDE;
virtual int OpenEntry(const std::string& key, disk_cache::Entry** entry,
- net::OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry,
- net::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;
@@ -107,8 +109,9 @@ class MockDiskCache : public disk_cache::Backend {
const base::Time initial_time,
const base::Time end_time,
const net::CompletionCallback& callback) OVERRIDE;
- virtual int DoomEntriesSince(const base::Time initial_time,
- net::OldCompletionCallback* callback) OVERRIDE;
+ virtual int DoomEntriesSince(
+ const base::Time initial_time,
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int OpenNextEntry(void** iter, disk_cache::Entry** next_entry,
const net::CompletionCallback& callback) OVERRIDE;
virtual void EndEnumeration(void** iter) OVERRIDE;
@@ -150,7 +153,7 @@ class MockBackendFactory : public net::HttpCache::BackendFactory {
public:
virtual int CreateBackend(net::NetLog* net_log,
disk_cache::Backend** backend,
- net::OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
};
class MockHttpCache {
@@ -197,24 +200,25 @@ class MockHttpCache {
// This version of the disk cache doesn't invoke CreateEntry callbacks.
class MockDiskCacheNoCB : public MockDiskCache {
virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry,
- net::OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
};
class MockBackendNoCbFactory : public net::HttpCache::BackendFactory {
public:
virtual int CreateBackend(net::NetLog* net_log,
disk_cache::Backend** backend,
- net::OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
};
// This backend factory allows us to control the backend instantiation.
class MockBlockingBackendFactory : public net::HttpCache::BackendFactory {
public:
MockBlockingBackendFactory();
+ virtual ~MockBlockingBackendFactory();
virtual int CreateBackend(net::NetLog* net_log,
disk_cache::Backend** backend,
- net::OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
// Completes the backend creation. Any blocked call will be notified via the
// provided callback.
@@ -223,13 +227,13 @@ class MockBlockingBackendFactory : public net::HttpCache::BackendFactory {
disk_cache::Backend** backend() { return backend_; }
void set_fail(bool fail) { fail_ = fail; }
- net::OldCompletionCallback* callback() { return callback_; }
+ const net::CompletionCallback& callback() { return callback_; }
private:
int Result() { return fail_ ? net::ERR_FAILED : net::OK; }
disk_cache::Backend** backend_;
- net::OldCompletionCallback* callback_;
+ net::CompletionCallback callback_;
bool block_;
bool fail_;
};
diff --git a/net/http/partial_data.cc b/net/http/partial_data.cc
index 290c0e7..4bdedac 100644
--- a/net/http/partial_data.cc
+++ b/net/http/partial_data.cc
@@ -4,6 +4,8 @@
#include "net/http/partial_data.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/format_macros.h"
#include "base/logging.h"
#include "base/string_number_conversions.h"
@@ -66,13 +68,12 @@ class PartialData::Core {
PartialData* owner_;
int64 start_;
- net::OldCompletionCallbackImpl<Core> callback_;
+
DISALLOW_COPY_AND_ASSIGN(Core);
};
PartialData::Core::Core(PartialData* owner)
- : owner_(owner),
- ALLOW_THIS_IN_INITIALIZER_LIST(callback_(this, &Core::OnIOComplete)) {
+ : owner_(owner) {
DCHECK(!owner_->core_);
owner_->core_ = this;
}
@@ -89,7 +90,9 @@ void PartialData::Core::Cancel() {
int PartialData::Core::GetAvailableRange(disk_cache::Entry* entry, int64 offset,
int len, int64* start) {
- int rv = entry->GetAvailableRange(offset, len, &start_, &callback_);
+ int rv = entry->GetAvailableRange(
+ offset, len, &start_, base::Bind(&PartialData::Core::OnIOComplete,
+ base::Unretained(this)));
if (rv != net::ERR_IO_PENDING) {
// The callback will not be invoked. Lets cleanup.
*start = start_;
@@ -416,8 +419,9 @@ void PartialData::FixContentLength(HttpResponseHeaders* headers) {
resource_size_));
}
-int PartialData::CacheRead(disk_cache::Entry* entry, IOBuffer* data,
- int data_len, OldCompletionCallback* callback) {
+int PartialData::CacheRead(
+ disk_cache::Entry* entry, IOBuffer* data, int data_len,
+ const net::CompletionCallback& callback) {
int read_len = std::min(data_len, cached_min_len_);
if (!read_len)
return 0;
@@ -436,12 +440,13 @@ int PartialData::CacheRead(disk_cache::Entry* entry, IOBuffer* data,
return rv;
}
-int PartialData::CacheWrite(disk_cache::Entry* entry, IOBuffer* data,
- int data_len, OldCompletionCallback* callback) {
+int PartialData::CacheWrite(
+ disk_cache::Entry* entry, IOBuffer* data, int data_len,
+ const net::CompletionCallback& callback) {
DVLOG(3) << "To write: " << data_len;
if (sparse_entry_) {
- return entry->WriteSparseData(current_range_start_, data, data_len,
- callback);
+ return entry->WriteSparseData(
+ current_range_start_, data, data_len, callback);
} else {
if (current_range_start_ > kint32max)
return ERR_INVALID_ARGUMENT;
diff --git a/net/http/partial_data.h b/net/http/partial_data.h
index bf14cf0..b996b98 100644
--- a/net/http/partial_data.h
+++ b/net/http/partial_data.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -98,12 +98,12 @@ class PartialData {
// operation completes, OnCacheReadCompleted() must be called with the result
// of the operation.
int CacheRead(disk_cache::Entry* entry, IOBuffer* data, int data_len,
- OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
// Writes |data_len| bytes to cache. This is basically a wrapper around the
// API of the cache that provides the right arguments for the current range.
int CacheWrite(disk_cache::Entry* entry, IOBuffer* data, int data_len,
- OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
// This method should be called when CacheRead() finishes the read, to update
// the internal state about the current range.
diff --git a/net/tools/crash_cache/crash_cache.cc b/net/tools/crash_cache/crash_cache.cc
index a8f6cdc..d616446 100644
--- a/net/tools/crash_cache/crash_cache.cc
+++ b/net/tools/crash_cache/crash_cache.cc
@@ -126,18 +126,21 @@ bool CreateTargetFolder(const FilePath& path, RankCrashes action,
// Makes sure that any pending task is processed.
void FlushQueue(disk_cache::Backend* cache) {
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
int rv =
- reinterpret_cast<disk_cache::BackendImpl*>(cache)->FlushQueueForTest(&cb);
+ reinterpret_cast<disk_cache::BackendImpl*>(cache)->FlushQueueForTest(
+ cb.callback());
cb.GetResult(rv); // Ignore the result;
}
-bool CreateCache(const FilePath& path, base::Thread* thread,
- disk_cache::Backend** cache, TestOldCompletionCallback* cb) {
+bool CreateCache(const FilePath& path,
+ base::Thread* thread,
+ disk_cache::Backend** cache,
+ net::TestCompletionCallback* cb) {
int size = 1024 * 1024;
int rv = disk_cache::BackendImpl::CreateBackend(
path, false, size, net::DISK_CACHE, disk_cache::kNoRandom,
- thread->message_loop_proxy(), NULL, cache, cb);
+ thread->message_loop_proxy(), NULL, cache, cb->callback());
return (cb->GetResult(rv) == net::OK && !(*cache)->GetEntryCount());
}
@@ -145,7 +148,7 @@ bool CreateCache(const FilePath& path, base::Thread* thread,
// Generates the files for an empty and one item cache.
int SimpleInsert(const FilePath& path, RankCrashes action,
base::Thread* cache_thread) {
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
disk_cache::Backend* cache;
if (!CreateCache(path, cache_thread, &cache, &cb))
return GENERIC;
@@ -158,7 +161,7 @@ int SimpleInsert(const FilePath& path, RankCrashes action,
}
disk_cache::Entry* entry;
- int rv = cache->CreateEntry(test_name, &entry, &cb);
+ int rv = cache->CreateEntry(test_name, &entry, cb.callback());
if (cb.GetResult(rv) != net::OK)
return GENERIC;
@@ -169,7 +172,7 @@ int SimpleInsert(const FilePath& path, RankCrashes action,
disk_cache::g_rankings_crash = action;
test_name = kCrashEntryName;
- rv = cache->CreateEntry(test_name, &entry, &cb);
+ rv = cache->CreateEntry(test_name, &entry, cb.callback());
if (cb.GetResult(rv) != net::OK)
return GENERIC;
@@ -182,13 +185,13 @@ int SimpleRemove(const FilePath& path, RankCrashes action,
DCHECK(action >= disk_cache::REMOVE_ONE_1);
DCHECK(action <= disk_cache::REMOVE_TAIL_3);
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
disk_cache::Backend* cache;
if (!CreateCache(path, cache_thread, &cache, &cb))
return GENERIC;
disk_cache::Entry* entry;
- int rv = cache->CreateEntry(kCrashEntryName, &entry, &cb);
+ int rv = cache->CreateEntry(kCrashEntryName, &entry, cb.callback());
if (cb.GetResult(rv) != net::OK)
return GENERIC;
@@ -196,7 +199,7 @@ int SimpleRemove(const FilePath& path, RankCrashes action,
FlushQueue(cache);
if (action >= disk_cache::REMOVE_TAIL_1) {
- rv = cache->CreateEntry("some other key", &entry, &cb);
+ rv = cache->CreateEntry("some other key", &entry, cb.callback());
if (cb.GetResult(rv) != net::OK)
return GENERIC;
@@ -204,7 +207,7 @@ int SimpleRemove(const FilePath& path, RankCrashes action,
FlushQueue(cache);
}
- rv = cache->OpenEntry(kCrashEntryName, &entry, &cb);
+ rv = cache->OpenEntry(kCrashEntryName, &entry, cb.callback());
if (cb.GetResult(rv) != net::OK)
return GENERIC;
@@ -221,26 +224,26 @@ int HeadRemove(const FilePath& path, RankCrashes action,
DCHECK(action >= disk_cache::REMOVE_HEAD_1);
DCHECK(action <= disk_cache::REMOVE_HEAD_4);
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
disk_cache::Backend* cache;
if (!CreateCache(path, cache_thread, &cache, &cb))
return GENERIC;
disk_cache::Entry* entry;
- int rv = cache->CreateEntry("some other key", &entry, &cb);
+ int rv = cache->CreateEntry("some other key", &entry, cb.callback());
if (cb.GetResult(rv) != net::OK)
return GENERIC;
entry->Close();
FlushQueue(cache);
- rv = cache->CreateEntry(kCrashEntryName, &entry, &cb);
+ rv = cache->CreateEntry(kCrashEntryName, &entry, cb.callback());
if (cb.GetResult(rv) != net::OK)
return GENERIC;
entry->Close();
FlushQueue(cache);
- rv = cache->OpenEntry(kCrashEntryName, &entry, &cb);
+ rv = cache->OpenEntry(kCrashEntryName, &entry, cb.callback());
if (cb.GetResult(rv) != net::OK)
return GENERIC;
@@ -265,7 +268,6 @@ int LoadOperations(const FilePath& path, RankCrashes action,
// No experiments and use a simple LRU.
cache->SetFlags(disk_cache::kNoRandom);
- TestOldCompletionCallback old_cb;
net::TestCompletionCallback cb;
int rv = cache->Init(cb.callback());
if (cb.GetResult(rv) != net::OK || cache->GetEntryCount())
@@ -277,14 +279,14 @@ int LoadOperations(const FilePath& path, RankCrashes action,
disk_cache::Entry* entry;
for (int i = 0; i < 100; i++) {
std::string key = GenerateKey(true);
- rv = cache->CreateEntry(key, &entry, &old_cb);
- if (old_cb.GetResult(rv) != net::OK)
+ rv = cache->CreateEntry(key, &entry, cb.callback());
+ if (cb.GetResult(rv) != net::OK)
return GENERIC;
entry->Close();
FlushQueue(cache);
if (50 == i && action >= disk_cache::REMOVE_LOAD_1) {
- rv = cache->CreateEntry(kCrashEntryName, &entry, &old_cb);
- if (old_cb.GetResult(rv) != net::OK)
+ rv = cache->CreateEntry(kCrashEntryName, &entry, cb.callback());
+ if (cb.GetResult(rv) != net::OK)
return GENERIC;
entry->Close();
FlushQueue(cache);
@@ -294,13 +296,13 @@ int LoadOperations(const FilePath& path, RankCrashes action,
if (action <= disk_cache::INSERT_LOAD_2) {
disk_cache::g_rankings_crash = action;
- rv = cache->CreateEntry(kCrashEntryName, &entry, &old_cb);
- if (old_cb.GetResult(rv) != net::OK)
+ rv = cache->CreateEntry(kCrashEntryName, &entry, cb.callback());
+ if (cb.GetResult(rv) != net::OK)
return GENERIC;
}
- rv = cache->OpenEntry(kCrashEntryName, &entry, &old_cb);
- if (old_cb.GetResult(rv) != net::OK)
+ rv = cache->OpenEntry(kCrashEntryName, &entry, cb.callback());
+ if (cb.GetResult(rv) != net::OK)
return GENERIC;
disk_cache::g_rankings_crash = action;
diff --git a/net/tools/dump_cache/cache_dumper.cc b/net/tools/dump_cache/cache_dumper.cc
index 8e830fa..dc236bd 100644
--- a/net/tools/dump_cache/cache_dumper.cc
+++ b/net/tools/dump_cache/cache_dumper.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -15,13 +15,13 @@
int CacheDumper::CreateEntry(const std::string& key,
disk_cache::Entry** entry,
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
return cache_->CreateEntry(key, entry, callback);
}
int CacheDumper::WriteEntry(disk_cache::Entry* entry, int index, int offset,
net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
return entry->WriteData(index, offset, buf, buf_len, callback, false);
}
@@ -66,7 +66,7 @@ bool SafeCreateDirectory(const std::wstring& path) {
int DiskDumper::CreateEntry(const std::string& key,
disk_cache::Entry** entry,
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
FilePath path(path_);
// The URL may not start with a valid protocol; search for it.
int urlpos = key.find("http");
@@ -147,7 +147,7 @@ void GetNormalizedHeaders(const net::HttpResponseInfo& info,
int DiskDumper::WriteEntry(disk_cache::Entry* entry, int index, int offset,
net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
if (!entry_)
return 0;
diff --git a/net/tools/dump_cache/cache_dumper.h b/net/tools/dump_cache/cache_dumper.h
index a062026..6ab30a5 100644
--- a/net/tools/dump_cache/cache_dumper.h
+++ b/net/tools/dump_cache/cache_dumper.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -30,13 +30,13 @@ class CacheDumpWriter {
// Returns a net error code.
virtual int CreateEntry(const std::string& key,
disk_cache::Entry** entry,
- net::OldCompletionCallback* callback) = 0;
+ const net::CompletionCallback& callback) = 0;
// Write to the current entry.
// Returns a net error code.
virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset,
net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) = 0;
+ const net::CompletionCallback& callback) = 0;
// Close the current entry.
virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used,
@@ -49,10 +49,10 @@ class CacheDumper : public CacheDumpWriter {
explicit CacheDumper(disk_cache::Backend* cache) : cache_(cache) {}
virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset,
net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used,
base::Time last_modified);
@@ -67,10 +67,10 @@ class DiskDumper : public CacheDumpWriter {
file_util::CreateDirectory(FilePath(path));
}
virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset,
net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback);
+ const net::CompletionCallback& callback);
virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used,
base::Time last_modified);
diff --git a/net/tools/dump_cache/upgrade.cc b/net/tools/dump_cache/upgrade.cc
index b5e7dd1..7766de5 100644
--- a/net/tools/dump_cache/upgrade.cc
+++ b/net/tools/dump_cache/upgrade.cc
@@ -214,11 +214,9 @@ bool BaseSM::IsPending() {
class MasterSM : public BaseSM {
public:
MasterSM(const std::wstring& path, HANDLE channel, bool dump_to_disk)
- : BaseSM(channel), path_(path), dump_to_disk_(dump_to_disk),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- create_callback_(this, &MasterSM::DoCreateEntryComplete)),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- write_callback_(this, &MasterSM::DoReadDataComplete)) {
+ : BaseSM(channel),
+ path_(path),
+ dump_to_disk_(dump_to_disk) {
}
virtual ~MasterSM() {
delete writer_;
@@ -268,8 +266,6 @@ class MasterSM : public BaseSM {
CacheDumpWriter* writer_;
const std::wstring& path_;
bool dump_to_disk_;
- net::OldCompletionCallbackImpl<MasterSM> create_callback_;
- net::OldCompletionCallbackImpl<MasterSM> write_callback_;
};
void MasterSM::OnIOCompleted(MessageLoopForIO::IOContext* context,
@@ -325,12 +321,12 @@ bool MasterSM::DoInit() {
writer_ = new DiskDumper(path_);
} else {
disk_cache::Backend* cache;
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE,
FilePath::FromWStringHack(path_), 0,
false,
cache_thread_.message_loop_proxy(),
- NULL, &cache, &cb);
+ NULL, &cache, cb.callback());
if (cb.GetResult(rv) != net::OK) {
printf("Unable to initialize new files\n");
return false;
@@ -398,9 +394,9 @@ void MasterSM::DoGetKey(int bytes_read) {
std::string key(input_->buffer);
DCHECK(key.size() == static_cast<size_t>(input_->msg.buffer_bytes - 1));
- int rv = writer_->CreateEntry(key,
- reinterpret_cast<disk_cache::Entry**>(&entry_),
- &create_callback_);
+ int rv = writer_->CreateEntry(
+ key, reinterpret_cast<disk_cache::Entry**>(&entry_),
+ base::Bind(&MasterSM::DoCreateEntryComplete, base::Unretained(this)));
if (rv != net::ERR_IO_PENDING)
DoCreateEntryComplete(rv);
@@ -512,8 +508,9 @@ void MasterSM::DoReadData(int bytes_read) {
scoped_refptr<net::WrappedIOBuffer> buf =
new net::WrappedIOBuffer(input_->buffer);
- int rv = writer_->WriteEntry(entry_, stream_, offset_, buf, read_size,
- &write_callback_);
+ int rv = writer_->WriteEntry(
+ entry_, stream_, offset_, buf, read_size,
+ base::Bind(&MasterSM::DoReadDataComplete, base::Unretained(this)));
if (rv == net::ERR_IO_PENDING) {
// We'll continue in DoReadDataComplete.
read_size_ = read_size;
@@ -594,24 +591,18 @@ class SlaveSM : public BaseSM {
void* iterator_;
Message msg_; // Used for DoReadDataComplete and DoGetEntryComplete.
- net::OldCompletionCallbackImpl<SlaveSM> read_callback_;
- net::OldCompletionCallbackImpl<SlaveSM> next_callback_;
scoped_ptr<disk_cache::BackendImpl> cache_;
};
SlaveSM::SlaveSM(const std::wstring& path, HANDLE channel)
- : BaseSM(channel), iterator_(NULL),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- read_callback_(this, &SlaveSM::DoReadDataComplete)),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- next_callback_(this, &SlaveSM::DoGetEntryComplete)) {
+ : BaseSM(channel), iterator_(NULL) {
disk_cache::Backend* cache;
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE,
FilePath::FromWStringHack(path), 0,
false,
cache_thread_.message_loop_proxy(),
- NULL, &cache, &cb);
+ NULL, &cache, cb.callback());
if (cb.GetResult(rv) != net::OK) {
printf("Unable to open cache files\n");
return;
@@ -742,7 +733,8 @@ int32 SlaveSM::GetEntryFromList() {
DCHECK(input_->msg.command == GET_PREV_ENTRY);
rv = cache_->OpenPrevEntry(&iterator_,
reinterpret_cast<disk_cache::Entry**>(&entry_),
- &next_callback_);
+ base::Bind(&SlaveSM::DoGetEntryComplete,
+ base::Unretained(this)));
}
DCHECK_EQ(net::ERR_IO_PENDING, rv);
return RESULT_PENDING;
@@ -844,7 +836,8 @@ void SlaveSM::DoReadData() {
scoped_refptr<net::WrappedIOBuffer> buf =
new net::WrappedIOBuffer(output_->buffer);
int ret = entry_->ReadData(stream, input_->msg.arg3, buf, size,
- &read_callback_);
+ base::Bind(&SlaveSM::DoReadDataComplete,
+ base::Unretained(this)));
if (ret == net::ERR_IO_PENDING) {
// Save the message so we can continue were we left.
msg_ = msg;
diff --git a/net/url_request/view_cache_helper.cc b/net/url_request/view_cache_helper.cc
index fbebb48..e5980d9 100644
--- a/net/url_request/view_cache_helper.cc
+++ b/net/url_request/view_cache_helper.cc
@@ -49,8 +49,6 @@ ViewCacheHelper::ViewCacheHelper()
data_(NULL),
next_state_(STATE_NONE),
ALLOW_THIS_IN_INITIALIZER_LIST(
- cache_callback_(this, &ViewCacheHelper::OnIOComplete)),
- ALLOW_THIS_IN_INITIALIZER_LIST(
entry_callback_(new CancelableOldCompletionCallback<ViewCacheHelper>(
this, &ViewCacheHelper::OnIOComplete))) {
}
@@ -221,7 +219,9 @@ int ViewCacheHelper::DoGetBackend() {
if (!http_cache)
return ERR_FAILED;
- return http_cache->GetBackend(&disk_cache_, &cache_callback_);
+ return http_cache->GetBackend(
+ &disk_cache_, base::Bind(&ViewCacheHelper::OnIOComplete,
+ base::Unretained(this)));
}
int ViewCacheHelper::DoGetBackendComplete(int result) {
@@ -266,7 +266,9 @@ int ViewCacheHelper::DoOpenNextEntryComplete(int result) {
int ViewCacheHelper::DoOpenEntry() {
next_state_ = STATE_OPEN_ENTRY_COMPLETE;
- return disk_cache_->OpenEntry(key_, &entry_, &cache_callback_);
+ return disk_cache_->OpenEntry(
+ key_, &entry_,
+ base::Bind(&ViewCacheHelper::OnIOComplete, base::Unretained(this)));
}
int ViewCacheHelper::DoOpenEntryComplete(int result) {
@@ -289,7 +291,9 @@ int ViewCacheHelper::DoReadResponse() {
return buf_len_;
buf_ = new IOBuffer(buf_len_);
- return entry_->ReadData(0, 0, buf_, buf_len_, entry_callback_);
+ return entry_->ReadData(
+ 0, 0, buf_, buf_len_,
+ base::Bind(&net::OldCompletionCallbackAdapter, entry_callback_));
}
int ViewCacheHelper::DoReadResponseComplete(int result) {
@@ -334,7 +338,9 @@ int ViewCacheHelper::DoReadData() {
return buf_len_;
buf_ = new IOBuffer(buf_len_);
- return entry_->ReadData(index_, 0, buf_, buf_len_, entry_callback_);
+ return entry_->ReadData(
+ index_, 0, buf_, buf_len_,
+ base::Bind(&net::OldCompletionCallbackAdapter, entry_callback_));
}
int ViewCacheHelper::DoReadDataComplete(int result) {
diff --git a/net/url_request/view_cache_helper.h b/net/url_request/view_cache_helper.h
index f6f7cc4..cd9b0f2 100644
--- a/net/url_request/view_cache_helper.h
+++ b/net/url_request/view_cache_helper.h
@@ -114,7 +114,6 @@ class NET_EXPORT ViewCacheHelper {
State next_state_;
- OldCompletionCallbackImpl<ViewCacheHelper> cache_callback_;
scoped_refptr<CancelableOldCompletionCallback<ViewCacheHelper> > entry_callback_;
DISALLOW_COPY_AND_ASSIGN(ViewCacheHelper);
diff --git a/net/url_request/view_cache_helper_unittest.cc b/net/url_request/view_cache_helper_unittest.cc
index 17bad61..a8c0822 100644
--- a/net/url_request/view_cache_helper_unittest.cc
+++ b/net/url_request/view_cache_helper_unittest.cc
@@ -47,8 +47,8 @@ void WriteHeaders(disk_cache::Entry* entry, int flags, const std::string data) {
reinterpret_cast<const char*>(pickle.data())));
int len = static_cast<int>(pickle.size());
- TestOldCompletionCallback cb;
- int rv = entry->WriteData(0, 0, buf, len, &cb, true);
+ net::TestCompletionCallback cb;
+ int rv = entry->WriteData(0, 0, buf, len, cb.callback(), true);
ASSERT_EQ(len, cb.GetResult(rv));
}
@@ -60,20 +60,20 @@ void WriteData(disk_cache::Entry* entry, int index, const std::string data) {
scoped_refptr<IOBuffer> buf(new IOBuffer(len));
memcpy(buf->data(), data.data(), data.length());
- TestOldCompletionCallback cb;
- int rv = entry->WriteData(index, 0, buf, len, &cb, true);
+ net::TestCompletionCallback cb;
+ int rv = entry->WriteData(index, 0, buf, len, cb.callback(), true);
ASSERT_EQ(len, cb.GetResult(rv));
}
void WriteToEntry(disk_cache::Backend* cache, const std::string key,
const std::string data0, const std::string data1,
const std::string data2) {
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
disk_cache::Entry* entry;
- int rv = cache->CreateEntry(key, &entry, &cb);
+ int rv = cache->CreateEntry(key, &entry, cb.callback());
rv = cb.GetResult(rv);
if (rv != OK) {
- rv = cache->OpenEntry(key, &entry, &cb);
+ rv = cache->OpenEntry(key, &entry, cb.callback());
ASSERT_EQ(OK, cb.GetResult(rv));
}
@@ -85,10 +85,11 @@ void WriteToEntry(disk_cache::Backend* cache, const std::string key,
}
void FillCache(URLRequestContext* context) {
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
disk_cache::Backend* cache;
int rv =
- context->http_transaction_factory()->GetCache()->GetBackend(&cache, &cb);
+ context->http_transaction_factory()->GetCache()->GetBackend(
+ &cache, cb.callback());
ASSERT_EQ(OK, cb.GetResult(rv));
std::string empty;
@@ -180,15 +181,16 @@ TEST(ViewCacheHelper, TruncatedFlag) {
scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext());
ViewCacheHelper helper;
- TestOldCompletionCallback cb;
+ net::TestCompletionCallback cb;
disk_cache::Backend* cache;
int rv =
- context->http_transaction_factory()->GetCache()->GetBackend(&cache, &cb);
+ context->http_transaction_factory()->GetCache()->GetBackend(
+ &cache, cb.callback());
ASSERT_EQ(OK, cb.GetResult(rv));
std::string key("the key");
disk_cache::Entry* entry;
- rv = cache->CreateEntry(key, &entry, &cb);
+ rv = cache->CreateEntry(key, &entry, cb.callback());
ASSERT_EQ(OK, cb.GetResult(rv));
// RESPONSE_INFO_TRUNCATED defined on response_info.cc