| 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 | 287 |
| 288 QuicServerInfo* GetForServer(const QuicServerId& server_id) override { | 288 QuicServerInfo* GetForServer(const QuicServerId& server_id) override { |
| 289 return new DiskCacheBasedQuicServerInfo(server_id, http_cache_); | 289 return new DiskCacheBasedQuicServerInfo(server_id, http_cache_); |
| 290 } | 290 } |
| 291 | 291 |
| 292 private: | 292 private: |
| 293 HttpCache* const http_cache_; | 293 HttpCache* const http_cache_; |
| 294 }; | 294 }; |
| 295 | 295 |
| 296 //----------------------------------------------------------------------------- | 296 //----------------------------------------------------------------------------- |
| 297 HttpCache::HttpCache(const HttpNetworkSession::Params& params, |
| 298 BackendFactory* backend_factory) |
| 299 : net_log_(params.net_log), |
| 300 backend_factory_(backend_factory), |
| 301 building_backend_(false), |
| 302 bypass_lock_for_test_(false), |
| 303 fail_conditionalization_for_test_(false), |
| 304 mode_(NORMAL), |
| 305 network_layer_(new HttpNetworkLayer(new HttpNetworkSession(params))), |
| 306 clock_(new base::DefaultClock()), |
| 307 weak_factory_(this) { |
| 308 SetupQuicServerInfoFactory(network_layer_->GetSession()); |
| 309 } |
| 310 |
| 311 |
| 297 // This call doesn't change the shared |session|'s QuicServerInfoFactory because | 312 // This call doesn't change the shared |session|'s QuicServerInfoFactory because |
| 298 // |session| is shared. | 313 // |session| is shared. |
| 299 HttpCache::HttpCache(HttpNetworkSession* session, | 314 HttpCache::HttpCache(HttpNetworkSession* session, |
| 300 BackendFactory* backend_factory, | 315 BackendFactory* backend_factory) |
| 301 bool set_up_quic_server_info) | 316 : net_log_(session->net_log()), |
| 302 : HttpCache(new HttpNetworkLayer(session), | 317 backend_factory_(backend_factory), |
| 303 session->net_log(), | 318 building_backend_(false), |
| 304 backend_factory, | 319 bypass_lock_for_test_(false), |
| 305 set_up_quic_server_info) {} | 320 fail_conditionalization_for_test_(false), |
| 321 mode_(NORMAL), |
| 322 network_layer_(new HttpNetworkLayer(session)), |
| 323 clock_(new base::DefaultClock()), |
| 324 weak_factory_(this) { |
| 325 } |
| 306 | 326 |
| 307 HttpCache::HttpCache(HttpTransactionFactory* network_layer, | 327 HttpCache::HttpCache(HttpTransactionFactory* network_layer, |
| 308 NetLog* net_log, | 328 NetLog* net_log, |
| 309 BackendFactory* backend_factory, | 329 BackendFactory* backend_factory) |
| 310 bool set_up_quic_server_info) | |
| 311 : net_log_(net_log), | 330 : net_log_(net_log), |
| 312 backend_factory_(backend_factory), | 331 backend_factory_(backend_factory), |
| 313 building_backend_(false), | 332 building_backend_(false), |
| 314 bypass_lock_for_test_(false), | 333 bypass_lock_for_test_(false), |
| 315 fail_conditionalization_for_test_(false), | 334 fail_conditionalization_for_test_(false), |
| 316 mode_(NORMAL), | 335 mode_(NORMAL), |
| 317 network_layer_(network_layer), | 336 network_layer_(network_layer), |
| 318 clock_(new base::DefaultClock()), | 337 clock_(new base::DefaultClock()), |
| 319 weak_factory_(this) { | 338 weak_factory_(this) { |
| 320 if (set_up_quic_server_info) | 339 SetupQuicServerInfoFactory(network_layer_->GetSession()); |
| 321 SetupQuicServerInfoFactory(network_layer_->GetSession()); | |
| 322 } | 340 } |
| 323 | 341 |
| 324 HttpCache::~HttpCache() { | 342 HttpCache::~HttpCache() { |
| 325 // Transactions should see an invalid cache after this point; otherwise they | 343 // Transactions should see an invalid cache after this point; otherwise they |
| 326 // could see an inconsistent object (half destroyed). | 344 // could see an inconsistent object (half destroyed). |
| 327 weak_factory_.InvalidateWeakPtrs(); | 345 weak_factory_.InvalidateWeakPtrs(); |
| 328 | 346 |
| 329 // If we have any active entries remaining, then we need to deactivate them. | 347 // If we have any active entries remaining, then we need to deactivate them. |
| 330 // We may have some pending calls to OnProcessPendingQueue, but since those | 348 // We may have some pending calls to OnProcessPendingQueue, but since those |
| 331 // won't run (due to our destruction), we can simply ignore the corresponding | 349 // 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... |
| 1163 building_backend_ = false; | 1181 building_backend_ = false; |
| 1164 DeletePendingOp(pending_op); | 1182 DeletePendingOp(pending_op); |
| 1165 } | 1183 } |
| 1166 | 1184 |
| 1167 // The cache may be gone when we return from the callback. | 1185 // The cache may be gone when we return from the callback. |
| 1168 if (!item->DoCallback(result, disk_cache_.get())) | 1186 if (!item->DoCallback(result, disk_cache_.get())) |
| 1169 item->NotifyTransaction(result, NULL); | 1187 item->NotifyTransaction(result, NULL); |
| 1170 } | 1188 } |
| 1171 | 1189 |
| 1172 } // namespace net | 1190 } // namespace net |
| OLD | NEW |