Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: net/disk_cache/backend_impl.cc

Issue 12192005: Add new simple disk cache backend. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build fix Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/disk_cache/simple/simple_backend_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 10 matching lines...) Expand all
21 #include "base/threading/worker_pool.h" 21 #include "base/threading/worker_pool.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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 256
256 // ------------------------------------------------------------------------ 257 // ------------------------------------------------------------------------
257 258
258 namespace disk_cache { 259 namespace disk_cache {
259 260
260 int CreateCacheBackend(net::CacheType type, const base::FilePath& path, 261 int CreateCacheBackend(net::CacheType type, const base::FilePath& path,
261 int max_bytes, 262 int max_bytes,
262 bool force, base::MessageLoopProxy* thread, 263 bool force, base::MessageLoopProxy* thread,
263 net::NetLog* net_log, Backend** backend, 264 net::NetLog* net_log, Backend** backend,
264 const net::CompletionCallback& callback) { 265 const net::CompletionCallback& callback) {
266 // TODO(pasko): Separate out cache creation when landing cache tracer.
265 DCHECK(!callback.is_null()); 267 DCHECK(!callback.is_null());
266 if (type == net::MEMORY_CACHE) { 268 if (type == net::MEMORY_CACHE) {
267 *backend = MemBackendImpl::CreateBackend(max_bytes, net_log); 269 *backend = MemBackendImpl::CreateBackend(max_bytes, net_log);
268 return *backend ? net::OK : net::ERR_FAILED; 270 return *backend ? net::OK : net::ERR_FAILED;
269 } 271 }
270 DCHECK(thread); 272 DCHECK(thread);
271 273
274 #if defined(USE_SIMPLE_CACHE_BACKEND)
275 return SimpleBackendImpl::CreateBackend(path, force, max_bytes, type, kNone,
276 thread, net_log, backend, callback);
277 #else
272 return BackendImpl::CreateBackend(path, force, max_bytes, type, kNone, thread, 278 return BackendImpl::CreateBackend(path, force, max_bytes, type, kNone, thread,
273 net_log, backend, callback); 279 net_log, backend, callback);
280 #endif
274 } 281 }
275 282
276 // Returns the preferred maximum number of bytes for the cache given the 283 // Returns the preferred maximum number of bytes for the cache given the
277 // number of available bytes. 284 // number of available bytes.
278 int PreferedCacheSize(int64 available) { 285 int PreferedCacheSize(int64 available) {
279 // Return 80% of the available space if there is not enough space to use 286 // Return 80% of the available space if there is not enough space to use
280 // kDefaultCacheSize. 287 // kDefaultCacheSize.
281 if (available < kDefaultCacheSize * 10 / 8) 288 if (available < kDefaultCacheSize * 10 / 8)
282 return static_cast<int32>(available * 8 / 10); 289 return static_cast<int32>(available * 8 / 10);
283 290
(...skipping 1957 matching lines...) Expand 10 before | Expand all | Expand 10 after
2241 if (total_memory > kMaxBuffersSize || total_memory <= 0) 2248 if (total_memory > kMaxBuffersSize || total_memory <= 0)
2242 total_memory = kMaxBuffersSize; 2249 total_memory = kMaxBuffersSize;
2243 2250
2244 done = true; 2251 done = true;
2245 } 2252 }
2246 2253
2247 return static_cast<int>(total_memory); 2254 return static_cast<int>(total_memory);
2248 } 2255 }
2249 2256
2250 } // namespace disk_cache 2257 } // namespace disk_cache
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/simple/simple_backend_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698