| 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" |
| 40 #include "net/http/http_cache_lookup_manager.h" | 41 #include "net/http/http_cache_lookup_manager.h" |
| 41 #include "net/http/http_cache_transaction.h" | 42 #include "net/http/http_cache_transaction.h" |
| 42 #include "net/http/http_network_layer.h" | 43 #include "net/http/http_network_layer.h" |
| 43 #include "net/http/http_network_session.h" | 44 #include "net/http/http_network_session.h" |
| 44 #include "net/http/http_request_info.h" | 45 #include "net/http/http_request_info.h" |
| 45 #include "net/http/http_response_headers.h" | 46 #include "net/http/http_response_headers.h" |
| 46 #include "net/http/http_response_info.h" | 47 #include "net/http/http_response_info.h" |
| 47 #include "net/http/http_util.h" | 48 #include "net/http/http_util.h" |
| 48 #include "net/log/net_log_with_source.h" | 49 #include "net/log/net_log_with_source.h" |
| 49 #include "net/quic/chromium/quic_server_info.h" | 50 #include "net/quic/chromium/quic_server_info.h" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 delete this; | 296 delete this; |
| 296 } | 297 } |
| 297 | 298 |
| 298 void HttpCache::MetadataWriter::OnIOComplete(int result) { | 299 void HttpCache::MetadataWriter::OnIOComplete(int result) { |
| 299 if (!verified_) | 300 if (!verified_) |
| 300 return VerifyResponse(result); | 301 return VerifyResponse(result); |
| 301 SelfDestroy(); | 302 SelfDestroy(); |
| 302 } | 303 } |
| 303 | 304 |
| 304 //----------------------------------------------------------------------------- | 305 //----------------------------------------------------------------------------- |
| 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 //----------------------------------------------------------------------------- |
| 305 HttpCache::HttpCache(HttpNetworkSession* session, | 324 HttpCache::HttpCache(HttpNetworkSession* session, |
| 306 std::unique_ptr<BackendFactory> backend_factory, | 325 std::unique_ptr<BackendFactory> backend_factory, |
| 307 bool is_main_cache) | 326 bool is_main_cache) |
| 308 : HttpCache(base::MakeUnique<HttpNetworkLayer>(session), | 327 : HttpCache(base::MakeUnique<HttpNetworkLayer>(session), |
| 309 std::move(backend_factory), | 328 std::move(backend_factory), |
| 310 is_main_cache) {} | 329 is_main_cache) {} |
| 311 | 330 |
| 312 HttpCache::HttpCache(std::unique_ptr<HttpTransactionFactory> network_layer, | 331 HttpCache::HttpCache(std::unique_ptr<HttpTransactionFactory> network_layer, |
| 313 std::unique_ptr<BackendFactory> backend_factory, | 332 std::unique_ptr<BackendFactory> backend_factory, |
| 314 bool is_main_cache) | 333 bool is_main_cache) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 327 // rather than having logic only used in unit tests here. | 346 // rather than having logic only used in unit tests here. |
| 328 if (!session) | 347 if (!session) |
| 329 return; | 348 return; |
| 330 | 349 |
| 331 net_log_ = session->net_log(); | 350 net_log_ = session->net_log(); |
| 332 if (!is_main_cache) | 351 if (!is_main_cache) |
| 333 return; | 352 return; |
| 334 | 353 |
| 335 session->SetServerPushDelegate( | 354 session->SetServerPushDelegate( |
| 336 base::MakeUnique<HttpCacheLookupManager>(this)); | 355 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 } |
| 337 } | 362 } |
| 338 | 363 |
| 339 HttpCache::~HttpCache() { | 364 HttpCache::~HttpCache() { |
| 340 // Transactions should see an invalid cache after this point; otherwise they | 365 // Transactions should see an invalid cache after this point; otherwise they |
| 341 // could see an inconsistent object (half destroyed). | 366 // could see an inconsistent object (half destroyed). |
| 342 weak_factory_.InvalidateWeakPtrs(); | 367 weak_factory_.InvalidateWeakPtrs(); |
| 343 | 368 |
| 344 // If we have any active entries remaining, then we need to deactivate them. | 369 // If we have any active entries remaining, then we need to deactivate them. |
| 345 // We may have some pending calls to OnProcessPendingQueue, but since those | 370 // We may have some pending calls to OnProcessPendingQueue, but since those |
| 346 // won't run (due to our destruction), we can simply ignore the corresponding | 371 // 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... |
| 1178 building_backend_ = false; | 1203 building_backend_ = false; |
| 1179 DeletePendingOp(pending_op); | 1204 DeletePendingOp(pending_op); |
| 1180 } | 1205 } |
| 1181 | 1206 |
| 1182 // The cache may be gone when we return from the callback. | 1207 // The cache may be gone when we return from the callback. |
| 1183 if (!item->DoCallback(result, disk_cache_.get())) | 1208 if (!item->DoCallback(result, disk_cache_.get())) |
| 1184 item->NotifyTransaction(result, NULL); | 1209 item->NotifyTransaction(result, NULL); |
| 1185 } | 1210 } |
| 1186 | 1211 |
| 1187 } // namespace net | 1212 } // namespace net |
| OLD | NEW |