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

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: Asanka fixes. Made more general for future <a ping> support. 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
Index: content/browser/loader/resource_loader.cc
diff --git a/content/browser/loader/resource_loader.cc b/content/browser/loader/resource_loader.cc
index 88c9c857d55e21cb6b8017de3f08821b32cf8964..c17f6e228f2f02dc1154b7b0552788ea08995197 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"
@@ -64,6 +66,10 @@ void PopulateResourceResponse(net::URLRequest* request,
} // namespace
+// The time in ms to delay a cancel of a detachable resource unless otherwise
+// specified by a flag.
+static const int kDefaultDelayDetachableCancelMs = 60000;
+
ResourceLoader::ResourceLoader(scoped_ptr<net::URLRequest> request,
scoped_ptr<ResourceHandler> handler,
ResourceLoaderDelegate* delegate)
@@ -458,6 +464,33 @@ void ResourceLoader::StartRequestInternal() {
delegate_->DidStartRequest(this);
}
+bool ResourceLoader::DelayCancelForDetachable(
+ const ResourceRequestInfoImpl& info, bool from_renderer) {
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ // Delay requests to cancel detachable resources. Detachable resources are
+ // those that may need to live beyond the lifetime of their renderers, but
+ // should not be allowed to continue indefinitely as the user cannot control
+ // them through the UI. Examples of detachable resources include prefetches
+ // and <a ping>.
+ if (from_renderer && !detached_timer_ && info.is_detachable() &&
+ command_line.HasSwitch(switches::kDelayDetachableCancellation)) {
asanka 2013/10/14 21:06:49 Is it possible to get two cancels from the rendere
+ // Start the delay timer.
+ detached_timer_.reset(new base::OneShotTimer<ResourceLoader>());
+
+ int delay_ms;
+ if (!base::StringToInt(command_line.GetSwitchValueASCII(
+ switches::kDelayDetachableCancellation),
+ &delay_ms)) {
+ delay_ms = kDefaultDelayDetachableCancelMs;
+ }
+
+ detached_timer_->Start(FROM_HERE, TimeDelta::FromMilliseconds(delay_ms),
+ this, &ResourceLoader::Cancel);
+ return true;
+ }
+ return false;
+}
+
void ResourceLoader::CancelRequestInternal(int error, bool from_renderer) {
VLOG(1) << "CancelRequestInternal: " << request_->url().spec();
@@ -469,6 +502,10 @@ void ResourceLoader::CancelRequestInternal(int error, bool from_renderer) {
if (from_renderer && (info->is_download() || info->is_stream()))
return;
+ if (DelayCancelForDetachable(*info, from_renderer)) {
+ return;
+ }
+
// TODO(darin): Perhaps we should really be looking to see if the status is
// IO_PENDING?
bool was_pending = request_->is_pending();

Powered by Google App Engine
This is Rietveld 408576698