diff options
Diffstat (limited to 'net/http/mock_http_cache.cc')
-rw-r--r-- | net/http/mock_http_cache.cc | 41 |
1 files changed, 17 insertions, 24 deletions
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)); } //----------------------------------------------------------------------------- |