Chromium Code Reviews| 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 a23b5a9336e5327187b117b1c04e2ecb1fab6804..3feefa422af01bf6a7838255fc5b23e3909ae857 100644 |
| --- a/chrome/browser/prerender/prerender_resource_throttle.cc |
| +++ b/chrome/browser/prerender/prerender_resource_throttle.cc |
| @@ -13,6 +13,7 @@ |
| #include "content/public/browser/resource_controller.h" |
| #include "content/public/browser/resource_request_info.h" |
| #include "content/public/browser/web_contents.h" |
| +#include "net/http/http_response_headers.h" |
| #include "net/url_request/redirect_info.h" |
| #include "net/url_request/url_request.h" |
| @@ -25,7 +26,7 @@ static const char kFollowOnlyWhenPrerenderShown[] = |
| "follow-only-when-prerender-shown"; |
| PrerenderContents* g_prerender_contents_for_testing; |
| -} |
| +} // namespace |
| void PrerenderResourceThrottle::OverridePrerenderContentsForTesting( |
| PrerenderContents* contents) { |
| @@ -67,6 +68,28 @@ void PrerenderResourceThrottle::WillRedirectRequest( |
| redirect_info.new_url)); |
| } |
| +void PrerenderResourceThrottle::WillProcessResponse(bool* defer) { |
|
pasko
2016/08/30 13:41:04
is it possible to detect redirects on the path to
droger
2016/08/30 14:31:41
Good idea.
We can detect redirects easily, and re
|
| + *defer = false; |
|
pasko
2016/08/30 13:41:04
I am not familiar with resource throttle API, of c
droger
2016/08/30 14:31:41
Done.
I wondered about this, and both cases defin
|
| + |
| + const content::ResourceRequestInfo* info = |
| + content::ResourceRequestInfo::ForRequest(request_); |
| + if (!info) |
| + return; |
| + |
| + bool is_no_store = false; |
| + const net::HttpResponseInfo& response_info = request_->response_info(); |
| + if (response_info.headers.get()) { |
| + is_no_store = |
| + response_info.headers->HasHeaderValue("cache-control", "no-store"); |
| + } |
| + |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::UI, FROM_HERE, |
| + base::Bind(&PrerenderResourceThrottle::WillProcessResponseOnUI, |
| + content::IsResourceTypeFrame(info->GetResourceType()), |
| + is_no_store, info->GetChildID(), info->GetRenderFrameID())); |
| +} |
| + |
| const char* PrerenderResourceThrottle::GetNameForLogging() const { |
| return "PrerenderResourceThrottle"; |
| } |
| @@ -79,6 +102,7 @@ void PrerenderResourceThrottle::Cancel() { |
| controller()->Cancel(); |
| } |
| +// static |
| void PrerenderResourceThrottle::WillStartRequestOnUI( |
| const base::WeakPtr<PrerenderResourceThrottle>& throttle, |
| const std::string& method, |
| @@ -116,6 +140,7 @@ void PrerenderResourceThrottle::WillStartRequestOnUI( |
| &PrerenderResourceThrottle::Resume, throttle)); |
| } |
| +// static |
| void PrerenderResourceThrottle::WillRedirectRequestOnUI( |
| const base::WeakPtr<PrerenderResourceThrottle>& throttle, |
| const std::string& follow_only_when_prerender_shown_header, |
| @@ -157,6 +182,24 @@ void PrerenderResourceThrottle::WillRedirectRequestOnUI( |
| &PrerenderResourceThrottle::Resume, throttle)); |
| } |
| +// static |
| +void PrerenderResourceThrottle::WillProcessResponseOnUI(bool is_main_resource, |
| + bool is_no_store, |
| + int render_process_id, |
| + int render_frame_id) { |
| + PrerenderContents* prerender_contents = |
|
pasko
2016/08/30 13:41:05
nit: DCHECK_CURRENTLY_ON
|
| + PrerenderContentsFromRenderFrame(render_process_id, render_frame_id); |
| + if (!prerender_contents) |
| + return; |
| + |
| + if (prerender_contents->prerender_mode() != PREFETCH_ONLY) |
| + return; |
| + |
| + prerender_contents->prerender_manager()->RecordResourcePrefetch( |
| + prerender_contents->origin(), is_main_resource, is_no_store); |
| +} |
| + |
| +// static |
| PrerenderContents* PrerenderResourceThrottle::PrerenderContentsFromRenderFrame( |
| int render_process_id, int render_frame_id) { |
| if (g_prerender_contents_for_testing) |