summaryrefslogtreecommitdiffstats
path: root/net/http/mock_http_cache.cc
diff options
context:
space:
mode:
authorttuttle <ttuttle@chromium.org>2015-04-23 12:42:29 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-23 19:42:48 +0000
commit859dc7ae4fac28a22afc10d62c7eb8d8fb2ef7f3 (patch)
tree0aaf024ced03282e40b46786570f2a821c015865 /net/http/mock_http_cache.cc
parent77137323157640d3eecae553956425c067054383 (diff)
downloadchromium_src-859dc7ae4fac28a22afc10d62c7eb8d8fb2ef7f3.zip
chromium_src-859dc7ae4fac28a22afc10d62c7eb8d8fb2ef7f3.tar.gz
chromium_src-859dc7ae4fac28a22afc10d62c7eb8d8fb2ef7f3.tar.bz2
net cleanup: Remove unnecessary namespace prefixes.
BUG=475208 Review URL: https://codereview.chromium.org/1095823003 Cr-Commit-Position: refs/heads/master@{#326610}
Diffstat (limited to 'net/http/mock_http_cache.cc')
-rw-r--r--net/http/mock_http_cache.cc240
1 files changed, 129 insertions, 111 deletions
diff --git a/net/http/mock_http_cache.cc b/net/http/mock_http_cache.cc
index a423a04..02b74bc 100644
--- a/net/http/mock_http_cache.cc
+++ b/net/http/mock_http_cache.cc
@@ -10,6 +10,8 @@
#include "net/base/net_errors.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace net {
+
namespace {
// We can override the test mode for a given operation by setting this global
@@ -36,7 +38,7 @@ int GetTestModeForEntry(const std::string& key) {
return t->test_mode;
}
-void CallbackForwader(const net::CompletionCallback& callback, int result) {
+void CallbackForwader(const CompletionCallback& callback, int result) {
callback.Run(result);
}
@@ -46,7 +48,7 @@ void CallbackForwader(const net::CompletionCallback& callback, int result) {
struct MockDiskEntry::CallbackInfo {
scoped_refptr<MockDiskEntry> entry;
- net::CompletionCallback callback;
+ CompletionCallback callback;
int result;
};
@@ -82,17 +84,19 @@ 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,
- const net::CompletionCallback& callback) {
+int MockDiskEntry::ReadData(int index,
+ int offset,
+ IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback) {
DCHECK(index >= 0 && index < kNumCacheEntryDataIndices);
DCHECK(!callback.is_null());
if (fail_requests_)
- return net::ERR_CACHE_READ_FAILURE;
+ return ERR_CACHE_READ_FAILURE;
if (offset < 0 || offset > static_cast<int>(data_[index].size()))
- return net::ERR_FAILED;
+ return ERR_FAILED;
if (static_cast<size_t>(offset) == data_[index].size())
return 0;
@@ -103,23 +107,26 @@ int MockDiskEntry::ReadData(
return num;
CallbackLater(callback, num);
- return net::ERR_IO_PENDING;
+ return ERR_IO_PENDING;
}
-int MockDiskEntry::WriteData(
- int index, int offset, net::IOBuffer* buf, int buf_len,
- const net::CompletionCallback& callback, bool truncate) {
+int MockDiskEntry::WriteData(int index,
+ int offset,
+ IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback,
+ bool truncate) {
DCHECK(index >= 0 && index < kNumCacheEntryDataIndices);
DCHECK(!callback.is_null());
DCHECK(truncate);
if (fail_requests_) {
- CallbackLater(callback, net::ERR_CACHE_READ_FAILURE);
- return net::ERR_IO_PENDING;
+ CallbackLater(callback, ERR_CACHE_READ_FAILURE);
+ return ERR_IO_PENDING;
}
if (offset < 0 || offset > static_cast<int>(data_[index].size()))
- return net::ERR_FAILED;
+ return ERR_FAILED;
data_[index].resize(offset + buf_len);
if (buf_len)
@@ -129,21 +136,23 @@ int MockDiskEntry::WriteData(
return buf_len;
CallbackLater(callback, buf_len);
- return net::ERR_IO_PENDING;
+ return ERR_IO_PENDING;
}
-int MockDiskEntry::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
- const net::CompletionCallback& callback) {
+int MockDiskEntry::ReadSparseData(int64 offset,
+ IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback) {
DCHECK(!callback.is_null());
if (fail_sparse_requests_)
- return net::ERR_NOT_IMPLEMENTED;
+ return ERR_NOT_IMPLEMENTED;
if (!sparse_ || busy_)
- return net::ERR_CACHE_OPERATION_NOT_SUPPORTED;
+ return ERR_CACHE_OPERATION_NOT_SUPPORTED;
if (offset < 0)
- return net::ERR_FAILED;
+ return ERR_FAILED;
if (fail_requests_)
- return net::ERR_CACHE_READ_FAILURE;
+ return ERR_CACHE_READ_FAILURE;
DCHECK(offset < kint32max);
int real_offset = static_cast<int>(offset);
@@ -160,29 +169,30 @@ int MockDiskEntry::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
CallbackLater(callback, num);
busy_ = true;
delayed_ = false;
- return net::ERR_IO_PENDING;
+ return ERR_IO_PENDING;
}
-int MockDiskEntry::WriteSparseData(int64 offset, net::IOBuffer* buf,
+int MockDiskEntry::WriteSparseData(int64 offset,
+ IOBuffer* buf,
int buf_len,
- const net::CompletionCallback& callback) {
+ const CompletionCallback& callback) {
DCHECK(!callback.is_null());
if (fail_sparse_requests_)
- return net::ERR_NOT_IMPLEMENTED;
+ return ERR_NOT_IMPLEMENTED;
if (busy_)
- return net::ERR_CACHE_OPERATION_NOT_SUPPORTED;
+ return ERR_CACHE_OPERATION_NOT_SUPPORTED;
if (!sparse_) {
if (data_[1].size())
- return net::ERR_CACHE_OPERATION_NOT_SUPPORTED;
+ return ERR_CACHE_OPERATION_NOT_SUPPORTED;
sparse_ = true;
}
if (offset < 0)
- return net::ERR_FAILED;
+ return ERR_FAILED;
if (!buf_len)
return 0;
if (fail_requests_)
- return net::ERR_CACHE_READ_FAILURE;
+ return ERR_CACHE_READ_FAILURE;
DCHECK(offset < kint32max);
int real_offset = static_cast<int>(offset);
@@ -195,19 +205,21 @@ int MockDiskEntry::WriteSparseData(int64 offset, net::IOBuffer* buf,
return buf_len;
CallbackLater(callback, buf_len);
- return net::ERR_IO_PENDING;
+ return ERR_IO_PENDING;
}
-int MockDiskEntry::GetAvailableRange(int64 offset, int len, int64* start,
- const net::CompletionCallback& callback) {
+int MockDiskEntry::GetAvailableRange(int64 offset,
+ int len,
+ int64* start,
+ const CompletionCallback& callback) {
DCHECK(!callback.is_null());
if (!sparse_ || busy_)
- return net::ERR_CACHE_OPERATION_NOT_SUPPORTED;
+ return ERR_CACHE_OPERATION_NOT_SUPPORTED;
if (offset < 0)
- return net::ERR_FAILED;
+ return ERR_FAILED;
if (fail_requests_)
- return net::ERR_CACHE_READ_FAILURE;
+ return ERR_CACHE_READ_FAILURE;
*start = offset;
DCHECK(offset < kint32max);
@@ -233,7 +245,7 @@ int MockDiskEntry::GetAvailableRange(int64 offset, int len, int64* start,
return count;
CallbackLater(callback, count);
- return net::ERR_IO_PENDING;
+ return ERR_IO_PENDING;
}
bool MockDiskEntry::CouldBeSparse() const {
@@ -246,21 +258,21 @@ void MockDiskEntry::CancelSparseIO() {
cancel_ = true;
}
-int MockDiskEntry::ReadyForSparseIO(const net::CompletionCallback& callback) {
+int MockDiskEntry::ReadyForSparseIO(const CompletionCallback& callback) {
if (fail_sparse_requests_)
- return net::ERR_NOT_IMPLEMENTED;
+ return ERR_NOT_IMPLEMENTED;
if (!cancel_)
- return net::OK;
+ return OK;
cancel_ = false;
DCHECK(!callback.is_null());
if (MockHttpCache::GetTestMode(test_mode_) & TEST_MODE_SYNC_CACHE_READ)
- return net::OK;
+ return OK;
// 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;
+ return ERR_IO_PENDING;
}
// If |value| is true, don't deliver any completion callbacks until called
@@ -272,7 +284,7 @@ void MockDiskEntry::IgnoreCallbacks(bool value) {
return;
ignore_callbacks_ = value;
if (!value)
- StoreAndDeliverCallbacks(false, NULL, net::CompletionCallback(), 0);
+ StoreAndDeliverCallbacks(false, NULL, CompletionCallback(), 0);
}
MockDiskEntry::~MockDiskEntry() {
@@ -281,7 +293,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(const net::CompletionCallback& callback,
+void MockDiskEntry::CallbackLater(const CompletionCallback& callback,
int result) {
if (ignore_callbacks_)
return StoreAndDeliverCallbacks(true, this, callback, result);
@@ -290,8 +302,8 @@ void MockDiskEntry::CallbackLater(const net::CompletionCallback& callback,
base::Bind(&MockDiskEntry::RunCallback, this, callback, result));
}
-void MockDiskEntry::RunCallback(
- const net::CompletionCallback& callback, int result) {
+void MockDiskEntry::RunCallback(const 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
@@ -313,9 +325,10 @@ void MockDiskEntry::RunCallback(
// 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, const net::CompletionCallback& callback,
- int result) {
+void MockDiskEntry::StoreAndDeliverCallbacks(bool store,
+ MockDiskEntry* entry,
+ const CompletionCallback& callback,
+ int result) {
static std::vector<CallbackInfo> callback_list;
if (store) {
CallbackInfo c = {entry, callback, result};
@@ -345,28 +358,29 @@ MockDiskCache::~MockDiskCache() {
ReleaseAll();
}
-net::CacheType MockDiskCache::GetCacheType() const {
- return net::DISK_CACHE;
+CacheType MockDiskCache::GetCacheType() const {
+ return DISK_CACHE;
}
int32 MockDiskCache::GetEntryCount() const {
return static_cast<int32>(entries_.size());
}
-int MockDiskCache::OpenEntry(const std::string& key, disk_cache::Entry** entry,
- const net::CompletionCallback& callback) {
+int MockDiskCache::OpenEntry(const std::string& key,
+ disk_cache::Entry** entry,
+ const CompletionCallback& callback) {
DCHECK(!callback.is_null());
if (fail_requests_)
- return net::ERR_CACHE_OPEN_FAILURE;
+ return ERR_CACHE_OPEN_FAILURE;
EntryMap::iterator it = entries_.find(key);
if (it == entries_.end())
- return net::ERR_CACHE_OPEN_FAILURE;
+ return ERR_CACHE_OPEN_FAILURE;
if (it->second->is_doomed()) {
it->second->Release();
entries_.erase(it);
- return net::ERR_CACHE_OPEN_FAILURE;
+ return ERR_CACHE_OPEN_FAILURE;
}
open_count_++;
@@ -378,18 +392,18 @@ int MockDiskCache::OpenEntry(const std::string& key, disk_cache::Entry** entry,
it->second->set_fail_requests();
if (GetTestModeForEntry(key) & TEST_MODE_SYNC_CACHE_START)
- return net::OK;
+ return OK;
- CallbackLater(callback, net::OK);
- return net::ERR_IO_PENDING;
+ CallbackLater(callback, OK);
+ return ERR_IO_PENDING;
}
int MockDiskCache::CreateEntry(const std::string& key,
disk_cache::Entry** entry,
- const net::CompletionCallback& callback) {
+ const CompletionCallback& callback) {
DCHECK(!callback.is_null());
if (fail_requests_)
- return net::ERR_CACHE_CREATE_FAILURE;
+ return ERR_CACHE_CREATE_FAILURE;
EntryMap::iterator it = entries_.find(key);
if (it != entries_.end()) {
@@ -397,7 +411,7 @@ int MockDiskCache::CreateEntry(const std::string& key,
if (double_create_check_)
NOTREACHED();
else
- return net::ERR_CACHE_CREATE_FAILURE;
+ return ERR_CACHE_CREATE_FAILURE;
}
it->second->Release();
entries_.erase(it);
@@ -420,14 +434,14 @@ int MockDiskCache::CreateEntry(const std::string& key,
new_entry->set_fail_sparse_requests();
if (GetTestModeForEntry(key) & TEST_MODE_SYNC_CACHE_START)
- return net::OK;
+ return OK;
- CallbackLater(callback, net::OK);
- return net::ERR_IO_PENDING;
+ CallbackLater(callback, OK);
+ return ERR_IO_PENDING;
}
int MockDiskCache::DoomEntry(const std::string& key,
- const net::CompletionCallback& callback) {
+ const CompletionCallback& callback) {
DCHECK(!callback.is_null());
EntryMap::iterator it = entries_.find(key);
if (it != entries_.end()) {
@@ -436,32 +450,32 @@ int MockDiskCache::DoomEntry(const std::string& key,
}
if (GetTestModeForEntry(key) & TEST_MODE_SYNC_CACHE_START)
- return net::OK;
+ return OK;
- CallbackLater(callback, net::OK);
- return net::ERR_IO_PENDING;
+ CallbackLater(callback, OK);
+ return ERR_IO_PENDING;
}
-int MockDiskCache::DoomAllEntries(const net::CompletionCallback& callback) {
- return net::ERR_NOT_IMPLEMENTED;
+int MockDiskCache::DoomAllEntries(const CompletionCallback& callback) {
+ return ERR_NOT_IMPLEMENTED;
}
int MockDiskCache::DoomEntriesBetween(const base::Time initial_time,
const base::Time end_time,
- const net::CompletionCallback& callback) {
- return net::ERR_NOT_IMPLEMENTED;
+ const CompletionCallback& callback) {
+ return ERR_NOT_IMPLEMENTED;
}
int MockDiskCache::DoomEntriesSince(const base::Time initial_time,
- const net::CompletionCallback& callback) {
- return net::ERR_NOT_IMPLEMENTED;
+ const CompletionCallback& callback) {
+ return ERR_NOT_IMPLEMENTED;
}
class MockDiskCache::NotImplementedIterator : public Iterator {
public:
int OpenNextEntry(disk_cache::Entry** next_entry,
- const net::CompletionCallback& callback) override {
- return net::ERR_NOT_IMPLEMENTED;
+ const CompletionCallback& callback) override {
+ return ERR_NOT_IMPLEMENTED;
}
};
@@ -483,7 +497,7 @@ void MockDiskCache::ReleaseAll() {
entries_.clear();
}
-void MockDiskCache::CallbackLater(const net::CompletionCallback& callback,
+void MockDiskCache::CallbackLater(const CompletionCallback& callback,
int result) {
base::MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(&CallbackForwader, callback, result));
@@ -491,11 +505,11 @@ void MockDiskCache::CallbackLater(const net::CompletionCallback& callback,
//-----------------------------------------------------------------------------
-int MockBackendFactory::CreateBackend(net::NetLog* net_log,
+int MockBackendFactory::CreateBackend(NetLog* net_log,
scoped_ptr<disk_cache::Backend>* backend,
- const net::CompletionCallback& callback) {
+ const CompletionCallback& callback) {
backend->reset(new MockDiskCache());
- return net::OK;
+ return OK;
}
//-----------------------------------------------------------------------------
@@ -504,24 +518,24 @@ MockHttpCache::MockHttpCache()
: http_cache_(new MockNetworkLayer(), NULL, new MockBackendFactory()) {
}
-MockHttpCache::MockHttpCache(net::HttpCache::BackendFactory* disk_cache_factory)
+MockHttpCache::MockHttpCache(HttpCache::BackendFactory* disk_cache_factory)
: http_cache_(new MockNetworkLayer(), NULL, disk_cache_factory) {
}
disk_cache::Backend* MockHttpCache::backend() {
- net::TestCompletionCallback cb;
+ TestCompletionCallback cb;
disk_cache::Backend* backend;
int rv = http_cache_.GetBackend(&backend, cb.callback());
rv = cb.GetResult(rv);
- return (rv == net::OK) ? backend : NULL;
+ return (rv == OK) ? backend : NULL;
}
MockDiskCache* MockHttpCache::disk_cache() {
return static_cast<MockDiskCache*>(backend());
}
-int MockHttpCache::CreateTransaction(scoped_ptr<net::HttpTransaction>* trans) {
- return http_cache_.CreateTransaction(net::DEFAULT_PRIORITY, trans);
+int MockHttpCache::CreateTransaction(scoped_ptr<HttpTransaction>* trans) {
+ return http_cache_.CreateTransaction(DEFAULT_PRIORITY, trans);
}
void MockHttpCache::BypassCacheLock() {
@@ -533,31 +547,31 @@ void MockHttpCache::FailConditionalizations() {
}
bool MockHttpCache::ReadResponseInfo(disk_cache::Entry* disk_entry,
- net::HttpResponseInfo* response_info,
+ HttpResponseInfo* response_info,
bool* response_truncated) {
int size = disk_entry->GetDataSize(0);
- net::TestCompletionCallback cb;
- scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(size));
+ TestCompletionCallback cb;
+ scoped_refptr<IOBuffer> buffer(new IOBuffer(size));
int rv = disk_entry->ReadData(0, 0, buffer.get(), size, cb.callback());
rv = cb.GetResult(rv);
EXPECT_EQ(size, rv);
- return net::HttpCache::ParseResponseInfo(buffer->data(), size,
- response_info,
- response_truncated);
+ return HttpCache::ParseResponseInfo(buffer->data(), size, response_info,
+ response_truncated);
}
-bool MockHttpCache::WriteResponseInfo(
- disk_cache::Entry* disk_entry, const net::HttpResponseInfo* response_info,
- bool skip_transient_headers, bool response_truncated) {
+bool MockHttpCache::WriteResponseInfo(disk_cache::Entry* disk_entry,
+ const HttpResponseInfo* response_info,
+ bool skip_transient_headers,
+ bool response_truncated) {
Pickle pickle;
response_info->Persist(
&pickle, skip_transient_headers, response_truncated);
- net::TestCompletionCallback cb;
- scoped_refptr<net::WrappedIOBuffer> data(new net::WrappedIOBuffer(
- reinterpret_cast<const char*>(pickle.data())));
+ TestCompletionCallback cb;
+ scoped_refptr<WrappedIOBuffer> data(
+ new WrappedIOBuffer(reinterpret_cast<const char*>(pickle.data())));
int len = static_cast<int>(pickle.size());
int rv = disk_entry->WriteData(0, 0, data.get(), len, cb.callback(), true);
@@ -567,17 +581,17 @@ bool MockHttpCache::WriteResponseInfo(
bool MockHttpCache::OpenBackendEntry(const std::string& key,
disk_cache::Entry** entry) {
- net::TestCompletionCallback cb;
+ TestCompletionCallback cb;
int rv = backend()->OpenEntry(key, entry, cb.callback());
- return (cb.GetResult(rv) == net::OK);
+ return (cb.GetResult(rv) == OK);
}
bool MockHttpCache::CreateBackendEntry(const std::string& key,
disk_cache::Entry** entry,
- net::NetLog* net_log) {
- net::TestCompletionCallback cb;
+ NetLog* net_log) {
+ TestCompletionCallback cb;
int rv = backend()->CreateEntry(key, entry, cb.callback());
- return (cb.GetResult(rv) == net::OK);
+ return (cb.GetResult(rv) == OK);
}
// Static.
@@ -597,17 +611,18 @@ void MockHttpCache::SetTestMode(int test_mode) {
int MockDiskCacheNoCB::CreateEntry(const std::string& key,
disk_cache::Entry** entry,
- const net::CompletionCallback& callback) {
- return net::ERR_IO_PENDING;
+ const CompletionCallback& callback) {
+ return ERR_IO_PENDING;
}
//-----------------------------------------------------------------------------
int MockBackendNoCbFactory::CreateBackend(
- net::NetLog* net_log, scoped_ptr<disk_cache::Backend>* backend,
- const net::CompletionCallback& callback) {
+ NetLog* net_log,
+ scoped_ptr<disk_cache::Backend>* backend,
+ const CompletionCallback& callback) {
backend->reset(new MockDiskCacheNoCB());
- return net::OK;
+ return OK;
}
//-----------------------------------------------------------------------------
@@ -622,8 +637,9 @@ MockBlockingBackendFactory::~MockBlockingBackendFactory() {
}
int MockBlockingBackendFactory::CreateBackend(
- net::NetLog* net_log, scoped_ptr<disk_cache::Backend>* backend,
- const net::CompletionCallback& callback) {
+ NetLog* net_log,
+ scoped_ptr<disk_cache::Backend>* backend,
+ const CompletionCallback& callback) {
if (!block_) {
if (!fail_)
backend->reset(new MockDiskCache());
@@ -632,7 +648,7 @@ int MockBlockingBackendFactory::CreateBackend(
backend_ = backend;
callback_ = callback;
- return net::ERR_IO_PENDING;
+ return ERR_IO_PENDING;
}
void MockBlockingBackendFactory::FinishCreation() {
@@ -640,8 +656,10 @@ void MockBlockingBackendFactory::FinishCreation() {
if (!callback_.is_null()) {
if (!fail_)
backend_->reset(new MockDiskCache());
- net::CompletionCallback cb = callback_;
+ CompletionCallback cb = callback_;
callback_.Reset();
cb.Run(Result()); // This object can be deleted here.
}
}
+
+} // namespace net