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

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

Issue 117533003: Make the blockfile cache an optional build product for chrome target. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 9 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/net.gyp » ('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 "base/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "base/metrics/field_trial.h" 6 #include "base/metrics/field_trial.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "net/base/cache_type.h" 8 #include "net/base/cache_type.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/disk_cache/blockfile/backend_impl.h"
11 #include "net/disk_cache/cache_util.h" 10 #include "net/disk_cache/cache_util.h"
12 #include "net/disk_cache/disk_cache.h" 11 #include "net/disk_cache/disk_cache.h"
13 #include "net/disk_cache/memory/mem_backend_impl.h" 12 #include "net/disk_cache/memory/mem_backend_impl.h"
14 #include "net/disk_cache/simple/simple_backend_impl.h" 13 #include "net/disk_cache/simple/simple_backend_impl.h"
15 14
15 #ifdef USE_BLOCKFILE_CACHE_BACKEND
16 #include "net/disk_cache/blockfile/backend_impl.h"
17 #endif
18
16 #ifdef USE_TRACING_CACHE_BACKEND 19 #ifdef USE_TRACING_CACHE_BACKEND
17 #include "net/disk_cache/tracing_cache_backend.h" 20 #include "net/disk_cache/tracing_cache_backend.h"
18 #endif 21 #endif
19 22
20 namespace { 23 namespace {
21 24
22 // Builds an instance of the backend depending on platform, type, experiments 25 // Builds an instance of the backend depending on platform, type, experiments
23 // etc. Takes care of the retry state. This object will self-destroy when 26 // etc. Takes care of the retry state. This object will self-destroy when
24 // finished. 27 // finished.
25 class CacheCreator { 28 class CacheCreator {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 if (backend_type_ == net::CACHE_BACKEND_SIMPLE && 87 if (backend_type_ == net::CACHE_BACKEND_SIMPLE &&
85 (type_ == net::DISK_CACHE || type_ == net::APP_CACHE || 88 (type_ == net::DISK_CACHE || type_ == net::APP_CACHE ||
86 type_ == net::MEDIA_CACHE)) { 89 type_ == net::MEDIA_CACHE)) {
87 disk_cache::SimpleBackendImpl* simple_cache = 90 disk_cache::SimpleBackendImpl* simple_cache =
88 new disk_cache::SimpleBackendImpl(path_, max_bytes_, type_, 91 new disk_cache::SimpleBackendImpl(path_, max_bytes_, type_,
89 thread_.get(), net_log_); 92 thread_.get(), net_log_);
90 created_cache_.reset(simple_cache); 93 created_cache_.reset(simple_cache);
91 return simple_cache->Init( 94 return simple_cache->Init(
92 base::Bind(&CacheCreator::OnIOComplete, base::Unretained(this))); 95 base::Bind(&CacheCreator::OnIOComplete, base::Unretained(this)));
93 } 96 }
97
98 #if defined(USE_BLOCKFILE_CACHE_BACKEND)
94 disk_cache::BackendImpl* new_cache = 99 disk_cache::BackendImpl* new_cache =
95 new disk_cache::BackendImpl(path_, thread_.get(), net_log_); 100 new disk_cache::BackendImpl(path_, thread_.get(), net_log_);
96 created_cache_.reset(new_cache); 101 created_cache_.reset(new_cache);
97 new_cache->SetMaxSize(max_bytes_); 102 new_cache->SetMaxSize(max_bytes_);
98 new_cache->SetType(type_); 103 new_cache->SetType(type_);
99 new_cache->SetFlags(flags_); 104 new_cache->SetFlags(flags_);
100 int rv = new_cache->Init( 105 int rv = new_cache->Init(
101 base::Bind(&CacheCreator::OnIOComplete, base::Unretained(this))); 106 base::Bind(&CacheCreator::OnIOComplete, base::Unretained(this)));
102 DCHECK_EQ(net::ERR_IO_PENDING, rv); 107 DCHECK_EQ(net::ERR_IO_PENDING, rv);
103 return rv; 108 return rv;
109 #else
110 return net::ERR_FAILED;
111 #endif
104 } 112 }
105 113
106 void CacheCreator::DoCallback(int result) { 114 void CacheCreator::DoCallback(int result) {
107 DCHECK_NE(net::ERR_IO_PENDING, result); 115 DCHECK_NE(net::ERR_IO_PENDING, result);
108 if (result == net::OK) { 116 if (result == net::OK) {
109 #ifndef USE_TRACING_CACHE_BACKEND 117 #ifndef USE_TRACING_CACHE_BACKEND
110 *backend_ = created_cache_.Pass(); 118 *backend_ = created_cache_.Pass();
111 #else 119 #else
112 *backend_.reset( 120 *backend_.reset(
113 new disk_cache::TracingCacheBackend(created_cache_.Pass())); 121 new disk_cache::TracingCacheBackend(created_cache_.Pass()));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 bool force, base::MessageLoopProxy* thread, 158 bool force, base::MessageLoopProxy* thread,
151 net::NetLog* net_log, scoped_ptr<Backend>* backend, 159 net::NetLog* net_log, scoped_ptr<Backend>* backend,
152 const net::CompletionCallback& callback) { 160 const net::CompletionCallback& callback) {
153 DCHECK(!callback.is_null()); 161 DCHECK(!callback.is_null());
154 if (type == net::MEMORY_CACHE) { 162 if (type == net::MEMORY_CACHE) {
155 *backend = disk_cache::MemBackendImpl::CreateBackend(max_bytes, net_log); 163 *backend = disk_cache::MemBackendImpl::CreateBackend(max_bytes, net_log);
156 return *backend ? net::OK : net::ERR_FAILED; 164 return *backend ? net::OK : net::ERR_FAILED;
157 } 165 }
158 DCHECK(thread); 166 DCHECK(thread);
159 CacheCreator* creator = new CacheCreator(path, force, max_bytes, type, 167 CacheCreator* creator = new CacheCreator(path, force, max_bytes, type,
160 backend_type, kNone, 168 backend_type, 0,
161 thread, net_log, backend, callback); 169 thread, net_log, backend, callback);
162 return creator->Run(); 170 return creator->Run();
163 } 171 }
164 172
165 } // namespace disk_cache 173 } // namespace disk_cache
OLDNEW
« no previous file with comments | « no previous file | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698