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

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: Possible AsyncResourceHandler support for detached resources. 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 request, 59 request,
58 &response->head.appcache_id, 60 &response->head.appcache_id,
59 &response->head.appcache_manifest_url); 61 &response->head.appcache_manifest_url);
60 // TODO(mmenke): Figure out if LOAD_ENABLE_LOAD_TIMING is safe to remove. 62 // TODO(mmenke): Figure out if LOAD_ENABLE_LOAD_TIMING is safe to remove.
61 if (request->load_flags() & net::LOAD_ENABLE_LOAD_TIMING) 63 if (request->load_flags() & net::LOAD_ENABLE_LOAD_TIMING)
62 request->GetLoadTimingInfo(&response->head.load_timing); 64 request->GetLoadTimingInfo(&response->head.load_timing);
63 } 65 }
64 66
65 } // namespace 67 } // namespace
66 68
69 // The time in ms to delay a cancel of a detachable resource unless otherwise
70 // specified by a flag.
71 static const int kDefaultDelayDetachableCancelMs = 60000;
mmenke 2013/10/17 18:33:48 nit: Just remove the static and move this up into
jkarlin2 2013/10/24 15:33:11 I needed a settable delay for testing so I removed
72
67 ResourceLoader::ResourceLoader(scoped_ptr<net::URLRequest> request, 73 ResourceLoader::ResourceLoader(scoped_ptr<net::URLRequest> request,
68 scoped_ptr<ResourceHandler> handler, 74 scoped_ptr<ResourceHandler> handler,
69 ResourceLoaderDelegate* delegate) 75 ResourceLoaderDelegate* delegate)
70 : weak_ptr_factory_(this) { 76 : weak_ptr_factory_(this) {
71 scoped_ptr<net::ClientCertStore> client_cert_store; 77 scoped_ptr<net::ClientCertStore> client_cert_store;
72 #if !defined(USE_OPENSSL) 78 #if !defined(USE_OPENSSL)
73 client_cert_store.reset(new net::ClientCertStoreImpl()); 79 client_cert_store.reset(new net::ClientCertStoreImpl());
74 #endif 80 #endif
75 Init(request.Pass(), handler.Pass(), delegate, client_cert_store.Pass()); 81 Init(request.Pass(), handler.Pass(), delegate, client_cert_store.Pass());
76 } 82 }
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 CancelRequest(false); 457 CancelRequest(false);
452 } 458 }
453 459
454 void ResourceLoader::StartRequestInternal() { 460 void ResourceLoader::StartRequestInternal() {
455 DCHECK(!request_->is_pending()); 461 DCHECK(!request_->is_pending());
456 request_->Start(); 462 request_->Start();
457 463
458 delegate_->DidStartRequest(this); 464 delegate_->DidStartRequest(this);
459 } 465 }
460 466
467 bool ResourceLoader::DelayCancelForDetachable(
468 const ResourceRequestInfoImpl& info, bool from_renderer) {
mmenke 2013/10/17 18:33:48 If a profile, along with its network stack, are de
jkarlin2 2013/10/24 15:33:11 ResourceContext::~ResourceContext() calls Resource
469 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
470 // Delay requests to cancel detachable resources. Detachable resources are
471 // those that may need to live beyond the lifetime of their renderers, but
472 // should not be allowed to continue indefinitely as the user cannot control
473 // them through the UI. An example detachable resource is a prefetch.
474 if (from_renderer && !detached_timer_ && info.is_detachable() &&
475 command_line.HasSwitch(switches::kDelayDetachableCancellation)) {
476 // Start the delay timer.
477 detached_timer_.reset(new base::OneShotTimer<ResourceLoader>());
478
479 int delay_ms;
480 if (!base::StringToInt(command_line.GetSwitchValueASCII(
481 switches::kDelayDetachableCancellation),
482 &delay_ms)) {
483 delay_ms = kDefaultDelayDetachableCancelMs;
484 }
485
486 detached_timer_->Start(FROM_HERE, TimeDelta::FromMilliseconds(delay_ms),
487 this, &ResourceLoader::Cancel);
488 return true;
489 }
490 return false;
491 }
492
461 void ResourceLoader::CancelRequestInternal(int error, bool from_renderer) { 493 void ResourceLoader::CancelRequestInternal(int error, bool from_renderer) {
462 VLOG(1) << "CancelRequestInternal: " << request_->url().spec(); 494 VLOG(1) << "CancelRequestInternal: " << request_->url().spec();
463 495
464 ResourceRequestInfoImpl* info = GetRequestInfo(); 496 ResourceRequestInfoImpl* info = GetRequestInfo();
465 497
466 // WebKit will send us a cancel for downloads since it no longer handles 498 // 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 499 // them. In this case, ignore the cancel since we handle downloads in the
468 // browser. 500 // browser.
469 if (from_renderer && (info->is_download() || info->is_stream())) 501 if (from_renderer && (info->is_download() || info->is_stream()))
470 return; 502 return;
471 503
504 if (DelayCancelForDetachable(*info, from_renderer)) {
505 return;
506 }
507
472 // TODO(darin): Perhaps we should really be looking to see if the status is 508 // TODO(darin): Perhaps we should really be looking to see if the status is
473 // IO_PENDING? 509 // IO_PENDING?
474 bool was_pending = request_->is_pending(); 510 bool was_pending = request_->is_pending();
475 511
476 if (login_delegate_.get()) { 512 if (login_delegate_.get()) {
477 login_delegate_->OnRequestCancelled(); 513 login_delegate_->OnRequestCancelled();
478 login_delegate_ = NULL; 514 login_delegate_ = NULL;
479 } 515 }
480 if (ssl_client_auth_handler_.get()) { 516 if (ssl_client_auth_handler_.get()) {
481 ssl_client_auth_handler_->OnRequestCancelled(); 517 ssl_client_auth_handler_->OnRequestCancelled();
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 // we resume. 691 // we resume.
656 deferred_stage_ = DEFERRED_FINISH; 692 deferred_stage_ = DEFERRED_FINISH;
657 } 693 }
658 } 694 }
659 695
660 void ResourceLoader::CallDidFinishLoading() { 696 void ResourceLoader::CallDidFinishLoading() {
661 delegate_->DidFinishLoading(this); 697 delegate_->DidFinishLoading(this);
662 } 698 }
663 699
664 } // namespace content 700 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698