Chromium Code Reviews| 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/memory/mem_backend_impl.h" | 5 #include "net/disk_cache/memory/mem_backend_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 MemBackendImpl::MemBackendImpl(net::NetLog* net_log) | 43 MemBackendImpl::MemBackendImpl(net::NetLog* net_log) |
| 44 : max_size_(0), current_size_(0), net_log_(net_log), weak_factory_(this) { | 44 : max_size_(0), current_size_(0), net_log_(net_log), weak_factory_(this) { |
| 45 } | 45 } |
| 46 | 46 |
| 47 MemBackendImpl::~MemBackendImpl() { | 47 MemBackendImpl::~MemBackendImpl() { |
| 48 DCHECK(CheckLRUListOrder(lru_list_)); | 48 DCHECK(CheckLRUListOrder(lru_list_)); |
| 49 while (!entries_.empty()) | 49 while (!entries_.empty()) |
| 50 entries_.begin()->second->Doom(); | 50 entries_.begin()->second->Doom(); |
| 51 DCHECK(!current_size_); | 51 DCHECK_EQ(0, current_size_); |
|
jkarlin
2017/03/30 15:04:42
Hmm. I'm skeptical that this DCHECK even makes sen
Randy Smith (Not in Mondays)
2017/03/30 16:38:11
Plausible skepticism. I'd say not your problem, t
jkarlin
2017/03/30 17:18:27
Acknowledged.
| |
| 52 } | 52 } |
| 53 | 53 |
| 54 // static | 54 // static |
| 55 std::unique_ptr<Backend> MemBackendImpl::CreateBackend(int max_bytes, | 55 std::unique_ptr<Backend> MemBackendImpl::CreateBackend(int max_bytes, |
| 56 net::NetLog* net_log) { | 56 net::NetLog* net_log) { |
| 57 std::unique_ptr<MemBackendImpl> cache(new MemBackendImpl(net_log)); | 57 std::unique_ptr<MemBackendImpl> cache(new MemBackendImpl(net_log)); |
| 58 cache->SetMaxSize(max_bytes); | 58 cache->SetMaxSize(max_bytes); |
| 59 if (cache->Init()) | 59 if (cache->Init()) |
| 60 return std::move(cache); | 60 return std::move(cache); |
| 61 | 61 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 // LinkedList<>::RemoveFromList() removes |entry| from |lru_list_|. | 121 // LinkedList<>::RemoveFromList() removes |entry| from |lru_list_|. |
| 122 entry->RemoveFromList(); | 122 entry->RemoveFromList(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void MemBackendImpl::ModifyStorageSize(int32_t delta) { | 125 void MemBackendImpl::ModifyStorageSize(int32_t delta) { |
| 126 current_size_ += delta; | 126 current_size_ += delta; |
| 127 if (delta > 0) | 127 if (delta > 0) |
| 128 EvictIfNeeded(); | 128 EvictIfNeeded(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 bool MemBackendImpl::HasExceededStorageSize() const { | |
| 132 return current_size_ > max_size_; | |
| 133 } | |
| 134 | |
| 131 net::CacheType MemBackendImpl::GetCacheType() const { | 135 net::CacheType MemBackendImpl::GetCacheType() const { |
| 132 return net::MEMORY_CACHE; | 136 return net::MEMORY_CACHE; |
| 133 } | 137 } |
| 134 | 138 |
| 135 int32_t MemBackendImpl::GetEntryCount() const { | 139 int32_t MemBackendImpl::GetEntryCount() const { |
| 136 return static_cast<int32_t>(entries_.size()); | 140 return static_cast<int32_t>(entries_.size()); |
| 137 } | 141 } |
| 138 | 142 |
| 139 int MemBackendImpl::OpenEntry(const std::string& key, | 143 int MemBackendImpl::OpenEntry(const std::string& key, |
| 140 Entry** entry, | 144 Entry** entry, |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 base::LinkNode<MemEntryImpl>* entry = lru_list_.head(); | 319 base::LinkNode<MemEntryImpl>* entry = lru_list_.head(); |
| 316 while (current_size_ > target_size && entry != lru_list_.end()) { | 320 while (current_size_ > target_size && entry != lru_list_.end()) { |
| 317 MemEntryImpl* to_doom = entry->value(); | 321 MemEntryImpl* to_doom = entry->value(); |
| 318 entry = entry->next(); | 322 entry = entry->next(); |
| 319 if (!to_doom->InUse()) | 323 if (!to_doom->InUse()) |
| 320 to_doom->Doom(); | 324 to_doom->Doom(); |
| 321 } | 325 } |
| 322 } | 326 } |
| 323 | 327 |
| 324 } // namespace disk_cache | 328 } // namespace disk_cache |
| OLD | NEW |