diff options
Diffstat (limited to 'net/http')
-rw-r--r-- | net/http/http_cache.cc | 3 | ||||
-rw-r--r-- | net/http/mock_http_cache.cc | 41 | ||||
-rw-r--r-- | net/http/mock_http_cache.h | 5 |
3 files changed, 21 insertions, 28 deletions
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_; |