Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: chrome/browser/prerender/prerender_resource_throttle.cc

Issue 2287993003: [NoStatePrefetch] Add UMA histogram to count prefetch requests (Closed)
Patch Set: histograms.xml Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/prerender/prerender_resource_throttle.h" 5 #include "chrome/browser/prerender/prerender_resource_throttle.h"
6 6
7 #include "base/metrics/histogram_macros.h"
7 #include "build/build_config.h" 8 #include "build/build_config.h"
8 #include "chrome/browser/prerender/prerender_final_status.h" 9 #include "chrome/browser/prerender/prerender_final_status.h"
9 #include "chrome/browser/prerender/prerender_manager.h" 10 #include "chrome/browser/prerender/prerender_manager.h"
10 #include "chrome/browser/prerender/prerender_util.h" 11 #include "chrome/browser/prerender/prerender_util.h"
11 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/render_frame_host.h" 13 #include "content/public/browser/render_frame_host.h"
13 #include "content/public/browser/resource_controller.h" 14 #include "content/public/browser/resource_controller.h"
14 #include "content/public/browser/resource_request_info.h" 15 #include "content/public/browser/resource_request_info.h"
15 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 #include "net/http/http_response_headers.h"
16 #include "net/url_request/redirect_info.h" 18 #include "net/url_request/redirect_info.h"
17 #include "net/url_request/url_request.h" 19 #include "net/url_request/url_request.h"
18 20
19 using content::ResourceType; 21 using content::ResourceType;
20 22
21 namespace prerender { 23 namespace prerender {
22 24
23 namespace { 25 namespace {
26
27 // This enum is used to define the buckets for an enumerated UMA histogram.
28 // Hence, existing enumerated constants should never be deleted or reordered,
29 // and new constants should only be appended at the end of the enumeration.
30 enum NoStatePrefetchResourceType {
pasko 2016/08/30 09:43:33 nit: enum class is shiny and modern
31 kMainResourceCacheable = 0,
32 kMainResourceNoStore = 1,
33 kSubResourceCacheable = 2,
34 kSubResourceNoStore = 3,
35
36 kNoStatePrefetchResourceTypeCount // Must be the last.
37 };
38
24 static const char kFollowOnlyWhenPrerenderShown[] = 39 static const char kFollowOnlyWhenPrerenderShown[] =
25 "follow-only-when-prerender-shown"; 40 "follow-only-when-prerender-shown";
26 41
27 PrerenderContents* g_prerender_contents_for_testing; 42 PrerenderContents* g_prerender_contents_for_testing;
28 } 43
44 } // namespace
29 45
30 void PrerenderResourceThrottle::OverridePrerenderContentsForTesting( 46 void PrerenderResourceThrottle::OverridePrerenderContentsForTesting(
31 PrerenderContents* contents) { 47 PrerenderContents* contents) {
32 g_prerender_contents_for_testing = contents; 48 g_prerender_contents_for_testing = contents;
33 } 49 }
34 50
35 PrerenderResourceThrottle::PrerenderResourceThrottle(net::URLRequest* request) 51 PrerenderResourceThrottle::PrerenderResourceThrottle(net::URLRequest* request)
36 : request_(request) { 52 : request_(request) {
37 } 53 }
38 54
(...skipping 21 matching lines...) Expand all
60 76
61 content::BrowserThread::PostTask( 77 content::BrowserThread::PostTask(
62 content::BrowserThread::UI, 78 content::BrowserThread::UI,
63 FROM_HERE, 79 FROM_HERE,
64 base::Bind(&PrerenderResourceThrottle::WillRedirectRequestOnUI, 80 base::Bind(&PrerenderResourceThrottle::WillRedirectRequestOnUI,
65 AsWeakPtr(), header, info->GetResourceType(), info->IsAsync(), 81 AsWeakPtr(), header, info->GetResourceType(), info->IsAsync(),
66 info->GetChildID(), info->GetRenderFrameID(), 82 info->GetChildID(), info->GetRenderFrameID(),
67 redirect_info.new_url)); 83 redirect_info.new_url));
68 } 84 }
69 85
86 void PrerenderResourceThrottle::WillProcessResponse(bool* defer) {
87 *defer = false;
88
89 const content::ResourceRequestInfo* info =
90 content::ResourceRequestInfo::ForRequest(request_);
91 if (!info)
92 return;
93
94 bool is_no_store = false;
95 const net::HttpResponseInfo& response_info = request_->response_info();
96 if (response_info.headers.get()) {
97 is_no_store =
98 response_info.headers->HasHeaderValue("cache-control", "no-store");
99 }
100
101 content::BrowserThread::PostTask(
102 content::BrowserThread::UI, FROM_HERE,
103 base::Bind(&PrerenderResourceThrottle::UpdatePrefetchHistogramOnUI,
104 content::IsResourceTypeFrame(info->GetResourceType()),
pasko 2016/08/30 09:43:33 will main resource redirects be recorded as sub-re
105 is_no_store, info->GetChildID(), info->GetRenderFrameID()));
106 }
107
70 const char* PrerenderResourceThrottle::GetNameForLogging() const { 108 const char* PrerenderResourceThrottle::GetNameForLogging() const {
71 return "PrerenderResourceThrottle"; 109 return "PrerenderResourceThrottle";
72 } 110 }
73 111
74 void PrerenderResourceThrottle::Resume() { 112 void PrerenderResourceThrottle::Resume() {
75 controller()->Resume(); 113 controller()->Resume();
76 } 114 }
77 115
78 void PrerenderResourceThrottle::Cancel() { 116 void PrerenderResourceThrottle::Cancel() {
79 controller()->Cancel(); 117 controller()->Cancel();
80 } 118 }
81 119
120 // static
82 void PrerenderResourceThrottle::WillStartRequestOnUI( 121 void PrerenderResourceThrottle::WillStartRequestOnUI(
83 const base::WeakPtr<PrerenderResourceThrottle>& throttle, 122 const base::WeakPtr<PrerenderResourceThrottle>& throttle,
84 const std::string& method, 123 const std::string& method,
85 ResourceType resource_type, 124 ResourceType resource_type,
86 int render_process_id, 125 int render_process_id,
87 int render_frame_id, 126 int render_frame_id,
88 const GURL& url) { 127 const GURL& url) {
89 bool cancel = false; 128 bool cancel = false;
90 PrerenderContents* prerender_contents = 129 PrerenderContents* prerender_contents =
91 PrerenderContentsFromRenderFrame(render_process_id, render_frame_id); 130 PrerenderContentsFromRenderFrame(render_process_id, render_frame_id);
(...skipping 17 matching lines...) Expand all
109 } 148 }
110 } 149 }
111 150
112 content::BrowserThread::PostTask( 151 content::BrowserThread::PostTask(
113 content::BrowserThread::IO, 152 content::BrowserThread::IO,
114 FROM_HERE, 153 FROM_HERE,
115 base::Bind(cancel ? &PrerenderResourceThrottle::Cancel : 154 base::Bind(cancel ? &PrerenderResourceThrottle::Cancel :
116 &PrerenderResourceThrottle::Resume, throttle)); 155 &PrerenderResourceThrottle::Resume, throttle));
117 } 156 }
118 157
158 // static
119 void PrerenderResourceThrottle::WillRedirectRequestOnUI( 159 void PrerenderResourceThrottle::WillRedirectRequestOnUI(
120 const base::WeakPtr<PrerenderResourceThrottle>& throttle, 160 const base::WeakPtr<PrerenderResourceThrottle>& throttle,
121 const std::string& follow_only_when_prerender_shown_header, 161 const std::string& follow_only_when_prerender_shown_header,
122 ResourceType resource_type, 162 ResourceType resource_type,
123 bool async, 163 bool async,
124 int render_process_id, 164 int render_process_id,
125 int render_frame_id, 165 int render_frame_id,
126 const GURL& new_url) { 166 const GURL& new_url) {
127 bool cancel = false; 167 bool cancel = false;
128 PrerenderContents* prerender_contents = 168 PrerenderContents* prerender_contents =
(...skipping 21 matching lines...) Expand all
150 } 190 }
151 } 191 }
152 192
153 content::BrowserThread::PostTask( 193 content::BrowserThread::PostTask(
154 content::BrowserThread::IO, 194 content::BrowserThread::IO,
155 FROM_HERE, 195 FROM_HERE,
156 base::Bind(cancel ? &PrerenderResourceThrottle::Cancel : 196 base::Bind(cancel ? &PrerenderResourceThrottle::Cancel :
157 &PrerenderResourceThrottle::Resume, throttle)); 197 &PrerenderResourceThrottle::Resume, throttle));
158 } 198 }
159 199
200 // static
201 void PrerenderResourceThrottle::UpdatePrefetchHistogramOnUI(
202 bool is_main_resource,
203 bool is_no_store,
204 int render_process_id,
205 int render_frame_id) {
206 PrerenderContents* prerender_contents =
207 PrerenderContentsFromRenderFrame(render_process_id, render_frame_id);
208 if (!prerender_contents)
209 return;
210
211 if (prerender_contents->prerender_mode() != PREFETCH_ONLY)
212 return;
213
214 NoStatePrefetchResourceType type =
215 is_main_resource
216 ? (is_no_store ? kMainResourceNoStore : kMainResourceCacheable)
217 : (is_no_store ? kSubResourceNoStore : kSubResourceCacheable);
218 UMA_HISTOGRAM_ENUMERATION("Prerender.NoStatePrefetchResourceCount", type,
219 kNoStatePrefetchResourceTypeCount);
220 }
221
222 // static
160 PrerenderContents* PrerenderResourceThrottle::PrerenderContentsFromRenderFrame( 223 PrerenderContents* PrerenderResourceThrottle::PrerenderContentsFromRenderFrame(
161 int render_process_id, int render_frame_id) { 224 int render_process_id, int render_frame_id) {
162 if (g_prerender_contents_for_testing) 225 if (g_prerender_contents_for_testing)
163 return g_prerender_contents_for_testing; 226 return g_prerender_contents_for_testing;
164 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID( 227 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID(
165 render_process_id, render_frame_id); 228 render_process_id, render_frame_id);
166 content::WebContents* web_contents = 229 content::WebContents* web_contents =
167 content::WebContents::FromRenderFrameHost(rfh); 230 content::WebContents::FromRenderFrameHost(rfh);
168 return PrerenderContents::FromWebContents(web_contents); 231 return PrerenderContents::FromWebContents(web_contents);
169 } 232 }
170 233
171 } // namespace prerender 234 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698