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..89668163038c4d37d26cea3b77d5b4eaf08e3057 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,6 +86,7 @@ void PrerenderResourceThrottle::OverridePrerenderContentsForTesting( |
PrerenderResourceThrottle::PrerenderResourceThrottle(net::URLRequest* request) |
: request_(request), |
load_flags_(net::LOAD_NORMAL), |
+ original_request_priority_(net::IDLE), |
prerender_throttle_info_(new PrerenderThrottleInfo()) {} |
PrerenderResourceThrottle::~PrerenderResourceThrottle() {} |
@@ -94,6 +96,25 @@ void PrerenderResourceThrottle::WillStartRequest(bool* defer) { |
const content::ResourceRequestInfo* info = |
content::ResourceRequestInfo::ForRequest(request_); |
*defer = true; |
+ |
+// 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); |
+ // original_request_priority_ can be kept to IDLE, so that the priority will |
+ // never be touched again. |
+ } else if (request_->priority() != net::IDLE) { |
+ original_request_priority_ = request_->priority(); |
+ content::ResourceDispatcherHost::Get()->ReprioritizeRequest(request_, |
+ net::IDLE); |
+ } |
+#endif // OS_ANDROID |
+ |
BrowserThread::PostTask( |
BrowserThread::UI, FROM_HERE, |
base::Bind(&PrerenderResourceThrottle::WillStartRequestOnUI, AsWeakPtr(), |
@@ -149,6 +170,17 @@ void PrerenderResourceThrottle::ResumeHandler() { |
Resume(); |
} |
+void PrerenderResourceThrottle::ResetResourcePriority() { |
+ if (original_request_priority_ == net::IDLE) { |
+ // IDLE means that the original request was either IDLE or must not be |
+ // changed. |
Charlie Harrison
2017/04/12 12:37:26
You could use a base::Optional to make this distin
droger
2017/04/12 13:20:54
Done.
|
+ return; |
+ } |
+ |
+ content::ResourceDispatcherHost::Get()->ReprioritizeRequest( |
+ request_, original_request_priority_); |
+} |
+ |
// static |
void PrerenderResourceThrottle::WillStartRequestOnUI( |
const base::WeakPtr<PrerenderResourceThrottle>& throttle, |
@@ -202,9 +234,15 @@ void PrerenderResourceThrottle::WillStartRequestOnUI( |
// Delay icon fetching until the contents are getting swapped in |
// to conserve network usage in mobile devices. |
prerender_contents->AddResourceThrottle(throttle); |
Charlie Harrison
2017/04/12 12:37:26
nit: newline below
droger
2017/04/12 13:20:54
Done.
|
+ // No need to add to call AddIdleResource() on Android. |
return; |
#endif |
} |
+ |
+#if !defined(OS_ANDROID) |
+ if (!cancel) |
+ prerender_contents->AddIdleResource(throttle); |
+#endif |
} |
BrowserThread::PostTask( |