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 weak_factory_(this) { | 295 weak_factory_(this) { |
298 HttpNetworkSession* session = network_layer_->GetSession(); | 296 SetupQuicServerInfoFactory(network_layer_->GetSession()); |
299 session->quic_stream_factory()->set_quic_server_info_factory( | |
300 quic_server_info_factory_.get()); | |
301 } | 297 } |
302 | 298 |
303 | 299 |
304 // This call doesn't change the shared |session|'s QuicServerInfoFactory because | 300 // This call doesn't change the shared |session|'s QuicServerInfoFactory because |
305 // |session| is shared. | 301 // |session| is shared. |
306 HttpCache::HttpCache(HttpNetworkSession* session, | 302 HttpCache::HttpCache(HttpNetworkSession* session, |
307 BackendFactory* backend_factory) | 303 BackendFactory* backend_factory) |
308 : net_log_(session->net_log()), | 304 : net_log_(session->net_log()), |
309 backend_factory_(backend_factory), | 305 backend_factory_(backend_factory), |
310 building_backend_(false), | 306 building_backend_(false), |
311 mode_(NORMAL), | 307 mode_(NORMAL), |
312 network_layer_(new HttpNetworkLayer(session)), | 308 network_layer_(new HttpNetworkLayer(session)), |
313 weak_factory_(this) { | 309 weak_factory_(this) { |
314 } | 310 } |
315 | 311 |
316 HttpCache::HttpCache(HttpTransactionFactory* network_layer, | 312 HttpCache::HttpCache(HttpTransactionFactory* network_layer, |
317 NetLog* net_log, | 313 NetLog* net_log, |
318 BackendFactory* backend_factory) | 314 BackendFactory* backend_factory) |
319 : net_log_(net_log), | 315 : net_log_(net_log), |
320 backend_factory_(backend_factory), | 316 backend_factory_(backend_factory), |
321 building_backend_(false), | 317 building_backend_(false), |
322 mode_(NORMAL), | 318 mode_(NORMAL), |
323 network_layer_(network_layer), | 319 network_layer_(network_layer), |
324 weak_factory_(this) { | 320 weak_factory_(this) { |
| 321 SetupQuicServerInfoFactory(network_layer_->GetSession()); |
325 } | 322 } |
326 | 323 |
327 HttpCache::~HttpCache() { | 324 HttpCache::~HttpCache() { |
328 // Transactions should see an invalid cache after this point; otherwise they | 325 // Transactions should see an invalid cache after this point; otherwise they |
329 // could see an inconsistent object (half destroyed). | 326 // could see an inconsistent object (half destroyed). |
330 weak_factory_.InvalidateWeakPtrs(); | 327 weak_factory_.InvalidateWeakPtrs(); |
331 | 328 |
332 // If we have any active entries remaining, then we need to deactivate them. | 329 // If we have any active entries remaining, then we need to deactivate them. |
333 // We may have some pending calls to OnProcessPendingQueue, but since those | 330 // We may have some pending calls to OnProcessPendingQueue, but since those |
334 // won't run (due to our destruction), we can simply ignore the corresponding | 331 // won't run (due to our destruction), we can simply ignore the corresponding |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 for (; it != pending_queue.end(); ++it) { | 997 for (; it != pending_queue.end(); ++it) { |
1001 if ((*it)->Matches(trans)) { | 998 if ((*it)->Matches(trans)) { |
1002 delete *it; | 999 delete *it; |
1003 pending_queue.erase(it); | 1000 pending_queue.erase(it); |
1004 return true; | 1001 return true; |
1005 } | 1002 } |
1006 } | 1003 } |
1007 return false; | 1004 return false; |
1008 } | 1005 } |
1009 | 1006 |
| 1007 void HttpCache::SetupQuicServerInfoFactory(HttpNetworkSession* session) { |
| 1008 if (session && session->params().enable_quic_persist_server_info && |
| 1009 !session->quic_stream_factory()->has_quic_server_info_factory()) { |
| 1010 DCHECK(!quic_server_info_factory_); |
| 1011 quic_server_info_factory_.reset(new QuicServerInfoFactoryAdaptor(this)); |
| 1012 session->quic_stream_factory()->set_quic_server_info_factory( |
| 1013 quic_server_info_factory_.get()); |
| 1014 } |
| 1015 } |
| 1016 |
1010 void HttpCache::ProcessPendingQueue(ActiveEntry* entry) { | 1017 void HttpCache::ProcessPendingQueue(ActiveEntry* entry) { |
1011 // Multiple readers may finish with an entry at once, so we want to batch up | 1018 // Multiple readers may finish with an entry at once, so we want to batch up |
1012 // calls to OnProcessPendingQueue. This flag also tells us that we should | 1019 // calls to OnProcessPendingQueue. This flag also tells us that we should |
1013 // not delete the entry before OnProcessPendingQueue runs. | 1020 // not delete the entry before OnProcessPendingQueue runs. |
1014 if (entry->will_process_pending_queue) | 1021 if (entry->will_process_pending_queue) |
1015 return; | 1022 return; |
1016 entry->will_process_pending_queue = true; | 1023 entry->will_process_pending_queue = true; |
1017 | 1024 |
1018 base::MessageLoop::current()->PostTask( | 1025 base::MessageLoop::current()->PostTask( |
1019 FROM_HERE, | 1026 FROM_HERE, |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1180 building_backend_ = false; | 1187 building_backend_ = false; |
1181 DeletePendingOp(pending_op); | 1188 DeletePendingOp(pending_op); |
1182 } | 1189 } |
1183 | 1190 |
1184 // The cache may be gone when we return from the callback. | 1191 // The cache may be gone when we return from the callback. |
1185 if (!item->DoCallback(result, disk_cache_.get())) | 1192 if (!item->DoCallback(result, disk_cache_.get())) |
1186 item->NotifyTransaction(result, NULL); | 1193 item->NotifyTransaction(result, NULL); |
1187 } | 1194 } |
1188 | 1195 |
1189 } // namespace net | 1196 } // namespace net |
OLD | NEW |