diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-04 21:43:49 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-04 21:43:49 +0000 |
commit | a2068a61d67a2e90789e45a8073e631899bdeb9c (patch) | |
tree | b8e80ea1d0cd464cd8422bb577161b7cad4d6edf /net/http | |
parent | 9b72d9a51a5e32f2600c27a65b6598745714c2be (diff) | |
download | chromium_src-a2068a61d67a2e90789e45a8073e631899bdeb9c.zip chromium_src-a2068a61d67a2e90789e45a8073e631899bdeb9c.tar.gz chromium_src-a2068a61d67a2e90789e45a8073e631899bdeb9c.tar.bz2 |
Disk cache: Interface for the sparse cache support.
This is just the interface declaration plus a mocked
implementation of the interface.
BUG=12258
TEST=none
Review URL: http://codereview.chromium.org/119072
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17669 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r-- | net/http/http_cache_unittest.cc | 79 |
1 files changed, 77 insertions, 2 deletions
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc index ef127a2..b58eb44 100644 --- a/net/http/http_cache_unittest.cc +++ b/net/http/http_cache_unittest.cc @@ -27,11 +27,11 @@ class MockDiskEntry : public disk_cache::Entry, public base::RefCounted<MockDiskEntry> { public: MockDiskEntry() - : test_mode_(0), doomed_(false) { + : test_mode_(0), doomed_(false), sparse_(false) { } MockDiskEntry(const std::string& key) - : key_(key), doomed_(false) { + : key_(key), doomed_(false), sparse_(false) { // // 'key' is prefixed with an identifier if it corresponds to a cached POST. // Skip past that to locate the actual URL. @@ -116,6 +116,80 @@ class MockDiskEntry : public disk_cache::Entry, return buf_len; } + virtual int ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, + net::CompletionCallback* completion_callback) { + if (!sparse_) + return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; + if (offset < 0) + return net::ERR_FAILED; + + DCHECK(offset < kint32max); + int real_offset = static_cast<int>(offset); + if (!buf_len) + return 0; + + int num = std::min(static_cast<int>(data_[1].size()) - real_offset, + buf_len); + memcpy(buf->data(), &data_[1][real_offset], num); + + if (!completion_callback || (test_mode_ & TEST_MODE_SYNC_CACHE_READ)) + return num; + + CallbackLater(completion_callback, num); + return net::ERR_IO_PENDING; + } + + virtual int WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len, + net::CompletionCallback* completion_callback) { + if (!sparse_) { + if (data_[1].size()) + return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; + sparse_ = true; + } + if (offset < 0) + return net::ERR_FAILED; + if (!buf_len) + return 0; + + DCHECK(offset < kint32max); + int real_offset = static_cast<int>(offset); + + if (static_cast<int>(data_[1].size()) < real_offset + buf_len) + data_[1].resize(real_offset + buf_len); + + memcpy(&data_[1][real_offset], buf->data(), buf_len); + return buf_len; + } + + virtual int GetAvailableRange(int64 offset, int len, int64* start) { + if (!sparse_) + return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; + if (offset < 0) + return net::ERR_FAILED; + + *start = offset; + DCHECK(offset < kint32max); + int real_offset = static_cast<int>(offset); + if (static_cast<int>(data_[1].size()) < real_offset) + return 0; + + int num = std::min(static_cast<int>(data_[1].size()) - real_offset, len); + int count = 0; + for (; num > 0; num--, real_offset++) { + if (!count) { + if (data_[1][real_offset]) { + count++; + *start = real_offset; + } + } else { + if (!data_[1][real_offset]) + break; + count++; + } + } + return count; + } + private: // Unlike the callbacks for MockHttpTransaction, we want this one to run even // if the consumer called Close on the MockDiskEntry. We achieve that by @@ -132,6 +206,7 @@ class MockDiskEntry : public disk_cache::Entry, std::vector<char> data_[2]; int test_mode_; bool doomed_; + bool sparse_; }; class MockDiskCache : public disk_cache::Backend { |