Home | History | Annotate | Download | only in disk_cache
      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.
      4 
      5 #include "net/disk_cache/mem_rankings.h"
      6 
      7 #include "base/logging.h"
      8 #include "net/disk_cache/mem_entry_impl.h"
      9 
     10 namespace disk_cache {
     11 
     12 MemRankings::~MemRankings() {
     13   DCHECK(!head_ && !tail_);
     14 }
     15 
     16 void MemRankings::Insert(MemEntryImpl* node) {
     17   if (head_)
     18     head_->set_prev(node);
     19 
     20   if (!tail_)
     21     tail_ = node;
     22 
     23   node->set_prev(NULL);
     24   node->set_next(head_);
     25   head_ = node;
     26 }
     27 
     28 void MemRankings::Remove(MemEntryImpl* node) {
     29   MemEntryImpl* prev = node->prev();
     30   MemEntryImpl* next = node->next();
     31 
     32   if (head_ == node)
     33     head_ = next;
     34 
     35   if (tail_ == node)
     36     tail_ = prev;
     37 
     38   if (prev)
     39     prev->set_next(next);
     40 
     41   if (next)
     42     next->set_prev(prev);
     43 
     44   node->set_next(NULL);
     45   node->set_prev(NULL);
     46 }
     47 
     48 void MemRankings::UpdateRank(MemEntryImpl* node) {
     49   Remove(node);
     50   Insert(node);
     51 }
     52 
     53 MemEntryImpl* MemRankings::GetNext(MemEntryImpl* node) {
     54   if (!node)
     55     return head_;
     56 
     57   return node->next();
     58 }
     59 
     60 MemEntryImpl* MemRankings::GetPrev(MemEntryImpl* node) {
     61   if (!node)
     62     return tail_;
     63 
     64   return node->prev();
     65 }
     66 
     67 }  // namespace disk_cache
     68