summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-17 21:59:39 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-17 21:59:39 +0000
commit3f73cd3125ed49700efa501a330eebc322421433 (patch)
treee1133de7529df3507f9003db310b515bdc45afac
parenta03c3d75111333c6f34ee8e6c2f3bac3208f4a13 (diff)
downloadchromium_src-3f73cd3125ed49700efa501a330eebc322421433.zip
chromium_src-3f73cd3125ed49700efa501a330eebc322421433.tar.gz
chromium_src-3f73cd3125ed49700efa501a330eebc322421433.tar.bz2
Disk Cache: Remove deprecated methods from the disk cache interface.
BUG=26730 TEST=current tests Review URL: http://codereview.chromium.org/2869005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50147 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/disk_cache/backend_impl.cc52
-rw-r--r--net/disk_cache/backend_impl.h24
-rw-r--r--net/disk_cache/backend_unittest.cc2
-rw-r--r--net/disk_cache/disk_cache.h54
-rw-r--r--net/disk_cache/disk_cache_perftest.cc8
-rw-r--r--net/disk_cache/entry_impl.h4
-rw-r--r--net/disk_cache/entry_unittest.cc86
-rw-r--r--net/disk_cache/mem_backend_impl.h18
-rw-r--r--net/disk_cache/mem_entry_impl.h4
-rw-r--r--net/disk_cache/sparse_control.cc12
-rw-r--r--net/disk_cache/sparse_control.h2
-rw-r--r--net/disk_cache/stress_cache.cc3
-rw-r--r--net/http/http_cache_unittest.cc41
-rw-r--r--net/tools/dump_cache/cache_dumper.cc17
-rw-r--r--net/tools/dump_cache/cache_dumper.h15
-rw-r--r--net/tools/dump_cache/upgrade.cc17
16 files changed, 168 insertions, 191 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index 8fa56f0..5e761e1 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -366,9 +366,9 @@ int32 BackendImpl::GetEntryCount() const {
return not_deleted;
}
-bool BackendImpl::OpenEntry(const std::string& key, Entry** entry) {
+EntryImpl* BackendImpl::OpenEntryImpl(const std::string& key) {
if (disabled_)
- return false;
+ return NULL;
TimeTicks start = TimeTicks::Now();
uint32 hash = Hash(key);
@@ -376,23 +376,27 @@ bool BackendImpl::OpenEntry(const std::string& key, Entry** entry) {
EntryImpl* cache_entry = MatchEntry(key, hash, false);
if (!cache_entry) {
stats_.OnEvent(Stats::OPEN_MISS);
- return false;
+ return NULL;
}
if (ENTRY_NORMAL != cache_entry->entry()->Data()->state) {
// The entry was already evicted.
cache_entry->Release();
stats_.OnEvent(Stats::OPEN_MISS);
- return false;
+ return NULL;
}
eviction_.OnOpenEntry(cache_entry);
- DCHECK(entry);
- *entry = cache_entry;
CACHE_UMA(AGE_MS, "OpenTime", GetSizeGroup(), start);
stats_.OnEvent(Stats::OPEN_HIT);
- return true;
+ return cache_entry;
+}
+
+bool BackendImpl::OpenEntry(const std::string& key, Entry** entry) {
+ DCHECK(entry);
+ *entry = OpenEntryImpl(key);
+ return (*entry) ? true : false;
}
int BackendImpl::OpenEntry(const std::string& key, Entry** entry,
@@ -403,12 +407,9 @@ int BackendImpl::OpenEntry(const std::string& key, Entry** entry,
return net::ERR_FAILED;
}
-bool BackendImpl::CreateEntry(const std::string& key, Entry** entry) {
+EntryImpl* BackendImpl::CreateEntryImpl(const std::string& key) {
if (disabled_ || key.empty())
- return false;
-
- DCHECK(entry);
- *entry = NULL;
+ return NULL;
TimeTicks start = TimeTicks::Now();
uint32 hash = Hash(key);
@@ -420,12 +421,12 @@ bool BackendImpl::CreateEntry(const std::string& key, Entry** entry) {
// a hash conflict.
EntryImpl* old_entry = MatchEntry(key, hash, false);
if (old_entry)
- return ResurrectEntry(old_entry, entry);
+ return ResurrectEntry(old_entry);
EntryImpl* parent_entry = MatchEntry(key, hash, true);
if (!parent_entry) {
NOTREACHED();
- return false;
+ return NULL;
}
parent.swap(&parent_entry);
}
@@ -441,7 +442,7 @@ bool BackendImpl::CreateEntry(const std::string& key, Entry** entry) {
if (!block_files_.CreateBlock(BLOCK_256, num_blocks, &entry_address)) {
LOG(ERROR) << "Create entry failed " << key.c_str();
stats_.OnEvent(Stats::CREATE_ERROR);
- return false;
+ return NULL;
}
Addr node_address(0);
@@ -449,7 +450,7 @@ bool BackendImpl::CreateEntry(const std::string& key, Entry** entry) {
block_files_.DeleteBlock(entry_address, false);
LOG(ERROR) << "Create entry failed " << key.c_str();
stats_.OnEvent(Stats::CREATE_ERROR);
- return false;
+ return NULL;
}
scoped_refptr<EntryImpl> cache_entry(new EntryImpl(this, entry_address));
@@ -460,7 +461,7 @@ bool BackendImpl::CreateEntry(const std::string& key, Entry** entry) {
block_files_.DeleteBlock(node_address, false);
LOG(ERROR) << "Create entry failed " << key.c_str();
stats_.OnEvent(Stats::CREATE_ERROR);
- return false;
+ return NULL;
}
// We are not failing the operation; let's add this to the map.
@@ -477,12 +478,16 @@ bool BackendImpl::CreateEntry(const std::string& key, Entry** entry) {
if (!parent.get())
data_->table[hash & mask_] = entry_address.value();
- cache_entry.swap(reinterpret_cast<EntryImpl**>(entry));
-
CACHE_UMA(AGE_MS, "CreateTime", GetSizeGroup(), start);
stats_.OnEvent(Stats::CREATE_HIT);
Trace("create entry hit ");
- return true;
+ return cache_entry.release();
+}
+
+bool BackendImpl::CreateEntry(const std::string& key, Entry** entry) {
+ DCHECK(entry);
+ *entry = CreateEntryImpl(key);
+ return (*entry) ? true : false;
}
int BackendImpl::CreateEntry(const std::string& key, Entry** entry,
@@ -1422,23 +1427,22 @@ EntryImpl* BackendImpl::GetEnumeratedEntry(CacheRankingsBlock* next,
return entry;
}
-bool BackendImpl::ResurrectEntry(EntryImpl* deleted_entry, Entry** entry) {
+EntryImpl* BackendImpl::ResurrectEntry(EntryImpl* deleted_entry) {
if (ENTRY_NORMAL == deleted_entry->entry()->Data()->state) {
deleted_entry->Release();
stats_.OnEvent(Stats::CREATE_MISS);
Trace("create entry miss ");
- return false;
+ return NULL;
}
// We are attempting to create an entry and found out that the entry was
// previously deleted.
eviction_.OnCreateEntry(deleted_entry);
- *entry = deleted_entry;
stats_.OnEvent(Stats::CREATE_HIT);
Trace("Resurrect entry hit ");
- return true;
+ return deleted_entry;
}
void BackendImpl::DestroyInvalidEntry(EntryImpl* entry) {
diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h
index aa87a63..706a0cb 100644
--- a/net/disk_cache/backend_impl.h
+++ b/net/disk_cache/backend_impl.h
@@ -63,25 +63,17 @@ class BackendImpl : public Backend {
// Backend interface.
virtual int32 GetEntryCount() const;
- virtual bool OpenEntry(const std::string& key, Entry** entry);
virtual int OpenEntry(const std::string& key, Entry** entry,
CompletionCallback* callback);
- virtual bool CreateEntry(const std::string& key, Entry** entry);
virtual int CreateEntry(const std::string& key, Entry** entry,
CompletionCallback* callback);
- virtual bool DoomEntry(const std::string& key);
virtual int DoomEntry(const std::string& key, CompletionCallback* callback);
- virtual bool DoomAllEntries();
virtual int DoomAllEntries(CompletionCallback* callback);
- virtual bool DoomEntriesBetween(const base::Time initial_time,
- const base::Time end_time);
virtual int DoomEntriesBetween(const base::Time initial_time,
const base::Time end_time,
CompletionCallback* callback);
- virtual bool DoomEntriesSince(const base::Time initial_time);
virtual int DoomEntriesSince(const base::Time initial_time,
CompletionCallback* callback);
- virtual bool OpenNextEntry(void** iter, Entry** next_entry);
virtual int OpenNextEntry(void** iter, Entry** next_entry,
CompletionCallback* callback);
virtual void EndEnumeration(void** iter);
@@ -208,6 +200,20 @@ class BackendImpl : public Backend {
// Same bahavior as OpenNextEntry but walks the list from back to front.
bool OpenPrevEntry(void** iter, Entry** prev_entry);
+ // Old Backend interface.
+ bool OpenEntry(const std::string& key, Entry** entry);
+ bool CreateEntry(const std::string& key, Entry** entry);
+ bool DoomEntry(const std::string& key);
+ bool DoomAllEntries();
+ bool DoomEntriesBetween(const base::Time initial_time,
+ const base::Time end_time);
+ bool DoomEntriesSince(const base::Time initial_time);
+ bool OpenNextEntry(void** iter, Entry** next_entry);
+
+ // Open or create an entry for the given |key|.
+ EntryImpl* OpenEntryImpl(const std::string& key);
+ EntryImpl* CreateEntryImpl(const std::string& key);
+
private:
typedef base::hash_map<CacheAddr, EntryImpl*> EntriesMap;
@@ -244,7 +250,7 @@ class BackendImpl : public Backend {
EntryImpl* GetEnumeratedEntry(CacheRankingsBlock* next, bool to_evict);
// Re-opens an entry that was previously deleted.
- bool ResurrectEntry(EntryImpl* deleted_entry, Entry** entry);
+ EntryImpl* ResurrectEntry(EntryImpl* deleted_entry);
void DestroyInvalidEntry(EntryImpl* entry);
void DestroyInvalidEntryFromEnumeration(EntryImpl* entry);
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index c659088..efb7925 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -1046,7 +1046,7 @@ void DiskCacheBackendTest::BackendTransaction(const std::wstring& name,
std::string key("the first key");
disk_cache::Entry* entry1;
- ASSERT_FALSE(cache_->OpenEntry(key, &entry1));
+ ASSERT_NE(net::OK, OpenEntry(key, &entry1));
int actual = cache_->GetEntryCount();
if (num_entries != actual) {
diff --git a/net/disk_cache/disk_cache.h b/net/disk_cache/disk_cache.h
index 2cddf6f..b2d76a4 100644
--- a/net/disk_cache/disk_cache.h
+++ b/net/disk_cache/disk_cache.h
@@ -65,13 +65,6 @@ class Backend {
// Returns the number of entries in the cache.
virtual int32 GetEntryCount() const = 0;
- // Opens an existing entry. Upon success, the out param holds a pointer
- // to a Entry object representing the specified disk cache entry.
- // When the entry pointer is no longer needed, the Close method
- // should be called.
- // Note: This method is deprecated.
- virtual bool OpenEntry(const std::string& key, Entry** entry) = 0;
-
// Opens an existing entry. Upon success, |entry| holds a pointer to an Entry
// object representing the specified disk cache entry. When the entry pointer
// is no longer needed, its Close method should be called. The return value is
@@ -81,13 +74,6 @@ class Backend {
virtual int OpenEntry(const std::string& key, Entry** entry,
CompletionCallback* callback) = 0;
- // Creates a new entry. Upon success, the out param holds a pointer
- // to a Entry object representing the newly created disk cache
- // entry. When the entry pointer is no longer needed, the Close
- // method should be called.
- // Note: This method is deprecated.
- virtual bool CreateEntry(const std::string& key, Entry** entry) = 0;
-
// Creates a new entry. Upon success, the out param holds a pointer to an
// Entry object representing the newly created disk cache entry. When the
// entry pointer is no longer needed, its Close method should be called. The
@@ -97,32 +83,18 @@ class Backend {
virtual int CreateEntry(const std::string& key, Entry** entry,
CompletionCallback* callback) = 0;
- // Marks the entry, specified by the given key, for deletion.
- // Note: This method is deprecated.
- virtual bool DoomEntry(const std::string& key) = 0;
-
// Marks the entry, specified by the given key, for deletion. The return value
// is a net error code. If this method returns ERR_IO_PENDING, the |callback|
// will be invoked after the entry is doomed.
virtual int DoomEntry(const std::string& key,
CompletionCallback* callback) = 0;
- // Marks all entries for deletion.
- // Note: This method is deprecated.
- virtual bool DoomAllEntries() = 0;
-
// Marks all entries for deletion. The return value is a net error code. If
// this method returns ERR_IO_PENDING, the |callback| will be invoked when the
// operation completes.
virtual int DoomAllEntries(CompletionCallback* callback) = 0;
// Marks a range of entries for deletion. This supports unbounded deletes in
- // either direction by using null Time values for either argument.
- // Note: This method is deprecated.
- virtual bool DoomEntriesBetween(const base::Time initial_time,
- const base::Time end_time) = 0;
-
- // Marks a range of entries for deletion. This supports unbounded deletes in
// either direction by using null Time values for either argument. The return
// value is a net error code. If this method returns ERR_IO_PENDING, the
// |callback| will be invoked when the operation completes.
@@ -130,28 +102,12 @@ class Backend {
const base::Time end_time,
CompletionCallback* callback) = 0;
- // Marks all entries accessed since initial_time for deletion.
- // Note: This method is deprecated.
- virtual bool DoomEntriesSince(const base::Time initial_time) = 0;
-
// Marks all entries accessed since |initial_time| for deletion. The return
// value is a net error code. If this method returns ERR_IO_PENDING, the
// |callback| will be invoked when the operation completes.
virtual int DoomEntriesSince(const base::Time initial_time,
CompletionCallback* callback) = 0;
- // Enumerate the cache. Initialize iter to NULL before calling this method
- // the first time. That will cause the enumeration to start at the head of
- // the cache. For subsequent calls, pass the same iter pointer again without
- // changing its value. This method returns false when there are no more
- // entries to enumerate. When the entry pointer is no longer needed, the
- // Close method should be called.
- //
- // NOTE: This method does not modify the last_used field of the entry,
- // and therefore it does not impact the eviction ranking of the entry.
- // Note: This method is deprecated.
- virtual bool OpenNextEntry(void** iter, Entry** next_entry) = 0;
-
// Enumerates the cache. Initialize |iter| to NULL before calling this method
// the first time. That will cause the enumeration to start at the head of
// the cache. For subsequent calls, pass the same |iter| pointer again without
@@ -294,16 +250,6 @@ class Entry {
// first byte that is stored within this range, and the return value is the
// minimum number of consecutive stored bytes. Note that it is possible that
// this entry has stored more than the returned value. This method returns a
- // net error code whenever the request cannot be completed successfully.
- // Note: This method is deprecated.
- virtual int GetAvailableRange(int64 offset, int len, int64* start) = 0;
-
- // Returns information about the currently stored portion of a sparse entry.
- // |offset| and |len| describe a particular range that should be scanned to
- // find out if it is stored or not. |start| will contain the offset of the
- // first byte that is stored within this range, and the return value is the
- // minimum number of consecutive stored bytes. Note that it is possible that
- // this entry has stored more than the returned value. This method returns a
// net error code whenever the request cannot be completed successfully. If
// this method returns ERR_IO_PENDING, the |callback| will be invoked when the
// operation completes, and |start| must remain valid until that point.
diff --git a/net/disk_cache/disk_cache_perftest.cc b/net/disk_cache/disk_cache_perftest.cc
index 6e0ca8a..1f1514d 100644
--- a/net/disk_cache/disk_cache_perftest.cc
+++ b/net/disk_cache/disk_cache_perftest.cc
@@ -66,7 +66,9 @@ int TimeWrite(int num_entries, disk_cache::Backend* cache,
entries->push_back(entry);
disk_cache::Entry* cache_entry;
- if (!cache->CreateEntry(entry.key, &cache_entry))
+ TestCompletionCallback cb;
+ int rv = cache->CreateEntry(entry.key, &cache_entry, &cb);
+ if (net::OK != cb.GetResult(rv))
break;
int ret = cache_entry->WriteData(0, 0, buffer1, kSize1, &callback, false);
if (net::ERR_IO_PENDING == ret)
@@ -112,7 +114,9 @@ int TimeRead(int num_entries, disk_cache::Backend* cache,
for (int i = 0; i < num_entries; i++) {
disk_cache::Entry* cache_entry;
- if (!cache->OpenEntry(entries[i].key, &cache_entry))
+ TestCompletionCallback cb;
+ int rv = cache->OpenEntry(entries[i].key, &cache_entry, &cb);
+ if (net::OK != cb.GetResult(rv))
break;
int ret = cache_entry->ReadData(0, 0, buffer1, kSize1, &callback);
if (net::ERR_IO_PENDING == ret)
diff --git a/net/disk_cache/entry_impl.h b/net/disk_cache/entry_impl.h
index 9c39223..8ab4d44 100644
--- a/net/disk_cache/entry_impl.h
+++ b/net/disk_cache/entry_impl.h
@@ -47,7 +47,6 @@ class EntryImpl : public Entry, public base::RefCounted<EntryImpl> {
net::CompletionCallback* completion_callback);
virtual int WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
net::CompletionCallback* completion_callback);
- virtual int GetAvailableRange(int64 offset, int len, int64* start);
virtual int GetAvailableRange(int64 offset, int len, int64* start,
CompletionCallback* callback);
virtual bool CouldBeSparse() const;
@@ -122,6 +121,9 @@ class EntryImpl : public Entry, public base::RefCounted<EntryImpl> {
~EntryImpl();
+ // Old Entry interface.
+ int GetAvailableRange(int64 offset, int len, int64* start);
+
// Initializes the storage for an internal or external data block.
bool CreateDataBlock(int index, int size);
diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc
index e2a17b0..95bbb47 100644
--- a/net/disk_cache/entry_unittest.cc
+++ b/net/disk_cache/entry_unittest.cc
@@ -1026,28 +1026,37 @@ void DiskCacheEntryTest::GetAvailableRange() {
// We stop at the first empty block.
int64 start;
- EXPECT_EQ(kSize, entry->GetAvailableRange(0x20F0000, kSize * 2, &start));
+ TestCompletionCallback cb;
+ int rv = entry->GetAvailableRange(0x20F0000, kSize * 2, &start, &cb);
+ EXPECT_EQ(kSize, cb.GetResult(rv));
EXPECT_EQ(0x20F0000, start);
start = 0;
- EXPECT_EQ(0, entry->GetAvailableRange(0, kSize, &start));
- EXPECT_EQ(0, entry->GetAvailableRange(0x20F0000 - kSize, kSize, &start));
- EXPECT_EQ(kSize, entry->GetAvailableRange(0, 0x2100000, &start));
+ rv = entry->GetAvailableRange(0, kSize, &start, &cb);
+ EXPECT_EQ(0, cb.GetResult(rv));
+ rv = entry->GetAvailableRange(0x20F0000 - kSize, kSize, &start, &cb);
+ EXPECT_EQ(0, cb.GetResult(rv));
+ rv = entry->GetAvailableRange(0, 0x2100000, &start, &cb);
+ EXPECT_EQ(kSize, cb.GetResult(rv));
EXPECT_EQ(0x20F0000, start);
// We should be able to Read based on the results of GetAvailableRange.
start = -1;
- EXPECT_EQ(0, entry->GetAvailableRange(0x2100000, kSize, &start));
- EXPECT_EQ(0, entry->ReadSparseData(start, buf, kSize, NULL));
+ rv = entry->GetAvailableRange(0x2100000, kSize, &start, &cb);
+ EXPECT_EQ(0, cb.GetResult(rv));
+ rv = entry->ReadSparseData(start, buf, kSize, &cb);
+ EXPECT_EQ(0, cb.GetResult(rv));
start = 0;
- EXPECT_EQ(0x2000, entry->GetAvailableRange(0x20F2000, kSize, &start));
+ rv = entry->GetAvailableRange(0x20F2000, kSize, &start, &cb);
+ EXPECT_EQ(0x2000, cb.GetResult(rv));
EXPECT_EQ(0x20F2000, start);
EXPECT_EQ(0x2000, entry->ReadSparseData(start, buf, kSize, NULL));
// Make sure that we respect the |len| argument.
start = 0;
- EXPECT_EQ(1, entry->GetAvailableRange(0x20F0001 - kSize, kSize, &start));
+ rv = entry->GetAvailableRange(0x20F0001 - kSize, kSize, &start, &cb);
+ EXPECT_EQ(1, cb.GetResult(rv));
EXPECT_EQ(0x20F0000, start);
entry->Close();
@@ -1163,31 +1172,38 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyMisalignedGetAvailableRange) {
EXPECT_EQ(8192, entry->WriteSparseData(50000, buf, 8192, NULL));
int64 start;
+ TestCompletionCallback cb;
// Test that we stop at a discontinuous child at the second block.
- EXPECT_EQ(1024, entry->GetAvailableRange(0, 10000, &start));
+ int rv = entry->GetAvailableRange(0, 10000, &start, &cb);
+ EXPECT_EQ(1024, cb.GetResult(rv));
EXPECT_EQ(0, start);
// Test that number of bytes is reported correctly when we start from the
// middle of a filled region.
- EXPECT_EQ(512, entry->GetAvailableRange(512, 10000, &start));
+ rv = entry->GetAvailableRange(512, 10000, &start, &cb);
+ EXPECT_EQ(512, cb.GetResult(rv));
EXPECT_EQ(512, start);
// Test that we found bytes in the child of next block.
- EXPECT_EQ(1024, entry->GetAvailableRange(1024, 10000, &start));
+ rv = entry->GetAvailableRange(1024, 10000, &start, &cb);
+ EXPECT_EQ(1024, cb.GetResult(rv));
EXPECT_EQ(5120, start);
// Test that the desired length is respected. It starts within a filled
// region.
- EXPECT_EQ(512, entry->GetAvailableRange(5500, 512, &start));
+ rv = entry->GetAvailableRange(5500, 512, &start, &cb);
+ EXPECT_EQ(512, cb.GetResult(rv));
EXPECT_EQ(5500, start);
// Test that the desired length is respected. It starts before a filled
// region.
- EXPECT_EQ(500, entry->GetAvailableRange(5000, 620, &start));
+ rv = entry->GetAvailableRange(5000, 620, &start, &cb);
+ EXPECT_EQ(500, cb.GetResult(rv));
EXPECT_EQ(5120, start);
// Test that multiple blocks are scanned.
- EXPECT_EQ(8192, entry->GetAvailableRange(40000, 20000, &start));
+ rv = entry->GetAvailableRange(40000, 20000, &start, &cb);
+ EXPECT_EQ(8192, cb.GetResult(rv));
EXPECT_EQ(50000, start);
entry->Close();
@@ -1292,37 +1308,48 @@ void DiskCacheEntryTest::PartialSparseEntry() {
EXPECT_EQ(500, entry->ReadSparseData(kSize, buf2, kSize, NULL));
EXPECT_EQ(0, entry->ReadSparseData(499, buf2, kSize, NULL));
+ int rv;
int64 start;
+ TestCompletionCallback cb;
if (memory_only_) {
- EXPECT_EQ(100, entry->GetAvailableRange(0, 600, &start));
+ rv = entry->GetAvailableRange(0, 600, &start, &cb);
+ EXPECT_EQ(100, cb.GetResult(rv));
EXPECT_EQ(500, start);
} else {
- EXPECT_EQ(1024, entry->GetAvailableRange(0, 2048, &start));
+ rv = entry->GetAvailableRange(0, 2048, &start, &cb);
+ EXPECT_EQ(1024, cb.GetResult(rv));
EXPECT_EQ(1024, start);
}
- EXPECT_EQ(500, entry->GetAvailableRange(kSize, kSize, &start));
+ rv = entry->GetAvailableRange(kSize, kSize, &start, &cb);
+ EXPECT_EQ(500, cb.GetResult(rv));
EXPECT_EQ(kSize, start);
- EXPECT_EQ(3616, entry->GetAvailableRange(20 * 1024, 10000, &start));
+ rv = entry->GetAvailableRange(20 * 1024, 10000, &start, &cb);
+ EXPECT_EQ(3616, cb.GetResult(rv));
EXPECT_EQ(20 * 1024, start);
// 1. Query before a filled 1KB block.
// 2. Query within a filled 1KB block.
// 3. Query beyond a filled 1KB block.
if (memory_only_) {
- EXPECT_EQ(3496, entry->GetAvailableRange(19400, kSize, &start));
+ rv = entry->GetAvailableRange(19400, kSize, &start, &cb);
+ EXPECT_EQ(3496, cb.GetResult(rv));
EXPECT_EQ(20000, start);
} else {
- EXPECT_EQ(3016, entry->GetAvailableRange(19400, kSize, &start));
+ rv = entry->GetAvailableRange(19400, kSize, &start, &cb);
+ EXPECT_EQ(3016, cb.GetResult(rv));
EXPECT_EQ(20480, start);
}
- EXPECT_EQ(1523, entry->GetAvailableRange(3073, kSize, &start));
+ rv = entry->GetAvailableRange(3073, kSize, &start, &cb);
+ EXPECT_EQ(1523, cb.GetResult(rv));
EXPECT_EQ(3073, start);
- EXPECT_EQ(0, entry->GetAvailableRange(4600, kSize, &start));
+ rv = entry->GetAvailableRange(4600, kSize, &start, &cb);
+ EXPECT_EQ(0, cb.GetResult(rv));
EXPECT_EQ(4600, start);
// Now make another write and verify that there is no hole in between.
EXPECT_EQ(kSize, entry->WriteSparseData(500 + kSize, buf1, kSize, NULL));
- EXPECT_EQ(7 * 1024 + 500, entry->GetAvailableRange(1024, 10000, &start));
+ rv = entry->GetAvailableRange(1024, 10000, &start, &cb);
+ EXPECT_EQ(7 * 1024 + 500, cb.GetResult(rv));
EXPECT_EQ(1024, start);
EXPECT_EQ(kSize, entry->ReadSparseData(kSize, buf2, kSize, NULL));
EXPECT_EQ(0, memcmp(buf2->data(), buf1->data() + kSize - 500, 500));
@@ -1403,7 +1430,7 @@ TEST_F(DiskCacheEntryTest, CancelSparseIO) {
scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize);
CacheTestFillBuffer(buf->data(), kSize, false);
- TestCompletionCallback cb1, cb2, cb3, cb4;
+ TestCompletionCallback cb1, cb2, cb3, cb4, cb5;
int64 offset = 0;
int tries = 0;
const int maxtries = 100; // Avoid hang on infinitely fast disks.
@@ -1418,8 +1445,8 @@ TEST_F(DiskCacheEntryTest, CancelSparseIO) {
// Cannot use the entry at this point.
offset = 0;
- EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED,
- entry->GetAvailableRange(offset, kSize, &offset));
+ int rv = entry->GetAvailableRange(offset, kSize, &offset, &cb5);
+ EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED, cb5.GetResult(rv));
EXPECT_EQ(net::OK, entry->ReadyForSparseIO(&cb2));
// We cancel the pending operation, and register multiple notifications.
@@ -1430,8 +1457,8 @@ TEST_F(DiskCacheEntryTest, CancelSparseIO) {
EXPECT_EQ(net::ERR_IO_PENDING, entry->ReadyForSparseIO(&cb4));
offset = 0;
- EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED,
- entry->GetAvailableRange(offset, kSize, &offset));
+ rv = entry->GetAvailableRange(offset, kSize, &offset, &cb5);
+ EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED, cb5.GetResult(rv));
EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED,
entry->ReadSparseData(offset, buf, kSize, NULL));
EXPECT_EQ(net::ERR_CACHE_OPERATION_NOT_SUPPORTED,
@@ -1443,7 +1470,8 @@ TEST_F(DiskCacheEntryTest, CancelSparseIO) {
EXPECT_EQ(net::OK, cb3.GetResult(net::ERR_IO_PENDING));
EXPECT_EQ(net::OK, cb4.GetResult(net::ERR_IO_PENDING));
- EXPECT_EQ(kSize, entry->GetAvailableRange(offset, kSize, &offset));
+ rv = entry->GetAvailableRange(offset, kSize, &offset, &cb5);
+ EXPECT_EQ(kSize, cb5.GetResult(rv));
EXPECT_EQ(net::OK, entry->ReadyForSparseIO(&cb2));
entry->Close();
}
diff --git a/net/disk_cache/mem_backend_impl.h b/net/disk_cache/mem_backend_impl.h
index 2072a56..c5e947f 100644
--- a/net/disk_cache/mem_backend_impl.h
+++ b/net/disk_cache/mem_backend_impl.h
@@ -35,25 +35,17 @@ class MemBackendImpl : public Backend {
// Backend interface.
virtual int32 GetEntryCount() const;
- virtual bool OpenEntry(const std::string& key, Entry** entry);
virtual int OpenEntry(const std::string& key, Entry** entry,
CompletionCallback* callback);
- virtual bool CreateEntry(const std::string& key, Entry** entry);
virtual int CreateEntry(const std::string& key, Entry** entry,
CompletionCallback* callback);
- virtual bool DoomEntry(const std::string& key);
virtual int DoomEntry(const std::string& key, CompletionCallback* callback);
- virtual bool DoomAllEntries();
virtual int DoomAllEntries(CompletionCallback* callback);
- virtual bool DoomEntriesBetween(const base::Time initial_time,
- const base::Time end_time);
virtual int DoomEntriesBetween(const base::Time initial_time,
const base::Time end_time,
CompletionCallback* callback);
- virtual bool DoomEntriesSince(const base::Time initial_time);
virtual int DoomEntriesSince(const base::Time initial_time,
CompletionCallback* callback);
- virtual bool OpenNextEntry(void** iter, Entry** next_entry);
virtual int OpenNextEntry(void** iter, Entry** next_entry,
CompletionCallback* callback);
virtual void EndEnumeration(void** iter);
@@ -85,6 +77,16 @@ class MemBackendImpl : public Backend {
void RemoveFromRankingList(MemEntryImpl* entry);
private:
+ // Old Backend interface.
+ bool OpenEntry(const std::string& key, Entry** entry);
+ bool CreateEntry(const std::string& key, Entry** entry);
+ bool DoomEntry(const std::string& key);
+ bool DoomAllEntries();
+ bool DoomEntriesBetween(const base::Time initial_time,
+ const base::Time end_time);
+ bool DoomEntriesSince(const base::Time initial_time);
+ bool OpenNextEntry(void** iter, Entry** next_entry);
+
// Deletes entries from the cache until the current size is below the limit.
// If empty is true, the whole cache will be trimmed, regardless of being in
// use.
diff --git a/net/disk_cache/mem_entry_impl.h b/net/disk_cache/mem_entry_impl.h
index 8703585..66535d5 100644
--- a/net/disk_cache/mem_entry_impl.h
+++ b/net/disk_cache/mem_entry_impl.h
@@ -67,7 +67,6 @@ class MemEntryImpl : public Entry {
net::CompletionCallback* completion_callback);
virtual int WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
net::CompletionCallback* completion_callback);
- virtual int GetAvailableRange(int64 offset, int len, int64* start);
virtual int GetAvailableRange(int64 offset, int len, int64* start,
CompletionCallback* callback);
virtual bool CouldBeSparse() const;
@@ -113,6 +112,9 @@ class MemEntryImpl : public Entry {
~MemEntryImpl();
+ // Old Entry interface.
+ int GetAvailableRange(int64 offset, int len, int64* start);
+
// Grows and cleans up the data buffer.
void PrepareTarget(int index, int offset, int buf_len);
diff --git a/net/disk_cache/sparse_control.cc b/net/disk_cache/sparse_control.cc
index e521c3e..2d9d3c1 100644
--- a/net/disk_cache/sparse_control.cc
+++ b/net/disk_cache/sparse_control.cc
@@ -374,8 +374,11 @@ bool SparseControl::OpenChild() {
}
// Se if we are tracking this child.
- bool child_present = ChildPresent();
- if (!child_present || !entry_->backend_->OpenEntry(key, &child_))
+ if (!ChildPresent())
+ return ContinueWithoutChild(key);
+
+ child_ = entry_->backend_->OpenEntryImpl(key);
+ if (!child_)
return ContinueWithoutChild(key);
EntryImpl* child = static_cast<EntryImpl*>(child_);
@@ -398,7 +401,7 @@ bool SparseControl::OpenChild() {
if (child_data_.header.last_block_len < 0 ||
child_data_.header.last_block_len > kBlockSize) {
- // Make sure this values are always within range.
+ // Make sure these values are always within range.
child_data_.header.last_block_len = 0;
child_data_.header.last_block = -1;
}
@@ -444,7 +447,8 @@ bool SparseControl::ContinueWithoutChild(const std::string& key) {
if (kGetRangeOperation == operation_)
return true;
- if (!entry_->backend_->CreateEntry(key, &child_)) {
+ child_ = entry_->backend_->CreateEntryImpl(key);
+ if (!child_) {
child_ = NULL;
result_ = net::ERR_CACHE_READ_FAILURE;
return false;
diff --git a/net/disk_cache/sparse_control.h b/net/disk_cache/sparse_control.h
index ee77b4b..b88f258 100644
--- a/net/disk_cache/sparse_control.h
+++ b/net/disk_cache/sparse_control.h
@@ -150,7 +150,7 @@ class SparseControl {
void DoAbortCallbacks();
EntryImpl* entry_; // The sparse entry.
- Entry* child_; // The current child entry.
+ EntryImpl* child_; // The current child entry.
SparseOperation operation_;
bool pending_; // True if any child IO operation returned pending.
bool finished_;
diff --git a/net/disk_cache/stress_cache.cc b/net/disk_cache/stress_cache.cc
index f5c7880..db84fd8 100644
--- a/net/disk_cache/stress_cache.cc
+++ b/net/disk_cache/stress_cache.cc
@@ -134,7 +134,8 @@ void StressTheCache(int iteration) {
if (rand() % 100 > 80) {
key = rand() % kNumKeys;
- cache->DoomEntry(keys[key]);
+ rv = cache->DoomEntry(keys[key], &cb);
+ cb.GetResult(rv);
}
if (!(i % 100))
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index ed2f377..c477779 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -215,11 +215,6 @@ class MockDiskEntry : public disk_cache::Entry,
return net::ERR_IO_PENDING;
}
- virtual int GetAvailableRange(int64 offset, int len, int64* start) {
- NOTREACHED();
- return net::ERR_NOT_IMPLEMENTED;
- }
-
virtual int GetAvailableRange(int64 offset, int len, int64* start,
net::CompletionCallback* callback) {
DCHECK(callback);
@@ -383,11 +378,6 @@ class MockDiskCache : public disk_cache::Backend {
return static_cast<int32>(entries_.size());
}
- virtual bool OpenEntry(const std::string& key, disk_cache::Entry** entry) {
- NOTREACHED();
- return false;
- }
-
virtual int OpenEntry(const std::string& key, disk_cache::Entry** entry,
net::CompletionCallback* callback) {
DCHECK(callback);
@@ -419,11 +409,6 @@ class MockDiskCache : public disk_cache::Backend {
return net::ERR_IO_PENDING;
}
- virtual bool CreateEntry(const std::string& key, disk_cache::Entry** entry) {
- NOTREACHED();
- return false;
- }
-
virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry,
net::CompletionCallback* callback) {
DCHECK(callback);
@@ -457,11 +442,6 @@ class MockDiskCache : public disk_cache::Backend {
return net::ERR_IO_PENDING;
}
- virtual bool DoomEntry(const std::string& key) {
- NOTREACHED();
- return false;
- }
-
virtual int DoomEntry(const std::string& key,
net::CompletionCallback* callback) {
DCHECK(callback);
@@ -478,42 +458,21 @@ class MockDiskCache : public disk_cache::Backend {
return net::ERR_IO_PENDING;
}
- virtual bool DoomAllEntries() {
- NOTREACHED();
- return false;
- }
-
virtual int DoomAllEntries(net::CompletionCallback* callback) {
return net::ERR_NOT_IMPLEMENTED;
}
- virtual bool DoomEntriesBetween(const Time initial_time,
- const Time end_time) {
- NOTREACHED();
- return false;
- }
-
virtual int DoomEntriesBetween(const base::Time initial_time,
const base::Time end_time,
net::CompletionCallback* callback) {
return net::ERR_NOT_IMPLEMENTED;
}
- virtual bool DoomEntriesSince(const Time initial_time) {
- NOTREACHED();
- return false;
- }
-
virtual int DoomEntriesSince(const base::Time initial_time,
net::CompletionCallback* callback) {
return net::ERR_NOT_IMPLEMENTED;
}
- virtual bool OpenNextEntry(void** iter, disk_cache::Entry** next_entry) {
- NOTREACHED();
- return false;
- }
-
virtual int OpenNextEntry(void** iter, disk_cache::Entry** next_entry,
net::CompletionCallback* callback) {
return net::ERR_NOT_IMPLEMENTED;
diff --git a/net/tools/dump_cache/cache_dumper.cc b/net/tools/dump_cache/cache_dumper.cc
index 71720af..f573b2a 100644
--- a/net/tools/dump_cache/cache_dumper.cc
+++ b/net/tools/dump_cache/cache_dumper.cc
@@ -5,15 +5,17 @@
#include "net/tools/dump_cache/cache_dumper.h"
#include "net/base/io_buffer.h"
+#include "net/base/net_errors.h"
#include "net/disk_cache/entry_impl.h"
#include "net/http/http_cache.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_response_info.h"
#include "net/tools/dump_cache/url_to_filename_encoder.h"
-bool CacheDumper::CreateEntry(const std::string& key,
- disk_cache::Entry** entry) {
- return cache_->CreateEntry(key, entry);
+int CacheDumper::CreateEntry(const std::string& key,
+ disk_cache::Entry** entry,
+ net::CompletionCallback* callback) {
+ return cache_->CreateEntry(key, entry, callback);
}
int CacheDumper::WriteEntry(disk_cache::Entry* entry, int index, int offset,
@@ -61,8 +63,9 @@ bool SafeCreateDirectory(const std::wstring& path) {
#endif
}
-bool DiskDumper::CreateEntry(const std::string& key,
- disk_cache::Entry** entry) {
+int DiskDumper::CreateEntry(const std::string& key,
+ disk_cache::Entry** entry,
+ net::CompletionCallback* callback) {
FilePath path(path_);
// The URL may not start with a valid protocol; search for it.
int urlpos = key.find("http");
@@ -94,10 +97,10 @@ bool DiskDumper::CreateEntry(const std::string& key,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (entry_ == INVALID_HANDLE_VALUE)
wprintf(L"CreateFileW (%s) failed: %d\n", file.c_str(), GetLastError());
- return entry_ != INVALID_HANDLE_VALUE;
+ return (entry_ != INVALID_HANDLE_VALUE) ? net::OK : net::ERR_FAILED;
#else
entry_ = file_util::OpenFile(entry_path_, "w+");
- return entry_ != NULL;
+ return (entry_ != NULL) ? net::OK : net::ERR_FAILED;
#endif
}
diff --git a/net/tools/dump_cache/cache_dumper.h b/net/tools/dump_cache/cache_dumper.h
index 1af8573..d2e6034 100644
--- a/net/tools/dump_cache/cache_dumper.h
+++ b/net/tools/dump_cache/cache_dumper.h
@@ -26,12 +26,13 @@ class CacheDumpWriter {
// Creates an entry to be written.
// On success, populates the |entry|.
- // Returns true on success, false otherwise.
- virtual bool CreateEntry(const std::string& key,
- disk_cache::Entry** entry) = 0;
+ // Returns a net error code.
+ virtual int CreateEntry(const std::string& key,
+ disk_cache::Entry** entry,
+ net::CompletionCallback* callback) = 0;
// Write to the current entry.
- // Returns true on success, false otherwise.
+ // Returns a net error code.
virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset,
net::IOBuffer* buf, int buf_len,
net::CompletionCallback* callback) = 0;
@@ -46,7 +47,8 @@ class CacheDumper : public CacheDumpWriter {
public:
explicit CacheDumper(disk_cache::Backend* cache) : cache_(cache) {}
- virtual bool CreateEntry(const std::string& key, disk_cache::Entry** entry);
+ virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry,
+ net::CompletionCallback* callback);
virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset,
net::IOBuffer* buf, int buf_len,
net::CompletionCallback* callback);
@@ -63,7 +65,8 @@ class DiskDumper : public CacheDumpWriter {
explicit DiskDumper(const std::wstring& path) : path_(path), entry_(NULL) {
file_util::CreateDirectory(FilePath(path));
}
- virtual bool CreateEntry(const std::string& key, disk_cache::Entry** entry);
+ virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry,
+ net::CompletionCallback* callback);
virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset,
net::IOBuffer* buf, int buf_len,
net::CompletionCallback* callback);
diff --git a/net/tools/dump_cache/upgrade.cc b/net/tools/dump_cache/upgrade.cc
index 4f565fe..5a3cd67 100644
--- a/net/tools/dump_cache/upgrade.cc
+++ b/net/tools/dump_cache/upgrade.cc
@@ -210,6 +210,8 @@ class MasterSM : public BaseSM {
MasterSM(const std::wstring& path, HANDLE channel, bool dump_to_disk)
: BaseSM(channel), path_(path), dump_to_disk_(dump_to_disk),
ALLOW_THIS_IN_INITIALIZER_LIST(
+ create_callback_(this, &MasterSM::DoCreateEntryComplete)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(
write_callback_(this, &MasterSM::DoReadDataComplete)) {
}
virtual ~MasterSM() {
@@ -236,6 +238,7 @@ class MasterSM : public BaseSM {
void SendGetPrevEntry();
void DoGetEntry();
void DoGetKey(int bytes_read);
+ void DoCreateEntryComplete(int result);
void DoGetUseTimes();
void SendGetDataSize();
void DoGetDataSize();
@@ -259,6 +262,7 @@ class MasterSM : public BaseSM {
CacheDumpWriter* writer_;
const std::wstring& path_;
bool dump_to_disk_;
+ net::CompletionCallbackImpl<MasterSM> create_callback_;
net::CompletionCallbackImpl<MasterSM> write_callback_;
};
@@ -388,8 +392,17 @@ void MasterSM::DoGetKey(int bytes_read) {
std::string key(input_->buffer);
DCHECK(key.size() == static_cast<size_t>(input_->msg.buffer_bytes - 1));
- if (!writer_->CreateEntry(key,
- reinterpret_cast<disk_cache::Entry**>(&entry_))) {
+ int rv = writer_->CreateEntry(key,
+ reinterpret_cast<disk_cache::Entry**>(&entry_),
+ &create_callback_);
+
+ if (rv != net::ERR_IO_PENDING)
+ DoCreateEntryComplete(rv);
+}
+
+void MasterSM::DoCreateEntryComplete(int result) {
+ std::string key(input_->buffer);
+ if (result != net::OK) {
printf("Skipping entry \"%s\": %d\n", key.c_str(), GetLastError());
return SendGetPrevEntry();
}