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/mem_backend_impl.h" | 5 #include "net/disk_cache/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 23 matching lines...) Expand all Loading... |
34 MemBackendImpl::~MemBackendImpl() { | 34 MemBackendImpl::~MemBackendImpl() { |
35 EntryMap::iterator it = entries_.begin(); | 35 EntryMap::iterator it = entries_.begin(); |
36 while (it != entries_.end()) { | 36 while (it != entries_.end()) { |
37 it->second->Doom(); | 37 it->second->Doom(); |
38 it = entries_.begin(); | 38 it = entries_.begin(); |
39 } | 39 } |
40 DCHECK(!current_size_); | 40 DCHECK(!current_size_); |
41 } | 41 } |
42 | 42 |
43 // Static. | 43 // Static. |
44 Backend* MemBackendImpl::CreateBackend(int max_bytes, net::NetLog* net_log) { | 44 scoped_ptr<Backend> MemBackendImpl::CreateBackend(int max_bytes, |
45 MemBackendImpl* cache = new MemBackendImpl(net_log); | 45 net::NetLog* net_log) { |
| 46 scoped_ptr<MemBackendImpl> cache(new MemBackendImpl(net_log)); |
46 cache->SetMaxSize(max_bytes); | 47 cache->SetMaxSize(max_bytes); |
47 if (cache->Init()) | 48 if (cache->Init()) |
48 return cache; | 49 return cache.PassAs<Backend>(); |
49 | 50 |
50 delete cache; | |
51 LOG(ERROR) << "Unable to create cache"; | 51 LOG(ERROR) << "Unable to create cache"; |
52 return NULL; | 52 return scoped_ptr<Backend>(); |
53 } | 53 } |
54 | 54 |
55 bool MemBackendImpl::Init() { | 55 bool MemBackendImpl::Init() { |
56 if (max_size_) | 56 if (max_size_) |
57 return true; | 57 return true; |
58 | 58 |
59 int64 total_memory = base::SysInfo::AmountOfPhysicalMemory(); | 59 int64 total_memory = base::SysInfo::AmountOfPhysicalMemory(); |
60 | 60 |
61 if (total_memory <= 0) { | 61 if (total_memory <= 0) { |
62 max_size_ = kDefaultCacheSize; | 62 max_size_ = kDefaultCacheSize; |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 if (current_size_ > max_size_) | 328 if (current_size_ > max_size_) |
329 TrimCache(false); | 329 TrimCache(false); |
330 } | 330 } |
331 | 331 |
332 void MemBackendImpl::SubstractStorageSize(int32 bytes) { | 332 void MemBackendImpl::SubstractStorageSize(int32 bytes) { |
333 current_size_ -= bytes; | 333 current_size_ -= bytes; |
334 DCHECK_GE(current_size_, 0); | 334 DCHECK_GE(current_size_, 0); |
335 } | 335 } |
336 | 336 |
337 } // namespace disk_cache | 337 } // namespace disk_cache |
OLD | NEW |