summaryrefslogtreecommitdiffstats
path: root/content/browser/loader/resource_loader.cc
diff options
context:
space:
mode:
authorjkarlin@google.com <jkarlin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-30 20:31:52 +0000
committerjkarlin@google.com <jkarlin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-30 20:31:52 +0000
commit54c1529f8d9906e174a4578a5dbdef30b23d21d8 (patch)
tree0490797063f9261c17bf5f4ad06f5c712c418d4f /content/browser/loader/resource_loader.cc
parent352fa30b2d8de684b4c09f97018b0c6144efaa56 (diff)
downloadchromium_src-54c1529f8d9906e174a4578a5dbdef30b23d21d8.zip
chromium_src-54c1529f8d9906e174a4578a5dbdef30b23d21d8.tar.gz
chromium_src-54c1529f8d9906e174a4578a5dbdef30b23d21d8.tar.bz2
Allows prefetch and other detachable requests to live beyond the renderer by delaying LinkLoader::Cancel requests by a few seconds and through the use of a new DetachedResourceHandler.
The general concept of a detachable resource should be useful for <a ping> as well. BUG=286186 Review URL: https://codereview.chromium.org/25772002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231910 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/loader/resource_loader.cc')
-rw-r--r--content/browser/loader/resource_loader.cc27
1 files changed, 27 insertions, 0 deletions
diff --git a/content/browser/loader/resource_loader.cc b/content/browser/loader/resource_loader.cc
index 846ad31..a995259 100644
--- a/content/browser/loader/resource_loader.cc
+++ b/content/browser/loader/resource_loader.cc
@@ -7,7 +7,9 @@
#include "base/command_line.h"
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h"
+#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
+#include "base/timer/timer.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/loader/cross_site_resource_handler.h"
#include "content/browser/loader/resource_loader_delegate.h"
@@ -36,6 +38,13 @@ using base::TimeTicks;
namespace content {
namespace {
+// TODO(jkarlin): The value is high to reduce the chance of the detachable
+// request timing out, forcing a blocked second request to open a new connection
+// and start over. Reduce this value once we have a better idea of what it
+// should be and once we stop blocking multiple simultaneous requests for the
+// same resource (see bugs 46104 and 31014).
+const int kDefaultDetachableDelayOnCancelMs = 30000;
+
void PopulateResourceResponse(net::URLRequest* request,
ResourceResponse* response) {
response->head.error_code = request->status().error();
@@ -74,6 +83,7 @@ ResourceLoader::ResourceLoader(scoped_ptr<net::URLRequest> request,
last_upload_position_(0),
waiting_for_upload_progress_ack_(false),
is_transferring_(false),
+ detachable_delay_on_cancel_ms_(kDefaultDetachableDelayOnCancelMs),
weak_ptr_factory_(this) {
request_->set_delegate(this);
handler_->SetController(this);
@@ -429,6 +439,18 @@ void ResourceLoader::StartRequestInternal() {
delegate_->DidStartRequest(this);
}
+void ResourceLoader::Detach() {
+ ResourceRequestInfoImpl* info = GetRequestInfo();
+
+ if (info->is_detached())
+ return;
+ info->set_detached();
+ detached_timer_.reset(new base::OneShotTimer<ResourceLoader>());
+ detached_timer_->Start(
+ FROM_HERE, TimeDelta::FromMilliseconds(detachable_delay_on_cancel_ms_),
+ this, &ResourceLoader::Cancel);
+}
+
void ResourceLoader::CancelRequestInternal(int error, bool from_renderer) {
VLOG(1) << "CancelRequestInternal: " << request_->url().spec();
@@ -440,6 +462,11 @@ void ResourceLoader::CancelRequestInternal(int error, bool from_renderer) {
if (from_renderer && (info->is_download() || info->is_stream()))
return;
+ if (from_renderer && info->is_detachable()) {
+ Detach();
+ return;
+ }
+
// TODO(darin): Perhaps we should really be looking to see if the status is
// IO_PENDING?
bool was_pending = request_->is_pending();