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

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

Issue 588243002: Reland of "Remove void** from disk_cache interface" w/ blockfile iter fix. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@1-webcacheimpl
Patch Set: cleanup presubmit Created 6 years, 2 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
« no previous file with comments | « net/disk_cache/blockfile/rankings.h ('k') | net/disk_cache/disk_cache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/rankings.h" 5 #include "net/disk_cache/blockfile/rankings.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "net/disk_cache/blockfile/backend_impl.h" 8 #include "net/disk_cache/blockfile/backend_impl.h"
9 #include "net/disk_cache/blockfile/disk_format.h" 9 #include "net/disk_cache/blockfile/disk_format.h"
10 #include "net/disk_cache/blockfile/entry_impl.h" 10 #include "net/disk_cache/blockfile/entry_impl.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 195
196 Rankings::ScopedRankingsBlock::ScopedRankingsBlock() : rankings_(NULL) {} 196 Rankings::ScopedRankingsBlock::ScopedRankingsBlock() : rankings_(NULL) {}
197 197
198 Rankings::ScopedRankingsBlock::ScopedRankingsBlock(Rankings* rankings) 198 Rankings::ScopedRankingsBlock::ScopedRankingsBlock(Rankings* rankings)
199 : rankings_(rankings) {} 199 : rankings_(rankings) {}
200 200
201 Rankings::ScopedRankingsBlock::ScopedRankingsBlock( 201 Rankings::ScopedRankingsBlock::ScopedRankingsBlock(
202 Rankings* rankings, CacheRankingsBlock* node) 202 Rankings* rankings, CacheRankingsBlock* node)
203 : scoped_ptr<CacheRankingsBlock>(node), rankings_(rankings) {} 203 : scoped_ptr<CacheRankingsBlock>(node), rankings_(rankings) {}
204 204
205 Rankings::Iterator::Iterator(Rankings* rankings) { 205 Rankings::Iterator::Iterator() {
206 memset(this, 0, sizeof(Iterator)); 206 memset(this, 0, sizeof(Iterator));
207 my_rankings = rankings;
208 } 207 }
209 208
210 Rankings::Iterator::~Iterator() { 209 void Rankings::Iterator::Reset() {
211 for (int i = 0; i < 3; i++) 210 if (my_rankings) {
212 ScopedRankingsBlock(my_rankings, nodes[i]); 211 for (int i = 0; i < 3; i++)
212 ScopedRankingsBlock(my_rankings, nodes[i]);
213 }
214 memset(this, 0, sizeof(Iterator));
213 } 215 }
214 216
215 Rankings::Rankings() : init_(false) {} 217 Rankings::Rankings() : init_(false) {}
216 218
217 Rankings::~Rankings() {} 219 Rankings::~Rankings() {}
218 220
219 bool Rankings::Init(BackendImpl* backend, bool count_lists) { 221 bool Rankings::Init(BackendImpl* backend, bool count_lists) {
220 DCHECK(!init_); 222 DCHECK(!init_);
221 if (init_) 223 if (init_)
222 return false; 224 return false;
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 CacheRankingsBlock* other = it->second; 892 CacheRankingsBlock* other = it->second;
891 *other->Data() = *node->Data(); 893 *other->Data() = *node->Data();
892 } 894 }
893 } 895 }
894 } 896 }
895 897
896 void Rankings::InvalidateIterators(CacheRankingsBlock* node) { 898 void Rankings::InvalidateIterators(CacheRankingsBlock* node) {
897 CacheAddr address = node->address().value(); 899 CacheAddr address = node->address().value();
898 for (IteratorList::iterator it = iterators_.begin(); it != iterators_.end(); 900 for (IteratorList::iterator it = iterators_.begin(); it != iterators_.end();
899 ++it) { 901 ++it) {
900 if (it->first == address) { 902 if (it->first == address)
901 DLOG(INFO) << "Invalidating iterator at 0x" << std::hex << address;
902 it->second->Discard(); 903 it->second->Discard();
903 }
904 } 904 }
905 } 905 }
906 906
907 void Rankings::IncrementCounter(List list) { 907 void Rankings::IncrementCounter(List list) {
908 if (!count_lists_) 908 if (!count_lists_)
909 return; 909 return;
910 910
911 DCHECK(control_data_->sizes[list] < kint32max); 911 DCHECK(control_data_->sizes[list] < kint32max);
912 if (control_data_->sizes[list] < kint32max) 912 if (control_data_->sizes[list] < kint32max)
913 control_data_->sizes[list]++; 913 control_data_->sizes[list]++;
914 } 914 }
915 915
916 void Rankings::DecrementCounter(List list) { 916 void Rankings::DecrementCounter(List list) {
917 if (!count_lists_) 917 if (!count_lists_)
918 return; 918 return;
919 919
920 DCHECK(control_data_->sizes[list] > 0); 920 DCHECK(control_data_->sizes[list] > 0);
921 if (control_data_->sizes[list] > 0) 921 if (control_data_->sizes[list] > 0)
922 control_data_->sizes[list]--; 922 control_data_->sizes[list]--;
923 } 923 }
924 924
925 } // namespace disk_cache 925 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/blockfile/rankings.h ('k') | net/disk_cache/disk_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698