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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "base/time/time.h" | 30 #include "base/time/time.h" |
31 #include "base/trace_event/memory_allocator_dump.h" | 31 #include "base/trace_event/memory_allocator_dump.h" |
32 #include "base/trace_event/memory_usage_estimator.h" | 32 #include "base/trace_event/memory_usage_estimator.h" |
33 #include "base/trace_event/process_memory_dump.h" | 33 #include "base/trace_event/process_memory_dump.h" |
34 #include "net/base/cache_type.h" | 34 #include "net/base/cache_type.h" |
35 #include "net/base/io_buffer.h" | 35 #include "net/base/io_buffer.h" |
36 #include "net/base/load_flags.h" | 36 #include "net/base/load_flags.h" |
37 #include "net/base/net_errors.h" | 37 #include "net/base/net_errors.h" |
38 #include "net/base/upload_data_stream.h" | 38 #include "net/base/upload_data_stream.h" |
39 #include "net/disk_cache/disk_cache.h" | 39 #include "net/disk_cache/disk_cache.h" |
40 #include "net/http/disk_cache_based_quic_server_info.h" | |
41 #include "net/http/http_cache_lookup_manager.h" | 40 #include "net/http/http_cache_lookup_manager.h" |
42 #include "net/http/http_cache_transaction.h" | 41 #include "net/http/http_cache_transaction.h" |
43 #include "net/http/http_network_layer.h" | 42 #include "net/http/http_network_layer.h" |
44 #include "net/http/http_network_session.h" | 43 #include "net/http/http_network_session.h" |
45 #include "net/http/http_request_info.h" | 44 #include "net/http/http_request_info.h" |
46 #include "net/http/http_response_headers.h" | 45 #include "net/http/http_response_headers.h" |
47 #include "net/http/http_response_info.h" | 46 #include "net/http/http_response_info.h" |
48 #include "net/http/http_util.h" | 47 #include "net/http/http_util.h" |
49 #include "net/log/net_log_with_source.h" | 48 #include "net/log/net_log_with_source.h" |
50 #include "net/quic/chromium/quic_server_info.h" | 49 #include "net/quic/chromium/quic_server_info.h" |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 delete this; | 295 delete this; |
297 } | 296 } |
298 | 297 |
299 void HttpCache::MetadataWriter::OnIOComplete(int result) { | 298 void HttpCache::MetadataWriter::OnIOComplete(int result) { |
300 if (!verified_) | 299 if (!verified_) |
301 return VerifyResponse(result); | 300 return VerifyResponse(result); |
302 SelfDestroy(); | 301 SelfDestroy(); |
303 } | 302 } |
304 | 303 |
305 //----------------------------------------------------------------------------- | 304 //----------------------------------------------------------------------------- |
306 | |
307 class HttpCache::QuicServerInfoFactoryAdaptor : public QuicServerInfoFactory { | |
308 public: | |
309 explicit QuicServerInfoFactoryAdaptor(HttpCache* http_cache) | |
310 : http_cache_(http_cache) { | |
311 } | |
312 | |
313 std::unique_ptr<QuicServerInfo> GetForServer( | |
314 const QuicServerId& server_id) override { | |
315 return base::MakeUnique<DiskCacheBasedQuicServerInfo>(server_id, | |
316 http_cache_); | |
317 } | |
318 | |
319 private: | |
320 HttpCache* const http_cache_; | |
321 }; | |
322 | |
323 //----------------------------------------------------------------------------- | |
324 HttpCache::HttpCache(HttpNetworkSession* session, | 305 HttpCache::HttpCache(HttpNetworkSession* session, |
325 std::unique_ptr<BackendFactory> backend_factory, | 306 std::unique_ptr<BackendFactory> backend_factory, |
326 bool is_main_cache) | 307 bool is_main_cache) |
327 : HttpCache(base::MakeUnique<HttpNetworkLayer>(session), | 308 : HttpCache(base::MakeUnique<HttpNetworkLayer>(session), |
328 std::move(backend_factory), | 309 std::move(backend_factory), |
329 is_main_cache) {} | 310 is_main_cache) {} |
330 | 311 |
331 HttpCache::HttpCache(std::unique_ptr<HttpTransactionFactory> network_layer, | 312 HttpCache::HttpCache(std::unique_ptr<HttpTransactionFactory> network_layer, |
332 std::unique_ptr<BackendFactory> backend_factory, | 313 std::unique_ptr<BackendFactory> backend_factory, |
333 bool is_main_cache) | 314 bool is_main_cache) |
(...skipping 12 matching lines...) Expand all Loading... |
346 // rather than having logic only used in unit tests here. | 327 // rather than having logic only used in unit tests here. |
347 if (!session) | 328 if (!session) |
348 return; | 329 return; |
349 | 330 |
350 net_log_ = session->net_log(); | 331 net_log_ = session->net_log(); |
351 if (!is_main_cache) | 332 if (!is_main_cache) |
352 return; | 333 return; |
353 | 334 |
354 session->SetServerPushDelegate( | 335 session->SetServerPushDelegate( |
355 base::MakeUnique<HttpCacheLookupManager>(this)); | 336 base::MakeUnique<HttpCacheLookupManager>(this)); |
356 | |
357 if (!session->quic_stream_factory()->has_quic_server_info_factory()) { | |
358 // QuicStreamFactory takes ownership of QuicServerInfoFactoryAdaptor. | |
359 session->quic_stream_factory()->set_quic_server_info_factory( | |
360 new QuicServerInfoFactoryAdaptor(this)); | |
361 } | |
362 } | 337 } |
363 | 338 |
364 HttpCache::~HttpCache() { | 339 HttpCache::~HttpCache() { |
365 // Transactions should see an invalid cache after this point; otherwise they | 340 // Transactions should see an invalid cache after this point; otherwise they |
366 // could see an inconsistent object (half destroyed). | 341 // could see an inconsistent object (half destroyed). |
367 weak_factory_.InvalidateWeakPtrs(); | 342 weak_factory_.InvalidateWeakPtrs(); |
368 | 343 |
369 // If we have any active entries remaining, then we need to deactivate them. | 344 // If we have any active entries remaining, then we need to deactivate them. |
370 // We may have some pending calls to OnProcessPendingQueue, but since those | 345 // We may have some pending calls to OnProcessPendingQueue, but since those |
371 // won't run (due to our destruction), we can simply ignore the corresponding | 346 // won't run (due to our destruction), we can simply ignore the corresponding |
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 building_backend_ = false; | 1178 building_backend_ = false; |
1204 DeletePendingOp(pending_op); | 1179 DeletePendingOp(pending_op); |
1205 } | 1180 } |
1206 | 1181 |
1207 // The cache may be gone when we return from the callback. | 1182 // The cache may be gone when we return from the callback. |
1208 if (!item->DoCallback(result, disk_cache_.get())) | 1183 if (!item->DoCallback(result, disk_cache_.get())) |
1209 item->NotifyTransaction(result, NULL); | 1184 item->NotifyTransaction(result, NULL); |
1210 } | 1185 } |
1211 | 1186 |
1212 } // namespace net | 1187 } // namespace net |
OLD | NEW |