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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/metrics/field_trial.h" | 6 #include "base/metrics/field_trial.h" |
7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
9 #include "net/disk_cache/backend_impl.h" | 9 #include "net/disk_cache/backend_impl.h" |
10 #include "net/disk_cache/cache_util.h" | 10 #include "net/disk_cache/cache_util.h" |
11 #include "net/disk_cache/mem_backend_impl.h" | 11 #include "net/disk_cache/mem_backend_impl.h" |
12 #include "net/disk_cache/simple/simple_backend_impl.h" | 12 #include "net/disk_cache/simple/simple_backend_impl.h" |
13 | 13 |
| 14 #ifdef USE_TRACING_CACHE_BACKEND |
| 15 #include "net/disk_cache/tracing_cache_backend.h" |
| 16 #endif |
| 17 |
14 namespace { | 18 namespace { |
15 | 19 |
16 // Builds an instance of the backend depending on platform, type, experiments | 20 // Builds an instance of the backend depending on platform, type, experiments |
17 // etc. Takes care of the retry state. This object will self-destroy when | 21 // etc. Takes care of the retry state. This object will self-destroy when |
18 // finished. | 22 // finished. |
19 class CacheCreator { | 23 class CacheCreator { |
20 public: | 24 public: |
21 CacheCreator(const base::FilePath& path, bool force, int max_bytes, | 25 CacheCreator(const base::FilePath& path, bool force, int max_bytes, |
22 net::CacheType type, uint32 flags, | 26 net::CacheType type, uint32 flags, |
23 base::MessageLoopProxy* thread, net::NetLog* net_log, | 27 base::MessageLoopProxy* thread, net::NetLog* net_log, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 108 |
105 void CacheCreator::DoCallback(int result) { | 109 void CacheCreator::DoCallback(int result) { |
106 DCHECK_NE(net::ERR_IO_PENDING, result); | 110 DCHECK_NE(net::ERR_IO_PENDING, result); |
107 if (result == net::OK) { | 111 if (result == net::OK) { |
108 // TODO(pasko): Separate creation of the Simple Backend from its | 112 // TODO(pasko): Separate creation of the Simple Backend from its |
109 // initialization, eliminate unnecessary use_simple_cache_backend_. | 113 // initialization, eliminate unnecessary use_simple_cache_backend_. |
110 if (use_simple_cache_backend_) | 114 if (use_simple_cache_backend_) |
111 created_cache_ = *backend_; | 115 created_cache_ = *backend_; |
112 else | 116 else |
113 *backend_ = created_cache_; | 117 *backend_ = created_cache_; |
| 118 #ifdef USE_TRACING_CACHE_BACKEND |
| 119 *backend_ = new disk_cache::TracingCacheBackend(*backend_); |
| 120 #endif |
114 } else { | 121 } else { |
115 LOG(ERROR) << "Unable to create cache"; | 122 LOG(ERROR) << "Unable to create cache"; |
116 *backend_ = NULL; | 123 *backend_ = NULL; |
117 delete created_cache_; | 124 delete created_cache_; |
118 } | 125 } |
119 callback_.Run(result); | 126 callback_.Run(result); |
120 delete this; | 127 delete this; |
121 } | 128 } |
122 | 129 |
123 // If the initialization of the cache fails, and |force| is true, we will | 130 // If the initialization of the cache fails, and |force| is true, we will |
(...skipping 29 matching lines...) Expand all Loading... |
153 if (type == net::MEMORY_CACHE) { | 160 if (type == net::MEMORY_CACHE) { |
154 *backend = disk_cache::MemBackendImpl::CreateBackend(max_bytes, net_log); | 161 *backend = disk_cache::MemBackendImpl::CreateBackend(max_bytes, net_log); |
155 return *backend ? net::OK : net::ERR_FAILED; | 162 return *backend ? net::OK : net::ERR_FAILED; |
156 } | 163 } |
157 DCHECK(thread); | 164 DCHECK(thread); |
158 CacheCreator* creator = new CacheCreator(path, force, max_bytes, type, kNone, | 165 CacheCreator* creator = new CacheCreator(path, force, max_bytes, type, kNone, |
159 thread, net_log, backend, callback); | 166 thread, net_log, backend, callback); |
160 return creator->Run(); | 167 return creator->Run(); |
161 } | 168 } |
162 | 169 |
163 | |
164 } // namespace disk_cache | 170 } // namespace disk_cache |
OLD | NEW |