Cache Backend Proxy to intercept all cache events from the IO thread.
[chromium-blink-merge.git] / net / disk_cache / mem_rankings.cc
blobd5f4a6536a792f48df0998d6e7a9a603b3577aa9
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
3 // found in the LICENSE file.
5 #include "net/disk_cache/mem_rankings.h"
7 #include "base/logging.h"
8 #include "net/disk_cache/mem_entry_impl.h"
10 namespace disk_cache {
12 MemRankings::~MemRankings() {
13 DCHECK(!head_ && !tail_);
16 void MemRankings::Insert(MemEntryImpl* node) {
17 if (head_)
18 head_->set_prev(node);
20 if (!tail_)
21 tail_ = node;
23 node->set_prev(NULL);
24 node->set_next(head_);
25 head_ = node;
28 void MemRankings::Remove(MemEntryImpl* node) {
29 MemEntryImpl* prev = node->prev();
30 MemEntryImpl* next = node->next();
32 if (head_ == node)
33 head_ = next;
35 if (tail_ == node)
36 tail_ = prev;
38 if (prev)
39 prev->set_next(next);
41 if (next)
42 next->set_prev(prev);
44 node->set_next(NULL);
45 node->set_prev(NULL);
48 void MemRankings::UpdateRank(MemEntryImpl* node) {
49 Remove(node);
50 Insert(node);
53 MemEntryImpl* MemRankings::GetNext(MemEntryImpl* node) {
54 if (!node)
55 return head_;
57 return node->next();
60 MemEntryImpl* MemRankings::GetPrev(MemEntryImpl* node) {
61 if (!node)
62 return tail_;
64 return node->prev();
67 } // namespace disk_cache