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 29 matching lines...) Expand all Loading... |
40 } | 40 } |
41 DCHECK(!current_size_); | 41 DCHECK(!current_size_); |
42 } | 42 } |
43 | 43 |
44 // Static. | 44 // Static. |
45 scoped_ptr<Backend> MemBackendImpl::CreateBackend(int max_bytes, | 45 scoped_ptr<Backend> MemBackendImpl::CreateBackend(int max_bytes, |
46 net::NetLog* net_log) { | 46 net::NetLog* net_log) { |
47 scoped_ptr<MemBackendImpl> cache(new MemBackendImpl(net_log)); | 47 scoped_ptr<MemBackendImpl> cache(new MemBackendImpl(net_log)); |
48 cache->SetMaxSize(max_bytes); | 48 cache->SetMaxSize(max_bytes); |
49 if (cache->Init()) | 49 if (cache->Init()) |
50 return cache.PassAs<Backend>(); | 50 return cache.Pass(); |
51 | 51 |
52 LOG(ERROR) << "Unable to create cache"; | 52 LOG(ERROR) << "Unable to create cache"; |
53 return scoped_ptr<Backend>(); | 53 return nullptr; |
54 } | 54 } |
55 | 55 |
56 bool MemBackendImpl::Init() { | 56 bool MemBackendImpl::Init() { |
57 if (max_size_) | 57 if (max_size_) |
58 return true; | 58 return true; |
59 | 59 |
60 int64 total_memory = base::SysInfo::AmountOfPhysicalMemory(); | 60 int64 total_memory = base::SysInfo::AmountOfPhysicalMemory(); |
61 | 61 |
62 if (total_memory <= 0) { | 62 if (total_memory <= 0) { |
63 max_size_ = kDefaultInMemoryCacheSize; | 63 max_size_ = kDefaultInMemoryCacheSize; |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 if (current_size_ > max_size_) | 336 if (current_size_ > max_size_) |
337 TrimCache(false); | 337 TrimCache(false); |
338 } | 338 } |
339 | 339 |
340 void MemBackendImpl::SubstractStorageSize(int32 bytes) { | 340 void MemBackendImpl::SubstractStorageSize(int32 bytes) { |
341 current_size_ -= bytes; | 341 current_size_ -= bytes; |
342 DCHECK_GE(current_size_, 0); | 342 DCHECK_GE(current_size_, 0); |
343 } | 343 } |
344 | 344 |
345 } // namespace disk_cache | 345 } // namespace disk_cache |
OLD | NEW |