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/cache_util.h" | 5 #include "net/disk_cache/cache_util.h" |
6 | 6 |
| 7 #include <limits> |
| 8 |
7 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
8 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
9 #include "base/location.h" | 11 #include "base/location.h" |
10 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
11 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
12 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
13 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
14 #include "base/threading/worker_pool.h" | 16 #include "base/threading/worker_pool.h" |
15 | 17 |
16 namespace { | 18 namespace { |
(...skipping 25 matching lines...) Expand all Loading... |
42 const std::string& name) { | 44 const std::string& name) { |
43 // We'll attempt to have up to kMaxOldFolders folders for deletion. | 45 // We'll attempt to have up to kMaxOldFolders folders for deletion. |
44 for (int i = 0; i < kMaxOldFolders; i++) { | 46 for (int i = 0; i < kMaxOldFolders; i++) { |
45 base::FilePath to_delete = GetPrefixedName(path, name, i); | 47 base::FilePath to_delete = GetPrefixedName(path, name, i); |
46 if (!base::PathExists(to_delete)) | 48 if (!base::PathExists(to_delete)) |
47 return to_delete; | 49 return to_delete; |
48 } | 50 } |
49 return base::FilePath(); | 51 return base::FilePath(); |
50 } | 52 } |
51 | 53 |
52 int64 PreferredCacheSizeInternal(int64 available) { | 54 int64_t PreferredCacheSizeInternal(int64_t available) { |
53 using disk_cache::kDefaultCacheSize; | 55 using disk_cache::kDefaultCacheSize; |
54 // Return 80% of the available space if there is not enough space to use | 56 // Return 80% of the available space if there is not enough space to use |
55 // kDefaultCacheSize. | 57 // kDefaultCacheSize. |
56 if (available < kDefaultCacheSize * 10 / 8) | 58 if (available < kDefaultCacheSize * 10 / 8) |
57 return available * 8 / 10; | 59 return available * 8 / 10; |
58 | 60 |
59 // Return kDefaultCacheSize if it uses 10% to 80% of the available space. | 61 // Return kDefaultCacheSize if it uses 10% to 80% of the available space. |
60 if (available < kDefaultCacheSize * 10) | 62 if (available < kDefaultCacheSize * 10) |
61 return kDefaultCacheSize; | 63 return kDefaultCacheSize; |
62 | 64 |
63 // Return 10% of the available space if the target size | 65 // Return 10% of the available space if the target size |
64 // (2.5 * kDefaultCacheSize) is more than 10%. | 66 // (2.5 * kDefaultCacheSize) is more than 10%. |
65 if (available < static_cast<int64>(kDefaultCacheSize) * 25) | 67 if (available < static_cast<int64_t>(kDefaultCacheSize) * 25) |
66 return available / 10; | 68 return available / 10; |
67 | 69 |
68 // Return the target size (2.5 * kDefaultCacheSize) if it uses 10% to 1% | 70 // Return the target size (2.5 * kDefaultCacheSize) if it uses 10% to 1% |
69 // of the available space. | 71 // of the available space. |
70 if (available < static_cast<int64>(kDefaultCacheSize) * 250) | 72 if (available < static_cast<int64_t>(kDefaultCacheSize) * 250) |
71 return kDefaultCacheSize * 5 / 2; | 73 return kDefaultCacheSize * 5 / 2; |
72 | 74 |
73 // Return 1% of the available space. | 75 // Return 1% of the available space. |
74 return available / 100; | 76 return available / 100; |
75 } | 77 } |
76 | 78 |
77 } // namespace | 79 } // namespace |
78 | 80 |
79 namespace disk_cache { | 81 namespace disk_cache { |
80 | 82 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 return false; | 136 return false; |
135 } | 137 } |
136 | 138 |
137 base::WorkerPool::PostTask( | 139 base::WorkerPool::PostTask( |
138 FROM_HERE, base::Bind(&CleanupCallback, path, name_str), true); | 140 FROM_HERE, base::Bind(&CleanupCallback, path, name_str), true); |
139 return true; | 141 return true; |
140 } | 142 } |
141 | 143 |
142 // Returns the preferred maximum number of bytes for the cache given the | 144 // Returns the preferred maximum number of bytes for the cache given the |
143 // number of available bytes. | 145 // number of available bytes. |
144 int PreferredCacheSize(int64 available) { | 146 int PreferredCacheSize(int64_t available) { |
145 if (available < 0) | 147 if (available < 0) |
146 return kDefaultCacheSize; | 148 return kDefaultCacheSize; |
147 | 149 |
148 // Limit cache size to somewhat less than kint32max to avoid potential | 150 // Limit cache size to somewhat less than kint32max to avoid potential |
149 // integer overflows in cache backend implementations. | 151 // integer overflows in cache backend implementations. |
150 DCHECK_LT(kDefaultCacheSize * 4, kint32max); | 152 DCHECK_LT(kDefaultCacheSize * 4, std::numeric_limits<int32_t>::max()); |
151 return static_cast<int32>(std::min( | 153 return static_cast<int32_t>( |
152 PreferredCacheSizeInternal(available), | 154 std::min(PreferredCacheSizeInternal(available), |
153 static_cast<int64>(kDefaultCacheSize * 4))); | 155 static_cast<int64_t>(kDefaultCacheSize * 4))); |
154 } | 156 } |
155 | 157 |
156 } // namespace disk_cache | 158 } // namespace disk_cache |
OLD | NEW |