summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-17 02:20:23 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-17 02:20:23 +0000
commit42c459638320b53e684fcebd60b6eca45f2cdea4 (patch)
treea05eb30440e2156175d89ce731098d0d4d4dc32b /net
parent4189b0de2312dc216ce2938a88b794c1987fe2eb (diff)
downloadchromium_src-42c459638320b53e684fcebd60b6eca45f2cdea4.zip
chromium_src-42c459638320b53e684fcebd60b6eca45f2cdea4.tar.gz
chromium_src-42c459638320b53e684fcebd60b6eca45f2cdea4.tar.bz2
Reland after fixes.
base::Bind: Remove even moar OldCompletionCallback. BUG=none TEST=none R=dpapad Review URL: http://codereview.chromium.org/8947024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114896 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/completion_callback.cc13
-rw-r--r--net/base/completion_callback.h8
-rw-r--r--net/disk_cache/backend_impl.cc84
-rw-r--r--net/disk_cache/backend_impl.h4
-rw-r--r--net/disk_cache/disk_cache.h2
-rw-r--r--net/disk_cache/disk_cache_test_base.cc8
-rw-r--r--net/disk_cache/entry_unittest.cc35
-rw-r--r--net/disk_cache/in_flight_backend_io.cc4
-rw-r--r--net/disk_cache/in_flight_backend_io.h7
-rw-r--r--net/disk_cache/mem_backend_impl.cc2
-rw-r--r--net/disk_cache/mem_backend_impl.h2
-rw-r--r--net/disk_cache/stress_cache.cc22
-rw-r--r--net/http/http_cache.cc3
-rw-r--r--net/http/mock_http_cache.cc41
-rw-r--r--net/http/mock_http_cache.h5
-rw-r--r--net/net.gyp1
-rw-r--r--net/tools/crash_cache/crash_cache.cc21
17 files changed, 142 insertions, 120 deletions
diff --git a/net/base/completion_callback.cc b/net/base/completion_callback.cc
new file mode 100644
index 0000000..f697de1
--- /dev/null
+++ b/net/base/completion_callback.cc
@@ -0,0 +1,13 @@
+// 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.
+
+#include "net/base/completion_callback.h"
+
+namespace net {
+
+void OldCompletionCallbackAdapter(OldCompletionCallback* callback, int result) {
+ callback->Run(result);
+}
+
+} // namespace net
diff --git a/net/base/completion_callback.h b/net/base/completion_callback.h
index cea6be3..f55a855 100644
--- a/net/base/completion_callback.h
+++ b/net/base/completion_callback.h
@@ -9,6 +9,7 @@
#include "base/callback_old.h"
#include "base/callback.h"
#include "base/cancelable_callback.h"
+#include "net/base/net_export.h"
namespace net {
@@ -17,6 +18,13 @@ namespace net {
typedef Callback1<int>::Type OldCompletionCallback;
typedef base::Callback<void(int)> CompletionCallback;
+// Temporary (in the code) adapter of OldCompletionCallback for use at call
+// sites that expect a CompletionCallback.
+//
+// TODO(jhawkins): Remove once OldCompletionCallback is removed.
+void NET_EXPORT OldCompletionCallbackAdapter(OldCompletionCallback* callback,
+ int result);
+
// Used to implement a OldCompletionCallback.
template <class T>
class OldCompletionCallbackImpl :
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index 2cc2f3a..847ecac 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -5,6 +5,7 @@
#include "net/disk_cache/backend_impl.h"
#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/message_loop.h"
@@ -183,7 +184,7 @@ bool InitExperiment(disk_cache::IndexHeader* header, uint32 mask) {
}
if (!header->create_time || !header->lru.filled)
- return true; // Wait untill we fill up the cache.
+ return true; // Wait until we fill up the cache.
int index_load = header->num_entries * 100 / (mask + 1);
if (index_load > 25) {
@@ -218,23 +219,29 @@ class CacheCreator {
base::MessageLoopProxy* thread, net::NetLog* net_log,
disk_cache::Backend** backend,
net::OldCompletionCallback* callback)
- : path_(path), force_(force), retry_(false), max_bytes_(max_bytes),
- type_(type), flags_(flags), thread_(thread), backend_(backend),
- callback_(callback), cache_(NULL), net_log_(net_log),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- my_callback_(this, &CacheCreator::OnIOComplete)) {
+ : path_(path),
+ force_(force),
+ retry_(false),
+ max_bytes_(max_bytes),
+ type_(type),
+ flags_(flags),
+ thread_(thread),
+ backend_(backend),
+ callback_(callback),
+ cache_(NULL),
+ net_log_(net_log) {
}
~CacheCreator() {}
// Creates the backend.
int Run();
- // Callback implementation.
- void OnIOComplete(int result);
-
private:
void DoCallback(int result);
+ // Callback implementation.
+ void OnIOComplete(int result);
+
const FilePath& path_;
bool force_;
bool retry_;
@@ -246,7 +253,6 @@ class CacheCreator {
net::OldCompletionCallback* callback_;
disk_cache::BackendImpl* cache_;
net::NetLog* net_log_;
- net::OldCompletionCallbackImpl<CacheCreator> my_callback_;
DISALLOW_COPY_AND_ASSIGN(CacheCreator);
};
@@ -256,11 +262,25 @@ int CacheCreator::Run() {
cache_->SetMaxSize(max_bytes_);
cache_->SetType(type_);
cache_->SetFlags(flags_);
- int rv = cache_->Init(&my_callback_);
+ int rv = cache_->Init(
+ base::Bind(&CacheCreator::OnIOComplete, base::Unretained(this)));
DCHECK_EQ(net::ERR_IO_PENDING, rv);
return rv;
}
+void CacheCreator::DoCallback(int result) {
+ DCHECK_NE(net::ERR_IO_PENDING, result);
+ if (result == net::OK) {
+ *backend_ = cache_;
+ } else {
+ LOG(ERROR) << "Unable to create cache";
+ *backend_ = NULL;
+ delete cache_;
+ }
+ callback_->Run(result);
+ delete this;
+}
+
void CacheCreator::OnIOComplete(int result) {
if (result == net::OK || !force_ || retry_)
return DoCallback(result);
@@ -279,35 +299,9 @@ void CacheCreator::OnIOComplete(int result) {
DCHECK_EQ(net::ERR_IO_PENDING, rv);
}
-void CacheCreator::DoCallback(int result) {
- DCHECK_NE(net::ERR_IO_PENDING, result);
- if (result == net::OK) {
- *backend_ = cache_;
- } else {
- LOG(ERROR) << "Unable to create cache";
- *backend_ = NULL;
- delete cache_;
- }
- callback_->Run(result);
- delete this;
-}
-
-// ------------------------------------------------------------------------
-
-// A task to perform final cleanup on the background thread.
-class FinalCleanup : public Task {
- public:
- explicit FinalCleanup(disk_cache::BackendImpl* backend) : backend_(backend) {}
- ~FinalCleanup() {}
-
- virtual void Run();
- private:
- disk_cache::BackendImpl* backend_;
- DISALLOW_EVIL_CONSTRUCTORS(FinalCleanup);
-};
-
-void FinalCleanup::Run() {
- backend_->CleanupCache();
+// A callback to perform final cleanup on the background thread.
+void FinalCleanupCallback(disk_cache::BackendImpl* backend) {
+ backend->CleanupCache();
}
} // namespace
@@ -420,8 +414,8 @@ BackendImpl::~BackendImpl() {
// Unit tests may use the same thread for everything.
CleanupCache();
} else {
- background_queue_.background_thread()->PostTask(FROM_HERE,
- new FinalCleanup(this));
+ background_queue_.background_thread()->PostTask(
+ FROM_HERE, base::Bind(&FinalCleanupCallback, base::Unretained(this)));
done_.Wait();
}
}
@@ -449,7 +443,7 @@ int BackendImpl::CreateBackend(const FilePath& full_path, bool force,
return creator->Run();
}
-int BackendImpl::Init(OldCompletionCallback* callback) {
+int BackendImpl::Init(const net::CompletionCallback& callback) {
background_queue_.Init(callback);
return net::ERR_IO_PENDING;
}
@@ -1389,8 +1383,8 @@ int BackendImpl::CreateEntry(const std::string& key, Entry** entry,
}
int BackendImpl::DoomEntry(const std::string& key,
- OldCompletionCallback* callback) {
- DCHECK(callback);
+ const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
background_queue_.DoomEntry(key, callback);
return net::ERR_IO_PENDING;
}
diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h
index 6c76c2c..6ef5906 100644
--- a/net/disk_cache/backend_impl.h
+++ b/net/disk_cache/backend_impl.h
@@ -59,7 +59,7 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend {
OldCompletionCallback* callback);
// Performs general initialization for this current instance of the cache.
- int Init(OldCompletionCallback* callback);
+ int Init(const net::CompletionCallback& callback);
// Performs the actual initialization and final cleanup on destruction.
int SyncInit();
@@ -263,7 +263,7 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend {
virtual int CreateEntry(const std::string& key, Entry** entry,
OldCompletionCallback* callback) OVERRIDE;
virtual int DoomEntry(const std::string& key,
- OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int DoomAllEntries(const net::CompletionCallback& callback) OVERRIDE;
virtual int DoomEntriesBetween(
const base::Time initial_time,
diff --git a/net/disk_cache/disk_cache.h b/net/disk_cache/disk_cache.h
index a678eec..59231f6 100644
--- a/net/disk_cache/disk_cache.h
+++ b/net/disk_cache/disk_cache.h
@@ -92,7 +92,7 @@ class NET_EXPORT Backend {
// is a net error code. If this method returns ERR_IO_PENDING, the |callback|
// will be invoked after the entry is doomed.
virtual int DoomEntry(const std::string& key,
- OldCompletionCallback* callback) = 0;
+ const net::CompletionCallback& callback) = 0;
// Marks all entries for deletion. The return value is a net error code. If
// this method returns ERR_IO_PENDING, the |callback| will be invoked when the
diff --git a/net/disk_cache/disk_cache_test_base.cc b/net/disk_cache/disk_cache_test_base.cc
index fef178e..3182166 100644
--- a/net/disk_cache/disk_cache_test_base.cc
+++ b/net/disk_cache/disk_cache_test_base.cc
@@ -119,8 +119,8 @@ int DiskCacheTestWithCache::CreateEntry(const std::string& key,
}
int DiskCacheTestWithCache::DoomEntry(const std::string& key) {
- TestOldCompletionCallback cb;
- int rv = cache_->DoomEntry(key, &cb);
+ net::TestCompletionCallback cb;
+ int rv = cache_->DoomEntry(key, cb.callback());
return cb.GetResult(rv);
}
@@ -304,7 +304,7 @@ void DiskCacheTestWithCache::InitDiskCacheImpl() {
cache_impl_->SetType(type_);
cache_impl_->SetFlags(disk_cache::kNoRandom);
- TestOldCompletionCallback cb;
- int rv = cache_impl_->Init(&cb);
+ net::TestCompletionCallback cb;
+ int rv = cache_impl_->Init(cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
}
diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc
index c537ef1..ef8ad89 100644
--- a/net/disk_cache/entry_unittest.cc
+++ b/net/disk_cache/entry_unittest.cc
@@ -1724,22 +1724,31 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyDoomSparseEntry) {
DoomSparseEntry();
}
-// A OldCompletionCallback that deletes the cache from within the callback. The way
-// a TestOldCompletionCallback works means that all tasks (even new ones) are
-// executed by the message loop before returning to the caller so the only way
-// to simulate a race is to execute what we want on the callback.
-class SparseTestOldCompletionCallback : public TestOldCompletionCallback {
+// A CompletionCallback wrapper that deletes the cache from within the callback.
+// The way an OldCompletionCallback works means that all tasks (even new ones)
+// are executed by the message loop before returning to the caller so the only
+// way to simulate a race is to execute what we want on the callback.
+class SparseTestCompletionCallback: public TestCompletionCallbackBase {
public:
- explicit SparseTestOldCompletionCallback(disk_cache::Backend* cache)
- : cache_(cache) {}
+ explicit SparseTestCompletionCallback(disk_cache::Backend* cache)
+ : cache_(cache),
+ ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
+ base::Bind(&SparseTestCompletionCallback::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:
+
disk_cache::Backend* cache_;
- DISALLOW_COPY_AND_ASSIGN(SparseTestOldCompletionCallback);
+ net::CompletionCallback callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(SparseTestCompletionCallback);
};
// Tests that we don't crash when the backend is deleted while we are working
@@ -1765,8 +1774,8 @@ TEST_F(DiskCacheEntryTest, DoomSparseEntry2) {
EXPECT_EQ(9, cache_->GetEntryCount());
entry->Close();
- SparseTestOldCompletionCallback cb(cache_);
- int rv = cache_->DoomEntry(key, &cb);
+ SparseTestCompletionCallback cb(cache_);
+ int rv = cache_->DoomEntry(key, cb.callback());
EXPECT_EQ(net::ERR_IO_PENDING, rv);
EXPECT_EQ(net::OK, cb.WaitForResult());
diff --git a/net/disk_cache/in_flight_backend_io.cc b/net/disk_cache/in_flight_backend_io.cc
index 5cc6a65..30a5500 100644
--- a/net/disk_cache/in_flight_backend_io.cc
+++ b/net/disk_cache/in_flight_backend_io.cc
@@ -314,7 +314,7 @@ InFlightBackendIO::InFlightBackendIO(BackendImpl* backend,
InFlightBackendIO::~InFlightBackendIO() {
}
-void InFlightBackendIO::Init(OldCompletionCallback* callback) {
+void InFlightBackendIO::Init(const net::CompletionCallback& callback) {
scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
operation->Init();
PostOperation(operation);
@@ -335,7 +335,7 @@ void InFlightBackendIO::CreateEntry(const std::string& key, Entry** entry,
}
void InFlightBackendIO::DoomEntry(const std::string& key,
- OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
operation->DoomEntry(key);
PostOperation(operation);
diff --git a/net/disk_cache/in_flight_backend_io.h b/net/disk_cache/in_flight_backend_io.h
index 8d4024a..c3a52d5 100644
--- a/net/disk_cache/in_flight_backend_io.h
+++ b/net/disk_cache/in_flight_backend_io.h
@@ -149,13 +149,14 @@ class InFlightBackendIO : public InFlightIO {
base::MessageLoopProxy* background_thread);
virtual ~InFlightBackendIO();
- // The operations we proxy:
- void Init(net::OldCompletionCallback* callback);
+ // Proxied operations.
+ void Init(const net::CompletionCallback& callback);
void OpenEntry(const std::string& key, Entry** entry,
net::OldCompletionCallback* callback);
void CreateEntry(const std::string& key, Entry** entry,
net::OldCompletionCallback* callback);
- void DoomEntry(const std::string& key, net::OldCompletionCallback* callback);
+ void DoomEntry(const std::string& key,
+ const net::CompletionCallback& callback);
void DoomAllEntries(const net::CompletionCallback& callback);
void DoomEntriesBetween(const base::Time initial_time,
const base::Time end_time,
diff --git a/net/disk_cache/mem_backend_impl.cc b/net/disk_cache/mem_backend_impl.cc
index bd07af2..89b5825 100644
--- a/net/disk_cache/mem_backend_impl.cc
+++ b/net/disk_cache/mem_backend_impl.cc
@@ -145,7 +145,7 @@ int MemBackendImpl::CreateEntry(const std::string& key, Entry** entry,
}
int MemBackendImpl::DoomEntry(const std::string& key,
- OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
if (DoomEntry(key))
return net::OK;
diff --git a/net/disk_cache/mem_backend_impl.h b/net/disk_cache/mem_backend_impl.h
index 8793cec..1b799f4 100644
--- a/net/disk_cache/mem_backend_impl.h
+++ b/net/disk_cache/mem_backend_impl.h
@@ -69,7 +69,7 @@ class NET_EXPORT_PRIVATE MemBackendImpl : public Backend {
virtual int CreateEntry(const std::string& key, Entry** entry,
OldCompletionCallback* callback) OVERRIDE;
virtual int DoomEntry(const std::string& key,
- OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int DoomAllEntries(const net::CompletionCallback& callback) OVERRIDE;
virtual int DoomEntriesBetween(
const base::Time initial_time,
diff --git a/net/disk_cache/stress_cache.cc b/net/disk_cache/stress_cache.cc
index a18df2a..52abb16 100644
--- a/net/disk_cache/stress_cache.cc
+++ b/net/disk_cache/stress_cache.cc
@@ -113,8 +113,8 @@ void StressTheCache(int iteration) {
cache->SetMaxSize(cache_size);
cache->SetFlags(disk_cache::kNoLoadProtection);
- TestOldCompletionCallback cb;
- int rv = cache->Init(&cb);
+ net::TestCompletionCallback cb;
+ int rv = cache->Init(cb.callback());
if (cb.GetResult(rv) != net::OK) {
printf("Unable to initialize cache.\n");
@@ -154,22 +154,24 @@ void StressTheCache(int iteration) {
if (entries[slot])
entries[slot]->Close();
- rv = cache->OpenEntry(keys[key], &entries[slot], &cb);
- if (cb.GetResult(rv) != net::OK) {
- rv = cache->CreateEntry(keys[key], &entries[slot], &cb);
- CHECK_EQ(net::OK, cb.GetResult(rv));
+ 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));
}
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, &cb, truncate);
- CHECK_EQ(size, cb.GetResult(rv));
+ rv = entries[slot]->WriteData(0, 0, buffer, size, &old_cb, truncate);
+ CHECK_EQ(size, old_cb.GetResult(rv));
if (rand() % 100 > 80) {
key = rand() % kNumKeys;
- rv = cache->DoomEntry(keys[key], &cb);
- cb.GetResult(rv);
+ net::TestCompletionCallback cb2;
+ rv = cache->DoomEntry(keys[key], cb2.callback());
+ cb2.GetResult(rv);
}
if (!(i % 100))
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc
index 78b0eaf..8ee0ac6 100644
--- a/net/http/http_cache.cc
+++ b/net/http/http_cache.cc
@@ -638,7 +638,8 @@ int HttpCache::AsyncDoomEntry(const std::string& key, Transaction* trans) {
BackendCallback* my_callback = new BackendCallback(this, pending_op);
pending_op->callback = my_callback;
- int rv = disk_cache_->DoomEntry(key, my_callback);
+ int rv = disk_cache_->DoomEntry(
+ key, base::Bind(&net::OldCompletionCallbackAdapter, my_callback));
if (rv != ERR_IO_PENDING) {
item->ClearTransaction();
my_callback->Run(rv);
diff --git a/net/http/mock_http_cache.cc b/net/http/mock_http_cache.cc
index 5fe148e..5145e66 100644
--- a/net/http/mock_http_cache.cc
+++ b/net/http/mock_http_cache.cc
@@ -6,11 +6,16 @@
#include "base/bind.h"
#include "base/message_loop.h"
+#include "net/base/completion_callback.h"
#include "net/base/net_errors.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
+// We can override the test mode for a given operation by setting this global
+// variable.
+int g_test_mode = 0;
+
int GetTestModeForEntry(const std::string& key) {
// 'key' is prefixed with an identifier if it corresponds to a cached POST.
// Skip past that to locate the actual URL.
@@ -31,9 +36,9 @@ int GetTestModeForEntry(const std::string& key) {
return t->test_mode;
}
-// We can override the test mode for a given operation by setting this global
-// variable.
-int g_test_mode = 0;
+void CallbackForwader(const net::CompletionCallback& callback, int result) {
+ callback.Run(result);
+}
} // namespace
@@ -325,20 +330,6 @@ bool MockDiskEntry::ignore_callbacks_ = false;
//-----------------------------------------------------------------------------
-class MockDiskCache::CallbackRunner : public Task {
- public:
- CallbackRunner(net::OldCompletionCallback* callback, int result)
- : callback_(callback), result_(result) {}
- virtual void Run() {
- callback_->Run(result_);
- }
-
- private:
- net::OldCompletionCallback* callback_;
- int result_;
- DISALLOW_COPY_AND_ASSIGN(CallbackRunner);
-};
-
MockDiskCache::MockDiskCache()
: open_count_(0), create_count_(0), fail_requests_(false),
soft_failures_(false), double_create_check_(true) {
@@ -379,7 +370,8 @@ int MockDiskCache::OpenEntry(const std::string& key, disk_cache::Entry** entry,
if (GetTestModeForEntry(key) & TEST_MODE_SYNC_CACHE_START)
return net::OK;
- CallbackLater(callback, net::OK);
+ CallbackLater(
+ base::Bind(&net::OldCompletionCallbackAdapter, callback), net::OK);
return net::ERR_IO_PENDING;
}
@@ -418,13 +410,14 @@ int MockDiskCache::CreateEntry(const std::string& key,
if (GetTestModeForEntry(key) & TEST_MODE_SYNC_CACHE_START)
return net::OK;
- CallbackLater(callback, net::OK);
+ CallbackLater(
+ base::Bind(&net::OldCompletionCallbackAdapter, callback), net::OK);
return net::ERR_IO_PENDING;
}
int MockDiskCache::DoomEntry(const std::string& key,
- net::OldCompletionCallback* callback) {
- DCHECK(callback);
+ const net::CompletionCallback& callback) {
+ DCHECK(!callback.is_null());
EntryMap::iterator it = entries_.find(key);
if (it != entries_.end()) {
it->second->Release();
@@ -475,10 +468,10 @@ void MockDiskCache::ReleaseAll() {
entries_.clear();
}
-void MockDiskCache::CallbackLater(net::OldCompletionCallback* callback,
+void MockDiskCache::CallbackLater(const net::CompletionCallback& callback,
int result) {
- MessageLoop::current()->PostTask(FROM_HERE,
- new CallbackRunner(callback, result));
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&CallbackForwader, callback, result));
}
//-----------------------------------------------------------------------------
diff --git a/net/http/mock_http_cache.h b/net/http/mock_http_cache.h
index 8e492a9..d934e49 100644
--- a/net/http/mock_http_cache.h
+++ b/net/http/mock_http_cache.h
@@ -101,7 +101,7 @@ class MockDiskCache : public disk_cache::Backend {
virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry,
net::OldCompletionCallback* callback) OVERRIDE;
virtual int DoomEntry(const std::string& key,
- net::OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
virtual int DoomAllEntries(const net::CompletionCallback& callback) OVERRIDE;
virtual int DoomEntriesBetween(
const base::Time initial_time,
@@ -135,9 +135,8 @@ class MockDiskCache : public disk_cache::Backend {
private:
typedef base::hash_map<std::string, MockDiskEntry*> EntryMap;
- class CallbackRunner;
- void CallbackLater(net::OldCompletionCallback* callback, int result);
+ void CallbackLater(const net::CompletionCallback& callback, int result);
EntryMap entries_;
int open_count_;
diff --git a/net/net.gyp b/net/net.gyp
index 2b8de74..8f399d7 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -72,6 +72,7 @@
'base/cert_verifier.h',
'base/cert_verify_result.cc',
'base/cert_verify_result.h',
+ 'base/completion_callback.cc',
'base/completion_callback.h',
'base/connection_type_histograms.cc',
'base/connection_type_histograms.h',
diff --git a/net/tools/crash_cache/crash_cache.cc b/net/tools/crash_cache/crash_cache.cc
index 9916dd6..a8f6cdc 100644
--- a/net/tools/crash_cache/crash_cache.cc
+++ b/net/tools/crash_cache/crash_cache.cc
@@ -265,8 +265,9 @@ int LoadOperations(const FilePath& path, RankCrashes action,
// No experiments and use a simple LRU.
cache->SetFlags(disk_cache::kNoRandom);
- TestOldCompletionCallback cb;
- int rv = cache->Init(&cb);
+ TestOldCompletionCallback old_cb;
+ net::TestCompletionCallback cb;
+ int rv = cache->Init(cb.callback());
if (cb.GetResult(rv) != net::OK || cache->GetEntryCount())
return GENERIC;
@@ -276,14 +277,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, &cb);
- if (cb.GetResult(rv) != net::OK)
+ rv = cache->CreateEntry(key, &entry, &old_cb);
+ if (old_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, &cb);
- if (cb.GetResult(rv) != net::OK)
+ rv = cache->CreateEntry(kCrashEntryName, &entry, &old_cb);
+ if (old_cb.GetResult(rv) != net::OK)
return GENERIC;
entry->Close();
FlushQueue(cache);
@@ -293,13 +294,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, &cb);
- if (cb.GetResult(rv) != net::OK)
+ rv = cache->CreateEntry(kCrashEntryName, &entry, &old_cb);
+ if (old_cb.GetResult(rv) != net::OK)
return GENERIC;
}
- rv = cache->OpenEntry(kCrashEntryName, &entry, &cb);
- if (cb.GetResult(rv) != net::OK)
+ rv = cache->OpenEntry(kCrashEntryName, &entry, &old_cb);
+ if (old_cb.GetResult(rv) != net::OK)
return GENERIC;
disk_cache::g_rankings_crash = action;