summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/entry_impl.cc
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-31 21:28:48 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-31 21:28:48 +0000
commitbdad42a47f2dfa5783554844d54337454256a0a3 (patch)
tree915326e540a38ccc7f393029313490bb68d071d5 /net/disk_cache/entry_impl.cc
parentd0a918234ecc13dbf5fa11fad7122f7e81e38840 (diff)
downloadchromium_src-bdad42a47f2dfa5783554844d54337454256a0a3.zip
chromium_src-bdad42a47f2dfa5783554844d54337454256a0a3.tar.gz
chromium_src-bdad42a47f2dfa5783554844d54337454256a0a3.tar.bz2
Change the order of functions on the cc file to follow the order of the header. No actual code change.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/entry_impl.cc')
-rw-r--r--net/disk_cache/entry_impl.cc485
1 files changed, 243 insertions, 242 deletions
diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc
index b25aad3..75ab5ab 100644
--- a/net/disk_cache/entry_impl.cc
+++ b/net/disk_cache/entry_impl.cc
@@ -174,70 +174,6 @@ EntryImpl::~EntryImpl() {
backend_->CacheEntryDestroyed();
}
-void EntryImpl::DeleteData(Addr address, int index) {
- if (!address.is_initialized())
- return;
- if (address.is_separate_file()) {
- if (files_[index])
- files_[index] = NULL; // Releases the object.
-
- if (!DeleteFile(backend_->GetFileName(address).c_str()))
- LOG(ERROR) << "Failed to delete " << backend_->GetFileName(address) <<
- " from the cache.";
- } else {
- backend_->DeleteBlock(address, true);
- }
-}
-
-bool EntryImpl::CreateEntry(Addr node_address, const std::string& key,
- uint32 hash) {
- Trace("Create entry In");
- EntryStore* entry_store = entry_.Data();
- RankingsNode* node = node_.Data();
- memset(entry_store, 0, sizeof(EntryStore) * entry_.address().num_blocks());
- memset(node, 0, sizeof(RankingsNode));
- if (!node_.LazyInit(backend_->File(node_address), node_address))
- return false;
-
- entry_store->rankings_node = node_address.value();
- node->contents = entry_.address().value();
- node->pointer = this;
-
- entry_store->hash = hash;
- entry_store->key_len = static_cast<int32>(key.size());
- if (entry_store->key_len > kMaxInternalKeyLength) {
- Addr address(0);
- if (!CreateBlock(entry_store->key_len + 1, &address))
- return false;
-
- entry_store->long_key = address.value();
- File* file = GetBackingFile(address, kKeyFileIndex);
-
- size_t offset = 0;
- if (address.is_block_file())
- offset = address.start_block() * address.BlockSize() + kBlockHeaderSize;
-
- if (!file || !file->Write(key.data(), key.size(), offset)) {
- DeleteData(address, kKeyFileIndex);
- return false;
- }
-
- if (address.is_separate_file())
- file->SetLength(key.size() + 1);
- } else {
- memcpy(entry_store->key, key.data(), key.size());
- entry_store->key[key.size()] = '\0';
- }
- backend_->ModifyStorageSize(0, static_cast<int32>(key.size()));
- node->dirty = backend_->GetCurrentEntryId();
- Log("Create Entry ");
- return true;
-}
-
-void EntryImpl::Close() {
- Release();
-}
-
void EntryImpl::Doom() {
if (doomed_)
return;
@@ -246,13 +182,8 @@ void EntryImpl::Doom() {
backend_->InternalDoomEntry(this);
}
-void EntryImpl::InternalDoom() {
- DCHECK(node_.HasData());
- if (!node_.Data()->dirty) {
- node_.Data()->dirty = backend_->GetCurrentEntryId();
- node_.Store();
- }
- doomed_ = true;
+void EntryImpl::Close() {
+ Release();
}
std::string EntryImpl::GetKey() const {
@@ -443,6 +374,231 @@ int EntryImpl::WriteData(int index, int offset, const char* buf, int buf_len,
return (completed || !completion_callback) ? buf_len : net::ERR_IO_PENDING;
}
+uint32 EntryImpl::GetHash() {
+ return entry_.Data()->hash;
+}
+
+bool EntryImpl::CreateEntry(Addr node_address, const std::string& key,
+ uint32 hash) {
+ Trace("Create entry In");
+ EntryStore* entry_store = entry_.Data();
+ RankingsNode* node = node_.Data();
+ memset(entry_store, 0, sizeof(EntryStore) * entry_.address().num_blocks());
+ memset(node, 0, sizeof(RankingsNode));
+ if (!node_.LazyInit(backend_->File(node_address), node_address))
+ return false;
+
+ entry_store->rankings_node = node_address.value();
+ node->contents = entry_.address().value();
+ node->pointer = this;
+
+ entry_store->hash = hash;
+ entry_store->key_len = static_cast<int32>(key.size());
+ if (entry_store->key_len > kMaxInternalKeyLength) {
+ Addr address(0);
+ if (!CreateBlock(entry_store->key_len + 1, &address))
+ return false;
+
+ entry_store->long_key = address.value();
+ File* file = GetBackingFile(address, kKeyFileIndex);
+
+ size_t offset = 0;
+ if (address.is_block_file())
+ offset = address.start_block() * address.BlockSize() + kBlockHeaderSize;
+
+ if (!file || !file->Write(key.data(), key.size(), offset)) {
+ DeleteData(address, kKeyFileIndex);
+ return false;
+ }
+
+ if (address.is_separate_file())
+ file->SetLength(key.size() + 1);
+ } else {
+ memcpy(entry_store->key, key.data(), key.size());
+ entry_store->key[key.size()] = '\0';
+ }
+ backend_->ModifyStorageSize(0, static_cast<int32>(key.size()));
+ node->dirty = backend_->GetCurrentEntryId();
+ Log("Create Entry ");
+ return true;
+}
+
+bool EntryImpl::IsSameEntry(const std::string& key, uint32 hash) {
+ if (entry_.Data()->hash != hash || entry_.Data()->key_len != key.size())
+ return false;
+
+ std::string my_key = GetKey();
+ return key.compare(my_key) ? false : true;
+}
+
+void EntryImpl::InternalDoom() {
+ DCHECK(node_.HasData());
+ if (!node_.Data()->dirty) {
+ node_.Data()->dirty = backend_->GetCurrentEntryId();
+ node_.Store();
+ }
+ doomed_ = true;
+}
+
+CacheAddr EntryImpl::GetNextAddress() {
+ return entry_.Data()->next;
+}
+
+void EntryImpl::SetNextAddress(Addr address) {
+ entry_.Data()->next = address.value();
+ bool success = entry_.Store();
+ DCHECK(success);
+}
+
+bool EntryImpl::LoadNodeAddress() {
+ Addr address(entry_.Data()->rankings_node);
+ if (!node_.LazyInit(backend_->File(address), address))
+ return false;
+ return node_.Load();
+}
+
+EntryImpl* EntryImpl::Update(EntryImpl* entry) {
+ DCHECK(entry->rankings()->HasData());
+
+ RankingsNode* rankings = entry->rankings()->Data();
+ if (rankings->pointer) {
+ // Already in memory. Prevent clearing the dirty flag on the destructor.
+ rankings->dirty = 0;
+ EntryImpl* real_node = reinterpret_cast<EntryImpl*>(rankings->pointer);
+ real_node->AddRef();
+ entry->Release();
+ return real_node;
+ } else {
+ rankings->dirty = entry->backend_->GetCurrentEntryId();
+ rankings->pointer = entry;
+ if (!entry->rankings()->Store()) {
+ entry->Release();
+ return NULL;
+ }
+ return entry;
+ }
+}
+
+bool EntryImpl::IsDirty(int32 current_id) {
+ DCHECK(node_.HasData());
+ return node_.Data()->dirty && current_id != node_.Data()->dirty;
+}
+
+void EntryImpl::ClearDirtyFlag() {
+ node_.Data()->dirty = 0;
+}
+
+void EntryImpl::SetPointerForInvalidEntry(int32 new_id) {
+ node_.Data()->dirty = new_id;
+ node_.Data()->pointer = this;
+ node_.Store();
+}
+
+bool EntryImpl::SanityCheck() {
+ if (!entry_.Data()->rankings_node || !entry_.Data()->key_len)
+ return false;
+
+ Addr rankings_addr(entry_.Data()->rankings_node);
+ if (!rankings_addr.is_initialized() || rankings_addr.is_separate_file() ||
+ rankings_addr.file_type() != RANKINGS)
+ return false;
+
+ Addr next_addr(entry_.Data()->next);
+ if (next_addr.is_initialized() &&
+ (next_addr.is_separate_file() || next_addr.file_type() != BLOCK_256))
+ return false;
+
+ return true;
+}
+
+void EntryImpl::IncrementIoCount() {
+ backend_->IncrementIoCount();
+}
+
+void EntryImpl::DecrementIoCount() {
+ backend_->DecrementIoCount();
+}
+
+bool EntryImpl::CreateDataBlock(int index, int size) {
+ Addr address(entry_.Data()->data_addr[index]);
+ DCHECK(0 == index || 1 == index);
+
+ if (!CreateBlock(size, &address))
+ return false;
+
+ entry_.Data()->data_addr[index] = address.value();
+ entry_.Store();
+ return true;
+}
+
+bool EntryImpl::CreateBlock(int size, Addr* address) {
+ DCHECK(!address->is_initialized());
+
+ FileType file_type = Addr::RequiredFileType(size);
+ if (EXTERNAL == file_type) {
+ if (size > backend_->MaxFileSize())
+ return false;
+ if (!backend_->CreateExternalFile(address))
+ return false;
+ } else {
+ int num_blocks = (size + Addr::BlockSizeForFileType(file_type) - 1) /
+ Addr::BlockSizeForFileType(file_type);
+
+ if (!backend_->CreateBlock(file_type, num_blocks, address))
+ return false;
+ }
+ return true;
+}
+
+void EntryImpl::DeleteData(Addr address, int index) {
+ if (!address.is_initialized())
+ return;
+ if (address.is_separate_file()) {
+ if (files_[index])
+ files_[index] = NULL; // Releases the object.
+
+ if (!DeleteFile(backend_->GetFileName(address).c_str()))
+ LOG(ERROR) << "Failed to delete " << backend_->GetFileName(address) <<
+ " from the cache.";
+ } else {
+ backend_->DeleteBlock(address, true);
+ }
+}
+
+void EntryImpl::UpdateRank(bool modified) {
+ if (!doomed_) {
+ // Everything is handled by the backend.
+ backend_->UpdateRank(&node_, true);
+ return;
+ }
+
+ Time current = Time::Now();
+ node_.Data()->last_used = current.ToInternalValue();
+
+ if (modified)
+ node_.Data()->last_modified = current.ToInternalValue();
+}
+
+File* EntryImpl::GetBackingFile(Addr address, int index) {
+ File* file;
+ if (address.is_separate_file())
+ file = GetExternalFile(address, index);
+ else
+ file = backend_->File(address);
+ return file;
+}
+
+File* EntryImpl::GetExternalFile(Addr address, int index) {
+ DCHECK(index >= 0 && index <= 2);
+ if (!files_[index].get()) {
+ // For a key file, use mixed mode IO.
+ scoped_refptr<File> file(new File(2 == index));
+ if (file->Init(backend_->GetFileName(address)))
+ files_[index].swap(file);
+ }
+ return files_[index].get();
+}
+
bool EntryImpl::PrepareTarget(int index, int offset, int buf_len,
bool truncate) {
Addr address(entry_.Data()->data_addr[index]);
@@ -512,21 +668,6 @@ bool EntryImpl::GrowUserBuffer(int index, int offset, int buf_len,
return true;
}
-bool EntryImpl::ImportSeparateFile(int index, int offset, int buf_len) {
- if (entry_.Data()->data_size[index] > offset + buf_len) {
- entry_.Data()->data_size[index] = offset + buf_len;
- unreported_size_[index] += offset + buf_len -
- entry_.Data()->data_size[index];
- }
-
- if (!MoveToLocalBuffer(index))
- return false;
-
- // Clear the end of the buffer.
- ClearInvalidData(user_buffers_[index].get(), 0, offset + buf_len);
- return true;
-}
-
bool EntryImpl::MoveToLocalBuffer(int index) {
Addr address(entry_.Data()->data_addr[index]);
DCHECK(!user_buffers_[index].get());
@@ -556,6 +697,22 @@ bool EntryImpl::MoveToLocalBuffer(int index) {
return true;
}
+bool EntryImpl::ImportSeparateFile(int index, int offset, int buf_len) {
+ if (entry_.Data()->data_size[index] > offset + buf_len) {
+ entry_.Data()->data_size[index] = offset + buf_len;
+ unreported_size_[index] += offset + buf_len -
+ entry_.Data()->data_size[index];
+ }
+
+ if (!MoveToLocalBuffer(index))
+ return false;
+
+ // Clear the end of the buffer.
+ ClearInvalidData(user_buffers_[index].get(), 0, offset + buf_len);
+ return true;
+}
+
+
// The common scenario is that this is called from the destructor of the entry,
// to write to disk what we have buffered. We don't want to hold the destructor
// until the actual IO finishes, so we'll send an asynchronous write that will
@@ -603,162 +760,6 @@ bool EntryImpl::Flush(int index, int size, bool async) {
return true;
}
-bool EntryImpl::LoadNodeAddress() {
- Addr address(entry_.Data()->rankings_node);
- if (!node_.LazyInit(backend_->File(address), address))
- return false;
- return node_.Load();
-}
-
-EntryImpl* EntryImpl::Update(EntryImpl* entry) {
- DCHECK(entry->rankings()->HasData());
-
- RankingsNode* rankings = entry->rankings()->Data();
- if (rankings->pointer) {
- // Already in memory. Prevent clearing the dirty flag on the destructor.
- rankings->dirty = 0;
- EntryImpl* real_node = reinterpret_cast<EntryImpl*>(rankings->pointer);
- real_node->AddRef();
- entry->Release();
- return real_node;
- } else {
- rankings->dirty = entry->backend_->GetCurrentEntryId();
- rankings->pointer = entry;
- if (!entry->rankings()->Store()) {
- entry->Release();
- return NULL;
- }
- return entry;
- }
-}
-
-bool EntryImpl::CreateDataBlock(int index, int size) {
- Addr address(entry_.Data()->data_addr[index]);
- DCHECK(0 == index || 1 == index);
-
- if (!CreateBlock(size, &address))
- return false;
-
- entry_.Data()->data_addr[index] = address.value();
- entry_.Store();
- return true;
-}
-
-bool EntryImpl::CreateBlock(int size, Addr* address) {
- DCHECK(!address->is_initialized());
-
- FileType file_type = Addr::RequiredFileType(size);
- if (EXTERNAL == file_type) {
- if (size > backend_->MaxFileSize())
- return false;
- if (!backend_->CreateExternalFile(address))
- return false;
- } else {
- int num_blocks = (size + Addr::BlockSizeForFileType(file_type) - 1) /
- Addr::BlockSizeForFileType(file_type);
-
- if (!backend_->CreateBlock(file_type, num_blocks, address))
- return false;
- }
- return true;
-}
-
-bool EntryImpl::IsSameEntry(const std::string& key, uint32 hash) {
- if (entry_.Data()->hash != hash || entry_.Data()->key_len != key.size())
- return false;
-
- std::string my_key = GetKey();
- return key.compare(my_key) ? false : true;
-}
-
-CacheAddr EntryImpl::GetNextAddress() {
- return entry_.Data()->next;
-}
-
-void EntryImpl::SetNextAddress(Addr address) {
- entry_.Data()->next = address.value();
- bool success = entry_.Store();
- DCHECK(success);
-}
-
-void EntryImpl::UpdateRank(bool modified) {
- if (!doomed_) {
- // Everything is handled by the backend.
- backend_->UpdateRank(&node_, true);
- return;
- }
-
- Time current = Time::Now();
- node_.Data()->last_used = current.ToInternalValue();
-
- if (modified)
- node_.Data()->last_modified = current.ToInternalValue();
-}
-
-File* EntryImpl::GetBackingFile(Addr address, int index) {
- File* file;
- if (address.is_separate_file())
- file = GetExternalFile(address, index);
- else
- file = backend_->File(address);
- return file;
-}
-
-File* EntryImpl::GetExternalFile(Addr address, int index) {
- DCHECK(index >= 0 && index <= 2);
- if (!files_[index].get()) {
- // For a key file, use mixed mode IO.
- scoped_refptr<File> file(new File(2 == index));
- if (file->Init(backend_->GetFileName(address)))
- files_[index].swap(file);
- }
- return files_[index].get();
-}
-
-uint32 EntryImpl::GetHash() {
- return entry_.Data()->hash;
-}
-
-bool EntryImpl::IsDirty(int32 current_id) {
- DCHECK(node_.HasData());
- return node_.Data()->dirty && current_id != node_.Data()->dirty;
-}
-
-void EntryImpl::ClearDirtyFlag() {
- node_.Data()->dirty = 0;
-}
-
-void EntryImpl::SetPointerForInvalidEntry(int32 new_id) {
- node_.Data()->dirty = new_id;
- node_.Data()->pointer = this;
- node_.Store();
-}
-
-bool EntryImpl::SanityCheck() {
- if (!entry_.Data()->rankings_node || !entry_.Data()->key_len)
- return false;
-
- Addr rankings_addr(entry_.Data()->rankings_node);
- if (!rankings_addr.is_initialized() || rankings_addr.is_separate_file() ||
- rankings_addr.file_type() != RANKINGS)
- return false;
-
- Addr next_addr(entry_.Data()->next);
- if (next_addr.is_initialized() &&
- (next_addr.is_separate_file() || next_addr.file_type() != BLOCK_256))
- return false;
-
- return true;
-}
-
-void EntryImpl::IncrementIoCount() {
- backend_->IncrementIoCount();
-}
-
-void EntryImpl::DecrementIoCount() {
- backend_->DecrementIoCount();
-}
-
void EntryImpl::Log(const char* msg) {
void* pointer = NULL;
int dirty = 0;