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

Side by Side Diff: net/disk_cache/backend_impl.cc

Issue 8658001: Disk cache: Add a hash to the entry's internal data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/disk_cache/backend_impl.h" 5 #include "net/disk_cache/backend_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 stats_.OnEvent(Stats::CREATE_ERROR); 812 stats_.OnEvent(Stats::CREATE_ERROR);
813 return NULL; 813 return NULL;
814 } 814 }
815 815
816 cache_entry->BeginLogging(net_log_, true); 816 cache_entry->BeginLogging(net_log_, true);
817 817
818 // We are not failing the operation; let's add this to the map. 818 // We are not failing the operation; let's add this to the map.
819 open_entries_[entry_address.value()] = cache_entry; 819 open_entries_[entry_address.value()] = cache_entry;
820 820
821 // Save the entry. 821 // Save the entry.
822 block_files_.GetFile(entry_address)->Store(cache_entry->entry()); 822 cache_entry->entry()->Store();
823 block_files_.GetFile(node_address)->Store(cache_entry->rankings()); 823 cache_entry->rankings()->Store();
gavinp 2011/11/29 15:47:42 Nice.
824 IncreaseNumEntries(); 824 IncreaseNumEntries();
825 entry_count_++; 825 entry_count_++;
826 826
827 // Link this entry through the index. 827 // Link this entry through the index.
828 if (parent.get()) { 828 if (parent.get()) {
829 parent->SetNextAddress(entry_address); 829 parent->SetNextAddress(entry_address);
830 } else { 830 } else {
831 data_->table[hash & mask_] = entry_address.value(); 831 data_->table[hash & mask_] = entry_address.value();
832 } 832 }
833 833
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 STRESS_NOTREACHED(); 1636 STRESS_NOTREACHED();
1637 return ERR_INVALID_ENTRY; 1637 return ERR_INVALID_ENTRY;
1638 } 1638 }
1639 1639
1640 STRESS_DCHECK(block_files_.IsValid( 1640 STRESS_DCHECK(block_files_.IsValid(
1641 Addr(cache_entry->entry()->Data()->rankings_node))); 1641 Addr(cache_entry->entry()->Data()->rankings_node)));
1642 1642
1643 if (!cache_entry->LoadNodeAddress()) 1643 if (!cache_entry->LoadNodeAddress())
1644 return ERR_READ_FAILURE; 1644 return ERR_READ_FAILURE;
1645 1645
1646 // Prevent overwriting the dirty flag on the destructor.
1647 cache_entry->SetDirtyFlag(GetCurrentEntryId());
1648
1649 if (!rankings_.SanityCheck(cache_entry->rankings(), false)) { 1646 if (!rankings_.SanityCheck(cache_entry->rankings(), false)) {
1650 STRESS_NOTREACHED(); 1647 STRESS_NOTREACHED();
1651 cache_entry->SetDirtyFlag(0); 1648 cache_entry->SetDirtyFlag(0);
1652 // Don't remove this from the list (it is not linked properly). Instead, 1649 // Don't remove this from the list (it is not linked properly). Instead,
1653 // break the link back to the entry because it is going away, and leave the 1650 // break the link back to the entry because it is going away, and leave the
1654 // rankings node to be deleted if we find it through a list. 1651 // rankings node to be deleted if we find it through a list.
1655 rankings_.SetContents(cache_entry->rankings(), 0); 1652 rankings_.SetContents(cache_entry->rankings(), 0);
1656 } else if (!rankings_.DataSanityCheck(cache_entry->rankings(), false)) { 1653 } else if (!rankings_.DataSanityCheck(cache_entry->rankings(), false)) {
1657 STRESS_NOTREACHED(); 1654 STRESS_NOTREACHED();
1658 cache_entry->SetDirtyFlag(0); 1655 cache_entry->SetDirtyFlag(0);
1659 rankings_.SetContents(cache_entry->rankings(), address.value()); 1656 rankings_.SetContents(cache_entry->rankings(), address.value());
1660 } 1657 }
1661 1658
1662 if (!cache_entry->DataSanityCheck()) { 1659 if (!cache_entry->DataSanityCheck()) {
1663 LOG(WARNING) << "Messed up entry found."; 1660 LOG(WARNING) << "Messed up entry found.";
1664 cache_entry->SetDirtyFlag(0); 1661 cache_entry->SetDirtyFlag(0);
1665 cache_entry->FixForDelete(); 1662 cache_entry->FixForDelete();
1666 } 1663 }
1667 1664
1665 // Prevent overwriting the dirty flag on the destructor.
1666 cache_entry->SetDirtyFlag(GetCurrentEntryId());
gavinp 2011/11/29 15:47:42 Why is this moving beyond the two sanity-check blo
rvargas (doing something else) 2011/11/29 19:08:56 Because this is reading Rankings; we want the firs
1667
1668 if (cache_entry->dirty()) { 1668 if (cache_entry->dirty()) {
1669 Trace("Dirty entry 0x%p 0x%x", reinterpret_cast<void*>(cache_entry.get()), 1669 Trace("Dirty entry 0x%p 0x%x", reinterpret_cast<void*>(cache_entry.get()),
1670 address.value()); 1670 address.value());
1671 } 1671 }
1672 1672
1673 open_entries_[address.value()] = cache_entry; 1673 open_entries_[address.value()] = cache_entry;
1674 1674
1675 cache_entry->BeginLogging(net_log_, false); 1675 cache_entry->BeginLogging(net_log_, false);
1676 cache_entry.swap(entry); 1676 cache_entry.swap(entry);
1677 return 0; 1677 return 0;
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
2212 ok = ok && block_files_.IsValid(cache_entry->rankings()->address()); 2212 ok = ok && block_files_.IsValid(cache_entry->rankings()->address());
2213 EntryStore* data = cache_entry->entry()->Data(); 2213 EntryStore* data = cache_entry->entry()->Data();
2214 for (size_t i = 0; i < arraysize(data->data_addr); i++) { 2214 for (size_t i = 0; i < arraysize(data->data_addr); i++) {
2215 if (data->data_addr[i]) { 2215 if (data->data_addr[i]) {
2216 Addr address(data->data_addr[i]); 2216 Addr address(data->data_addr[i]);
2217 if (address.is_block_file()) 2217 if (address.is_block_file())
2218 ok = ok && block_files_.IsValid(address); 2218 ok = ok && block_files_.IsValid(address);
2219 } 2219 }
2220 } 2220 }
2221 2221
2222 RankingsNode* rankings = cache_entry->rankings()->Data(); 2222 return ok && cache_entry->rankings()->VerifyHash();
2223 return ok && !rankings->dummy;
2224 } 2223 }
2225 2224
2226 int BackendImpl::MaxBuffersSize() { 2225 int BackendImpl::MaxBuffersSize() {
2227 static int64 total_memory = base::SysInfo::AmountOfPhysicalMemory(); 2226 static int64 total_memory = base::SysInfo::AmountOfPhysicalMemory();
2228 static bool done = false; 2227 static bool done = false;
2229 2228
2230 if (!done) { 2229 if (!done) {
2231 const int kMaxBuffersSize = 30 * 1024 * 1024; 2230 const int kMaxBuffersSize = 30 * 1024 * 1024;
2232 2231
2233 // We want to use up to 2% of the computer's memory. 2232 // We want to use up to 2% of the computer's memory.
2234 total_memory = total_memory * 2 / 100; 2233 total_memory = total_memory * 2 / 100;
2235 if (total_memory > kMaxBuffersSize || total_memory <= 0) 2234 if (total_memory > kMaxBuffersSize || total_memory <= 0)
2236 total_memory = kMaxBuffersSize; 2235 total_memory = kMaxBuffersSize;
2237 2236
2238 done = true; 2237 done = true;
2239 } 2238 }
2240 2239
2241 return static_cast<int>(total_memory); 2240 return static_cast<int>(total_memory);
2242 } 2241 }
2243 2242
2244 } // namespace disk_cache 2243 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698