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/backend_impl.h" | 5 #include "net/disk_cache/backend_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
22 #include "base/time.h" | 22 #include "base/time.h" |
23 #include "base/timer.h" | 23 #include "base/timer.h" |
24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
25 #include "net/disk_cache/cache_util.h" | 25 #include "net/disk_cache/cache_util.h" |
26 #include "net/disk_cache/entry_impl.h" | 26 #include "net/disk_cache/entry_impl.h" |
27 #include "net/disk_cache/errors.h" | 27 #include "net/disk_cache/errors.h" |
28 #include "net/disk_cache/experiments.h" | 28 #include "net/disk_cache/experiments.h" |
29 #include "net/disk_cache/file.h" | 29 #include "net/disk_cache/file.h" |
30 #include "net/disk_cache/mem_backend_impl.h" | 30 #include "net/disk_cache/mem_backend_impl.h" |
| 31 #include "net/disk_cache/simple/simple_backend_impl.h" |
31 | 32 |
32 // This has to be defined before including histogram_macros.h from this file. | 33 // This has to be defined before including histogram_macros.h from this file. |
33 #define NET_DISK_CACHE_BACKEND_IMPL_CC_ | 34 #define NET_DISK_CACHE_BACKEND_IMPL_CC_ |
34 #include "net/disk_cache/histogram_macros.h" | 35 #include "net/disk_cache/histogram_macros.h" |
35 | 36 |
36 using base::Time; | 37 using base::Time; |
37 using base::TimeDelta; | 38 using base::TimeDelta; |
38 using base::TimeTicks; | 39 using base::TimeTicks; |
39 | 40 |
40 namespace { | 41 namespace { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 } // namespace | 253 } // namespace |
253 | 254 |
254 // ------------------------------------------------------------------------ | 255 // ------------------------------------------------------------------------ |
255 | 256 |
256 namespace disk_cache { | 257 namespace disk_cache { |
257 | 258 |
258 int CreateCacheBackend(net::CacheType type, const FilePath& path, int max_bytes, | 259 int CreateCacheBackend(net::CacheType type, const FilePath& path, int max_bytes, |
259 bool force, base::MessageLoopProxy* thread, | 260 bool force, base::MessageLoopProxy* thread, |
260 net::NetLog* net_log, Backend** backend, | 261 net::NetLog* net_log, Backend** backend, |
261 const net::CompletionCallback& callback) { | 262 const net::CompletionCallback& callback) { |
| 263 // TODO(pasko): Separate out cache creation when landing cache tracer. |
262 DCHECK(!callback.is_null()); | 264 DCHECK(!callback.is_null()); |
263 if (type == net::MEMORY_CACHE) { | 265 if (type == net::MEMORY_CACHE) { |
264 *backend = MemBackendImpl::CreateBackend(max_bytes, net_log); | 266 *backend = MemBackendImpl::CreateBackend(max_bytes, net_log); |
265 return *backend ? net::OK : net::ERR_FAILED; | 267 return *backend ? net::OK : net::ERR_FAILED; |
266 } | 268 } |
267 DCHECK(thread); | 269 DCHECK(thread); |
268 | 270 |
| 271 #if defined(USE_SIMPLE_BACKEND) |
| 272 return SimpleBackendImpl::CreateBackend(path, force, max_bytes, type, kNone, |
| 273 thread, net_log, backend, callback); |
| 274 #else |
269 return BackendImpl::CreateBackend(path, force, max_bytes, type, kNone, thread, | 275 return BackendImpl::CreateBackend(path, force, max_bytes, type, kNone, thread, |
270 net_log, backend, callback); | 276 net_log, backend, callback); |
| 277 #endif |
271 } | 278 } |
272 | 279 |
273 // Returns the preferred maximum number of bytes for the cache given the | 280 // Returns the preferred maximum number of bytes for the cache given the |
274 // number of available bytes. | 281 // number of available bytes. |
275 int PreferedCacheSize(int64 available) { | 282 int PreferedCacheSize(int64 available) { |
276 // Return 80% of the available space if there is not enough space to use | 283 // Return 80% of the available space if there is not enough space to use |
277 // kDefaultCacheSize. | 284 // kDefaultCacheSize. |
278 if (available < kDefaultCacheSize * 10 / 8) | 285 if (available < kDefaultCacheSize * 10 / 8) |
279 return static_cast<int32>(available * 8 / 10); | 286 return static_cast<int32>(available * 8 / 10); |
280 | 287 |
(...skipping 1955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2236 if (total_memory > kMaxBuffersSize || total_memory <= 0) | 2243 if (total_memory > kMaxBuffersSize || total_memory <= 0) |
2237 total_memory = kMaxBuffersSize; | 2244 total_memory = kMaxBuffersSize; |
2238 | 2245 |
2239 done = true; | 2246 done = true; |
2240 } | 2247 } |
2241 | 2248 |
2242 return static_cast<int>(total_memory); | 2249 return static_cast<int>(total_memory); |
2243 } | 2250 } |
2244 | 2251 |
2245 } // namespace disk_cache | 2252 } // namespace disk_cache |
OLD | NEW |