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

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

Issue 2287993003: [NoStatePrefetch] Add UMA histogram to count prefetch requests (Closed)
Patch Set: comment 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 "build/build_config.h" 7 #include "build/build_config.h"
8 #include "chrome/browser/prerender/prerender_final_status.h" 8 #include "chrome/browser/prerender/prerender_final_status.h"
9 #include "chrome/browser/prerender/prerender_manager.h" 9 #include "chrome/browser/prerender/prerender_manager.h"
10 #include "chrome/browser/prerender/prerender_util.h" 10 #include "chrome/browser/prerender/prerender_util.h"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/render_frame_host.h" 12 #include "content/public/browser/render_frame_host.h"
13 #include "content/public/browser/resource_controller.h" 13 #include "content/public/browser/resource_controller.h"
14 #include "content/public/browser/resource_request_info.h" 14 #include "content/public/browser/resource_request_info.h"
15 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
16 #include "net/http/http_response_headers.h"
16 #include "net/url_request/redirect_info.h" 17 #include "net/url_request/redirect_info.h"
17 #include "net/url_request/url_request.h" 18 #include "net/url_request/url_request.h"
18 19
19 using content::ResourceType; 20 using content::ResourceType;
20 21
21 namespace prerender { 22 namespace prerender {
22 23
23 namespace { 24 namespace {
24 static const char kFollowOnlyWhenPrerenderShown[] = 25 static const char kFollowOnlyWhenPrerenderShown[] =
25 "follow-only-when-prerender-shown"; 26 "follow-only-when-prerender-shown";
26 27
27 PrerenderContents* g_prerender_contents_for_testing; 28 PrerenderContents* g_prerender_contents_for_testing;
28 } 29 } // namespace
29 30
30 void PrerenderResourceThrottle::OverridePrerenderContentsForTesting( 31 void PrerenderResourceThrottle::OverridePrerenderContentsForTesting(
31 PrerenderContents* contents) { 32 PrerenderContents* contents) {
32 g_prerender_contents_for_testing = contents; 33 g_prerender_contents_for_testing = contents;
33 } 34 }
34 35
35 PrerenderResourceThrottle::PrerenderResourceThrottle(net::URLRequest* request) 36 PrerenderResourceThrottle::PrerenderResourceThrottle(net::URLRequest* request)
36 : request_(request) { 37 : request_(request) {
37 } 38 }
38 39
(...skipping 21 matching lines...) Expand all
60 61
61 content::BrowserThread::PostTask( 62 content::BrowserThread::PostTask(
62 content::BrowserThread::UI, 63 content::BrowserThread::UI,
63 FROM_HERE, 64 FROM_HERE,
64 base::Bind(&PrerenderResourceThrottle::WillRedirectRequestOnUI, 65 base::Bind(&PrerenderResourceThrottle::WillRedirectRequestOnUI,
65 AsWeakPtr(), header, info->GetResourceType(), info->IsAsync(), 66 AsWeakPtr(), header, info->GetResourceType(), info->IsAsync(),
66 info->GetChildID(), info->GetRenderFrameID(), 67 info->GetChildID(), info->GetRenderFrameID(),
67 redirect_info.new_url)); 68 redirect_info.new_url));
68 } 69 }
69 70
71 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
72 *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
73
74 const content::ResourceRequestInfo* info =
75 content::ResourceRequestInfo::ForRequest(request_);
76 if (!info)
77 return;
78
79 bool is_no_store = false;
80 const net::HttpResponseInfo& response_info = request_->response_info();
81 if (response_info.headers.get()) {
82 is_no_store =
83 response_info.headers->HasHeaderValue("cache-control", "no-store");
84 }
85
86 content::BrowserThread::PostTask(
87 content::BrowserThread::UI, FROM_HERE,
88 base::Bind(&PrerenderResourceThrottle::WillProcessResponseOnUI,
89 content::IsResourceTypeFrame(info->GetResourceType()),
90 is_no_store, info->GetChildID(), info->GetRenderFrameID()));
91 }
92
70 const char* PrerenderResourceThrottle::GetNameForLogging() const { 93 const char* PrerenderResourceThrottle::GetNameForLogging() const {
71 return "PrerenderResourceThrottle"; 94 return "PrerenderResourceThrottle";
72 } 95 }
73 96
74 void PrerenderResourceThrottle::Resume() { 97 void PrerenderResourceThrottle::Resume() {
75 controller()->Resume(); 98 controller()->Resume();
76 } 99 }
77 100
78 void PrerenderResourceThrottle::Cancel() { 101 void PrerenderResourceThrottle::Cancel() {
79 controller()->Cancel(); 102 controller()->Cancel();
80 } 103 }
81 104
105 // static
82 void PrerenderResourceThrottle::WillStartRequestOnUI( 106 void PrerenderResourceThrottle::WillStartRequestOnUI(
83 const base::WeakPtr<PrerenderResourceThrottle>& throttle, 107 const base::WeakPtr<PrerenderResourceThrottle>& throttle,
84 const std::string& method, 108 const std::string& method,
85 ResourceType resource_type, 109 ResourceType resource_type,
86 int render_process_id, 110 int render_process_id,
87 int render_frame_id, 111 int render_frame_id,
88 const GURL& url) { 112 const GURL& url) {
89 bool cancel = false; 113 bool cancel = false;
90 PrerenderContents* prerender_contents = 114 PrerenderContents* prerender_contents =
91 PrerenderContentsFromRenderFrame(render_process_id, render_frame_id); 115 PrerenderContentsFromRenderFrame(render_process_id, render_frame_id);
(...skipping 17 matching lines...) Expand all
109 } 133 }
110 } 134 }
111 135
112 content::BrowserThread::PostTask( 136 content::BrowserThread::PostTask(
113 content::BrowserThread::IO, 137 content::BrowserThread::IO,
114 FROM_HERE, 138 FROM_HERE,
115 base::Bind(cancel ? &PrerenderResourceThrottle::Cancel : 139 base::Bind(cancel ? &PrerenderResourceThrottle::Cancel :
116 &PrerenderResourceThrottle::Resume, throttle)); 140 &PrerenderResourceThrottle::Resume, throttle));
117 } 141 }
118 142
143 // static
119 void PrerenderResourceThrottle::WillRedirectRequestOnUI( 144 void PrerenderResourceThrottle::WillRedirectRequestOnUI(
120 const base::WeakPtr<PrerenderResourceThrottle>& throttle, 145 const base::WeakPtr<PrerenderResourceThrottle>& throttle,
121 const std::string& follow_only_when_prerender_shown_header, 146 const std::string& follow_only_when_prerender_shown_header,
122 ResourceType resource_type, 147 ResourceType resource_type,
123 bool async, 148 bool async,
124 int render_process_id, 149 int render_process_id,
125 int render_frame_id, 150 int render_frame_id,
126 const GURL& new_url) { 151 const GURL& new_url) {
127 bool cancel = false; 152 bool cancel = false;
128 PrerenderContents* prerender_contents = 153 PrerenderContents* prerender_contents =
(...skipping 21 matching lines...) Expand all
150 } 175 }
151 } 176 }
152 177
153 content::BrowserThread::PostTask( 178 content::BrowserThread::PostTask(
154 content::BrowserThread::IO, 179 content::BrowserThread::IO,
155 FROM_HERE, 180 FROM_HERE,
156 base::Bind(cancel ? &PrerenderResourceThrottle::Cancel : 181 base::Bind(cancel ? &PrerenderResourceThrottle::Cancel :
157 &PrerenderResourceThrottle::Resume, throttle)); 182 &PrerenderResourceThrottle::Resume, throttle));
158 } 183 }
159 184
185 // static
186 void PrerenderResourceThrottle::WillProcessResponseOnUI(bool is_main_resource,
187 bool is_no_store,
188 int render_process_id,
189 int render_frame_id) {
190 PrerenderContents* prerender_contents =
pasko 2016/08/30 13:41:05 nit: DCHECK_CURRENTLY_ON
191 PrerenderContentsFromRenderFrame(render_process_id, render_frame_id);
192 if (!prerender_contents)
193 return;
194
195 if (prerender_contents->prerender_mode() != PREFETCH_ONLY)
196 return;
197
198 prerender_contents->prerender_manager()->RecordResourcePrefetch(
199 prerender_contents->origin(), is_main_resource, is_no_store);
200 }
201
202 // static
160 PrerenderContents* PrerenderResourceThrottle::PrerenderContentsFromRenderFrame( 203 PrerenderContents* PrerenderResourceThrottle::PrerenderContentsFromRenderFrame(
161 int render_process_id, int render_frame_id) { 204 int render_process_id, int render_frame_id) {
162 if (g_prerender_contents_for_testing) 205 if (g_prerender_contents_for_testing)
163 return g_prerender_contents_for_testing; 206 return g_prerender_contents_for_testing;
164 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID( 207 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID(
165 render_process_id, render_frame_id); 208 render_process_id, render_frame_id);
166 content::WebContents* web_contents = 209 content::WebContents* web_contents =
167 content::WebContents::FromRenderFrameHost(rfh); 210 content::WebContents::FromRenderFrameHost(rfh);
168 return PrerenderContents::FromWebContents(web_contents); 211 return PrerenderContents::FromWebContents(web_contents);
169 } 212 }
170 213
171 } // namespace prerender 214 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698