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 <utility> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
9 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
10 #include "net/disk_cache/cache_util.h" | 12 #include "net/disk_cache/cache_util.h" |
11 #include "net/disk_cache/memory/mem_entry_impl.h" | 13 #include "net/disk_cache/memory/mem_entry_impl.h" |
12 | 14 |
13 using base::Time; | 15 using base::Time; |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
(...skipping 23 matching lines...) Expand all Loading... |
40 } | 42 } |
41 DCHECK(!current_size_); | 43 DCHECK(!current_size_); |
42 } | 44 } |
43 | 45 |
44 // Static. | 46 // Static. |
45 scoped_ptr<Backend> MemBackendImpl::CreateBackend(int max_bytes, | 47 scoped_ptr<Backend> MemBackendImpl::CreateBackend(int max_bytes, |
46 net::NetLog* net_log) { | 48 net::NetLog* net_log) { |
47 scoped_ptr<MemBackendImpl> cache(new MemBackendImpl(net_log)); | 49 scoped_ptr<MemBackendImpl> cache(new MemBackendImpl(net_log)); |
48 cache->SetMaxSize(max_bytes); | 50 cache->SetMaxSize(max_bytes); |
49 if (cache->Init()) | 51 if (cache->Init()) |
50 return cache.Pass(); | 52 return std::move(cache); |
51 | 53 |
52 LOG(ERROR) << "Unable to create cache"; | 54 LOG(ERROR) << "Unable to create cache"; |
53 return nullptr; | 55 return nullptr; |
54 } | 56 } |
55 | 57 |
56 bool MemBackendImpl::Init() { | 58 bool MemBackendImpl::Init() { |
57 if (max_size_) | 59 if (max_size_) |
58 return true; | 60 return true; |
59 | 61 |
60 int64_t total_memory = base::SysInfo::AmountOfPhysicalMemory(); | 62 int64_t total_memory = base::SysInfo::AmountOfPhysicalMemory(); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 if (current_size_ > max_size_) | 344 if (current_size_ > max_size_) |
343 TrimCache(false); | 345 TrimCache(false); |
344 } | 346 } |
345 | 347 |
346 void MemBackendImpl::SubstractStorageSize(int32_t bytes) { | 348 void MemBackendImpl::SubstractStorageSize(int32_t bytes) { |
347 current_size_ -= bytes; | 349 current_size_ -= bytes; |
348 DCHECK_GE(current_size_, 0); | 350 DCHECK_GE(current_size_, 0); |
349 } | 351 } |
350 | 352 |
351 } // namespace disk_cache | 353 } // namespace disk_cache |
OLD | NEW |