| OLD | NEW |
| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 195 |
| 196 } // namespace | 196 } // namespace |
| 197 | 197 |
| 198 namespace disk_cache { | 198 namespace disk_cache { |
| 199 | 199 |
| 200 Rankings::ScopedRankingsBlock::ScopedRankingsBlock() : rankings_(NULL) {} | 200 Rankings::ScopedRankingsBlock::ScopedRankingsBlock() : rankings_(NULL) {} |
| 201 | 201 |
| 202 Rankings::ScopedRankingsBlock::ScopedRankingsBlock(Rankings* rankings) | 202 Rankings::ScopedRankingsBlock::ScopedRankingsBlock(Rankings* rankings) |
| 203 : rankings_(rankings) {} | 203 : rankings_(rankings) {} |
| 204 | 204 |
| 205 Rankings::ScopedRankingsBlock::ScopedRankingsBlock( | 205 Rankings::ScopedRankingsBlock::ScopedRankingsBlock(Rankings* rankings, |
| 206 Rankings* rankings, CacheRankingsBlock* node) | 206 CacheRankingsBlock* node) |
| 207 : scoped_ptr<CacheRankingsBlock>(node), rankings_(rankings) {} | 207 : std::unique_ptr<CacheRankingsBlock>(node), rankings_(rankings) {} |
| 208 | 208 |
| 209 Rankings::Iterator::Iterator() { | 209 Rankings::Iterator::Iterator() { |
| 210 memset(this, 0, sizeof(Iterator)); | 210 memset(this, 0, sizeof(Iterator)); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void Rankings::Iterator::Reset() { | 213 void Rankings::Iterator::Reset() { |
| 214 if (my_rankings) { | 214 if (my_rankings) { |
| 215 for (int i = 0; i < 3; i++) | 215 for (int i = 0; i < 3; i++) |
| 216 ScopedRankingsBlock(my_rankings, nodes[i]); | 216 ScopedRankingsBlock(my_rankings, nodes[i]); |
| 217 } | 217 } |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 Addr* last, Addr* second_last, int* num_items) { | 820 Addr* last, Addr* second_last, int* num_items) { |
| 821 Addr current = forward ? heads_[list] : tails_[list]; | 821 Addr current = forward ? heads_[list] : tails_[list]; |
| 822 *last = *second_last = current; | 822 *last = *second_last = current; |
| 823 *num_items = 0; | 823 *num_items = 0; |
| 824 if (!current.is_initialized()) | 824 if (!current.is_initialized()) |
| 825 return ERR_NO_ERROR; | 825 return ERR_NO_ERROR; |
| 826 | 826 |
| 827 if (!current.SanityCheckForRankings()) | 827 if (!current.SanityCheckForRankings()) |
| 828 return ERR_INVALID_HEAD; | 828 return ERR_INVALID_HEAD; |
| 829 | 829 |
| 830 scoped_ptr<CacheRankingsBlock> node; | 830 std::unique_ptr<CacheRankingsBlock> node; |
| 831 Addr prev_addr(current); | 831 Addr prev_addr(current); |
| 832 do { | 832 do { |
| 833 node.reset(new CacheRankingsBlock(backend_->File(current), current)); | 833 node.reset(new CacheRankingsBlock(backend_->File(current), current)); |
| 834 node->Load(); | 834 node->Load(); |
| 835 if (!SanityCheck(node.get(), true)) | 835 if (!SanityCheck(node.get(), true)) |
| 836 return ERR_INVALID_ENTRY; | 836 return ERR_INVALID_ENTRY; |
| 837 | 837 |
| 838 CacheAddr next = forward ? node->Data()->next : node->Data()->prev; | 838 CacheAddr next = forward ? node->Data()->next : node->Data()->prev; |
| 839 CacheAddr prev = forward ? node->Data()->prev : node->Data()->next; | 839 CacheAddr prev = forward ? node->Data()->prev : node->Data()->next; |
| 840 | 840 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 void Rankings::DecrementCounter(List list) { | 920 void Rankings::DecrementCounter(List list) { |
| 921 if (!count_lists_) | 921 if (!count_lists_) |
| 922 return; | 922 return; |
| 923 | 923 |
| 924 DCHECK(control_data_->sizes[list] > 0); | 924 DCHECK(control_data_->sizes[list] > 0); |
| 925 if (control_data_->sizes[list] > 0) | 925 if (control_data_->sizes[list] > 0) |
| 926 control_data_->sizes[list]--; | 926 control_data_->sizes[list]--; |
| 927 } | 927 } |
| 928 | 928 |
| 929 } // namespace disk_cache | 929 } // namespace disk_cache |
| OLD | NEW |