Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: net/disk_cache/mem_backend_impl.cc

Issue 20737002: Change the API of disk_cache::CreateCacheBackend to use scoped_ptr (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix new test Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/mem_backend_impl.h ('k') | net/disk_cache/tracing_cache_backend.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « net/disk_cache/mem_backend_impl.h ('k') | net/disk_cache/tracing_cache_backend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698