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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/sys_info.h" | 8 #include "base/sys_info.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/disk_cache/cache_util.h" | 10 #include "net/disk_cache/cache_util.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 return 0; | 22 return 0; |
23 | 23 |
24 return high_water - kCleanUpMargin; | 24 return high_water - kCleanUpMargin; |
25 } | 25 } |
26 | 26 |
27 } // namespace | 27 } // namespace |
28 | 28 |
29 namespace disk_cache { | 29 namespace disk_cache { |
30 | 30 |
31 MemBackendImpl::MemBackendImpl(net::NetLog* net_log) | 31 MemBackendImpl::MemBackendImpl(net::NetLog* net_log) |
32 : max_size_(0), current_size_(0), net_log_(net_log) {} | 32 : max_size_(0), current_size_(0), net_log_(net_log) { |
| 33 } |
33 | 34 |
34 MemBackendImpl::~MemBackendImpl() { | 35 MemBackendImpl::~MemBackendImpl() { |
35 EntryMap::iterator it = entries_.begin(); | 36 EntryMap::iterator it = entries_.begin(); |
36 while (it != entries_.end()) { | 37 while (it != entries_.end()) { |
37 it->second->Doom(); | 38 it->second->Doom(); |
38 it = entries_.begin(); | 39 it = entries_.begin(); |
39 } | 40 } |
40 DCHECK(!current_size_); | 41 DCHECK(!current_size_); |
41 } | 42 } |
42 | 43 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 126 } |
126 | 127 |
127 net::CacheType MemBackendImpl::GetCacheType() const { | 128 net::CacheType MemBackendImpl::GetCacheType() const { |
128 return net::MEMORY_CACHE; | 129 return net::MEMORY_CACHE; |
129 } | 130 } |
130 | 131 |
131 int32 MemBackendImpl::GetEntryCount() const { | 132 int32 MemBackendImpl::GetEntryCount() const { |
132 return static_cast<int32>(entries_.size()); | 133 return static_cast<int32>(entries_.size()); |
133 } | 134 } |
134 | 135 |
135 int MemBackendImpl::OpenEntry(const std::string& key, Entry** entry, | 136 int MemBackendImpl::OpenEntry(const std::string& key, |
| 137 Entry** entry, |
136 const CompletionCallback& callback) { | 138 const CompletionCallback& callback) { |
137 if (OpenEntry(key, entry)) | 139 if (OpenEntry(key, entry)) |
138 return net::OK; | 140 return net::OK; |
139 | 141 |
140 return net::ERR_FAILED; | 142 return net::ERR_FAILED; |
141 } | 143 } |
142 | 144 |
143 int MemBackendImpl::CreateEntry(const std::string& key, Entry** entry, | 145 int MemBackendImpl::CreateEntry(const std::string& key, |
| 146 Entry** entry, |
144 const CompletionCallback& callback) { | 147 const CompletionCallback& callback) { |
145 if (CreateEntry(key, entry)) | 148 if (CreateEntry(key, entry)) |
146 return net::OK; | 149 return net::OK; |
147 | 150 |
148 return net::ERR_FAILED; | 151 return net::ERR_FAILED; |
149 } | 152 } |
150 | 153 |
151 int MemBackendImpl::DoomEntry(const std::string& key, | 154 int MemBackendImpl::DoomEntry(const std::string& key, |
152 const CompletionCallback& callback) { | 155 const CompletionCallback& callback) { |
153 if (DoomEntry(key)) | 156 if (DoomEntry(key)) |
(...skipping 19 matching lines...) Expand all Loading... |
173 } | 176 } |
174 | 177 |
175 int MemBackendImpl::DoomEntriesSince(const base::Time initial_time, | 178 int MemBackendImpl::DoomEntriesSince(const base::Time initial_time, |
176 const CompletionCallback& callback) { | 179 const CompletionCallback& callback) { |
177 if (DoomEntriesSince(initial_time)) | 180 if (DoomEntriesSince(initial_time)) |
178 return net::OK; | 181 return net::OK; |
179 | 182 |
180 return net::ERR_FAILED; | 183 return net::ERR_FAILED; |
181 } | 184 } |
182 | 185 |
183 int MemBackendImpl::OpenNextEntry(void** iter, Entry** next_entry, | 186 int MemBackendImpl::OpenNextEntry(void** iter, |
| 187 Entry** next_entry, |
184 const CompletionCallback& callback) { | 188 const CompletionCallback& callback) { |
185 if (OpenNextEntry(iter, next_entry)) | 189 if (OpenNextEntry(iter, next_entry)) |
186 return net::OK; | 190 return net::OK; |
187 | 191 |
188 return net::ERR_FAILED; | 192 return net::ERR_FAILED; |
189 } | 193 } |
190 | 194 |
191 void MemBackendImpl::EndEnumeration(void** iter) { | 195 void MemBackendImpl::EndEnumeration(void** iter) { |
192 *iter = NULL; | 196 *iter = NULL; |
193 } | 197 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 if (current_size_ > max_size_) | 332 if (current_size_ > max_size_) |
329 TrimCache(false); | 333 TrimCache(false); |
330 } | 334 } |
331 | 335 |
332 void MemBackendImpl::SubstractStorageSize(int32 bytes) { | 336 void MemBackendImpl::SubstractStorageSize(int32 bytes) { |
333 current_size_ -= bytes; | 337 current_size_ -= bytes; |
334 DCHECK_GE(current_size_, 0); | 338 DCHECK_GE(current_size_, 0); |
335 } | 339 } |
336 | 340 |
337 } // namespace disk_cache | 341 } // namespace disk_cache |
OLD | NEW |