Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Unified Diff: net/http/http_cache_unittest.cc

Issue 119072: Disk cache: Interface for the sparse cache support.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« net/base/net_error_list.h ('K') | « net/disk_cache/mem_entry_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_cache_unittest.cc
===================================================================
--- net/http/http_cache_unittest.cc (revision 17450)
+++ net/http/http_cache_unittest.cc (working copy)
@@ -27,11 +27,11 @@
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 @@
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 @@
std::vector<char> data_[2];
int test_mode_;
bool doomed_;
+ bool sparse_;
};
class MockDiskCache : public disk_cache::Backend {
« net/base/net_error_list.h ('K') | « net/disk_cache/mem_entry_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698