OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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" |
11 #include "net/disk_cache/mem_entry_impl.h" | 11 #include "net/disk_cache/mem_entry_impl.h" |
12 | 12 |
13 using base::Time; | 13 using base::Time; |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 const int kDefaultCacheSize = 10 * 1024 * 1024; | 17 const int kDefaultCacheSize = 10 * 1024 * 1024; |
18 const int kCleanUpMargin = 1024 * 1024; | 18 const int kCleanUpMargin = 1024 * 1024; |
19 | 19 |
20 int LowWaterAdjust(int high_water) { | 20 int LowWaterAdjust(int high_water) { |
21 if (high_water < kCleanUpMargin) | 21 if (high_water < kCleanUpMargin) |
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 Backend* CreateInMemoryCacheBackend(int max_bytes) { | 31 // Static. |
| 32 Backend* MemBackendImpl::CreateBackend(int max_bytes) { |
32 MemBackendImpl* cache = new MemBackendImpl(); | 33 MemBackendImpl* cache = new MemBackendImpl(); |
33 cache->SetMaxSize(max_bytes); | 34 cache->SetMaxSize(max_bytes); |
34 if (cache->Init()) | 35 if (cache->Init()) |
35 return cache; | 36 return cache; |
36 | 37 |
37 delete cache; | 38 delete cache; |
38 LOG(ERROR) << "Unable to create cache"; | 39 LOG(ERROR) << "Unable to create cache"; |
39 return NULL; | 40 return NULL; |
40 } | 41 } |
41 | 42 |
42 // ------------------------------------------------------------------------ | |
43 | |
44 bool MemBackendImpl::Init() { | 43 bool MemBackendImpl::Init() { |
45 if (max_size_) | 44 if (max_size_) |
46 return true; | 45 return true; |
47 | 46 |
48 int64 total_memory = base::SysInfo::AmountOfPhysicalMemory(); | 47 int64 total_memory = base::SysInfo::AmountOfPhysicalMemory(); |
49 | 48 |
50 if (total_memory <= 0) { | 49 if (total_memory <= 0) { |
51 max_size_ = kDefaultCacheSize; | 50 max_size_ = kDefaultCacheSize; |
52 return true; | 51 return true; |
53 } | 52 } |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 | 308 |
310 void MemBackendImpl::InsertIntoRankingList(MemEntryImpl* entry) { | 309 void MemBackendImpl::InsertIntoRankingList(MemEntryImpl* entry) { |
311 rankings_.Insert(entry); | 310 rankings_.Insert(entry); |
312 } | 311 } |
313 | 312 |
314 void MemBackendImpl::RemoveFromRankingList(MemEntryImpl* entry) { | 313 void MemBackendImpl::RemoveFromRankingList(MemEntryImpl* entry) { |
315 rankings_.Remove(entry); | 314 rankings_.Remove(entry); |
316 } | 315 } |
317 | 316 |
318 } // namespace disk_cache | 317 } // namespace disk_cache |
OLD | NEW |