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

Side by Side Diff: chrome/renderer/page_load_histograms.cc

Issue 125303002: Change the detection of preview request to via header. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/renderer/page_load_histograms.h" 5 #include "chrome/renderer/page_load_histograms.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 return static_cast<URLPattern::SchemeMasks>(0); 166 return static_cast<URLPattern::SchemeMasks>(0);
167 } 167 }
168 168
169 // Returns true if the data reduction proxy was used. Note, this function will 169 // Returns true if the data reduction proxy was used. Note, this function will
170 // produce a false positive if a page is fetched using SPDY and using a proxy, 170 // produce a false positive if a page is fetched using SPDY and using a proxy,
171 // and |kDatReductionProxyViaValue| is added to the Via header. 171 // and |kDatReductionProxyViaValue| is added to the Via header.
172 // TODO(bengr): Plumb the hostname of the proxy from |HttpNetworkTransaction| 172 // TODO(bengr): Plumb the hostname of the proxy from |HttpNetworkTransaction|
173 // and check if it matches |SPDY_PROXY_AUTH_ORIGIN|. 173 // and check if it matches |SPDY_PROXY_AUTH_ORIGIN|.
174 bool DataReductionProxyWasUsed(WebFrame* frame) { 174 bool DataReductionProxyWasUsed(WebFrame* frame) {
175 #if defined(SPDY_PROXY_AUTH_ORIGIN) 175 #if defined(SPDY_PROXY_AUTH_ORIGIN)
176 const char kDatReductionProxyViaValue[] = "1.1 Chrome Compression Proxy";
177 return ViaHeaderContains(frame, kDatReductionProxyViaValue);
178 #endif
179 return false;
180 }
181
182 // Helper function to check for string in 'via' header.
183 bool ViaHeaderContains(WebFrame* frame, const std::string& viaValue) {
jochen (gone - plz use gerrit) 2014/01/07 10:22:23 via_value
ksimbili 2014/01/08 01:11:38 Done.
176 const char kViaHeaderName[] = "Via"; 184 const char kViaHeaderName[] = "Via";
177 const char kDatReductionProxyViaValue[] = "1.1 Chrome Compression Proxy";
178 185
179 DocumentState* document_state = 186 DocumentState* document_state =
180 DocumentState::FromDataSource(frame->dataSource()); 187 DocumentState::FromDataSource(frame->dataSource());
181 if (!document_state->was_fetched_via_proxy()) 188 if (!document_state->was_fetched_via_proxy())
182 return false; 189 return false;
183 190
184 std::string via_header(base::UTF16ToUTF8( 191 std::string via_header(base::UTF16ToUTF8(
185 frame->dataSource()->response().httpHeaderField(kViaHeaderName))); 192 frame->dataSource()->response().httpHeaderField(kViaHeaderName)));
186 return via_header.find(kDatReductionProxyViaValue) != std::string::npos; 193 return via_header.find(viaValue) != std::string::npos;
bengr 2014/01/07 17:16:09 This is overly inclusive. E.g., if some other prox
ksimbili 2014/01/08 01:11:38 Done.
187 #endif
188 return false;
189 } 194 }
190 195
191 // Returns true if the provided URL is a referrer string that came from 196 // Returns true if the provided URL is a referrer string that came from
192 // a Google Web Search results page. This is a little non-deterministic 197 // a Google Web Search results page. This is a little non-deterministic
193 // because desktop and mobile websearch differ and sometimes just provide 198 // because desktop and mobile websearch differ and sometimes just provide
194 // http://www.google.com/ as the referrer. In the case of /url we can be sure 199 // http://www.google.com/ as the referrer. In the case of /url we can be sure
195 // that it came from websearch but we will be generous and allow for cases 200 // that it came from websearch but we will be generous and allow for cases
196 // where a non-Google URL was provided a bare Google URL as a referrer. 201 // where a non-Google URL was provided a bare Google URL as a referrer.
197 // The domain validation matches the code used by the prerenderer for similar 202 // The domain validation matches the code used by the prerenderer for similar
198 // purposes. 203 // purposes.
(...skipping 23 matching lines...) Expand all
222 return kNoExperiment; 227 return kNoExperiment;
223 228
224 int experiment_id; 229 int experiment_id;
225 if (!base::StringToInt(value, &experiment_id)) 230 if (!base::StringToInt(value, &experiment_id))
226 return kNoExperiment; 231 return kNoExperiment;
227 if (0 < experiment_id && experiment_id <= kMaxExperimentID) 232 if (0 < experiment_id && experiment_id <= kMaxExperimentID)
228 return experiment_id; 233 return experiment_id;
229 return kNoExperiment; 234 return kNoExperiment;
230 } 235 }
231 236
232 // Appends "cerivrj_*" and "gcjeid" query parameters from preview_url to url.
233 // Returns true if "cerivrj_*" query is found.
234 // This will be used only for search results URLs.
235 bool AppendPreviewQueryFromURL(const GURL& preview_url, GURL* url) {
236 bool preview_query_found = false;
237 for (net::QueryIterator it(preview_url); !it.IsAtEnd(); it.Advance()) {
238 const std::string param_name = it.GetKey();
239 bool is_preview = StartsWithASCII(param_name, "cerivrj_", true);
240 if (url && (is_preview || param_name == "gcjeid"))
241 net::AppendQueryParameter(*url, param_name, it.GetValue());
242 preview_query_found = preview_query_found || is_preview;
243 }
244 return preview_query_found;
245 }
246
247 // Returns true if the provided referrer URL is the preview URL of the current
248 // URL. Preview URL differs from original only with "cerivrj_*", "gcjeid" query
249 // parameters.
250 bool IsReferrerPreviewOfURL(const GURL& url,
251 const base::string16& referrer_str) {
252 GURL referrer(referrer_str);
253 if (referrer.is_valid()) {
254 GURL generated_preview_url(url);
255 // Now try to copy "cerivrj_*" and "gcjeid" paramters to url and check if
256 // they exactly match.
257 if (AppendPreviewQueryFromURL(referrer, &generated_preview_url))
258 return generated_preview_url == referrer;
259 }
260 return false;
261 }
262
263 // Returns preview state by looking at url and referer url. 237 // Returns preview state by looking at url and referer url.
264 void GetPreviewState(const GURL& url, 238 void GetPreviewState(WebFrame* frame,
265 const base::string16& referrer,
266 bool came_from_websearch, 239 bool came_from_websearch,
267 bool data_reduction_proxy_was_used, 240 bool data_reduction_proxy_was_used,
268 GwsPreviewState* preview_state, 241 GwsPreviewState* preview_state,
269 int* preview_experiment_id) { 242 int* preview_experiment_id) {
270 // Conditions for GWS preview are, 243 // Conditions for GWS preview are,
271 // 1. Data reduction proxy was used. 244 // 1. Data reduction proxy was used.
272 // 2. URL is loaded from web search. 245 // 2. URL is loaded from web search.
273 // If the URL contains "cerivrj_*' query parameter record under 246 // Based on via header PREVIEW/PREVIEW_WAS_SHOWN/PREVIEW_NOT_USED is
274 // "Preview". 247 // determined.
275 if (data_reduction_proxy_was_used) { 248 if (data_reduction_proxy_was_used) {
276 if (came_from_websearch) { 249 if (came_from_websearch) {
277 *preview_state = 250 *preview_state =
278 AppendPreviewQueryFromURL(url, NULL) ? PREVIEW : PREVIEW_NOT_USED; 251 ViaHeaderContains(frame, "promise-preview") ? PREVIEW :
bengr 2014/01/07 17:16:09 I would use annotations that are less likely to ap
ksimbili 2014/01/08 01:11:38 Via header was the way we(flywheel and promise tea
bengr 2014/01/09 17:32:46 I know. I just don't think you should use a header
279 } else if (IsReferrerPreviewOfURL(url, referrer)) { 252 PREVIEW_NOT_USED;
253 } else if (ViaHeaderContains(frame, "promise-original")) {
280 *preview_state = PREVIEW_WAS_SHOWN; 254 *preview_state = PREVIEW_WAS_SHOWN;
281 *preview_experiment_id = GetQueryStringBasedExperiment(GURL(referrer)); 255 *preview_experiment_id = GetQueryStringBasedExperiment(
256 GURL(frame->document().referrer()));
282 } 257 }
283 } 258 }
284 } 259 }
285 260
286 void DumpPerformanceTiming(const WebPerformance& performance, 261 void DumpPerformanceTiming(const WebPerformance& performance,
287 DocumentState* document_state, 262 DocumentState* document_state,
288 bool data_reduction_proxy_was_used, 263 bool data_reduction_proxy_was_used,
289 bool came_from_websearch, 264 bool came_from_websearch,
290 int websearch_chrome_joint_experiment_id, 265 int websearch_chrome_joint_experiment_id,
291 GwsPreviewState preview_state, 266 GwsPreviewState preview_state,
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 IsFromGoogleSearchResult(frame->document().url(), 528 IsFromGoogleSearchResult(frame->document().url(),
554 GURL(frame->document().referrer())); 529 GURL(frame->document().referrer()));
555 int websearch_chrome_joint_experiment_id = kNoExperiment; 530 int websearch_chrome_joint_experiment_id = kNoExperiment;
556 if (came_from_websearch) { 531 if (came_from_websearch) {
557 websearch_chrome_joint_experiment_id = 532 websearch_chrome_joint_experiment_id =
558 GetQueryStringBasedExperiment(GURL(frame->document().referrer())); 533 GetQueryStringBasedExperiment(GURL(frame->document().referrer()));
559 } 534 }
560 535
561 GwsPreviewState preview_state = PREVIEW_NONE; 536 GwsPreviewState preview_state = PREVIEW_NONE;
562 int preview_experiment_id = websearch_chrome_joint_experiment_id; 537 int preview_experiment_id = websearch_chrome_joint_experiment_id;
563 GetPreviewState(frame->document().url(), frame->document().referrer(), 538 GetPreviewState(frame, came_from_websearch, data_reduction_proxy_was_used,
564 came_from_websearch, data_reduction_proxy_was_used,
565 &preview_state, &preview_experiment_id); 539 &preview_state, &preview_experiment_id);
566 540
567 // Times based on the Web Timing metrics. 541 // Times based on the Web Timing metrics.
568 // http://www.w3.org/TR/navigation-timing/ 542 // http://www.w3.org/TR/navigation-timing/
569 // TODO(tonyg, jar): We are in the process of vetting these metrics against 543 // TODO(tonyg, jar): We are in the process of vetting these metrics against
570 // the existing ones. Once we understand any differences, we will standardize 544 // the existing ones. Once we understand any differences, we will standardize
571 // on a single set of metrics. 545 // on a single set of metrics.
572 DumpPerformanceTiming(frame->performance(), document_state, 546 DumpPerformanceTiming(frame->performance(), document_state,
573 data_reduction_proxy_was_used, 547 data_reduction_proxy_was_used,
574 came_from_websearch, 548 came_from_websearch,
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 1021
1048 DCHECK(document_state); 1022 DCHECK(document_state);
1049 DCHECK(ds); 1023 DCHECK(ds);
1050 GURL url(ds->request().url()); 1024 GURL url(ds->request().url());
1051 Time start = document_state->start_load_time(); 1025 Time start = document_state->start_load_time();
1052 Time finish = document_state->finish_load_time(); 1026 Time finish = document_state->finish_load_time();
1053 // TODO(mbelshe): should we log more stats? 1027 // TODO(mbelshe): should we log more stats?
1054 VLOG(1) << "PLT: " << (finish - start).InMilliseconds() << "ms " 1028 VLOG(1) << "PLT: " << (finish - start).InMilliseconds() << "ms "
1055 << url.spec(); 1029 << url.spec();
1056 } 1030 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698