| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/rankings.h" | 5 #include "net/disk_cache/rankings.h" |
| 6 | 6 |
| 7 #include "base/histogram.h" | 7 #include "base/histogram.h" |
| 8 #include "net/disk_cache/backend_impl.h" | 8 #include "net/disk_cache/backend_impl.h" |
| 9 #include "net/disk_cache/entry_impl.h" | 9 #include "net/disk_cache/entry_impl.h" |
| 10 #include "net/disk_cache/errors.h" | 10 #include "net/disk_cache/errors.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 NOTREACHED(); | 167 NOTREACHED(); |
| 168 return; | 168 return; |
| 169 } | 169 } |
| 170 #endif // NDEBUG | 170 #endif // NDEBUG |
| 171 } | 171 } |
| 172 | 172 |
| 173 } // namespace | 173 } // namespace |
| 174 | 174 |
| 175 namespace disk_cache { | 175 namespace disk_cache { |
| 176 | 176 |
| 177 bool Rankings::Init(BackendImpl* backend) { | 177 bool Rankings::Init(BackendImpl* backend, bool count_lists) { |
| 178 DCHECK(!init_); | 178 DCHECK(!init_); |
| 179 if (init_) | 179 if (init_) |
| 180 return false; | 180 return false; |
| 181 | 181 |
| 182 backend_ = backend; | 182 backend_ = backend; |
| 183 | |
| 184 control_data_ = backend_->GetLruData(); | 183 control_data_ = backend_->GetLruData(); |
| 184 count_lists_ = count_lists; |
| 185 | 185 |
| 186 ReadHeads(); | 186 ReadHeads(); |
| 187 ReadTails(); | 187 ReadTails(); |
| 188 | 188 |
| 189 if (control_data_->transaction) | 189 if (control_data_->transaction) |
| 190 CompleteTransaction(); | 190 CompleteTransaction(); |
| 191 | 191 |
| 192 init_ = true; | 192 init_ = true; |
| 193 return true; | 193 return true; |
| 194 } | 194 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 274 |
| 275 Time now = Time::Now(); | 275 Time now = Time::Now(); |
| 276 node->Data()->last_used = now.ToInternalValue(); | 276 node->Data()->last_used = now.ToInternalValue(); |
| 277 if (modified) | 277 if (modified) |
| 278 node->Data()->last_modified = now.ToInternalValue(); | 278 node->Data()->last_modified = now.ToInternalValue(); |
| 279 node->Store(); | 279 node->Store(); |
| 280 GenerateCrash(ON_INSERT_3); | 280 GenerateCrash(ON_INSERT_3); |
| 281 | 281 |
| 282 // The last thing to do is move our head to point to a node already stored. | 282 // The last thing to do is move our head to point to a node already stored. |
| 283 WriteHead(list); | 283 WriteHead(list); |
| 284 IncrementCounter(list); |
| 284 GenerateCrash(ON_INSERT_4); | 285 GenerateCrash(ON_INSERT_4); |
| 285 } | 286 } |
| 286 | 287 |
| 287 // If a, b and r are elements on the list, and we want to remove r, the possible | 288 // If a, b and r are elements on the list, and we want to remove r, the possible |
| 288 // states for the objects if a crash happens are (where y(x, z) means for object | 289 // states for the objects if a crash happens are (where y(x, z) means for object |
| 289 // y, prev is x and next is z): | 290 // y, prev is x and next is z): |
| 290 // A. One element: | 291 // A. One element: |
| 291 // 1. r(r, r), head(r), tail(r) initial state | 292 // 1. r(r, r), head(r), tail(r) initial state |
| 292 // 2. r(r, r), head(0), tail(r) WriteHead() | 293 // 2. r(r, r), head(0), tail(r) WriteHead() |
| 293 // 3. r(r, r), head(0), tail(0) WriteTail() | 294 // 3. r(r, r), head(0), tail(0) WriteTail() |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 node->Data()->next = 0; | 371 node->Data()->next = 0; |
| 371 node->Data()->prev = 0; | 372 node->Data()->prev = 0; |
| 372 | 373 |
| 373 // The last thing to get to disk is the node itself, so before that there is | 374 // The last thing to get to disk is the node itself, so before that there is |
| 374 // enough info to recover. | 375 // enough info to recover. |
| 375 next.Store(); | 376 next.Store(); |
| 376 GenerateCrash(ON_REMOVE_7); | 377 GenerateCrash(ON_REMOVE_7); |
| 377 prev.Store(); | 378 prev.Store(); |
| 378 GenerateCrash(ON_REMOVE_8); | 379 GenerateCrash(ON_REMOVE_8); |
| 379 node->Store(); | 380 node->Store(); |
| 381 DecrementCounter(list); |
| 380 UpdateIterators(&next); | 382 UpdateIterators(&next); |
| 381 UpdateIterators(&prev); | 383 UpdateIterators(&prev); |
| 382 } | 384 } |
| 383 | 385 |
| 384 // A crash in between Remove and Insert will lead to a dirty entry not on the | 386 // A crash in between Remove and Insert will lead to a dirty entry not on the |
| 385 // list. We want to avoid that case as much as we can (as while waiting for IO), | 387 // list. We want to avoid that case as much as we can (as while waiting for IO), |
| 386 // but the net effect is just an assert on debug when attempting to remove the | 388 // but the net effect is just an assert on debug when attempting to remove the |
| 387 // entry. Otherwise we'll need reentrant transactions, which is an overkill. | 389 // entry. Otherwise we'll need reentrant transactions, which is an overkill. |
| 388 void Rankings::UpdateRank(CacheRankingsBlock* node, bool modified, List list) { | 390 void Rankings::UpdateRank(CacheRankingsBlock* node, bool modified, List list) { |
| 389 Time start = Time::Now(); | 391 Time start = Time::Now(); |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 for (IteratorList::iterator it = iterators_.begin(); it != iterators_.end(); | 742 for (IteratorList::iterator it = iterators_.begin(); it != iterators_.end(); |
| 741 ++it) { | 743 ++it) { |
| 742 if (it->first == address) { | 744 if (it->first == address) { |
| 743 CacheRankingsBlock* other = it->second; | 745 CacheRankingsBlock* other = it->second; |
| 744 other->Data()->next = node->Data()->next; | 746 other->Data()->next = node->Data()->next; |
| 745 other->Data()->prev = node->Data()->prev; | 747 other->Data()->prev = node->Data()->prev; |
| 746 } | 748 } |
| 747 } | 749 } |
| 748 } | 750 } |
| 749 | 751 |
| 752 void Rankings::IncrementCounter(List list) { |
| 753 if (!count_lists_) |
| 754 return; |
| 755 |
| 756 DCHECK(control_data_->sizes[list] < kint32max); |
| 757 if (control_data_->sizes[list] < kint32max) |
| 758 control_data_->sizes[list]++; |
| 759 } |
| 760 |
| 761 void Rankings::DecrementCounter(List list) { |
| 762 if (!count_lists_) |
| 763 return; |
| 764 |
| 765 DCHECK(control_data_->sizes[list] > 0); |
| 766 if (control_data_->sizes[list] > 0) |
| 767 control_data_->sizes[list]--; |
| 768 } |
| 769 |
| 750 } // namespace disk_cache | 770 } // namespace disk_cache |
| OLD | NEW |