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

Unified 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: Rebase. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/loader/resource_loader.h ('k') | content/browser/loader/resource_request_info_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/loader/resource_loader.cc
diff --git a/content/browser/loader/resource_loader.cc b/content/browser/loader/resource_loader.cc
index 846ad31521d1a3e0af1aa4b899b0a5cefc6a8f4f..a9952599c2aab194134aacb92aae45017e1f2757 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();
« no previous file with comments | « content/browser/loader/resource_loader.h ('k') | content/browser/loader/resource_request_info_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698