Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: content/browser/loader/resource_loader.cc

Issue 25772002: Allows prefetch requests to live beyond the renderer by delaying (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed all comments. Lots of tests. Using AsyncResourceHandler. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/browser/loader/resource_loader.h" 5 #include "content/browser/loader/resource_loader.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/string_number_conversions.h"
10 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "base/timer/timer.h"
11 #include "content/browser/child_process_security_policy_impl.h" 13 #include "content/browser/child_process_security_policy_impl.h"
12 #include "content/browser/loader/cross_site_resource_handler.h" 14 #include "content/browser/loader/cross_site_resource_handler.h"
13 #include "content/browser/loader/resource_loader_delegate.h" 15 #include "content/browser/loader/resource_loader_delegate.h"
14 #include "content/browser/loader/resource_request_info_impl.h" 16 #include "content/browser/loader/resource_request_info_impl.h"
15 #include "content/browser/ssl/ssl_client_auth_handler.h" 17 #include "content/browser/ssl/ssl_client_auth_handler.h"
16 #include "content/browser/ssl/ssl_manager.h" 18 #include "content/browser/ssl/ssl_manager.h"
17 #include "content/common/ssl_status_serialization.h" 19 #include "content/common/ssl_status_serialization.h"
18 #include "content/public/browser/cert_store.h" 20 #include "content/public/browser/cert_store.h"
19 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" 21 #include "content/public/browser/resource_dispatcher_host_login_delegate.h"
20 #include "content/public/browser/site_instance.h" 22 #include "content/public/browser/site_instance.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 ResourceLoaderDelegate* delegate, 205 ResourceLoaderDelegate* delegate,
204 scoped_ptr<net::ClientCertStore> client_cert_store) { 206 scoped_ptr<net::ClientCertStore> client_cert_store) {
205 deferred_stage_ = DEFERRED_NONE; 207 deferred_stage_ = DEFERRED_NONE;
206 request_ = request.Pass(); 208 request_ = request.Pass();
207 handler_ = handler.Pass(); 209 handler_ = handler.Pass();
208 delegate_ = delegate; 210 delegate_ = delegate;
209 last_upload_position_ = 0; 211 last_upload_position_ = 0;
210 waiting_for_upload_progress_ack_ = false; 212 waiting_for_upload_progress_ack_ = false;
211 is_transferring_ = false; 213 is_transferring_ = false;
212 client_cert_store_ = client_cert_store.Pass(); 214 client_cert_store_ = client_cert_store.Pass();
215 detachable_delay_ms_ = 60000;
mmenke 2013/10/24 20:27:21 Wonder if we should reduce this... Regardless, th
jkarlin2 2013/10/25 14:10:21 Done. Yes, 60 seconds is long. It's just until w
mmenke 2013/10/25 14:57:51 I suggest starting short (Like the current behavio
jkarlin2 2013/10/25 18:24:54 I originally had it at seconds. cbentzel had reco
jkarlin2 2013/10/25 18:28:21 I meant to say that I originally had it at 3 secon
213 216
214 request_->set_delegate(this); 217 request_->set_delegate(this);
215 handler_->SetController(this); 218 handler_->SetController(this);
216 } 219 }
217 220
218 void ResourceLoader::OnReceivedRedirect(net::URLRequest* unused, 221 void ResourceLoader::OnReceivedRedirect(net::URLRequest* unused,
219 const GURL& new_url, 222 const GURL& new_url,
220 bool* defer) { 223 bool* defer) {
221 DCHECK_EQ(request_.get(), unused); 224 DCHECK_EQ(request_.get(), unused);
222 225
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 CancelRequest(false); 454 CancelRequest(false);
452 } 455 }
453 456
454 void ResourceLoader::StartRequestInternal() { 457 void ResourceLoader::StartRequestInternal() {
455 DCHECK(!request_->is_pending()); 458 DCHECK(!request_->is_pending());
456 request_->Start(); 459 request_->Start();
457 460
458 delegate_->DidStartRequest(this); 461 delegate_->DidStartRequest(this);
459 } 462 }
460 463
464 void ResourceLoader::CancelAfterTimeout() {
465 if (detached_timer_)
466 return;
467
468 detached_timer_.reset(new base::OneShotTimer<ResourceLoader>());
469 detached_timer_->Start(FROM_HERE,
470 TimeDelta::FromMilliseconds(detachable_delay_ms_),
471 this, &ResourceLoader::Cancel);
472 }
473
461 void ResourceLoader::CancelRequestInternal(int error, bool from_renderer) { 474 void ResourceLoader::CancelRequestInternal(int error, bool from_renderer) {
462 VLOG(1) << "CancelRequestInternal: " << request_->url().spec(); 475 VLOG(1) << "CancelRequestInternal: " << request_->url().spec();
463 476
464 ResourceRequestInfoImpl* info = GetRequestInfo(); 477 ResourceRequestInfoImpl* info = GetRequestInfo();
465 478
466 // WebKit will send us a cancel for downloads since it no longer handles 479 // WebKit will send us a cancel for downloads since it no longer handles
467 // them. In this case, ignore the cancel since we handle downloads in the 480 // them. In this case, ignore the cancel since we handle downloads in the
468 // browser. 481 // browser.
469 if (from_renderer && (info->is_download() || info->is_stream())) 482 if (from_renderer && (info->is_download() || info->is_stream()))
470 return; 483 return;
471 484
485 if (from_renderer && info->is_detachable()) {
486 CancelAfterTimeout();
487 return;
488 }
489
472 // TODO(darin): Perhaps we should really be looking to see if the status is 490 // TODO(darin): Perhaps we should really be looking to see if the status is
473 // IO_PENDING? 491 // IO_PENDING?
474 bool was_pending = request_->is_pending(); 492 bool was_pending = request_->is_pending();
475 493
476 if (login_delegate_.get()) { 494 if (login_delegate_.get()) {
477 login_delegate_->OnRequestCancelled(); 495 login_delegate_->OnRequestCancelled();
478 login_delegate_ = NULL; 496 login_delegate_ = NULL;
479 } 497 }
480 if (ssl_client_auth_handler_.get()) { 498 if (ssl_client_auth_handler_.get()) {
481 ssl_client_auth_handler_->OnRequestCancelled(); 499 ssl_client_auth_handler_->OnRequestCancelled();
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 // we resume. 673 // we resume.
656 deferred_stage_ = DEFERRED_FINISH; 674 deferred_stage_ = DEFERRED_FINISH;
657 } 675 }
658 } 676 }
659 677
660 void ResourceLoader::CallDidFinishLoading() { 678 void ResourceLoader::CallDidFinishLoading() {
661 delegate_->DidFinishLoading(this); 679 delegate_->DidFinishLoading(this);
662 } 680 }
663 681
664 } // namespace content 682 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698