Chromium Code Reviews| 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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 mode_(NORMAL), | 293 mode_(NORMAL), |
| 294 quic_server_info_factory_(params.enable_quic_persist_server_info ? | |
| 295 new QuicServerInfoFactoryAdaptor(this) : NULL), | |
| 296 network_layer_(new HttpNetworkLayer(new HttpNetworkSession(params))) { | 294 network_layer_(new HttpNetworkLayer(new HttpNetworkSession(params))) { |
| 297 HttpNetworkSession* session = network_layer_->GetSession(); | 295 SetupNetworkSession(network_layer_->GetSession()); |
| 298 session->quic_stream_factory()->set_quic_server_info_factory( | |
| 299 quic_server_info_factory_.get()); | |
| 300 } | 296 } |
| 301 | 297 |
| 302 | 298 |
| 303 // This call doesn't change the shared |session|'s QuicServerInfoFactory because | 299 // This call doesn't change the shared |session|'s QuicServerInfoFactory because |
| 304 // |session| is shared. | 300 // |session| is shared. |
| 305 HttpCache::HttpCache(HttpNetworkSession* session, | 301 HttpCache::HttpCache(HttpNetworkSession* session, |
| 306 BackendFactory* backend_factory) | 302 BackendFactory* backend_factory) |
| 307 : net_log_(session->net_log()), | 303 : net_log_(session->net_log()), |
| 308 backend_factory_(backend_factory), | 304 backend_factory_(backend_factory), |
| 309 building_backend_(false), | 305 building_backend_(false), |
| 310 mode_(NORMAL), | 306 mode_(NORMAL), |
| 311 network_layer_(new HttpNetworkLayer(session)) { | 307 network_layer_(new HttpNetworkLayer(session)) { |
| 312 } | 308 } |
| 313 | 309 |
| 314 HttpCache::HttpCache(HttpTransactionFactory* network_layer, | 310 HttpCache::HttpCache(HttpTransactionFactory* network_layer, |
| 315 NetLog* net_log, | 311 NetLog* net_log, |
| 316 BackendFactory* backend_factory) | 312 BackendFactory* backend_factory, |
| 313 bool setup_network_session) | |
| 317 : net_log_(net_log), | 314 : net_log_(net_log), |
| 318 backend_factory_(backend_factory), | 315 backend_factory_(backend_factory), |
| 319 building_backend_(false), | 316 building_backend_(false), |
| 320 mode_(NORMAL), | 317 mode_(NORMAL), |
| 321 network_layer_(network_layer) { | 318 network_layer_(network_layer) { |
| 319 if (setup_network_session) | |
| 320 SetupNetworkSession(network_layer_->GetSession()); | |
| 322 } | 321 } |
| 323 | 322 |
| 324 HttpCache::~HttpCache() { | 323 HttpCache::~HttpCache() { |
| 325 // If we have any active entries remaining, then we need to deactivate them. | 324 // If we have any active entries remaining, then we need to deactivate them. |
| 326 // We may have some pending calls to OnProcessPendingQueue, but since those | 325 // We may have some pending calls to OnProcessPendingQueue, but since those |
| 327 // won't run (due to our destruction), we can simply ignore the corresponding | 326 // won't run (due to our destruction), we can simply ignore the corresponding |
| 328 // will_process_pending_queue flag. | 327 // will_process_pending_queue flag. |
| 329 while (!active_entries_.empty()) { | 328 while (!active_entries_.empty()) { |
| 330 ActiveEntry* entry = active_entries_.begin()->second; | 329 ActiveEntry* entry = active_entries_.begin()->second; |
| 331 entry->will_process_pending_queue = false; | 330 entry->will_process_pending_queue = false; |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 993 for (; it != pending_queue.end(); ++it) { | 992 for (; it != pending_queue.end(); ++it) { |
| 994 if ((*it)->Matches(trans)) { | 993 if ((*it)->Matches(trans)) { |
| 995 delete *it; | 994 delete *it; |
| 996 pending_queue.erase(it); | 995 pending_queue.erase(it); |
| 997 return true; | 996 return true; |
| 998 } | 997 } |
| 999 } | 998 } |
| 1000 return false; | 999 return false; |
| 1001 } | 1000 } |
| 1002 | 1001 |
| 1002 void HttpCache::SetupNetworkSession(HttpNetworkSession* session) { | |
| 1003 if (session->params().enable_quic_persist_server_info) { | |
|
rvargas (doing something else)
2014/04/29 23:40:45
couldn't we use this condition to avoid having an
eustas
2014/05/07 13:47:17
Unfortunately, this condition doesn't (and shouldn
| |
| 1004 DCHECK(!quic_server_info_factory_.get()); | |
|
rvargas (doing something else)
2014/04/29 23:40:45
nit: shouldn't need get() here
eustas
2014/05/07 13:47:17
Done.
| |
| 1005 quic_server_info_factory_.reset(new QuicServerInfoFactoryAdaptor(this)); | |
| 1006 session->quic_stream_factory()->set_quic_server_info_factory( | |
| 1007 quic_server_info_factory_.get()); | |
| 1008 } | |
| 1009 } | |
| 1010 | |
| 1003 void HttpCache::ProcessPendingQueue(ActiveEntry* entry) { | 1011 void HttpCache::ProcessPendingQueue(ActiveEntry* entry) { |
| 1004 // Multiple readers may finish with an entry at once, so we want to batch up | 1012 // Multiple readers may finish with an entry at once, so we want to batch up |
| 1005 // calls to OnProcessPendingQueue. This flag also tells us that we should | 1013 // calls to OnProcessPendingQueue. This flag also tells us that we should |
| 1006 // not delete the entry before OnProcessPendingQueue runs. | 1014 // not delete the entry before OnProcessPendingQueue runs. |
| 1007 if (entry->will_process_pending_queue) | 1015 if (entry->will_process_pending_queue) |
| 1008 return; | 1016 return; |
| 1009 entry->will_process_pending_queue = true; | 1017 entry->will_process_pending_queue = true; |
| 1010 | 1018 |
| 1011 base::MessageLoop::current()->PostTask( | 1019 base::MessageLoop::current()->PostTask( |
| 1012 FROM_HERE, | 1020 FROM_HERE, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1173 building_backend_ = false; | 1181 building_backend_ = false; |
| 1174 DeletePendingOp(pending_op); | 1182 DeletePendingOp(pending_op); |
| 1175 } | 1183 } |
| 1176 | 1184 |
| 1177 // The cache may be gone when we return from the callback. | 1185 // The cache may be gone when we return from the callback. |
| 1178 if (!item->DoCallback(result, disk_cache_.get())) | 1186 if (!item->DoCallback(result, disk_cache_.get())) |
| 1179 item->NotifyTransaction(result, NULL); | 1187 item->NotifyTransaction(result, NULL); |
| 1180 } | 1188 } |
| 1181 | 1189 |
| 1182 } // namespace net | 1190 } // namespace net |
| OLD | NEW |