Index: chrome/browser/prerender/prerender_resource_throttle.cc |
diff --git a/chrome/browser/prerender/prerender_resource_throttle.cc b/chrome/browser/prerender/prerender_resource_throttle.cc |
index afd908fe6db2c2b387927c3fea5619109a906278..b6ed41fdabf0878b3bce20130d8cb5f42a0cec50 100644 |
--- a/chrome/browser/prerender/prerender_resource_throttle.cc |
+++ b/chrome/browser/prerender/prerender_resource_throttle.cc |
@@ -12,6 +12,7 @@ |
#include "chrome/browser/prerender/prerender_manager.h" |
#include "chrome/browser/prerender/prerender_util.h" |
#include "content/public/browser/browser_thread.h" |
+#include "content/public/browser/resource_dispatcher_host.h" |
#include "content/public/browser/web_contents.h" |
#include "net/base/load_flags.h" |
#include "net/http/http_response_headers.h" |
@@ -85,7 +86,29 @@ void PrerenderResourceThrottle::OverridePrerenderContentsForTesting( |
PrerenderResourceThrottle::PrerenderResourceThrottle(net::URLRequest* request) |
: request_(request), |
load_flags_(net::LOAD_NORMAL), |
- prerender_throttle_info_(new PrerenderThrottleInfo()) {} |
+ prerender_throttle_info_(new PrerenderThrottleInfo()) { |
+// Priorities for prerendering requests are lowered, to avoid competing with |
+// other page loads, except on Android where this is less likely to be a |
+// problem. In some cases, this may negatively impact the performance of |
+// prerendering, see https://crbug.com/652746 for details. |
+#if !defined(OS_ANDROID) |
+ // Requests with the IGNORE_LIMITS flag set (i.e., sync XHRs) |
+ // should remain at MAXIMUM_PRIORITY. |
+ if (request_->load_flags() & net::LOAD_IGNORE_LIMITS) { |
+ DCHECK_EQ(request_->priority(), net::MAXIMUM_PRIORITY); |
+ } else if (request_->priority() != net::IDLE) { |
+ original_request_priority_ = request_->priority(); |
+ // In practice, the resource scheduler does not know about the request yet, |
+ // and it falls back to calling request_->SetPriority(), so it would be |
+ // possible to do just that here. It is cleaner and more robust to go |
+ // through the resource dispatcher host though. |
+ if (content::ResourceDispatcherHost::Get()) { |
+ content::ResourceDispatcherHost::Get()->ReprioritizeRequest(request_, |
+ net::IDLE); |
+ } |
+ } |
+#endif // OS_ANDROID |
+} |
PrerenderResourceThrottle::~PrerenderResourceThrottle() {} |
@@ -94,6 +117,7 @@ void PrerenderResourceThrottle::WillStartRequest(bool* defer) { |
const content::ResourceRequestInfo* info = |
content::ResourceRequestInfo::ForRequest(request_); |
*defer = true; |
+ |
BrowserThread::PostTask( |
BrowserThread::UI, FROM_HERE, |
base::Bind(&PrerenderResourceThrottle::WillStartRequestOnUI, AsWeakPtr(), |
@@ -149,6 +173,16 @@ void PrerenderResourceThrottle::ResumeHandler() { |
Resume(); |
} |
+void PrerenderResourceThrottle::ResetResourcePriority() { |
+ if (!original_request_priority_) |
+ return; |
+ |
+ if (content::ResourceDispatcherHost::Get()) { |
+ content::ResourceDispatcherHost::Get()->ReprioritizeRequest( |
+ request_, original_request_priority_.value()); |
+ } |
+} |
+ |
// static |
void PrerenderResourceThrottle::WillStartRequestOnUI( |
const base::WeakPtr<PrerenderResourceThrottle>& throttle, |
@@ -202,9 +236,16 @@ void PrerenderResourceThrottle::WillStartRequestOnUI( |
// Delay icon fetching until the contents are getting swapped in |
// to conserve network usage in mobile devices. |
prerender_contents->AddResourceThrottle(throttle); |
+ |
+ // No need to call AddIdleResource() on Android. |
return; |
#endif |
} |
+ |
+#if !defined(OS_ANDROID) |
+ if (!cancel) |
+ prerender_contents->AddIdleResource(throttle); |
+#endif |
} |
BrowserThread::PostTask( |