| Index: net/disk_cache/blockfile/rankings.cc
|
| diff --git a/net/disk_cache/blockfile/rankings.cc b/net/disk_cache/blockfile/rankings.cc
|
| index 7c93b431bcbbb8fd3cb1eba85e6dfb9e69ee3ef4..28e212fa148dccc85bf376aa58aa588c8d077d53 100644
|
| --- a/net/disk_cache/blockfile/rankings.cc
|
| +++ b/net/disk_cache/blockfile/rankings.cc
|
| @@ -25,10 +25,7 @@ NET_EXPORT_PRIVATE RankCrashes g_rankings_crash = NO_CRASH;
|
|
|
| namespace {
|
|
|
| -enum Operation {
|
| - INSERT = 1,
|
| - REMOVE
|
| -};
|
| +enum Operation { INSERT = 1, REMOVE };
|
|
|
| // This class provides a simple lock for the LRU list of rankings. Whenever an
|
| // entry is to be inserted or removed from the list, a transaction object should
|
| @@ -41,16 +38,21 @@ class Transaction {
|
| // avoid having the compiler doing optimizations on when to read or write
|
| // from user_data because it is the basis of the crash detection. Maybe
|
| // volatile is not enough for that, but it should be a good hint.
|
| - Transaction(volatile disk_cache::LruData* data, disk_cache::Addr addr,
|
| - Operation op, int list);
|
| + Transaction(volatile disk_cache::LruData* data,
|
| + disk_cache::Addr addr,
|
| + Operation op,
|
| + int list);
|
| ~Transaction();
|
| +
|
| private:
|
| volatile disk_cache::LruData* data_;
|
| DISALLOW_COPY_AND_ASSIGN(Transaction);
|
| };
|
|
|
| Transaction::Transaction(volatile disk_cache::LruData* data,
|
| - disk_cache::Addr addr, Operation op, int list)
|
| + disk_cache::Addr addr,
|
| + Operation op,
|
| + int list)
|
| : data_(data) {
|
| DCHECK(!data_->transaction);
|
| DCHECK(addr.is_initialized());
|
| @@ -68,8 +70,18 @@ Transaction::~Transaction() {
|
|
|
| // Code locations that can generate crashes.
|
| enum CrashLocation {
|
| - ON_INSERT_1, ON_INSERT_2, ON_INSERT_3, ON_INSERT_4, ON_REMOVE_1, ON_REMOVE_2,
|
| - ON_REMOVE_3, ON_REMOVE_4, ON_REMOVE_5, ON_REMOVE_6, ON_REMOVE_7, ON_REMOVE_8
|
| + ON_INSERT_1,
|
| + ON_INSERT_2,
|
| + ON_INSERT_3,
|
| + ON_INSERT_4,
|
| + ON_REMOVE_1,
|
| + ON_REMOVE_2,
|
| + ON_REMOVE_3,
|
| + ON_REMOVE_4,
|
| + ON_REMOVE_5,
|
| + ON_REMOVE_6,
|
| + ON_REMOVE_7,
|
| + ON_REMOVE_8
|
| };
|
|
|
| #ifndef NDEBUG
|
| @@ -193,14 +205,17 @@ void UpdateTimes(disk_cache::CacheRankingsBlock* node, bool modified) {
|
|
|
| namespace disk_cache {
|
|
|
| -Rankings::ScopedRankingsBlock::ScopedRankingsBlock() : rankings_(NULL) {}
|
| +Rankings::ScopedRankingsBlock::ScopedRankingsBlock() : rankings_(NULL) {
|
| +}
|
|
|
| Rankings::ScopedRankingsBlock::ScopedRankingsBlock(Rankings* rankings)
|
| - : rankings_(rankings) {}
|
| + : rankings_(rankings) {
|
| +}
|
|
|
| -Rankings::ScopedRankingsBlock::ScopedRankingsBlock(
|
| - Rankings* rankings, CacheRankingsBlock* node)
|
| - : scoped_ptr<CacheRankingsBlock>(node), rankings_(rankings) {}
|
| +Rankings::ScopedRankingsBlock::ScopedRankingsBlock(Rankings* rankings,
|
| + CacheRankingsBlock* node)
|
| + : scoped_ptr<CacheRankingsBlock>(node), rankings_(rankings) {
|
| +}
|
|
|
| Rankings::Iterator::Iterator(Rankings* rankings) {
|
| memset(this, 0, sizeof(Iterator));
|
| @@ -212,9 +227,11 @@ Rankings::Iterator::~Iterator() {
|
| ScopedRankingsBlock(my_rankings, nodes[i]);
|
| }
|
|
|
| -Rankings::Rankings() : init_(false) {}
|
| +Rankings::Rankings() : init_(false) {
|
| +}
|
|
|
| -Rankings::~Rankings() {}
|
| +Rankings::~Rankings() {
|
| +}
|
|
|
| bool Rankings::Init(BackendImpl* backend, bool count_lists) {
|
| DCHECK(!init_);
|
| @@ -255,7 +272,7 @@ void Rankings::Insert(CacheRankingsBlock* node, bool modified, List list) {
|
| if (!GetRanking(&head))
|
| return;
|
|
|
| - if (head.Data()->prev != my_head.value() && // Normal path.
|
| + if (head.Data()->prev != my_head.value() && // Normal path.
|
| head.Data()->prev != node->address().value()) { // FinishInsert().
|
| backend_->CriticalError(ERR_INVALID_LINKS);
|
| return;
|
| @@ -316,8 +333,11 @@ void Rankings::Insert(CacheRankingsBlock* node, bool modified, List list) {
|
| // 3. a(x, a), r(a, r), head(x), tail(a) prev.Store()
|
| // 4. a(x, a), r(0, 0), head(x), tail(a) next.Store()
|
| void Rankings::Remove(CacheRankingsBlock* node, List list, bool strict) {
|
| - Trace("Remove 0x%x (0x%x 0x%x) l %d", node->address().value(),
|
| - node->Data()->next, node->Data()->prev, list);
|
| + Trace("Remove 0x%x (0x%x 0x%x) l %d",
|
| + node->address().value(),
|
| + node->Data()->next,
|
| + node->Data()->prev,
|
| + list);
|
| DCHECK(node->HasData());
|
| if (strict)
|
| InvalidateIterators(node);
|
| @@ -742,17 +762,20 @@ void Rankings::RevertRemove(CacheRankingsBlock* node) {
|
| backend_->FlushIndex();
|
| }
|
|
|
| -bool Rankings::CheckLinks(CacheRankingsBlock* node, CacheRankingsBlock* prev,
|
| - CacheRankingsBlock* next, List* list) {
|
| +bool Rankings::CheckLinks(CacheRankingsBlock* node,
|
| + CacheRankingsBlock* prev,
|
| + CacheRankingsBlock* next,
|
| + List* list) {
|
| CacheAddr node_addr = node->address().value();
|
| - if (prev->Data()->next == node_addr &&
|
| - next->Data()->prev == node_addr) {
|
| + if (prev->Data()->next == node_addr && next->Data()->prev == node_addr) {
|
| // A regular linked node.
|
| return true;
|
| }
|
|
|
| - Trace("CheckLinks 0x%x (0x%x 0x%x)", node_addr,
|
| - prev->Data()->next, next->Data()->prev);
|
| + Trace("CheckLinks 0x%x (0x%x 0x%x)",
|
| + node_addr,
|
| + prev->Data()->next,
|
| + next->Data()->prev);
|
|
|
| if (node_addr != prev->address().value() &&
|
| node_addr != next->address().value() &&
|
| @@ -766,8 +789,7 @@ bool Rankings::CheckLinks(CacheRankingsBlock* node, CacheRankingsBlock* prev,
|
| return false;
|
| }
|
|
|
| - if (prev->Data()->next == node_addr ||
|
| - next->Data()->prev == node_addr) {
|
| + if (prev->Data()->next == node_addr || next->Data()->prev == node_addr) {
|
| // Only one link is weird, lets double check.
|
| if (prev->Data()->next != node_addr && IsHead(node_addr, list))
|
| return true;
|
| @@ -799,8 +821,13 @@ bool Rankings::CheckSingleLink(CacheRankingsBlock* prev,
|
| int Rankings::CheckList(List list) {
|
| Addr last1, last2;
|
| int head_items;
|
| - int rv = CheckListSection(list, last1, last2, true, // Head to tail.
|
| - &last1, &last2, &head_items);
|
| + int rv = CheckListSection(list,
|
| + last1,
|
| + last2,
|
| + true, // Head to tail.
|
| + &last1,
|
| + &last2,
|
| + &head_items);
|
| if (rv == ERR_NO_ERROR)
|
| return head_items;
|
|
|
| @@ -810,8 +837,13 @@ int Rankings::CheckList(List list) {
|
| // Note that the returned error codes assume a forward walk (from head to tail)
|
| // so they have to be adjusted accordingly by the caller. We use two stop values
|
| // to be able to detect a corrupt node at the end that is not linked going back.
|
| -int Rankings::CheckListSection(List list, Addr end1, Addr end2, bool forward,
|
| - Addr* last, Addr* second_last, int* num_items) {
|
| +int Rankings::CheckListSection(List list,
|
| + Addr end1,
|
| + Addr end2,
|
| + bool forward,
|
| + Addr* last,
|
| + Addr* second_last,
|
| + int* num_items) {
|
| Addr current = forward ? heads_[list] : tails_[list];
|
| *last = *second_last = current;
|
| *num_items = 0;
|
|
|