| 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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 private: | 283 private: |
| 284 HttpCache* const http_cache_; | 284 HttpCache* const http_cache_; |
| 285 }; | 285 }; |
| 286 | 286 |
| 287 //----------------------------------------------------------------------------- | 287 //----------------------------------------------------------------------------- |
| 288 HttpCache::HttpCache(const net::HttpNetworkSession::Params& params, | 288 HttpCache::HttpCache(const net::HttpNetworkSession::Params& params, |
| 289 BackendFactory* backend_factory) | 289 BackendFactory* backend_factory) |
| 290 : net_log_(params.net_log), | 290 : net_log_(params.net_log), |
| 291 backend_factory_(backend_factory), | 291 backend_factory_(backend_factory), |
| 292 building_backend_(false), | 292 building_backend_(false), |
| 293 bypass_lock_for_test_(false), |
| 293 mode_(NORMAL), | 294 mode_(NORMAL), |
| 294 network_layer_(new HttpNetworkLayer(new HttpNetworkSession(params))), | 295 network_layer_(new HttpNetworkLayer(new HttpNetworkSession(params))), |
| 295 weak_factory_(this) { | 296 weak_factory_(this) { |
| 296 SetupQuicServerInfoFactory(network_layer_->GetSession()); | 297 SetupQuicServerInfoFactory(network_layer_->GetSession()); |
| 297 } | 298 } |
| 298 | 299 |
| 299 | 300 |
| 300 // This call doesn't change the shared |session|'s QuicServerInfoFactory because | 301 // This call doesn't change the shared |session|'s QuicServerInfoFactory because |
| 301 // |session| is shared. | 302 // |session| is shared. |
| 302 HttpCache::HttpCache(HttpNetworkSession* session, | 303 HttpCache::HttpCache(HttpNetworkSession* session, |
| 303 BackendFactory* backend_factory) | 304 BackendFactory* backend_factory) |
| 304 : net_log_(session->net_log()), | 305 : net_log_(session->net_log()), |
| 305 backend_factory_(backend_factory), | 306 backend_factory_(backend_factory), |
| 306 building_backend_(false), | 307 building_backend_(false), |
| 308 bypass_lock_for_test_(false), |
| 307 mode_(NORMAL), | 309 mode_(NORMAL), |
| 308 network_layer_(new HttpNetworkLayer(session)), | 310 network_layer_(new HttpNetworkLayer(session)), |
| 309 weak_factory_(this) { | 311 weak_factory_(this) { |
| 310 } | 312 } |
| 311 | 313 |
| 312 HttpCache::HttpCache(HttpTransactionFactory* network_layer, | 314 HttpCache::HttpCache(HttpTransactionFactory* network_layer, |
| 313 NetLog* net_log, | 315 NetLog* net_log, |
| 314 BackendFactory* backend_factory) | 316 BackendFactory* backend_factory) |
| 315 : net_log_(net_log), | 317 : net_log_(net_log), |
| 316 backend_factory_(backend_factory), | 318 backend_factory_(backend_factory), |
| 317 building_backend_(false), | 319 building_backend_(false), |
| 320 bypass_lock_for_test_(false), |
| 318 mode_(NORMAL), | 321 mode_(NORMAL), |
| 319 network_layer_(network_layer), | 322 network_layer_(network_layer), |
| 320 weak_factory_(this) { | 323 weak_factory_(this) { |
| 321 SetupQuicServerInfoFactory(network_layer_->GetSession()); | 324 SetupQuicServerInfoFactory(network_layer_->GetSession()); |
| 322 } | 325 } |
| 323 | 326 |
| 324 HttpCache::~HttpCache() { | 327 HttpCache::~HttpCache() { |
| 325 // Transactions should see an invalid cache after this point; otherwise they | 328 // Transactions should see an invalid cache after this point; otherwise they |
| 326 // could see an inconsistent object (half destroyed). | 329 // could see an inconsistent object (half destroyed). |
| 327 weak_factory_.InvalidateWeakPtrs(); | 330 weak_factory_.InvalidateWeakPtrs(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 } | 453 } |
| 451 | 454 |
| 452 int HttpCache::CreateTransaction(RequestPriority priority, | 455 int HttpCache::CreateTransaction(RequestPriority priority, |
| 453 scoped_ptr<HttpTransaction>* trans) { | 456 scoped_ptr<HttpTransaction>* trans) { |
| 454 // Do lazy initialization of disk cache if needed. | 457 // Do lazy initialization of disk cache if needed. |
| 455 if (!disk_cache_.get()) { | 458 if (!disk_cache_.get()) { |
| 456 // We don't care about the result. | 459 // We don't care about the result. |
| 457 CreateBackend(NULL, net::CompletionCallback()); | 460 CreateBackend(NULL, net::CompletionCallback()); |
| 458 } | 461 } |
| 459 | 462 |
| 460 trans->reset(new HttpCache::Transaction(priority, this)); | 463 HttpCache::Transaction* transaction = |
| 464 new HttpCache::Transaction(priority, this); |
| 465 if (bypass_lock_for_test_) |
| 466 transaction->BypassLockForTest(); |
| 467 |
| 468 trans->reset(transaction); |
| 461 return OK; | 469 return OK; |
| 462 } | 470 } |
| 463 | 471 |
| 464 HttpCache* HttpCache::GetCache() { | 472 HttpCache* HttpCache::GetCache() { |
| 465 return this; | 473 return this; |
| 466 } | 474 } |
| 467 | 475 |
| 468 HttpNetworkSession* HttpCache::GetSession() { | 476 HttpNetworkSession* HttpCache::GetSession() { |
| 469 net::HttpNetworkLayer* network = | 477 net::HttpNetworkLayer* network = |
| 470 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); | 478 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); |
| (...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 building_backend_ = false; | 1195 building_backend_ = false; |
| 1188 DeletePendingOp(pending_op); | 1196 DeletePendingOp(pending_op); |
| 1189 } | 1197 } |
| 1190 | 1198 |
| 1191 // The cache may be gone when we return from the callback. | 1199 // The cache may be gone when we return from the callback. |
| 1192 if (!item->DoCallback(result, disk_cache_.get())) | 1200 if (!item->DoCallback(result, disk_cache_.get())) |
| 1193 item->NotifyTransaction(result, NULL); | 1201 item->NotifyTransaction(result, NULL); |
| 1194 } | 1202 } |
| 1195 | 1203 |
| 1196 } // namespace net | 1204 } // namespace net |
| OLD | NEW |