summaryrefslogtreecommitdiffstats
path: root/net/disk_cache
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-07 23:02:11 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-07 23:02:11 +0000
commit4b3c95dd199586b4c540800be8cd223e948e5e3f (patch)
treec97ef865a3c85f09e920d8b1bc4024a56bb8e8cf /net/disk_cache
parentd160ec0e875e98829684f040d843e6a292dbb3ba (diff)
downloadchromium_src-4b3c95dd199586b4c540800be8cd223e948e5e3f.zip
chromium_src-4b3c95dd199586b4c540800be8cd223e948e5e3f.tar.gz
chromium_src-4b3c95dd199586b4c540800be8cd223e948e5e3f.tar.bz2
Start reordering the methods in headers in net/.
This patch also starts reordering some of the cc files to match their headers. More of both cleanups will be done in future patches. BUG=68682 TEST=compiles Review URL: http://codereview.chromium.org/6085013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70799 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r--net/disk_cache/backend_impl.cc192
-rw-r--r--net/disk_cache/backend_impl.h36
-rw-r--r--net/disk_cache/entry_impl.cc714
-rw-r--r--net/disk_cache/entry_impl.h44
-rw-r--r--net/disk_cache/file.h4
-rw-r--r--net/disk_cache/mem_backend_impl.cc216
-rw-r--r--net/disk_cache/mem_backend_impl.h42
-rw-r--r--net/disk_cache/rankings.h5
8 files changed, 626 insertions, 627 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index 223c970..31320a78 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -435,102 +435,6 @@ BackendImpl::~BackendImpl() {
// ------------------------------------------------------------------------
-int32 BackendImpl::GetEntryCount() const {
- if (!index_ || disabled_)
- return 0;
- // num_entries includes entries already evicted.
- int32 not_deleted = data_->header.num_entries -
- data_->header.lru.sizes[Rankings::DELETED];
-
- if (not_deleted < 0) {
- NOTREACHED();
- not_deleted = 0;
- }
-
- return not_deleted;
-}
-
-int BackendImpl::OpenEntry(const std::string& key, Entry** entry,
- CompletionCallback* callback) {
- DCHECK(callback);
- background_queue_.OpenEntry(key, entry, callback);
- return net::ERR_IO_PENDING;
-}
-
-int BackendImpl::CreateEntry(const std::string& key, Entry** entry,
- CompletionCallback* callback) {
- DCHECK(callback);
- background_queue_.CreateEntry(key, entry, callback);
- return net::ERR_IO_PENDING;
-}
-
-int BackendImpl::DoomEntry(const std::string& key,
- CompletionCallback* callback) {
- DCHECK(callback);
- background_queue_.DoomEntry(key, callback);
- return net::ERR_IO_PENDING;
-}
-
-int BackendImpl::DoomAllEntries(CompletionCallback* callback) {
- DCHECK(callback);
- background_queue_.DoomAllEntries(callback);
- return net::ERR_IO_PENDING;
-}
-
-int BackendImpl::DoomEntriesBetween(const base::Time initial_time,
- const base::Time end_time,
- CompletionCallback* callback) {
- DCHECK(callback);
- background_queue_.DoomEntriesBetween(initial_time, end_time, callback);
- return net::ERR_IO_PENDING;
-}
-
-int BackendImpl::DoomEntriesSince(const base::Time initial_time,
- CompletionCallback* callback) {
- DCHECK(callback);
- background_queue_.DoomEntriesSince(initial_time, callback);
- return net::ERR_IO_PENDING;
-}
-
-int BackendImpl::OpenNextEntry(void** iter, Entry** next_entry,
- CompletionCallback* callback) {
- DCHECK(callback);
- background_queue_.OpenNextEntry(iter, next_entry, callback);
- return net::ERR_IO_PENDING;
-}
-
-void BackendImpl::EndEnumeration(void** iter) {
- background_queue_.EndEnumeration(*iter);
- *iter = NULL;
-}
-
-void BackendImpl::GetStats(StatsItems* stats) {
- if (disabled_)
- return;
-
- std::pair<std::string, std::string> item;
-
- item.first = "Entries";
- item.second = base::StringPrintf("%d", data_->header.num_entries);
- stats->push_back(item);
-
- item.first = "Pending IO";
- item.second = base::StringPrintf("%d", num_pending_io_);
- stats->push_back(item);
-
- item.first = "Max size";
- item.second = base::StringPrintf("%d", max_size_);
- stats->push_back(item);
-
- item.first = "Current size";
- item.second = base::StringPrintf("%d", data_->header.num_bytes);
- stats->push_back(item);
-
- stats_.GetItems(stats);
-}
-
-// ------------------------------------------------------------------------
-
int BackendImpl::SyncInit() {
DCHECK(!init_);
if (init_)
@@ -1355,6 +1259,102 @@ int BackendImpl::SelfCheck() {
// ------------------------------------------------------------------------
+int32 BackendImpl::GetEntryCount() const {
+ if (!index_ || disabled_)
+ return 0;
+ // num_entries includes entries already evicted.
+ int32 not_deleted = data_->header.num_entries -
+ data_->header.lru.sizes[Rankings::DELETED];
+
+ if (not_deleted < 0) {
+ NOTREACHED();
+ not_deleted = 0;
+ }
+
+ return not_deleted;
+}
+
+int BackendImpl::OpenEntry(const std::string& key, Entry** entry,
+ CompletionCallback* callback) {
+ DCHECK(callback);
+ background_queue_.OpenEntry(key, entry, callback);
+ return net::ERR_IO_PENDING;
+}
+
+int BackendImpl::CreateEntry(const std::string& key, Entry** entry,
+ CompletionCallback* callback) {
+ DCHECK(callback);
+ background_queue_.CreateEntry(key, entry, callback);
+ return net::ERR_IO_PENDING;
+}
+
+int BackendImpl::DoomEntry(const std::string& key,
+ CompletionCallback* callback) {
+ DCHECK(callback);
+ background_queue_.DoomEntry(key, callback);
+ return net::ERR_IO_PENDING;
+}
+
+int BackendImpl::DoomAllEntries(CompletionCallback* callback) {
+ DCHECK(callback);
+ background_queue_.DoomAllEntries(callback);
+ return net::ERR_IO_PENDING;
+}
+
+int BackendImpl::DoomEntriesBetween(const base::Time initial_time,
+ const base::Time end_time,
+ CompletionCallback* callback) {
+ DCHECK(callback);
+ background_queue_.DoomEntriesBetween(initial_time, end_time, callback);
+ return net::ERR_IO_PENDING;
+}
+
+int BackendImpl::DoomEntriesSince(const base::Time initial_time,
+ CompletionCallback* callback) {
+ DCHECK(callback);
+ background_queue_.DoomEntriesSince(initial_time, callback);
+ return net::ERR_IO_PENDING;
+}
+
+int BackendImpl::OpenNextEntry(void** iter, Entry** next_entry,
+ CompletionCallback* callback) {
+ DCHECK(callback);
+ background_queue_.OpenNextEntry(iter, next_entry, callback);
+ return net::ERR_IO_PENDING;
+}
+
+void BackendImpl::EndEnumeration(void** iter) {
+ background_queue_.EndEnumeration(*iter);
+ *iter = NULL;
+}
+
+void BackendImpl::GetStats(StatsItems* stats) {
+ if (disabled_)
+ return;
+
+ std::pair<std::string, std::string> item;
+
+ item.first = "Entries";
+ item.second = base::StringPrintf("%d", data_->header.num_entries);
+ stats->push_back(item);
+
+ item.first = "Pending IO";
+ item.second = base::StringPrintf("%d", num_pending_io_);
+ stats->push_back(item);
+
+ item.first = "Max size";
+ item.second = base::StringPrintf("%d", max_size_);
+ stats->push_back(item);
+
+ item.first = "Current size";
+ item.second = base::StringPrintf("%d", data_->header.num_bytes);
+ stats->push_back(item);
+
+ stats_.GetItems(stats);
+}
+
+// ------------------------------------------------------------------------
+
// We just created a new file so we're going to write the header and set the
// file length to include the hash table (zero filled).
bool BackendImpl::CreateBackingStore(disk_cache::File* file) {
diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h
index b481525..74a1eafd 100644
--- a/net/disk_cache/backend_impl.h
+++ b/net/disk_cache/backend_impl.h
@@ -60,24 +60,6 @@ class BackendImpl : public Backend {
// Performs general initialization for this current instance of the cache.
int Init(CompletionCallback* callback);
- // Backend interface.
- virtual int32 GetEntryCount() const;
- virtual int OpenEntry(const std::string& key, Entry** entry,
- CompletionCallback* callback);
- virtual int CreateEntry(const std::string& key, Entry** entry,
- CompletionCallback* callback);
- virtual int DoomEntry(const std::string& key, CompletionCallback* callback);
- virtual int DoomAllEntries(CompletionCallback* callback);
- virtual int DoomEntriesBetween(const base::Time initial_time,
- const base::Time end_time,
- CompletionCallback* callback);
- virtual int DoomEntriesSince(const base::Time initial_time,
- CompletionCallback* callback);
- virtual int OpenNextEntry(void** iter, Entry** next_entry,
- CompletionCallback* callback);
- virtual void EndEnumeration(void** iter);
- virtual void GetStats(StatsItems* stats);
-
// Performs the actual initialization and final cleanup on destruction.
int SyncInit();
void CleanupCache();
@@ -262,6 +244,24 @@ class BackendImpl : public Backend {
// or an error code (negative value).
int SelfCheck();
+ // Backend interface.
+ virtual int32 GetEntryCount() const;
+ virtual int OpenEntry(const std::string& key, Entry** entry,
+ CompletionCallback* callback);
+ virtual int CreateEntry(const std::string& key, Entry** entry,
+ CompletionCallback* callback);
+ virtual int DoomEntry(const std::string& key, CompletionCallback* callback);
+ virtual int DoomAllEntries(CompletionCallback* callback);
+ virtual int DoomEntriesBetween(const base::Time initial_time,
+ const base::Time end_time,
+ CompletionCallback* callback);
+ virtual int DoomEntriesSince(const base::Time initial_time,
+ CompletionCallback* callback);
+ virtual int OpenNextEntry(void** iter, Entry** next_entry,
+ CompletionCallback* callback);
+ virtual void EndEnumeration(void** iter);
+ virtual void GetStats(StatsItems* stats);
+
private:
typedef base::hash_map<CacheAddr, EntryImpl*> EntriesMap;
diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc
index 3cb895f..ff05e11 100644
--- a/net/disk_cache/entry_impl.cc
+++ b/net/disk_cache/entry_impl.cc
@@ -375,197 +375,6 @@ EntryImpl::EntryImpl(BackendImpl* backend, Addr address, bool read_only)
}
}
-// When an entry is deleted from the cache, we clean up all the data associated
-// with it for two reasons: to simplify the reuse of the block (we know that any
-// unused block is filled with zeros), and to simplify the handling of write /
-// read partial information from an entry (don't have to worry about returning
-// data related to a previous cache entry because the range was not fully
-// written before).
-EntryImpl::~EntryImpl() {
- Log("~EntryImpl in");
-
- // Save the sparse info to disk. This will generate IO for this entry and
- // maybe for a child entry, so it is important to do it before deleting this
- // entry.
- sparse_.reset();
-
- // Remove this entry from the list of open entries.
- backend_->OnEntryDestroyBegin(entry_.address());
-
- if (doomed_) {
- DeleteEntryData(true);
- } else {
- net_log_.AddEvent(net::NetLog::TYPE_DISK_CACHE_CLOSE, NULL);
- bool ret = true;
- for (int index = 0; index < kNumStreams; index++) {
- if (user_buffers_[index].get()) {
- if (!(ret = Flush(index, 0)))
- LOG(ERROR) << "Failed to save user data";
- }
- if (unreported_size_[index]) {
- backend_->ModifyStorageSize(
- entry_.Data()->data_size[index] - unreported_size_[index],
- entry_.Data()->data_size[index]);
- }
- }
-
- if (!ret) {
- // There was a failure writing the actual data. Mark the entry as dirty.
- int current_id = backend_->GetCurrentEntryId();
- node_.Data()->dirty = current_id == 1 ? -1 : current_id - 1;
- node_.Store();
- } else if (node_.HasData() && node_.Data()->dirty) {
- node_.Data()->dirty = 0;
- node_.Store();
- }
- }
-
- Trace("~EntryImpl out 0x%p", reinterpret_cast<void*>(this));
- net_log_.EndEvent(net::NetLog::TYPE_DISK_CACHE_ENTRY, NULL);
- backend_->OnEntryDestroyEnd();
-}
-
-void EntryImpl::Doom() {
- backend_->background_queue()->DoomEntryImpl(this);
-}
-
-void EntryImpl::Close() {
- backend_->background_queue()->CloseEntryImpl(this);
-}
-
-std::string EntryImpl::GetKey() const {
- CacheEntryBlock* entry = const_cast<CacheEntryBlock*>(&entry_);
- if (entry->Data()->key_len <= kMaxInternalKeyLength)
- return std::string(entry->Data()->key);
-
- // We keep a copy of the key so that we can always return it, even if the
- // backend is disabled.
- if (!key_.empty())
- return key_;
-
- Addr address(entry->Data()->long_key);
- DCHECK(address.is_initialized());
- size_t offset = 0;
- if (address.is_block_file())
- offset = address.start_block() * address.BlockSize() + kBlockHeaderSize;
-
- COMPILE_ASSERT(kNumStreams == kKeyFileIndex, invalid_key_index);
- File* key_file = const_cast<EntryImpl*>(this)->GetBackingFile(address,
- kKeyFileIndex);
-
- if (!key_file ||
- !key_file->Read(WriteInto(&key_, entry->Data()->key_len + 1),
- entry->Data()->key_len + 1, offset))
- key_.clear();
- return key_;
-}
-
-Time EntryImpl::GetLastUsed() const {
- CacheRankingsBlock* node = const_cast<CacheRankingsBlock*>(&node_);
- return Time::FromInternalValue(node->Data()->last_used);
-}
-
-Time EntryImpl::GetLastModified() const {
- CacheRankingsBlock* node = const_cast<CacheRankingsBlock*>(&node_);
- return Time::FromInternalValue(node->Data()->last_modified);
-}
-
-int32 EntryImpl::GetDataSize(int index) const {
- if (index < 0 || index >= kNumStreams)
- return 0;
-
- CacheEntryBlock* entry = const_cast<CacheEntryBlock*>(&entry_);
- return entry->Data()->data_size[index];
-}
-
-int EntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
- net::CompletionCallback* callback) {
- if (!callback)
- return ReadDataImpl(index, offset, buf, buf_len, callback);
-
- DCHECK(node_.Data()->dirty || read_only_);
- if (index < 0 || index >= kNumStreams)
- return net::ERR_INVALID_ARGUMENT;
-
- int entry_size = entry_.Data()->data_size[index];
- if (offset >= entry_size || offset < 0 || !buf_len)
- return 0;
-
- if (buf_len < 0)
- return net::ERR_INVALID_ARGUMENT;
-
- backend_->background_queue()->ReadData(this, index, offset, buf, buf_len,
- callback);
- return net::ERR_IO_PENDING;
-}
-
-int EntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
- CompletionCallback* callback, bool truncate) {
- if (!callback)
- return WriteDataImpl(index, offset, buf, buf_len, callback, truncate);
-
- DCHECK(node_.Data()->dirty || read_only_);
- if (index < 0 || index >= kNumStreams)
- return net::ERR_INVALID_ARGUMENT;
-
- if (offset < 0 || buf_len < 0)
- return net::ERR_INVALID_ARGUMENT;
-
- backend_->background_queue()->WriteData(this, index, offset, buf, buf_len,
- truncate, callback);
- return net::ERR_IO_PENDING;
-}
-
-int EntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
- net::CompletionCallback* callback) {
- if (!callback)
- return ReadSparseDataImpl(offset, buf, buf_len, callback);
-
- backend_->background_queue()->ReadSparseData(this, offset, buf, buf_len,
- callback);
- return net::ERR_IO_PENDING;
-}
-
-int EntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
- net::CompletionCallback* callback) {
- if (!callback)
- return WriteSparseDataImpl(offset, buf, buf_len, callback);
-
- backend_->background_queue()->WriteSparseData(this, offset, buf, buf_len,
- callback);
- return net::ERR_IO_PENDING;
-}
-
-int EntryImpl::GetAvailableRange(int64 offset, int len, int64* start,
- CompletionCallback* callback) {
- backend_->background_queue()->GetAvailableRange(this, offset, len, start,
- callback);
- return net::ERR_IO_PENDING;
-}
-
-bool EntryImpl::CouldBeSparse() const {
- if (sparse_.get())
- return true;
-
- scoped_ptr<SparseControl> sparse;
- sparse.reset(new SparseControl(const_cast<EntryImpl*>(this)));
- return sparse->CouldBeSparse();
-}
-
-void EntryImpl::CancelSparseIO() {
- backend_->background_queue()->CancelSparseIO(this);
-}
-
-int EntryImpl::ReadyForSparseIO(net::CompletionCallback* callback) {
- if (!sparse_.get())
- return net::OK;
-
- backend_->background_queue()->ReadyForSparseIO(this, callback);
- return net::ERR_IO_PENDING;
-}
-
-// ------------------------------------------------------------------------
-
void EntryImpl::DoomImpl() {
if (doomed_)
return;
@@ -614,171 +423,6 @@ int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf,
return result;
}
-int EntryImpl::InternalReadData(int index, int offset, net::IOBuffer* buf,
- int buf_len, CompletionCallback* callback) {
- DCHECK(node_.Data()->dirty || read_only_);
- DVLOG(2) << "Read from " << index << " at " << offset << " : " << buf_len;
- if (index < 0 || index >= kNumStreams)
- return net::ERR_INVALID_ARGUMENT;
-
- int entry_size = entry_.Data()->data_size[index];
- if (offset >= entry_size || offset < 0 || !buf_len)
- return 0;
-
- if (buf_len < 0)
- return net::ERR_INVALID_ARGUMENT;
-
- TimeTicks start = TimeTicks::Now();
-
- if (offset + buf_len > entry_size)
- buf_len = entry_size - offset;
-
- UpdateRank(false);
-
- backend_->OnEvent(Stats::READ_DATA);
- backend_->OnRead(buf_len);
-
- Addr address(entry_.Data()->data_addr[index]);
- int eof = address.is_initialized() ? entry_size : 0;
- if (user_buffers_[index].get() &&
- user_buffers_[index]->PreRead(eof, offset, &buf_len)) {
- // Complete the operation locally.
- buf_len = user_buffers_[index]->Read(offset, buf, buf_len);
- ReportIOTime(kRead, start);
- return buf_len;
- }
-
- address.set_value(entry_.Data()->data_addr[index]);
- DCHECK(address.is_initialized());
- if (!address.is_initialized())
- return net::ERR_FAILED;
-
- File* file = GetBackingFile(address, index);
- if (!file)
- return net::ERR_FAILED;
-
- size_t file_offset = offset;
- if (address.is_block_file()) {
- DCHECK_LE(offset + buf_len, kMaxBlockSize);
- file_offset += address.start_block() * address.BlockSize() +
- kBlockHeaderSize;
- }
-
- SyncCallback* io_callback = NULL;
- if (callback) {
- io_callback = new SyncCallback(this, buf, callback,
- net::NetLog::TYPE_DISK_CACHE_READ_DATA);
- }
-
- bool completed;
- if (!file->Read(buf->data(), buf_len, file_offset, io_callback, &completed)) {
- if (io_callback)
- io_callback->Discard();
- return net::ERR_FAILED;
- }
-
- if (io_callback && completed)
- io_callback->Discard();
-
- ReportIOTime(kRead, start);
- return (completed || !callback) ? buf_len : net::ERR_IO_PENDING;
-}
-
-int EntryImpl::InternalWriteData(int index, int offset, net::IOBuffer* buf,
- int buf_len, CompletionCallback* callback,
- bool truncate) {
- DCHECK(node_.Data()->dirty || read_only_);
- DVLOG(2) << "Write to " << index << " at " << offset << " : " << buf_len;
- if (index < 0 || index >= kNumStreams)
- return net::ERR_INVALID_ARGUMENT;
-
- if (offset < 0 || buf_len < 0)
- return net::ERR_INVALID_ARGUMENT;
-
- int max_file_size = backend_->MaxFileSize();
-
- // offset or buf_len could be negative numbers.
- if (offset > max_file_size || buf_len > max_file_size ||
- offset + buf_len > max_file_size) {
- int size = offset + buf_len;
- if (size <= max_file_size)
- size = kint32max;
- backend_->TooMuchStorageRequested(size);
- return net::ERR_FAILED;
- }
-
- TimeTicks start = TimeTicks::Now();
-
- // Read the size at this point (it may change inside prepare).
- int entry_size = entry_.Data()->data_size[index];
- bool extending = entry_size < offset + buf_len;
- truncate = truncate && entry_size > offset + buf_len;
- Trace("To PrepareTarget 0x%x", entry_.address().value());
- if (!PrepareTarget(index, offset, buf_len, truncate))
- return net::ERR_FAILED;
-
- Trace("From PrepareTarget 0x%x", entry_.address().value());
- if (extending || truncate)
- UpdateSize(index, entry_size, offset + buf_len);
-
- UpdateRank(true);
-
- backend_->OnEvent(Stats::WRITE_DATA);
- backend_->OnWrite(buf_len);
-
- if (user_buffers_[index].get()) {
- // Complete the operation locally.
- user_buffers_[index]->Write(offset, buf, buf_len);
- ReportIOTime(kWrite, start);
- return buf_len;
- }
-
- Addr address(entry_.Data()->data_addr[index]);
- if (offset + buf_len == 0) {
- if (truncate) {
- DCHECK(!address.is_initialized());
- }
- return 0;
- }
-
- File* file = GetBackingFile(address, index);
- if (!file)
- return net::ERR_FAILED;
-
- size_t file_offset = offset;
- if (address.is_block_file()) {
- DCHECK_LE(offset + buf_len, kMaxBlockSize);
- file_offset += address.start_block() * address.BlockSize() +
- kBlockHeaderSize;
- } else if (truncate || (extending && !buf_len)) {
- if (!file->SetLength(offset + buf_len))
- return net::ERR_FAILED;
- }
-
- if (!buf_len)
- return 0;
-
- SyncCallback* io_callback = NULL;
- if (callback) {
- io_callback = new SyncCallback(this, buf, callback,
- net::NetLog::TYPE_DISK_CACHE_WRITE_DATA);
- }
-
- bool completed;
- if (!file->Write(buf->data(), buf_len, file_offset, io_callback,
- &completed)) {
- if (io_callback)
- io_callback->Discard();
- return net::ERR_FAILED;
- }
-
- if (io_callback && completed)
- io_callback->Discard();
-
- ReportIOTime(kWrite, start);
- return (completed || !callback) ? buf_len : net::ERR_IO_PENDING;
-}
-
int EntryImpl::ReadSparseDataImpl(int64 offset, net::IOBuffer* buf, int buf_len,
CompletionCallback* callback) {
DCHECK(node_.Data()->dirty || read_only_);
@@ -827,8 +471,6 @@ int EntryImpl::ReadyForSparseIOImpl(CompletionCallback* callback) {
return sparse_->ReadyToUse(callback);
}
-// ------------------------------------------------------------------------
-
uint32 EntryImpl::GetHash() {
return entry_.Data()->hash;
}
@@ -1061,6 +703,362 @@ const net::BoundNetLog& EntryImpl::net_log() const {
return net_log_;
}
+void EntryImpl::Doom() {
+ backend_->background_queue()->DoomEntryImpl(this);
+}
+
+void EntryImpl::Close() {
+ backend_->background_queue()->CloseEntryImpl(this);
+}
+
+std::string EntryImpl::GetKey() const {
+ CacheEntryBlock* entry = const_cast<CacheEntryBlock*>(&entry_);
+ if (entry->Data()->key_len <= kMaxInternalKeyLength)
+ return std::string(entry->Data()->key);
+
+ // We keep a copy of the key so that we can always return it, even if the
+ // backend is disabled.
+ if (!key_.empty())
+ return key_;
+
+ Addr address(entry->Data()->long_key);
+ DCHECK(address.is_initialized());
+ size_t offset = 0;
+ if (address.is_block_file())
+ offset = address.start_block() * address.BlockSize() + kBlockHeaderSize;
+
+ COMPILE_ASSERT(kNumStreams == kKeyFileIndex, invalid_key_index);
+ File* key_file = const_cast<EntryImpl*>(this)->GetBackingFile(address,
+ kKeyFileIndex);
+
+ if (!key_file ||
+ !key_file->Read(WriteInto(&key_, entry->Data()->key_len + 1),
+ entry->Data()->key_len + 1, offset))
+ key_.clear();
+ return key_;
+}
+
+Time EntryImpl::GetLastUsed() const {
+ CacheRankingsBlock* node = const_cast<CacheRankingsBlock*>(&node_);
+ return Time::FromInternalValue(node->Data()->last_used);
+}
+
+Time EntryImpl::GetLastModified() const {
+ CacheRankingsBlock* node = const_cast<CacheRankingsBlock*>(&node_);
+ return Time::FromInternalValue(node->Data()->last_modified);
+}
+
+int32 EntryImpl::GetDataSize(int index) const {
+ if (index < 0 || index >= kNumStreams)
+ return 0;
+
+ CacheEntryBlock* entry = const_cast<CacheEntryBlock*>(&entry_);
+ return entry->Data()->data_size[index];
+}
+
+int EntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback) {
+ if (!callback)
+ return ReadDataImpl(index, offset, buf, buf_len, callback);
+
+ DCHECK(node_.Data()->dirty || read_only_);
+ if (index < 0 || index >= kNumStreams)
+ return net::ERR_INVALID_ARGUMENT;
+
+ int entry_size = entry_.Data()->data_size[index];
+ if (offset >= entry_size || offset < 0 || !buf_len)
+ return 0;
+
+ if (buf_len < 0)
+ return net::ERR_INVALID_ARGUMENT;
+
+ backend_->background_queue()->ReadData(this, index, offset, buf, buf_len,
+ callback);
+ return net::ERR_IO_PENDING;
+}
+
+int EntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
+ CompletionCallback* callback, bool truncate) {
+ if (!callback)
+ return WriteDataImpl(index, offset, buf, buf_len, callback, truncate);
+
+ DCHECK(node_.Data()->dirty || read_only_);
+ if (index < 0 || index >= kNumStreams)
+ return net::ERR_INVALID_ARGUMENT;
+
+ if (offset < 0 || buf_len < 0)
+ return net::ERR_INVALID_ARGUMENT;
+
+ backend_->background_queue()->WriteData(this, index, offset, buf, buf_len,
+ truncate, callback);
+ return net::ERR_IO_PENDING;
+}
+
+int EntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback) {
+ if (!callback)
+ return ReadSparseDataImpl(offset, buf, buf_len, callback);
+
+ backend_->background_queue()->ReadSparseData(this, offset, buf, buf_len,
+ callback);
+ return net::ERR_IO_PENDING;
+}
+
+int EntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback) {
+ if (!callback)
+ return WriteSparseDataImpl(offset, buf, buf_len, callback);
+
+ backend_->background_queue()->WriteSparseData(this, offset, buf, buf_len,
+ callback);
+ return net::ERR_IO_PENDING;
+}
+
+int EntryImpl::GetAvailableRange(int64 offset, int len, int64* start,
+ CompletionCallback* callback) {
+ backend_->background_queue()->GetAvailableRange(this, offset, len, start,
+ callback);
+ return net::ERR_IO_PENDING;
+}
+
+bool EntryImpl::CouldBeSparse() const {
+ if (sparse_.get())
+ return true;
+
+ scoped_ptr<SparseControl> sparse;
+ sparse.reset(new SparseControl(const_cast<EntryImpl*>(this)));
+ return sparse->CouldBeSparse();
+}
+
+void EntryImpl::CancelSparseIO() {
+ backend_->background_queue()->CancelSparseIO(this);
+}
+
+int EntryImpl::ReadyForSparseIO(net::CompletionCallback* callback) {
+ if (!sparse_.get())
+ return net::OK;
+
+ backend_->background_queue()->ReadyForSparseIO(this, callback);
+ return net::ERR_IO_PENDING;
+}
+
+// When an entry is deleted from the cache, we clean up all the data associated
+// with it for two reasons: to simplify the reuse of the block (we know that any
+// unused block is filled with zeros), and to simplify the handling of write /
+// read partial information from an entry (don't have to worry about returning
+// data related to a previous cache entry because the range was not fully
+// written before).
+EntryImpl::~EntryImpl() {
+ Log("~EntryImpl in");
+
+ // Save the sparse info to disk. This will generate IO for this entry and
+ // maybe for a child entry, so it is important to do it before deleting this
+ // entry.
+ sparse_.reset();
+
+ // Remove this entry from the list of open entries.
+ backend_->OnEntryDestroyBegin(entry_.address());
+
+ if (doomed_) {
+ DeleteEntryData(true);
+ } else {
+ net_log_.AddEvent(net::NetLog::TYPE_DISK_CACHE_CLOSE, NULL);
+ bool ret = true;
+ for (int index = 0; index < kNumStreams; index++) {
+ if (user_buffers_[index].get()) {
+ if (!(ret = Flush(index, 0)))
+ LOG(ERROR) << "Failed to save user data";
+ }
+ if (unreported_size_[index]) {
+ backend_->ModifyStorageSize(
+ entry_.Data()->data_size[index] - unreported_size_[index],
+ entry_.Data()->data_size[index]);
+ }
+ }
+
+ if (!ret) {
+ // There was a failure writing the actual data. Mark the entry as dirty.
+ int current_id = backend_->GetCurrentEntryId();
+ node_.Data()->dirty = current_id == 1 ? -1 : current_id - 1;
+ node_.Store();
+ } else if (node_.HasData() && node_.Data()->dirty) {
+ node_.Data()->dirty = 0;
+ node_.Store();
+ }
+ }
+
+ Trace("~EntryImpl out 0x%p", reinterpret_cast<void*>(this));
+ net_log_.EndEvent(net::NetLog::TYPE_DISK_CACHE_ENTRY, NULL);
+ backend_->OnEntryDestroyEnd();
+}
+
+// ------------------------------------------------------------------------
+
+int EntryImpl::InternalReadData(int index, int offset, net::IOBuffer* buf,
+ int buf_len, CompletionCallback* callback) {
+ DCHECK(node_.Data()->dirty || read_only_);
+ DVLOG(2) << "Read from " << index << " at " << offset << " : " << buf_len;
+ if (index < 0 || index >= kNumStreams)
+ return net::ERR_INVALID_ARGUMENT;
+
+ int entry_size = entry_.Data()->data_size[index];
+ if (offset >= entry_size || offset < 0 || !buf_len)
+ return 0;
+
+ if (buf_len < 0)
+ return net::ERR_INVALID_ARGUMENT;
+
+ TimeTicks start = TimeTicks::Now();
+
+ if (offset + buf_len > entry_size)
+ buf_len = entry_size - offset;
+
+ UpdateRank(false);
+
+ backend_->OnEvent(Stats::READ_DATA);
+ backend_->OnRead(buf_len);
+
+ Addr address(entry_.Data()->data_addr[index]);
+ int eof = address.is_initialized() ? entry_size : 0;
+ if (user_buffers_[index].get() &&
+ user_buffers_[index]->PreRead(eof, offset, &buf_len)) {
+ // Complete the operation locally.
+ buf_len = user_buffers_[index]->Read(offset, buf, buf_len);
+ ReportIOTime(kRead, start);
+ return buf_len;
+ }
+
+ address.set_value(entry_.Data()->data_addr[index]);
+ DCHECK(address.is_initialized());
+ if (!address.is_initialized())
+ return net::ERR_FAILED;
+
+ File* file = GetBackingFile(address, index);
+ if (!file)
+ return net::ERR_FAILED;
+
+ size_t file_offset = offset;
+ if (address.is_block_file()) {
+ DCHECK_LE(offset + buf_len, kMaxBlockSize);
+ file_offset += address.start_block() * address.BlockSize() +
+ kBlockHeaderSize;
+ }
+
+ SyncCallback* io_callback = NULL;
+ if (callback) {
+ io_callback = new SyncCallback(this, buf, callback,
+ net::NetLog::TYPE_DISK_CACHE_READ_DATA);
+ }
+
+ bool completed;
+ if (!file->Read(buf->data(), buf_len, file_offset, io_callback, &completed)) {
+ if (io_callback)
+ io_callback->Discard();
+ return net::ERR_FAILED;
+ }
+
+ if (io_callback && completed)
+ io_callback->Discard();
+
+ ReportIOTime(kRead, start);
+ return (completed || !callback) ? buf_len : net::ERR_IO_PENDING;
+}
+
+int EntryImpl::InternalWriteData(int index, int offset, net::IOBuffer* buf,
+ int buf_len, CompletionCallback* callback,
+ bool truncate) {
+ DCHECK(node_.Data()->dirty || read_only_);
+ DVLOG(2) << "Write to " << index << " at " << offset << " : " << buf_len;
+ if (index < 0 || index >= kNumStreams)
+ return net::ERR_INVALID_ARGUMENT;
+
+ if (offset < 0 || buf_len < 0)
+ return net::ERR_INVALID_ARGUMENT;
+
+ int max_file_size = backend_->MaxFileSize();
+
+ // offset or buf_len could be negative numbers.
+ if (offset > max_file_size || buf_len > max_file_size ||
+ offset + buf_len > max_file_size) {
+ int size = offset + buf_len;
+ if (size <= max_file_size)
+ size = kint32max;
+ backend_->TooMuchStorageRequested(size);
+ return net::ERR_FAILED;
+ }
+
+ TimeTicks start = TimeTicks::Now();
+
+ // Read the size at this point (it may change inside prepare).
+ int entry_size = entry_.Data()->data_size[index];
+ bool extending = entry_size < offset + buf_len;
+ truncate = truncate && entry_size > offset + buf_len;
+ Trace("To PrepareTarget 0x%x", entry_.address().value());
+ if (!PrepareTarget(index, offset, buf_len, truncate))
+ return net::ERR_FAILED;
+
+ Trace("From PrepareTarget 0x%x", entry_.address().value());
+ if (extending || truncate)
+ UpdateSize(index, entry_size, offset + buf_len);
+
+ UpdateRank(true);
+
+ backend_->OnEvent(Stats::WRITE_DATA);
+ backend_->OnWrite(buf_len);
+
+ if (user_buffers_[index].get()) {
+ // Complete the operation locally.
+ user_buffers_[index]->Write(offset, buf, buf_len);
+ ReportIOTime(kWrite, start);
+ return buf_len;
+ }
+
+ Addr address(entry_.Data()->data_addr[index]);
+ if (offset + buf_len == 0) {
+ if (truncate) {
+ DCHECK(!address.is_initialized());
+ }
+ return 0;
+ }
+
+ File* file = GetBackingFile(address, index);
+ if (!file)
+ return net::ERR_FAILED;
+
+ size_t file_offset = offset;
+ if (address.is_block_file()) {
+ DCHECK_LE(offset + buf_len, kMaxBlockSize);
+ file_offset += address.start_block() * address.BlockSize() +
+ kBlockHeaderSize;
+ } else if (truncate || (extending && !buf_len)) {
+ if (!file->SetLength(offset + buf_len))
+ return net::ERR_FAILED;
+ }
+
+ if (!buf_len)
+ return 0;
+
+ SyncCallback* io_callback = NULL;
+ if (callback) {
+ io_callback = new SyncCallback(this, buf, callback,
+ net::NetLog::TYPE_DISK_CACHE_WRITE_DATA);
+ }
+
+ bool completed;
+ if (!file->Write(buf->data(), buf_len, file_offset, io_callback,
+ &completed)) {
+ if (io_callback)
+ io_callback->Discard();
+ return net::ERR_FAILED;
+ }
+
+ if (io_callback && completed)
+ io_callback->Discard();
+
+ ReportIOTime(kWrite, start);
+ return (completed || !callback) ? buf_len : net::ERR_IO_PENDING;
+}
+
// ------------------------------------------------------------------------
bool EntryImpl::CreateDataBlock(int index, int size) {
diff --git a/net/disk_cache/entry_impl.h b/net/disk_cache/entry_impl.h
index d24e861..e56fc6b 100644
--- a/net/disk_cache/entry_impl.h
+++ b/net/disk_cache/entry_impl.h
@@ -33,28 +33,6 @@ class EntryImpl : public Entry, public base::RefCounted<EntryImpl> {
EntryImpl(BackendImpl* backend, Addr address, bool read_only);
- // Entry interface.
- virtual void Doom();
- virtual void Close();
- virtual std::string GetKey() const;
- virtual base::Time GetLastUsed() const;
- virtual base::Time GetLastModified() const;
- virtual int32 GetDataSize(int index) const;
- virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
- net::CompletionCallback* completion_callback);
- virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
- net::CompletionCallback* completion_callback,
- bool truncate);
- virtual int ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
- 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,
- CompletionCallback* callback);
- virtual bool CouldBeSparse() const;
- virtual void CancelSparseIO();
- virtual int ReadyForSparseIO(net::CompletionCallback* completion_callback);
-
// Background implementation of the Entry interface.
void DoomImpl();
int ReadDataImpl(int index, int offset, net::IOBuffer* buf, int buf_len,
@@ -138,6 +116,28 @@ class EntryImpl : public Entry, public base::RefCounted<EntryImpl> {
const net::BoundNetLog& net_log() const;
+ // Entry interface.
+ virtual void Doom();
+ virtual void Close();
+ virtual std::string GetKey() const;
+ virtual base::Time GetLastUsed() const;
+ virtual base::Time GetLastModified() const;
+ virtual int32 GetDataSize(int index) const;
+ virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* completion_callback);
+ virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* completion_callback,
+ bool truncate);
+ virtual int ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
+ 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,
+ CompletionCallback* callback);
+ virtual bool CouldBeSparse() const;
+ virtual void CancelSparseIO();
+ virtual int ReadyForSparseIO(net::CompletionCallback* completion_callback);
+
private:
enum {
kNumStreams = 3
diff --git a/net/disk_cache/file.h b/net/disk_cache/file.h
index c266311..129c3dd 100644
--- a/net/disk_cache/file.h
+++ b/net/disk_cache/file.h
@@ -18,11 +18,11 @@ namespace disk_cache {
// This interface is used to support asynchronous ReadData and WriteData calls.
class FileIOCallback {
public:
+ virtual ~FileIOCallback() {}
+
// Notified of the actual number of bytes read or written. This value is
// negative if an error occurred.
virtual void OnFileIOComplete(int bytes_copied) = 0;
-
- virtual ~FileIOCallback() {}
};
// Simple wrapper around a file that allows asynchronous operations.
diff --git a/net/disk_cache/mem_backend_impl.cc b/net/disk_cache/mem_backend_impl.cc
index 288a66e..1122bca 100644
--- a/net/disk_cache/mem_backend_impl.cc
+++ b/net/disk_cache/mem_backend_impl.cc
@@ -28,6 +28,17 @@ int LowWaterAdjust(int high_water) {
namespace disk_cache {
+MemBackendImpl::MemBackendImpl() : max_size_(0), current_size_(0) {}
+
+MemBackendImpl::~MemBackendImpl() {
+ EntryMap::iterator it = entries_.begin();
+ while (it != entries_.end()) {
+ it->second->Doom();
+ it = entries_.begin();
+ }
+ DCHECK(!current_size_);
+}
+
// Static.
Backend* MemBackendImpl::CreateBackend(int max_bytes) {
MemBackendImpl* cache = new MemBackendImpl();
@@ -62,17 +73,6 @@ bool MemBackendImpl::Init() {
return true;
}
-MemBackendImpl::MemBackendImpl() : max_size_(0), current_size_(0) {}
-
-MemBackendImpl::~MemBackendImpl() {
- EntryMap::iterator it = entries_.begin();
- while (it != entries_.end()) {
- it->second->Doom();
- it = entries_.begin();
- }
- DCHECK(!current_size_);
-}
-
bool MemBackendImpl::SetMaxSize(int max_bytes) {
COMPILE_ASSERT(sizeof(max_bytes) == sizeof(max_size_), unsupported_int_model);
if (max_bytes < 0)
@@ -86,10 +86,107 @@ bool MemBackendImpl::SetMaxSize(int max_bytes) {
return true;
}
+void MemBackendImpl::InternalDoomEntry(MemEntryImpl* entry) {
+ // Only parent entries can be passed into this method.
+ DCHECK(entry->type() == MemEntryImpl::kParentEntry);
+
+ rankings_.Remove(entry);
+ EntryMap::iterator it = entries_.find(entry->GetKey());
+ if (it != entries_.end())
+ entries_.erase(it);
+ else
+ NOTREACHED();
+
+ entry->InternalDoom();
+}
+
+void MemBackendImpl::UpdateRank(MemEntryImpl* node) {
+ rankings_.UpdateRank(node);
+}
+
+void MemBackendImpl::ModifyStorageSize(int32 old_size, int32 new_size) {
+ if (old_size >= new_size)
+ SubstractStorageSize(old_size - new_size);
+ else
+ AddStorageSize(new_size - old_size);
+}
+
+int MemBackendImpl::MaxFileSize() const {
+ return max_size_ / 8;
+}
+
+void MemBackendImpl::InsertIntoRankingList(MemEntryImpl* entry) {
+ rankings_.Insert(entry);
+}
+
+void MemBackendImpl::RemoveFromRankingList(MemEntryImpl* entry) {
+ rankings_.Remove(entry);
+}
+
int32 MemBackendImpl::GetEntryCount() const {
return static_cast<int32>(entries_.size());
}
+int MemBackendImpl::OpenEntry(const std::string& key, Entry** entry,
+ CompletionCallback* callback) {
+ if (OpenEntry(key, entry))
+ return net::OK;
+
+ return net::ERR_FAILED;
+}
+
+int MemBackendImpl::CreateEntry(const std::string& key, Entry** entry,
+ CompletionCallback* callback) {
+ if (CreateEntry(key, entry))
+ return net::OK;
+
+ return net::ERR_FAILED;
+}
+
+int MemBackendImpl::DoomEntry(const std::string& key,
+ CompletionCallback* callback) {
+ if (DoomEntry(key))
+ return net::OK;
+
+ return net::ERR_FAILED;
+}
+
+int MemBackendImpl::DoomAllEntries(CompletionCallback* callback) {
+ if (DoomAllEntries())
+ return net::OK;
+
+ return net::ERR_FAILED;
+}
+
+int MemBackendImpl::DoomEntriesBetween(const base::Time initial_time,
+ const base::Time end_time,
+ CompletionCallback* callback) {
+ if (DoomEntriesBetween(initial_time, end_time))
+ return net::OK;
+
+ return net::ERR_FAILED;
+}
+
+int MemBackendImpl::DoomEntriesSince(const base::Time initial_time,
+ CompletionCallback* callback) {
+ if (DoomEntriesSince(initial_time))
+ return net::OK;
+
+ return net::ERR_FAILED;
+}
+
+int MemBackendImpl::OpenNextEntry(void** iter, Entry** next_entry,
+ CompletionCallback* callback) {
+ if (OpenNextEntry(iter, next_entry))
+ return net::OK;
+
+ return net::ERR_FAILED;
+}
+
+void MemBackendImpl::EndEnumeration(void** iter) {
+ *iter = NULL;
+}
+
bool MemBackendImpl::OpenEntry(const std::string& key, Entry** entry) {
EntryMap::iterator it = entries_.find(key);
if (it == entries_.end())
@@ -101,14 +198,6 @@ bool MemBackendImpl::OpenEntry(const std::string& key, Entry** entry) {
return true;
}
-int MemBackendImpl::OpenEntry(const std::string& key, Entry** entry,
- CompletionCallback* callback) {
- if (OpenEntry(key, entry))
- return net::OK;
-
- return net::ERR_FAILED;
-}
-
bool MemBackendImpl::CreateEntry(const std::string& key, Entry** entry) {
EntryMap::iterator it = entries_.find(key);
if (it != entries_.end())
@@ -127,14 +216,6 @@ bool MemBackendImpl::CreateEntry(const std::string& key, Entry** entry) {
return true;
}
-int MemBackendImpl::CreateEntry(const std::string& key, Entry** entry,
- CompletionCallback* callback) {
- if (CreateEntry(key, entry))
- return net::OK;
-
- return net::ERR_FAILED;
-}
-
bool MemBackendImpl::DoomEntry(const std::string& key) {
Entry* entry;
if (!OpenEntry(key, &entry))
@@ -145,40 +226,11 @@ bool MemBackendImpl::DoomEntry(const std::string& key) {
return true;
}
-int MemBackendImpl::DoomEntry(const std::string& key,
- CompletionCallback* callback) {
- if (DoomEntry(key))
- return net::OK;
-
- return net::ERR_FAILED;
-}
-
-void MemBackendImpl::InternalDoomEntry(MemEntryImpl* entry) {
- // Only parent entries can be passed into this method.
- DCHECK(entry->type() == MemEntryImpl::kParentEntry);
-
- rankings_.Remove(entry);
- EntryMap::iterator it = entries_.find(entry->GetKey());
- if (it != entries_.end())
- entries_.erase(it);
- else
- NOTREACHED();
-
- entry->InternalDoom();
-}
-
bool MemBackendImpl::DoomAllEntries() {
TrimCache(true);
return true;
}
-int MemBackendImpl::DoomAllEntries(CompletionCallback* callback) {
- if (DoomAllEntries())
- return net::OK;
-
- return net::ERR_FAILED;
-}
-
bool MemBackendImpl::DoomEntriesBetween(const Time initial_time,
const Time end_time) {
if (end_time.is_null())
@@ -205,15 +257,6 @@ bool MemBackendImpl::DoomEntriesBetween(const Time initial_time,
return true;
}
-int MemBackendImpl::DoomEntriesBetween(const base::Time initial_time,
- const base::Time end_time,
- CompletionCallback* callback) {
- if (DoomEntriesBetween(initial_time, end_time))
- return net::OK;
-
- return net::ERR_FAILED;
-}
-
bool MemBackendImpl::DoomEntriesSince(const Time initial_time) {
for (;;) {
// Get the entry in the front.
@@ -226,14 +269,6 @@ bool MemBackendImpl::DoomEntriesSince(const Time initial_time) {
}
}
-int MemBackendImpl::DoomEntriesSince(const base::Time initial_time,
- CompletionCallback* callback) {
- if (DoomEntriesSince(initial_time))
- return net::OK;
-
- return net::ERR_FAILED;
-}
-
bool MemBackendImpl::OpenNextEntry(void** iter, Entry** next_entry) {
MemEntryImpl* current = reinterpret_cast<MemEntryImpl*>(*iter);
MemEntryImpl* node = rankings_.GetNext(current);
@@ -251,18 +286,6 @@ bool MemBackendImpl::OpenNextEntry(void** iter, Entry** next_entry) {
return NULL != node;
}
-int MemBackendImpl::OpenNextEntry(void** iter, Entry** next_entry,
- CompletionCallback* callback) {
- if (OpenNextEntry(iter, next_entry))
- return net::OK;
-
- return net::ERR_FAILED;
-}
-
-void MemBackendImpl::EndEnumeration(void** iter) {
- *iter = NULL;
-}
-
void MemBackendImpl::TrimCache(bool empty) {
MemEntryImpl* next = rankings_.GetPrev(NULL);
@@ -293,27 +316,4 @@ void MemBackendImpl::SubstractStorageSize(int32 bytes) {
DCHECK(current_size_ >= 0);
}
-void MemBackendImpl::ModifyStorageSize(int32 old_size, int32 new_size) {
- if (old_size >= new_size)
- SubstractStorageSize(old_size - new_size);
- else
- AddStorageSize(new_size - old_size);
-}
-
-void MemBackendImpl::UpdateRank(MemEntryImpl* node) {
- rankings_.UpdateRank(node);
-}
-
-int MemBackendImpl::MaxFileSize() const {
- return max_size_ / 8;
-}
-
-void MemBackendImpl::InsertIntoRankingList(MemEntryImpl* entry) {
- rankings_.Insert(entry);
-}
-
-void MemBackendImpl::RemoveFromRankingList(MemEntryImpl* entry) {
- rankings_.Remove(entry);
-}
-
} // namespace disk_cache
diff --git a/net/disk_cache/mem_backend_impl.h b/net/disk_cache/mem_backend_impl.h
index c78c670..9b920ac5 100644
--- a/net/disk_cache/mem_backend_impl.h
+++ b/net/disk_cache/mem_backend_impl.h
@@ -34,25 +34,6 @@ class MemBackendImpl : public Backend {
// Performs general initialization for this current instance of the cache.
bool Init();
- // Backend interface.
- virtual int32 GetEntryCount() const;
- virtual int OpenEntry(const std::string& key, Entry** entry,
- CompletionCallback* callback);
- virtual int CreateEntry(const std::string& key, Entry** entry,
- CompletionCallback* callback);
- virtual int DoomEntry(const std::string& key, CompletionCallback* callback);
- virtual int DoomAllEntries(CompletionCallback* callback);
- virtual int DoomEntriesBetween(const base::Time initial_time,
- const base::Time end_time,
- CompletionCallback* callback);
- virtual int DoomEntriesSince(const base::Time initial_time,
- CompletionCallback* callback);
- virtual int OpenNextEntry(void** iter, Entry** next_entry,
- CompletionCallback* callback);
- virtual void EndEnumeration(void** iter);
- virtual void GetStats(
- std::vector<std::pair<std::string, std::string> >* stats) {}
-
// Sets the maximum size for the total amount of data stored by this instance.
bool SetMaxSize(int max_bytes);
@@ -77,7 +58,28 @@ class MemBackendImpl : public Backend {
// MemEntryImpl to remove a child entry from the ranking list.
void RemoveFromRankingList(MemEntryImpl* entry);
+ // Backend interface.
+ virtual int32 GetEntryCount() const;
+ virtual int OpenEntry(const std::string& key, Entry** entry,
+ CompletionCallback* callback);
+ virtual int CreateEntry(const std::string& key, Entry** entry,
+ CompletionCallback* callback);
+ virtual int DoomEntry(const std::string& key, CompletionCallback* callback);
+ virtual int DoomAllEntries(CompletionCallback* callback);
+ virtual int DoomEntriesBetween(const base::Time initial_time,
+ const base::Time end_time,
+ CompletionCallback* callback);
+ virtual int DoomEntriesSince(const base::Time initial_time,
+ CompletionCallback* callback);
+ virtual int OpenNextEntry(void** iter, Entry** next_entry,
+ CompletionCallback* callback);
+ virtual void EndEnumeration(void** iter);
+ virtual void GetStats(
+ std::vector<std::pair<std::string, std::string> >* stats) {}
+
private:
+ typedef base::hash_map<std::string, MemEntryImpl*> EntryMap;
+
// Old Backend interface.
bool OpenEntry(const std::string& key, Entry** entry);
bool CreateEntry(const std::string& key, Entry** entry);
@@ -97,8 +99,6 @@ class MemBackendImpl : public Backend {
void AddStorageSize(int32 bytes);
void SubstractStorageSize(int32 bytes);
- typedef base::hash_map<std::string, MemEntryImpl*> EntryMap;
-
EntryMap entries_;
MemRankings rankings_; // Rankings to be able to trim the cache.
int32 max_size_; // Maximum data size for this instance.
diff --git a/net/disk_cache/rankings.h b/net/disk_cache/rankings.h
index 6066fbf..baf777e 100644
--- a/net/disk_cache/rankings.h
+++ b/net/disk_cache/rankings.h
@@ -93,11 +93,12 @@ class Rankings {
// If we have multiple lists, we have to iterate through all at the same time.
// This structure keeps track of where we are on the iteration.
struct Iterator {
+ explicit Iterator(Rankings* rankings);
+ ~Iterator();
+
List list; // Which entry was returned to the user.
CacheRankingsBlock* nodes[3]; // Nodes on the first three lists.
Rankings* my_rankings;
- explicit Iterator(Rankings* rankings);
- ~Iterator();
};
Rankings();