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