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..038bbfa469dec7f542b2eb799a617a6855ccec51 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; |
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
|
+ |
ResourceLoader::ResourceLoader(scoped_ptr<net::URLRequest> request, |
scoped_ptr<ResourceHandler> handler, |
ResourceLoaderDelegate* delegate) |
@@ -458,6 +464,32 @@ void ResourceLoader::StartRequestInternal() { |
delegate_->DidStartRequest(this); |
} |
+bool ResourceLoader::DelayCancelForDetachable( |
+ 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
|
+ 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. An example detachable resource is a prefetch. |
+ if (from_renderer && !detached_timer_ && info.is_detachable() && |
+ command_line.HasSwitch(switches::kDelayDetachableCancellation)) { |
+ // 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 +501,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(); |