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

Side by Side Diff: net/disk_cache/blockfile/backend_impl_v3.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/blockfile/backend_impl_v3.h" 5 #include "net/disk_cache/blockfile/backend_impl_v3.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 DCHECK(!init_); 83 DCHECK(!init_);
84 if (init_) 84 if (init_)
85 return net::ERR_FAILED; 85 return net::ERR_FAILED;
86 86
87 return net::ERR_IO_PENDING; 87 return net::ERR_IO_PENDING;
88 } 88 }
89 89
90 // ------------------------------------------------------------------------ 90 // ------------------------------------------------------------------------
91 91
92 #if defined(V3_NOT_JUST_YET_READY) 92 #if defined(V3_NOT_JUST_YET_READY)
93 int BackendImplV3::OpenPrevEntry(void** iter, Entry** prev_entry, 93 int BackendImplV3::OpenPrevEntry(void** iter,
94 Entry** prev_entry,
94 const CompletionCallback& callback) { 95 const CompletionCallback& callback) {
95 DCHECK(!callback.is_null()); 96 DCHECK(!callback.is_null());
96 return OpenFollowingEntry(true, iter, prev_entry, callback); 97 return OpenFollowingEntry(true, iter, prev_entry, callback);
97 } 98 }
98 #endif // defined(V3_NOT_JUST_YET_READY). 99 #endif // defined(V3_NOT_JUST_YET_READY).
99 100
100 bool BackendImplV3::SetMaxSize(int max_bytes) { 101 bool BackendImplV3::SetMaxSize(int max_bytes) {
101 COMPILE_ASSERT(sizeof(max_bytes) == sizeof(max_size_), unsupported_int_model); 102 COMPILE_ASSERT(sizeof(max_bytes) == sizeof(max_size_), unsupported_int_model);
102 if (max_bytes < 0) 103 if (max_bytes < 0)
103 return false; 104 return false;
104 105
105 // Zero size means use the default. 106 // Zero size means use the default.
106 if (!max_bytes) 107 if (!max_bytes)
107 return true; 108 return true;
108 109
109 // Avoid a DCHECK later on. 110 // Avoid a DCHECK later on.
110 if (max_bytes >= kint32max - kint32max / 10) 111 if (max_bytes >= kint32max - kint32max / 10)
111 max_bytes = kint32max - kint32max / 10 - 1; 112 max_bytes = kint32max - kint32max / 10 - 1;
112 113
113 user_flags_ |= MAX_SIZE; 114 user_flags_ |= MAX_SIZE;
114 max_size_ = max_bytes; 115 max_size_ = max_bytes;
115 return true; 116 return true;
116 } 117 }
117 118
118 void BackendImplV3::SetType(net::CacheType type) { 119 void BackendImplV3::SetType(net::CacheType type) {
119 DCHECK_NE(net::MEMORY_CACHE, type); 120 DCHECK_NE(net::MEMORY_CACHE, type);
120 cache_type_ = type; 121 cache_type_ = type;
121 } 122 }
122 123
123 bool BackendImplV3::CreateBlock(FileType block_type, int block_count, 124 bool BackendImplV3::CreateBlock(FileType block_type,
125 int block_count,
124 Addr* block_address) { 126 Addr* block_address) {
125 return block_files_.CreateBlock(block_type, block_count, block_address); 127 return block_files_.CreateBlock(block_type, block_count, block_address);
126 } 128 }
127 129
128 #if defined(V3_NOT_JUST_YET_READY) 130 #if defined(V3_NOT_JUST_YET_READY)
129 void BackendImplV3::UpdateRank(EntryImplV3* entry, bool modified) { 131 void BackendImplV3::UpdateRank(EntryImplV3* entry, bool modified) {
130 if (read_only_ || (!modified && cache_type() == net::SHADER_CACHE)) 132 if (read_only_ || (!modified && cache_type() == net::SHADER_CACHE))
131 return; 133 return;
132 eviction_.UpdateRank(entry, modified); 134 eviction_.UpdateRank(entry, modified);
133 } 135 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 } 231 }
230 232
231 bool BackendImplV3::IsLoaded() const { 233 bool BackendImplV3::IsLoaded() const {
232 if (user_flags_ & NO_LOAD_PROTECTION) 234 if (user_flags_ & NO_LOAD_PROTECTION)
233 return false; 235 return false;
234 236
235 return user_load_; 237 return user_load_;
236 } 238 }
237 239
238 std::string BackendImplV3::HistogramName(const char* name) const { 240 std::string BackendImplV3::HistogramName(const char* name) const {
239 static const char* names[] = { "Http", "", "Media", "AppCache", "Shader" }; 241 static const char* names[] = {"Http", "", "Media", "AppCache", "Shader"};
240 DCHECK_NE(cache_type_, net::MEMORY_CACHE); 242 DCHECK_NE(cache_type_, net::MEMORY_CACHE);
241 return base::StringPrintf("DiskCache3.%s_%s", name, names[cache_type_]); 243 return base::StringPrintf("DiskCache3.%s_%s", name, names[cache_type_]);
242 } 244 }
243 245
244 base::WeakPtr<BackendImplV3> BackendImplV3::GetWeakPtr() { 246 base::WeakPtr<BackendImplV3> BackendImplV3::GetWeakPtr() {
245 return ptr_factory_.GetWeakPtr(); 247 return ptr_factory_.GetWeakPtr();
246 } 248 }
247 249
248 #if defined(V3_NOT_JUST_YET_READY) 250 #if defined(V3_NOT_JUST_YET_READY)
249 // We want to remove biases from some histograms so we only send data once per 251 // We want to remove biases from some histograms so we only send data once per
(...skipping 22 matching lines...) Expand all
272 274
273 Time create_time = Time::FromInternalValue(header->create_time); 275 Time create_time = Time::FromInternalValue(header->create_time);
274 CACHE_UMA(AGE, "FillupAge", create_time); 276 CACHE_UMA(AGE, "FillupAge", create_time);
275 277
276 int64 use_time = stats_.GetCounter(Stats::TIMER); 278 int64 use_time = stats_.GetCounter(Stats::TIMER);
277 CACHE_UMA(HOURS, "FillupTime", static_cast<int>(use_time / 120)); 279 CACHE_UMA(HOURS, "FillupTime", static_cast<int>(use_time / 120));
278 CACHE_UMA(PERCENTAGE, "FirstHitRatio", stats_.GetHitRatio()); 280 CACHE_UMA(PERCENTAGE, "FirstHitRatio", stats_.GetHitRatio());
279 281
280 if (!use_time) 282 if (!use_time)
281 use_time = 1; 283 use_time = 1;
282 CACHE_UMA(COUNTS_10000, "FirstEntryAccessRate", 284 CACHE_UMA(COUNTS_10000,
285 "FirstEntryAccessRate",
283 static_cast<int>(header->num_entries / use_time)); 286 static_cast<int>(header->num_entries / use_time));
284 CACHE_UMA(COUNTS, "FirstByteIORate", 287 CACHE_UMA(COUNTS,
288 "FirstByteIORate",
285 static_cast<int>((header->num_bytes / 1024) / use_time)); 289 static_cast<int>((header->num_bytes / 1024) / use_time));
286 290
287 int avg_size = header->num_bytes / GetEntryCount(); 291 int avg_size = header->num_bytes / GetEntryCount();
288 CACHE_UMA(COUNTS, "FirstEntrySize", avg_size); 292 CACHE_UMA(COUNTS, "FirstEntrySize", avg_size);
289 293
290 int large_entries_bytes = stats_.GetLargeEntriesSize(); 294 int large_entries_bytes = stats_.GetLargeEntriesSize();
291 int large_ratio = large_entries_bytes * 100 / header->num_bytes; 295 int large_ratio = large_entries_bytes * 100 / header->num_bytes;
292 CACHE_UMA(PERCENTAGE, "FirstLargeEntriesRatio", large_ratio); 296 CACHE_UMA(PERCENTAGE, "FirstLargeEntriesRatio", large_ratio);
293 297
294 if (!lru_eviction_) { 298 if (!lru_eviction_) {
295 CACHE_UMA(PERCENTAGE, "FirstResurrectRatio", stats_.GetResurrectRatio()); 299 CACHE_UMA(PERCENTAGE, "FirstResurrectRatio", stats_.GetResurrectRatio());
296 CACHE_UMA(PERCENTAGE, "FirstNoUseRatio", 300 CACHE_UMA(PERCENTAGE,
301 "FirstNoUseRatio",
297 header->num_no_use_entries * 100 / header->num_entries); 302 header->num_no_use_entries * 100 / header->num_entries);
298 CACHE_UMA(PERCENTAGE, "FirstLowUseRatio", 303 CACHE_UMA(PERCENTAGE,
304 "FirstLowUseRatio",
299 header->num_low_use_entries * 100 / header->num_entries); 305 header->num_low_use_entries * 100 / header->num_entries);
300 CACHE_UMA(PERCENTAGE, "FirstHighUseRatio", 306 CACHE_UMA(PERCENTAGE,
307 "FirstHighUseRatio",
301 header->num_high_use_entries * 100 / header->num_entries); 308 header->num_high_use_entries * 100 / header->num_entries);
302 } 309 }
303 310
304 stats_.ResetRatios(); 311 stats_.ResetRatios();
305 } 312 }
306 313
307 void BackendImplV3::OnEvent(Stats::Counters an_event) { 314 void BackendImplV3::OnEvent(Stats::Counters an_event) {
308 stats_.OnEvent(an_event); 315 stats_.OnEvent(an_event);
309 } 316 }
310 317
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 return cache_type_; 430 return cache_type_;
424 } 431 }
425 432
426 int32 BackendImplV3::GetEntryCount() const { 433 int32 BackendImplV3::GetEntryCount() const {
427 if (disabled_) 434 if (disabled_)
428 return 0; 435 return 0;
429 DCHECK(init_); 436 DCHECK(init_);
430 return index_.header()->num_entries; 437 return index_.header()->num_entries;
431 } 438 }
432 439
433 int BackendImplV3::OpenEntry(const std::string& key, Entry** entry, 440 int BackendImplV3::OpenEntry(const std::string& key,
441 Entry** entry,
434 const CompletionCallback& callback) { 442 const CompletionCallback& callback) {
435 if (disabled_) 443 if (disabled_)
436 return NULL; 444 return NULL;
437 445
438 TimeTicks start = TimeTicks::Now(); 446 TimeTicks start = TimeTicks::Now();
439 uint32 hash = base::Hash(key); 447 uint32 hash = base::Hash(key);
440 Trace("Open hash 0x%x", hash); 448 Trace("Open hash 0x%x", hash);
441 449
442 bool error; 450 bool error;
443 EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error); 451 EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error);
(...skipping 13 matching lines...) Expand all
457 CACHE_UMA(COUNTS_10000, "AllOpenBySize.Miss", 0, current_size); 465 CACHE_UMA(COUNTS_10000, "AllOpenBySize.Miss", 0, current_size);
458 CACHE_UMA(HOURS, "AllOpenByTotalHours.Miss", 0, total_hours); 466 CACHE_UMA(HOURS, "AllOpenByTotalHours.Miss", 0, total_hours);
459 CACHE_UMA(HOURS, "AllOpenByUseHours.Miss", 0, use_hours); 467 CACHE_UMA(HOURS, "AllOpenByUseHours.Miss", 0, use_hours);
460 stats_.OnEvent(Stats::OPEN_MISS); 468 stats_.OnEvent(Stats::OPEN_MISS);
461 return NULL; 469 return NULL;
462 } 470 }
463 471
464 eviction_.OnOpenEntry(cache_entry); 472 eviction_.OnOpenEntry(cache_entry);
465 entry_count_++; 473 entry_count_++;
466 474
467 Trace("Open hash 0x%x end: 0x%x", hash, 475 Trace("Open hash 0x%x end: 0x%x",
476 hash,
468 cache_entry->entry()->address().value()); 477 cache_entry->entry()->address().value());
469 CACHE_UMA(AGE_MS, "OpenTime", 0, start); 478 CACHE_UMA(AGE_MS, "OpenTime", 0, start);
470 CACHE_UMA(COUNTS_10000, "AllOpenBySize.Hit", 0, current_size); 479 CACHE_UMA(COUNTS_10000, "AllOpenBySize.Hit", 0, current_size);
471 CACHE_UMA(HOURS, "AllOpenByTotalHours.Hit", 0, total_hours); 480 CACHE_UMA(HOURS, "AllOpenByTotalHours.Hit", 0, total_hours);
472 CACHE_UMA(HOURS, "AllOpenByUseHours.Hit", 0, use_hours); 481 CACHE_UMA(HOURS, "AllOpenByUseHours.Hit", 0, use_hours);
473 stats_.OnEvent(Stats::OPEN_HIT); 482 stats_.OnEvent(Stats::OPEN_HIT);
474 SIMPLE_STATS_COUNTER("disk_cache.hit"); 483 SIMPLE_STATS_COUNTER("disk_cache.hit");
475 return cache_entry; 484 return cache_entry;
476 } 485 }
477 486
478 int BackendImplV3::CreateEntry(const std::string& key, Entry** entry, 487 int BackendImplV3::CreateEntry(const std::string& key,
488 Entry** entry,
479 const CompletionCallback& callback) { 489 const CompletionCallback& callback) {
480 if (disabled_ || key.empty()) 490 if (disabled_ || key.empty())
481 return NULL; 491 return NULL;
482 492
483 TimeTicks start = TimeTicks::Now(); 493 TimeTicks start = TimeTicks::Now();
484 Trace("Create hash 0x%x", hash); 494 Trace("Create hash 0x%x", hash);
485 495
486 scoped_refptr<EntryImpl> parent; 496 scoped_refptr<EntryImpl> parent;
487 Addr entry_address(data_->table[hash & mask_]); 497 Addr entry_address(data_->table[hash & mask_]);
488 if (entry_address.is_initialized()) { 498 if (entry_address.is_initialized()) {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 EntryImpl* node; 629 EntryImpl* node;
620 void* iter = NULL; 630 void* iter = NULL;
621 EntryImpl* next = OpenNextEntryImpl(&iter); 631 EntryImpl* next = OpenNextEntryImpl(&iter);
622 if (!next) 632 if (!next)
623 return net::OK; 633 return net::OK;
624 634
625 while (next) { 635 while (next) {
626 node = next; 636 node = next;
627 next = OpenNextEntryImpl(&iter); 637 next = OpenNextEntryImpl(&iter);
628 638
629 if (node->GetLastUsed() >= initial_time && 639 if (node->GetLastUsed() >= initial_time && node->GetLastUsed() < end_time) {
630 node->GetLastUsed() < end_time) {
631 node->DoomImpl(); 640 node->DoomImpl();
632 } else if (node->GetLastUsed() < initial_time) { 641 } else if (node->GetLastUsed() < initial_time) {
633 if (next) 642 if (next)
634 next->Release(); 643 next->Release();
635 next = NULL; 644 next = NULL;
636 SyncEndEnumeration(iter); 645 SyncEndEnumeration(iter);
637 } 646 }
638 647
639 node->Release(); 648 node->Release();
640 } 649 }
(...skipping 19 matching lines...) Expand all
660 SyncEndEnumeration(iter); 669 SyncEndEnumeration(iter);
661 return net::OK; 670 return net::OK;
662 } 671 }
663 672
664 entry->DoomImpl(); 673 entry->DoomImpl();
665 entry->Release(); 674 entry->Release();
666 SyncEndEnumeration(iter); // Dooming the entry invalidates the iterator. 675 SyncEndEnumeration(iter); // Dooming the entry invalidates the iterator.
667 } 676 }
668 } 677 }
669 678
670 int BackendImplV3::OpenNextEntry(void** iter, Entry** next_entry, 679 int BackendImplV3::OpenNextEntry(void** iter,
680 Entry** next_entry,
671 const CompletionCallback& callback) { 681 const CompletionCallback& callback) {
672 DCHECK(!callback.is_null()); 682 DCHECK(!callback.is_null());
673 background_queue_.OpenNextEntry(iter, next_entry, callback); 683 background_queue_.OpenNextEntry(iter, next_entry, callback);
674 return net::ERR_IO_PENDING; 684 return net::ERR_IO_PENDING;
675 } 685 }
676 686
677 void BackendImplV3::EndEnumeration(void** iter) { 687 void BackendImplV3::EndEnumeration(void** iter) {
678 scoped_ptr<IndexIterator> iterator( 688 scoped_ptr<IndexIterator> iterator(reinterpret_cast<IndexIterator*>(*iter));
679 reinterpret_cast<IndexIterator*>(*iter));
680 *iter = NULL; 689 *iter = NULL;
681 } 690 }
682 691
683 void BackendImplV3::GetStats(StatsItems* stats) { 692 void BackendImplV3::GetStats(StatsItems* stats) {
684 if (disabled_) 693 if (disabled_)
685 return; 694 return;
686 695
687 std::pair<std::string, std::string> item; 696 std::pair<std::string, std::string> item;
688 697
689 item.first = "Entries"; 698 item.first = "Entries";
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 // of bigger caches. TODO(rvargas): remove this limit. 760 // of bigger caches. TODO(rvargas): remove this limit.
752 if (max_size_ > kDefaultCacheSize * 4) 761 if (max_size_ > kDefaultCacheSize * 4)
753 max_size_ = kDefaultCacheSize * 4; 762 max_size_ = kDefaultCacheSize * 4;
754 763
755 if (!table_len) 764 if (!table_len)
756 return; 765 return;
757 766
758 // If we already have a table, adjust the size to it. 767 // If we already have a table, adjust the size to it.
759 int current_max_size = MaxStorageSizeForTable(table_len); 768 int current_max_size = MaxStorageSizeForTable(table_len);
760 if (max_size_ > current_max_size) 769 if (max_size_ > current_max_size)
761 max_size_= current_max_size; 770 max_size_ = current_max_size;
762 } 771 }
763 772
764 bool BackendImplV3::InitStats() { 773 bool BackendImplV3::InitStats() {
765 Addr address(data_->header.stats); 774 Addr address(data_->header.stats);
766 int size = stats_.StorageSize(); 775 int size = stats_.StorageSize();
767 776
768 if (!address.is_initialized()) { 777 if (!address.is_initialized()) {
769 FileType file_type = Addr::RequiredFileType(size); 778 FileType file_type = Addr::RequiredFileType(size);
770 DCHECK_NE(file_type, EXTERNAL); 779 DCHECK_NE(file_type, EXTERNAL);
771 int num_blocks = Addr::RequiredBlocks(size, file_type); 780 int num_blocks = Addr::RequiredBlocks(size, file_type);
772 781
773 if (!CreateBlock(file_type, num_blocks, &address)) 782 if (!CreateBlock(file_type, num_blocks, &address))
774 return false; 783 return false;
775 return stats_.Init(NULL, 0, address); 784 return stats_.Init(NULL, 0, address);
776 } 785 }
777 786
778 if (!address.is_block_file()) { 787 if (!address.is_block_file()) {
779 NOTREACHED(); 788 NOTREACHED();
780 return false; 789 return false;
781 } 790 }
782 791
783 // Load the required data. 792 // Load the required data.
784 size = address.num_blocks() * address.BlockSize(); 793 size = address.num_blocks() * address.BlockSize();
785 MappedFile* file = File(address); 794 MappedFile* file = File(address);
786 if (!file) 795 if (!file)
787 return false; 796 return false;
788 797
789 scoped_ptr<char[]> data(new char[size]); 798 scoped_ptr<char[]> data(new char[size]);
790 size_t offset = address.start_block() * address.BlockSize() + 799 size_t offset =
791 kBlockHeaderSize; 800 address.start_block() * address.BlockSize() + kBlockHeaderSize;
792 if (!file->Read(data.get(), size, offset)) 801 if (!file->Read(data.get(), size, offset))
793 return false; 802 return false;
794 803
795 if (!stats_.Init(data.get(), size, address)) 804 if (!stats_.Init(data.get(), size, address))
796 return false; 805 return false;
797 if (cache_type_ == net::DISK_CACHE && ShouldReportAgain()) 806 if (cache_type_ == net::DISK_CACHE && ShouldReportAgain())
798 stats_.InitSizeHistogram(); 807 stats_.InitSizeHistogram();
799 return true; 808 return true;
800 } 809 }
801 810
802 void BackendImplV3::StoreStats() { 811 void BackendImplV3::StoreStats() {
803 int size = stats_.StorageSize(); 812 int size = stats_.StorageSize();
804 scoped_ptr<char[]> data(new char[size]); 813 scoped_ptr<char[]> data(new char[size]);
805 Addr address; 814 Addr address;
806 size = stats_.SerializeStats(data.get(), size, &address); 815 size = stats_.SerializeStats(data.get(), size, &address);
807 DCHECK(size); 816 DCHECK(size);
808 if (!address.is_initialized()) 817 if (!address.is_initialized())
809 return; 818 return;
810 819
811 MappedFile* file = File(address); 820 MappedFile* file = File(address);
812 if (!file) 821 if (!file)
813 return; 822 return;
814 823
815 size_t offset = address.start_block() * address.BlockSize() + 824 size_t offset =
816 kBlockHeaderSize; 825 address.start_block() * address.BlockSize() + kBlockHeaderSize;
817 file->Write(data.get(), size, offset); // ignore result. 826 file->Write(data.get(), size, offset); // ignore result.
818 } 827 }
819 828
820 void BackendImplV3::RestartCache(bool failure) { 829 void BackendImplV3::RestartCache(bool failure) {
821 int64 errors = stats_.GetCounter(Stats::FATAL_ERROR); 830 int64 errors = stats_.GetCounter(Stats::FATAL_ERROR);
822 int64 full_dooms = stats_.GetCounter(Stats::DOOM_CACHE); 831 int64 full_dooms = stats_.GetCounter(Stats::DOOM_CACHE);
823 int64 partial_dooms = stats_.GetCounter(Stats::DOOM_RECENT); 832 int64 partial_dooms = stats_.GetCounter(Stats::DOOM_RECENT);
824 int64 last_report = stats_.GetCounter(Stats::LAST_REPORT); 833 int64 last_report = stats_.GetCounter(Stats::LAST_REPORT);
825 834
826 PrepareForRestart(); 835 PrepareForRestart();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 if (IsLoaded()) { 923 if (IsLoaded()) {
915 CACHE_UMA(AGE_MS, "LoadTime", 0, start); 924 CACHE_UMA(AGE_MS, "LoadTime", 0, start);
916 } 925 }
917 926
918 if (!cache_entry->SanityCheck()) { 927 if (!cache_entry->SanityCheck()) {
919 LOG(WARNING) << "Messed up entry found."; 928 LOG(WARNING) << "Messed up entry found.";
920 STRESS_NOTREACHED(); 929 STRESS_NOTREACHED();
921 return ERR_INVALID_ENTRY; 930 return ERR_INVALID_ENTRY;
922 } 931 }
923 932
924 STRESS_DCHECK(block_files_.IsValid( 933 STRESS_DCHECK(
925 Addr(cache_entry->entry()->Data()->rankings_node))); 934 block_files_.IsValid(Addr(cache_entry->entry()->Data()->rankings_node)));
926 935
927 if (!cache_entry->LoadNodeAddress()) 936 if (!cache_entry->LoadNodeAddress())
928 return ERR_READ_FAILURE; 937 return ERR_READ_FAILURE;
929 938
930 if (!rankings_.SanityCheck(cache_entry->rankings(), false)) { 939 if (!rankings_.SanityCheck(cache_entry->rankings(), false)) {
931 STRESS_NOTREACHED(); 940 STRESS_NOTREACHED();
932 cache_entry->SetDirtyFlag(0); 941 cache_entry->SetDirtyFlag(0);
933 // Don't remove this from the list (it is not linked properly). Instead, 942 // Don't remove this from the list (it is not linked properly). Instead,
934 // break the link back to the entry because it is going away, and leave the 943 // break the link back to the entry because it is going away, and leave the
935 // rankings node to be deleted if we find it through a list. 944 // rankings node to be deleted if we find it through a list.
936 rankings_.SetContents(cache_entry->rankings(), 0); 945 rankings_.SetContents(cache_entry->rankings(), 0);
937 } else if (!rankings_.DataSanityCheck(cache_entry->rankings(), false)) { 946 } else if (!rankings_.DataSanityCheck(cache_entry->rankings(), false)) {
938 STRESS_NOTREACHED(); 947 STRESS_NOTREACHED();
939 cache_entry->SetDirtyFlag(0); 948 cache_entry->SetDirtyFlag(0);
940 rankings_.SetContents(cache_entry->rankings(), address.value()); 949 rankings_.SetContents(cache_entry->rankings(), address.value());
941 } 950 }
942 951
943 if (!cache_entry->DataSanityCheck()) { 952 if (!cache_entry->DataSanityCheck()) {
944 LOG(WARNING) << "Messed up entry found."; 953 LOG(WARNING) << "Messed up entry found.";
945 cache_entry->SetDirtyFlag(0); 954 cache_entry->SetDirtyFlag(0);
946 cache_entry->FixForDelete(); 955 cache_entry->FixForDelete();
947 } 956 }
948 957
949 // Prevent overwriting the dirty flag on the destructor. 958 // Prevent overwriting the dirty flag on the destructor.
950 cache_entry->SetDirtyFlag(GetCurrentEntryId()); 959 cache_entry->SetDirtyFlag(GetCurrentEntryId());
951 960
952 if (cache_entry->dirty()) { 961 if (cache_entry->dirty()) {
953 Trace("Dirty entry 0x%p 0x%x", reinterpret_cast<void*>(cache_entry.get()), 962 Trace("Dirty entry 0x%p 0x%x",
963 reinterpret_cast<void*>(cache_entry.get()),
954 address.value()); 964 address.value());
955 } 965 }
956 966
957 open_entries_[address.value()] = cache_entry.get(); 967 open_entries_[address.value()] = cache_entry.get();
958 968
959 cache_entry->BeginLogging(net_log_, false); 969 cache_entry->BeginLogging(net_log_, false);
960 cache_entry.swap(entry); 970 cache_entry.swap(entry);
961 return 0; 971 return 0;
962 } 972 }
963 973
964 // This is the actual implementation for OpenNextEntry and OpenPrevEntry. 974 // This is the actual implementation for OpenNextEntry and OpenPrevEntry.
965 int BackendImplV3::OpenFollowingEntry(bool forward, void** iter, 975 int BackendImplV3::OpenFollowingEntry(bool forward,
976 void** iter,
966 Entry** next_entry, 977 Entry** next_entry,
967 const CompletionCallback& callback) { 978 const CompletionCallback& callback) {
968 if (disabled_) 979 if (disabled_)
969 return net::ERR_FAILED; 980 return net::ERR_FAILED;
970 981
971 DCHECK(iter); 982 DCHECK(iter);
972 983
973 const int kListsToSearch = 3; 984 const int kListsToSearch = 3;
974 scoped_refptr<EntryImpl> entries[kListsToSearch]; 985 scoped_refptr<EntryImpl> entries[kListsToSearch];
975 scoped_ptr<Rankings::Iterator> iterator( 986 scoped_ptr<Rankings::Iterator> iterator(
976 reinterpret_cast<Rankings::Iterator*>(*iter)); 987 reinterpret_cast<Rankings::Iterator*>(*iter));
977 *iter = NULL; 988 *iter = NULL;
978 989
979 if (!iterator.get()) { 990 if (!iterator.get()) {
980 iterator.reset(new Rankings::Iterator(&rankings_)); 991 iterator.reset(new Rankings::Iterator(&rankings_));
981 bool ret = false; 992 bool ret = false;
982 993
983 // Get an entry from each list. 994 // Get an entry from each list.
984 for (int i = 0; i < kListsToSearch; i++) { 995 for (int i = 0; i < kListsToSearch; i++) {
985 EntryImpl* temp = NULL; 996 EntryImpl* temp = NULL;
986 ret |= OpenFollowingEntryFromList(forward, static_cast<Rankings::List>(i), 997 ret |= OpenFollowingEntryFromList(
987 &iterator->nodes[i], &temp); 998 forward, static_cast<Rankings::List>(i), &iterator->nodes[i], &temp);
988 entries[i].swap(&temp); // The entry was already addref'd. 999 entries[i].swap(&temp); // The entry was already addref'd.
989 } 1000 }
990 if (!ret) 1001 if (!ret)
991 return NULL; 1002 return NULL;
992 } else { 1003 } else {
993 // Get the next entry from the last list, and the actual entries for the 1004 // Get the next entry from the last list, and the actual entries for the
994 // elements on the other lists. 1005 // elements on the other lists.
995 for (int i = 0; i < kListsToSearch; i++) { 1006 for (int i = 0; i < kListsToSearch; i++) {
996 EntryImpl* temp = NULL; 1007 EntryImpl* temp = NULL;
997 if (iterator->list == i) { 1008 if (iterator->list == i) {
998 OpenFollowingEntryFromList(forward, iterator->list, 1009 OpenFollowingEntryFromList(
999 &iterator->nodes[i], &temp); 1010 forward, iterator->list, &iterator->nodes[i], &temp);
1000 } else { 1011 } else {
1001 temp = GetEnumeratedEntry(iterator->nodes[i], 1012 temp = GetEnumeratedEntry(iterator->nodes[i],
1002 static_cast<Rankings::List>(i)); 1013 static_cast<Rankings::List>(i));
1003 } 1014 }
1004 1015
1005 entries[i].swap(&temp); // The entry was already addref'd. 1016 entries[i].swap(&temp); // The entry was already addref'd.
1006 } 1017 }
1007 } 1018 }
1008 1019
1009 int newest = -1; 1020 int newest = -1;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 1107
1097 num_refs_ = num_pending_io_ = max_refs_ = 0; 1108 num_refs_ = num_pending_io_ = max_refs_ = 0;
1098 entry_count_ = byte_count_ = 0; 1109 entry_count_ = byte_count_ = 0;
1099 1110
1100 if (!restarted_) { 1111 if (!restarted_) {
1101 buffer_bytes_ = 0; 1112 buffer_bytes_ = 0;
1102 trace_object_ = TraceObject::GetTraceObject(); 1113 trace_object_ = TraceObject::GetTraceObject();
1103 // Create a recurrent timer of 30 secs. 1114 // Create a recurrent timer of 30 secs.
1104 int timer_delay = unit_test_ ? 1000 : 30000; 1115 int timer_delay = unit_test_ ? 1000 : 30000;
1105 timer_.reset(new base::RepeatingTimer<BackendImplV3>()); 1116 timer_.reset(new base::RepeatingTimer<BackendImplV3>());
1106 timer_->Start(FROM_HERE, TimeDelta::FromMilliseconds(timer_delay), this, 1117 timer_->Start(FROM_HERE,
1118 TimeDelta::FromMilliseconds(timer_delay),
1119 this,
1107 &BackendImplV3::OnStatsTimer); 1120 &BackendImplV3::OnStatsTimer);
1108 } 1121 }
1109 1122
1110 init_ = true; 1123 init_ = true;
1111 Trace("Init"); 1124 Trace("Init");
1112 1125
1113 if (data_->header.experiment != NO_EXPERIMENT && 1126 if (data_->header.experiment != NO_EXPERIMENT &&
1114 cache_type_ != net::DISK_CACHE) { 1127 cache_type_ != net::DISK_CACHE) {
1115 // No experiment for other caches. 1128 // No experiment for other caches.
1116 return net::ERR_FAILED; 1129 return net::ERR_FAILED;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 1328
1316 int current_size = header->num_bytes / (1024 * 1024); 1329 int current_size = header->num_bytes / (1024 * 1024);
1317 int max_size = max_size_ / (1024 * 1024); 1330 int max_size = max_size_ / (1024 * 1024);
1318 1331
1319 CACHE_UMA(COUNTS_10000, "Size", current_size); 1332 CACHE_UMA(COUNTS_10000, "Size", current_size);
1320 CACHE_UMA(COUNTS_10000, "MaxSize", max_size); 1333 CACHE_UMA(COUNTS_10000, "MaxSize", max_size);
1321 if (!max_size) 1334 if (!max_size)
1322 max_size++; 1335 max_size++;
1323 CACHE_UMA(PERCENTAGE, "UsedSpace", current_size * 100 / max_size); 1336 CACHE_UMA(PERCENTAGE, "UsedSpace", current_size * 100 / max_size);
1324 1337
1325 CACHE_UMA(COUNTS_10000, "AverageOpenEntries", 1338 CACHE_UMA(COUNTS_10000,
1339 "AverageOpenEntries",
1326 static_cast<int>(stats_.GetCounter(Stats::OPEN_ENTRIES))); 1340 static_cast<int>(stats_.GetCounter(Stats::OPEN_ENTRIES)));
1327 CACHE_UMA(COUNTS_10000, "MaxOpenEntries", 1341 CACHE_UMA(COUNTS_10000,
1342 "MaxOpenEntries",
1328 static_cast<int>(stats_.GetCounter(Stats::MAX_ENTRIES))); 1343 static_cast<int>(stats_.GetCounter(Stats::MAX_ENTRIES)));
1329 stats_.SetCounter(Stats::MAX_ENTRIES, 0); 1344 stats_.SetCounter(Stats::MAX_ENTRIES, 0);
1330 1345
1331 CACHE_UMA(COUNTS_10000, "TotalFatalErrors", 1346 CACHE_UMA(COUNTS_10000,
1347 "TotalFatalErrors",
1332 static_cast<int>(stats_.GetCounter(Stats::FATAL_ERROR))); 1348 static_cast<int>(stats_.GetCounter(Stats::FATAL_ERROR)));
1333 CACHE_UMA(COUNTS_10000, "TotalDoomCache", 1349 CACHE_UMA(COUNTS_10000,
1350 "TotalDoomCache",
1334 static_cast<int>(stats_.GetCounter(Stats::DOOM_CACHE))); 1351 static_cast<int>(stats_.GetCounter(Stats::DOOM_CACHE)));
1335 CACHE_UMA(COUNTS_10000, "TotalDoomRecentEntries", 1352 CACHE_UMA(COUNTS_10000,
1353 "TotalDoomRecentEntries",
1336 static_cast<int>(stats_.GetCounter(Stats::DOOM_RECENT))); 1354 static_cast<int>(stats_.GetCounter(Stats::DOOM_RECENT)));
1337 stats_.SetCounter(Stats::FATAL_ERROR, 0); 1355 stats_.SetCounter(Stats::FATAL_ERROR, 0);
1338 stats_.SetCounter(Stats::DOOM_CACHE, 0); 1356 stats_.SetCounter(Stats::DOOM_CACHE, 0);
1339 stats_.SetCounter(Stats::DOOM_RECENT, 0); 1357 stats_.SetCounter(Stats::DOOM_RECENT, 0);
1340 1358
1341 int64 total_hours = stats_.GetCounter(Stats::TIMER) / 120; 1359 int64 total_hours = stats_.GetCounter(Stats::TIMER) / 120;
1342 if (!(header->flags & CACHE_EVICTED)) { 1360 if (!(header->flags & CACHE_EVICTED)) {
1343 CACHE_UMA(HOURS, "TotalTimeNotFull", static_cast<int>(total_hours)); 1361 CACHE_UMA(HOURS, "TotalTimeNotFull", static_cast<int>(total_hours));
1344 return; 1362 return;
1345 } 1363 }
(...skipping 22 matching lines...) Expand all
1368 int avg_size = header->num_bytes / GetEntryCount(); 1386 int avg_size = header->num_bytes / GetEntryCount();
1369 CACHE_UMA(COUNTS, "EntrySize", avg_size); 1387 CACHE_UMA(COUNTS, "EntrySize", avg_size);
1370 CACHE_UMA(COUNTS, "EntriesFull", header->num_entries); 1388 CACHE_UMA(COUNTS, "EntriesFull", header->num_entries);
1371 1389
1372 int large_entries_bytes = stats_.GetLargeEntriesSize(); 1390 int large_entries_bytes = stats_.GetLargeEntriesSize();
1373 int large_ratio = large_entries_bytes * 100 / header->num_bytes; 1391 int large_ratio = large_entries_bytes * 100 / header->num_bytes;
1374 CACHE_UMA(PERCENTAGE, "LargeEntriesRatio", large_ratio); 1392 CACHE_UMA(PERCENTAGE, "LargeEntriesRatio", large_ratio);
1375 1393
1376 if (!lru_eviction_) { 1394 if (!lru_eviction_) {
1377 CACHE_UMA(PERCENTAGE, "ResurrectRatio", stats_.GetResurrectRatio()); 1395 CACHE_UMA(PERCENTAGE, "ResurrectRatio", stats_.GetResurrectRatio());
1378 CACHE_UMA(PERCENTAGE, "NoUseRatio", 1396 CACHE_UMA(PERCENTAGE,
1397 "NoUseRatio",
1379 header->num_no_use_entries * 100 / header->num_entries); 1398 header->num_no_use_entries * 100 / header->num_entries);
1380 CACHE_UMA(PERCENTAGE, "LowUseRatio", 1399 CACHE_UMA(PERCENTAGE,
1400 "LowUseRatio",
1381 header->num_low_use_entries * 100 / header->num_entries); 1401 header->num_low_use_entries * 100 / header->num_entries);
1382 CACHE_UMA(PERCENTAGE, "HighUseRatio", 1402 CACHE_UMA(PERCENTAGE,
1403 "HighUseRatio",
1383 header->num_high_use_entries * 100 / header->num_entries); 1404 header->num_high_use_entries * 100 / header->num_entries);
1384 CACHE_UMA(PERCENTAGE, "DeletedRatio", 1405 CACHE_UMA(PERCENTAGE,
1406 "DeletedRatio",
1385 header->num_evicted_entries * 100 / header->num_entries); 1407 header->num_evicted_entries * 100 / header->num_entries);
1386 } 1408 }
1387 1409
1388 stats_.ResetRatios(); 1410 stats_.ResetRatios();
1389 stats_.SetCounter(Stats::TRIM_ENTRY, 0); 1411 stats_.SetCounter(Stats::TRIM_ENTRY, 0);
1390 1412
1391 if (cache_type_ == net::DISK_CACHE) 1413 if (cache_type_ == net::DISK_CACHE)
1392 block_files_.ReportStats(); 1414 block_files_.ReportStats();
1393 } 1415 }
1394 1416
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1491 1513
1492 DCHECK_EQ(i, cache_entry->entry()->Data()->hash & mask_); 1514 DCHECK_EQ(i, cache_entry->entry()->Data()->hash & mask_);
1493 address.set_value(cache_entry->GetNextAddress()); 1515 address.set_value(cache_entry->GetNextAddress());
1494 if (!address.is_initialized()) 1516 if (!address.is_initialized())
1495 break; 1517 break;
1496 } 1518 }
1497 } 1519 }
1498 1520
1499 Trace("CheckAllEntries End"); 1521 Trace("CheckAllEntries End");
1500 if (num_entries + num_dirty != data_->header.num_entries) { 1522 if (num_entries + num_dirty != data_->header.num_entries) {
1501 LOG(ERROR) << "Number of entries " << num_entries << " " << num_dirty << 1523 LOG(ERROR) << "Number of entries " << num_entries << " " << num_dirty << " "
1502 " " << data_->header.num_entries; 1524 << data_->header.num_entries;
1503 DCHECK_LT(num_entries, data_->header.num_entries); 1525 DCHECK_LT(num_entries, data_->header.num_entries);
1504 return ERR_NUM_ENTRIES_MISMATCH; 1526 return ERR_NUM_ENTRIES_MISMATCH;
1505 } 1527 }
1506 1528
1507 return num_dirty; 1529 return num_dirty;
1508 } 1530 }
1509 1531
1510 bool BackendImplV3::CheckEntry(EntryImpl* cache_entry) { 1532 bool BackendImplV3::CheckEntry(EntryImpl* cache_entry) {
1511 bool ok = block_files_.IsValid(cache_entry->entry()->address()); 1533 bool ok = block_files_.IsValid(cache_entry->entry()->address());
1512 ok = ok && block_files_.IsValid(cache_entry->rankings()->address()); 1534 ok = ok && block_files_.IsValid(cache_entry->rankings()->address());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 } 1569 }
1548 1570
1549 net::CacheType BackendImplV3::GetCacheType() const { 1571 net::CacheType BackendImplV3::GetCacheType() const {
1550 return cache_type_; 1572 return cache_type_;
1551 } 1573 }
1552 1574
1553 int32 BackendImplV3::GetEntryCount() const { 1575 int32 BackendImplV3::GetEntryCount() const {
1554 return 0; 1576 return 0;
1555 } 1577 }
1556 1578
1557 int BackendImplV3::OpenEntry(const std::string& key, Entry** entry, 1579 int BackendImplV3::OpenEntry(const std::string& key,
1580 Entry** entry,
1558 const CompletionCallback& callback) { 1581 const CompletionCallback& callback) {
1559 return net::ERR_FAILED; 1582 return net::ERR_FAILED;
1560 } 1583 }
1561 1584
1562 int BackendImplV3::CreateEntry(const std::string& key, Entry** entry, 1585 int BackendImplV3::CreateEntry(const std::string& key,
1586 Entry** entry,
1563 const CompletionCallback& callback) { 1587 const CompletionCallback& callback) {
1564 return net::ERR_FAILED; 1588 return net::ERR_FAILED;
1565 } 1589 }
1566 1590
1567 int BackendImplV3::DoomEntry(const std::string& key, 1591 int BackendImplV3::DoomEntry(const std::string& key,
1568 const CompletionCallback& callback) { 1592 const CompletionCallback& callback) {
1569 return net::ERR_FAILED; 1593 return net::ERR_FAILED;
1570 } 1594 }
1571 1595
1572 int BackendImplV3::DoomAllEntries(const CompletionCallback& callback) { 1596 int BackendImplV3::DoomAllEntries(const CompletionCallback& callback) {
1573 return net::ERR_FAILED; 1597 return net::ERR_FAILED;
1574 } 1598 }
1575 1599
1576 int BackendImplV3::DoomEntriesBetween(base::Time initial_time, 1600 int BackendImplV3::DoomEntriesBetween(base::Time initial_time,
1577 base::Time end_time, 1601 base::Time end_time,
1578 const CompletionCallback& callback) { 1602 const CompletionCallback& callback) {
1579 return net::ERR_FAILED; 1603 return net::ERR_FAILED;
1580 } 1604 }
1581 1605
1582 int BackendImplV3::DoomEntriesSince(base::Time initial_time, 1606 int BackendImplV3::DoomEntriesSince(base::Time initial_time,
1583 const CompletionCallback& callback) { 1607 const CompletionCallback& callback) {
1584 return net::ERR_FAILED; 1608 return net::ERR_FAILED;
1585 } 1609 }
1586 1610
1587 int BackendImplV3::OpenNextEntry(void** iter, Entry** next_entry, 1611 int BackendImplV3::OpenNextEntry(void** iter,
1612 Entry** next_entry,
1588 const CompletionCallback& callback) { 1613 const CompletionCallback& callback) {
1589 return net::ERR_FAILED; 1614 return net::ERR_FAILED;
1590 } 1615 }
1591 1616
1592 void BackendImplV3::EndEnumeration(void** iter) { 1617 void BackendImplV3::EndEnumeration(void** iter) {
1593 NOTIMPLEMENTED(); 1618 NOTIMPLEMENTED();
1594 } 1619 }
1595 1620
1596 void BackendImplV3::GetStats(StatsItems* stats) { 1621 void BackendImplV3::GetStats(StatsItems* stats) {
1597 NOTIMPLEMENTED(); 1622 NOTIMPLEMENTED();
1598 } 1623 }
1599 1624
1600 void BackendImplV3::OnExternalCacheHit(const std::string& key) { 1625 void BackendImplV3::OnExternalCacheHit(const std::string& key) {
1601 NOTIMPLEMENTED(); 1626 NOTIMPLEMENTED();
1602 } 1627 }
1603 1628
1604 void BackendImplV3::CleanupCache() { 1629 void BackendImplV3::CleanupCache() {
1605 } 1630 }
1606 1631
1607 } // namespace disk_cache 1632 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698