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/http/http_cache.h" | 5 #include "net/http/http_cache.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... | |
26 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
27 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
28 #include "base/strings/stringprintf.h" | 28 #include "base/strings/stringprintf.h" |
29 #include "base/threading/worker_pool.h" | 29 #include "base/threading/worker_pool.h" |
30 #include "net/base/cache_type.h" | 30 #include "net/base/cache_type.h" |
31 #include "net/base/io_buffer.h" | 31 #include "net/base/io_buffer.h" |
32 #include "net/base/load_flags.h" | 32 #include "net/base/load_flags.h" |
33 #include "net/base/net_errors.h" | 33 #include "net/base/net_errors.h" |
34 #include "net/base/upload_data_stream.h" | 34 #include "net/base/upload_data_stream.h" |
35 #include "net/disk_cache/disk_cache.h" | 35 #include "net/disk_cache/disk_cache.h" |
36 #include "net/http/disk_based_cert_cache.h" | |
36 #include "net/http/disk_cache_based_quic_server_info.h" | 37 #include "net/http/disk_cache_based_quic_server_info.h" |
37 #include "net/http/http_cache_transaction.h" | 38 #include "net/http/http_cache_transaction.h" |
38 #include "net/http/http_network_layer.h" | 39 #include "net/http/http_network_layer.h" |
39 #include "net/http/http_network_session.h" | 40 #include "net/http/http_network_session.h" |
40 #include "net/http/http_request_info.h" | 41 #include "net/http/http_request_info.h" |
41 #include "net/http/http_response_headers.h" | 42 #include "net/http/http_response_headers.h" |
42 #include "net/http/http_response_info.h" | 43 #include "net/http/http_response_info.h" |
43 #include "net/http/http_util.h" | 44 #include "net/http/http_util.h" |
44 #include "net/quic/crypto/quic_server_info.h" | 45 #include "net/quic/crypto/quic_server_info.h" |
45 | 46 |
46 namespace { | 47 namespace { |
47 | 48 |
49 bool UseCertCache() { | |
wtc
2014/07/08 00:14:03
IMPORTANT: Should we also use a command-line optio
Ryan Sleevi
2014/07/08 00:34:18
wtc: What's the use case here? I discouraged Brand
wtc
2014/07/08 01:54:41
A command-line option is a common way to allow us
| |
50 return base::FieldTrialList::FindFullName("CertCacheTrial") == | |
51 "ExperimentGroup"; | |
wtc
2014/07/08 18:24:21
IMPORTANT: Users in the field trial will have new
Ryan Sleevi
2014/07/08 18:29:08
Yes. We're using the DiskCache.
wtc
2014/07/08 19:00:11
Suppose we change the URI scheme to "cert2:". Won'
| |
52 } | |
53 | |
48 // Adaptor to delete a file on a worker thread. | 54 // Adaptor to delete a file on a worker thread. |
49 void DeletePath(base::FilePath path) { | 55 void DeletePath(base::FilePath path) { |
50 base::DeleteFile(path, false); | 56 base::DeleteFile(path, false); |
51 } | 57 } |
52 | 58 |
53 } // namespace | 59 } // namespace |
54 | 60 |
55 namespace net { | 61 namespace net { |
56 | 62 |
57 HttpCache::DefaultBackend::DefaultBackend(CacheType type, | 63 HttpCache::DefaultBackend::DefaultBackend(CacheType type, |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 entry->pending_queue.clear(); | 345 entry->pending_queue.clear(); |
340 entry->readers.clear(); | 346 entry->readers.clear(); |
341 entry->writer = NULL; | 347 entry->writer = NULL; |
342 DeactivateEntry(entry); | 348 DeactivateEntry(entry); |
343 } | 349 } |
344 | 350 |
345 STLDeleteElements(&doomed_entries_); | 351 STLDeleteElements(&doomed_entries_); |
346 | 352 |
347 // Before deleting pending_ops_, we have to make sure that the disk cache is | 353 // Before deleting pending_ops_, we have to make sure that the disk cache is |
348 // done with said operations, or it will attempt to use deleted data. | 354 // done with said operations, or it will attempt to use deleted data. |
349 disk_cache_.reset(); | 355 disk_cache_.reset(); |
wtc
2014/07/08 00:14:03
Should we call cert_cache_.reset() before calling
Ryan Sleevi
2014/07/08 00:34:18
Yes
| |
350 | 356 |
351 PendingOpsMap::iterator pending_it = pending_ops_.begin(); | 357 PendingOpsMap::iterator pending_it = pending_ops_.begin(); |
352 for (; pending_it != pending_ops_.end(); ++pending_it) { | 358 for (; pending_it != pending_ops_.end(); ++pending_it) { |
353 // We are not notifying the transactions about the cache going away, even | 359 // We are not notifying the transactions about the cache going away, even |
354 // though they are waiting for a callback that will never fire. | 360 // though they are waiting for a callback that will never fire. |
355 PendingOp* pending_op = pending_it->second; | 361 PendingOp* pending_op = pending_it->second; |
356 delete pending_op->writer; | 362 delete pending_op->writer; |
357 bool delete_pending_op = true; | 363 bool delete_pending_op = true; |
358 if (building_backend_) { | 364 if (building_backend_) { |
359 // If we don't have a backend, when its construction finishes it will | 365 // If we don't have a backend, when its construction finishes it will |
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1167 DCHECK_EQ(WI_CREATE_BACKEND, op); | 1173 DCHECK_EQ(WI_CREATE_BACKEND, op); |
1168 | 1174 |
1169 // We don't need the callback anymore. | 1175 // We don't need the callback anymore. |
1170 pending_op->callback.Reset(); | 1176 pending_op->callback.Reset(); |
1171 | 1177 |
1172 if (backend_factory_.get()) { | 1178 if (backend_factory_.get()) { |
1173 // We may end up calling OnBackendCreated multiple times if we have pending | 1179 // We may end up calling OnBackendCreated multiple times if we have pending |
1174 // work items. The first call saves the backend and releases the factory, | 1180 // work items. The first call saves the backend and releases the factory, |
1175 // and the last call clears building_backend_. | 1181 // and the last call clears building_backend_. |
1176 backend_factory_.reset(); // Reclaim memory. | 1182 backend_factory_.reset(); // Reclaim memory. |
1177 if (result == OK) | 1183 if (result == OK) { |
1178 disk_cache_ = pending_op->backend.Pass(); | 1184 disk_cache_ = pending_op->backend.Pass(); |
1185 if (UseCertCache()) | |
1186 cert_cache_.reset(new DiskBasedCertCache(disk_cache_.get())); | |
1187 } | |
1179 } | 1188 } |
1180 | 1189 |
1181 if (!pending_op->pending_queue.empty()) { | 1190 if (!pending_op->pending_queue.empty()) { |
1182 WorkItem* pending_item = pending_op->pending_queue.front(); | 1191 WorkItem* pending_item = pending_op->pending_queue.front(); |
1183 pending_op->pending_queue.pop_front(); | 1192 pending_op->pending_queue.pop_front(); |
1184 DCHECK_EQ(WI_CREATE_BACKEND, pending_item->operation()); | 1193 DCHECK_EQ(WI_CREATE_BACKEND, pending_item->operation()); |
1185 | 1194 |
1186 // We want to process a single callback at a time, because the cache may | 1195 // We want to process a single callback at a time, because the cache may |
1187 // go away from the callback. | 1196 // go away from the callback. |
1188 pending_op->writer = pending_item; | 1197 pending_op->writer = pending_item; |
1189 | 1198 |
1190 base::MessageLoop::current()->PostTask( | 1199 base::MessageLoop::current()->PostTask( |
1191 FROM_HERE, | 1200 FROM_HERE, |
1192 base::Bind(&HttpCache::OnBackendCreated, GetWeakPtr(), | 1201 base::Bind(&HttpCache::OnBackendCreated, GetWeakPtr(), |
1193 result, pending_op)); | 1202 result, pending_op)); |
1194 } else { | 1203 } else { |
1195 building_backend_ = false; | 1204 building_backend_ = false; |
1196 DeletePendingOp(pending_op); | 1205 DeletePendingOp(pending_op); |
1197 } | 1206 } |
1198 | 1207 |
1199 // The cache may be gone when we return from the callback. | 1208 // The cache may be gone when we return from the callback. |
1200 if (!item->DoCallback(result, disk_cache_.get())) | 1209 if (!item->DoCallback(result, disk_cache_.get())) |
1201 item->NotifyTransaction(result, NULL); | 1210 item->NotifyTransaction(result, NULL); |
1202 } | 1211 } |
1203 | 1212 |
1204 } // namespace net | 1213 } // namespace net |
OLD | NEW |