| 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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 UpdateIterators(&next); | 387 UpdateIterators(&next); |
| 388 UpdateIterators(&prev); | 388 UpdateIterators(&prev); |
| 389 } | 389 } |
| 390 | 390 |
| 391 // A crash in between Remove and Insert will lead to a dirty entry not on the | 391 // A crash in between Remove and Insert will lead to a dirty entry not on the |
| 392 // list. We want to avoid that case as much as we can (as while waiting for IO), | 392 // list. We want to avoid that case as much as we can (as while waiting for IO), |
| 393 // but the net effect is just an assert on debug when attempting to remove the | 393 // but the net effect is just an assert on debug when attempting to remove the |
| 394 // entry. Otherwise we'll need reentrant transactions, which is an overkill. | 394 // entry. Otherwise we'll need reentrant transactions, which is an overkill. |
| 395 void Rankings::UpdateRank(CacheRankingsBlock* node, bool modified, List list) { | 395 void Rankings::UpdateRank(CacheRankingsBlock* node, bool modified, List list) { |
| 396 Time start = Time::Now(); | 396 Time start = Time::Now(); |
| 397 NotAnIterator(node); |
| 397 Remove(node, list); | 398 Remove(node, list); |
| 398 Insert(node, modified, list); | 399 Insert(node, modified, list); |
| 399 CACHE_UMA(AGE_MS, "UpdateRank", 0, start); | 400 CACHE_UMA(AGE_MS, "UpdateRank", 0, start); |
| 400 } | 401 } |
| 401 | 402 |
| 402 void Rankings::CompleteTransaction() { | 403 void Rankings::CompleteTransaction() { |
| 403 Addr node_addr(static_cast<CacheAddr>(control_data_->transaction)); | 404 Addr node_addr(static_cast<CacheAddr>(control_data_->transaction)); |
| 404 if (!node_addr.is_initialized() || node_addr.is_separate_file()) { | 405 if (!node_addr.is_initialized() || node_addr.is_separate_file()) { |
| 405 NOTREACHED(); | 406 NOTREACHED(); |
| 406 LOG(ERROR) << "Invalid rankings info."; | 407 LOG(ERROR) << "Invalid rankings info."; |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 for (IteratorList::iterator it = iterators_.begin(); it != iterators_.end(); | 748 for (IteratorList::iterator it = iterators_.begin(); it != iterators_.end(); |
| 748 ++it) { | 749 ++it) { |
| 749 if (it->first == address) { | 750 if (it->first == address) { |
| 750 CacheRankingsBlock* other = it->second; | 751 CacheRankingsBlock* other = it->second; |
| 751 other->Data()->next = node->Data()->next; | 752 other->Data()->next = node->Data()->next; |
| 752 other->Data()->prev = node->Data()->prev; | 753 other->Data()->prev = node->Data()->prev; |
| 753 } | 754 } |
| 754 } | 755 } |
| 755 } | 756 } |
| 756 | 757 |
| 758 void Rankings::NotAnIterator(CacheRankingsBlock* node) { |
| 759 #ifdef NDEBUG |
| 760 // This method is only enabled for debug builds. |
| 761 return; |
| 762 #endif |
| 763 CacheAddr address = node->address().value(); |
| 764 for (IteratorList::iterator it = iterators_.begin(); it != iterators_.end(); |
| 765 ++it) { |
| 766 if (it->first == address) |
| 767 NOTREACHED(); |
| 768 } |
| 769 } |
| 770 |
| 757 void Rankings::IncrementCounter(List list) { | 771 void Rankings::IncrementCounter(List list) { |
| 758 if (!count_lists_) | 772 if (!count_lists_) |
| 759 return; | 773 return; |
| 760 | 774 |
| 761 DCHECK(control_data_->sizes[list] < kint32max); | 775 DCHECK(control_data_->sizes[list] < kint32max); |
| 762 if (control_data_->sizes[list] < kint32max) | 776 if (control_data_->sizes[list] < kint32max) |
| 763 control_data_->sizes[list]++; | 777 control_data_->sizes[list]++; |
| 764 } | 778 } |
| 765 | 779 |
| 766 void Rankings::DecrementCounter(List list) { | 780 void Rankings::DecrementCounter(List list) { |
| 767 if (!count_lists_) | 781 if (!count_lists_) |
| 768 return; | 782 return; |
| 769 | 783 |
| 770 DCHECK(control_data_->sizes[list] > 0); | 784 DCHECK(control_data_->sizes[list] > 0); |
| 771 if (control_data_->sizes[list] > 0) | 785 if (control_data_->sizes[list] > 0) |
| 772 control_data_->sizes[list]--; | 786 control_data_->sizes[list]--; |
| 773 } | 787 } |
| 774 | 788 |
| 775 } // namespace disk_cache | 789 } // namespace disk_cache |
| OLD | NEW |