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..a0594d42b428f6d7c3829bdbafdc7cf3a22ec9dd 100644 |
| --- a/chrome/browser/prerender/prerender_resource_throttle.cc |
| +++ b/chrome/browser/prerender/prerender_resource_throttle.cc |
| @@ -4,6 +4,7 @@ |
| #include "chrome/browser/prerender/prerender_resource_throttle.h" |
| +#include "base/metrics/histogram_macros.h" |
| #include "build/build_config.h" |
| #include "chrome/browser/prerender/prerender_final_status.h" |
| #include "chrome/browser/prerender/prerender_manager.h" |
| @@ -13,6 +14,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" |
| @@ -21,11 +23,25 @@ using content::ResourceType; |
| namespace prerender { |
| namespace { |
| + |
| +// This enum is used to define the buckets for an enumerated UMA histogram. |
| +// Hence, existing enumerated constants should never be deleted or reordered, |
| +// and new constants should only be appended at the end of the enumeration. |
| +enum NoStatePrefetchResourceType { |
|
pasko
2016/08/30 09:43:33
nit: enum class is shiny and modern
|
| + kMainResourceCacheable = 0, |
| + kMainResourceNoStore = 1, |
| + kSubResourceCacheable = 2, |
| + kSubResourceNoStore = 3, |
| + |
| + kNoStatePrefetchResourceTypeCount // Must be the last. |
| +}; |
| + |
| static const char kFollowOnlyWhenPrerenderShown[] = |
| "follow-only-when-prerender-shown"; |
| PrerenderContents* g_prerender_contents_for_testing; |
| -} |
| + |
| +} // namespace |
| void PrerenderResourceThrottle::OverridePrerenderContentsForTesting( |
| PrerenderContents* contents) { |
| @@ -67,6 +83,28 @@ void PrerenderResourceThrottle::WillRedirectRequest( |
| redirect_info.new_url)); |
| } |
| +void PrerenderResourceThrottle::WillProcessResponse(bool* defer) { |
| + *defer = false; |
| + |
| + 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::UpdatePrefetchHistogramOnUI, |
| + content::IsResourceTypeFrame(info->GetResourceType()), |
|
pasko
2016/08/30 09:43:33
will main resource redirects be recorded as sub-re
|
| + is_no_store, info->GetChildID(), info->GetRenderFrameID())); |
| +} |
| + |
| const char* PrerenderResourceThrottle::GetNameForLogging() const { |
| return "PrerenderResourceThrottle"; |
| } |
| @@ -79,6 +117,7 @@ void PrerenderResourceThrottle::Cancel() { |
| controller()->Cancel(); |
| } |
| +// static |
| void PrerenderResourceThrottle::WillStartRequestOnUI( |
| const base::WeakPtr<PrerenderResourceThrottle>& throttle, |
| const std::string& method, |
| @@ -116,6 +155,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 +197,29 @@ void PrerenderResourceThrottle::WillRedirectRequestOnUI( |
| &PrerenderResourceThrottle::Resume, throttle)); |
| } |
| +// static |
| +void PrerenderResourceThrottle::UpdatePrefetchHistogramOnUI( |
| + bool is_main_resource, |
| + bool is_no_store, |
| + int render_process_id, |
| + int render_frame_id) { |
| + PrerenderContents* prerender_contents = |
| + PrerenderContentsFromRenderFrame(render_process_id, render_frame_id); |
| + if (!prerender_contents) |
| + return; |
| + |
| + if (prerender_contents->prerender_mode() != PREFETCH_ONLY) |
| + return; |
| + |
| + NoStatePrefetchResourceType type = |
| + is_main_resource |
| + ? (is_no_store ? kMainResourceNoStore : kMainResourceCacheable) |
| + : (is_no_store ? kSubResourceNoStore : kSubResourceCacheable); |
| + UMA_HISTOGRAM_ENUMERATION("Prerender.NoStatePrefetchResourceCount", type, |
| + kNoStatePrefetchResourceTypeCount); |
| +} |
| + |
| +// static |
| PrerenderContents* PrerenderResourceThrottle::PrerenderContentsFromRenderFrame( |
| int render_process_id, int render_frame_id) { |
| if (g_prerender_contents_for_testing) |