15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2011 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_PRERENDER_PRERENDER_UTIL_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_PRERENDER_PRERENDER_UTIL_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
9116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/public/common/resource_type.h"
10eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "url/gurl.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace net {
138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class HttpResponseHeaders;
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class URLRequest;
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace prerender {
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)extern const char kChromeNavigateExtraDataKey[];
20a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ID indicating that no experiment is active.
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const uint8 kNoExperiment = 0;
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Extracts a urlencoded URL stored in a url= query parameter from a URL
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// supplied, if available, and stores it in alias_url.  Returns whether or not
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the operation succeeded (i.e. a valid URL was found).
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool MaybeGetQueryStringBasedAliasURL(const GURL& url, GURL* alias_url);
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Extracts an experiment stored in the query parameter
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// lpe= from the URL supplied, and returns it.
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns kNoExperiment if no experiment ID is found, or if the ID
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// is not an integer in the range 1 to 9.
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)uint8 GetQueryStringBasedExperiment(const GURL& url);
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Indicates whether the URL provided has a Google domain
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool IsGoogleDomain(const GURL& url);
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Indicates whether the URL provided could be a Google search result page.
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool IsGoogleSearchResultURL(const GURL& url);
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The prerender contents of some experiments should never be swapped in
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// by pretending to never match on the URL.  This function will return true
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// iff this is the case for the experiment_id specified.
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool IsNoSwapInExperiment(uint8 experiment_id);
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The prerender contents of some experiments should behave identical to the
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// control group, regardless of the field trial.  This function will return true
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// iff this is the case for the experiment_id specified.
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool IsControlGroupExperiment(uint8 experiment_id);
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Called by URLRequestResponseStarted to gather data about Pagespeed headers
528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// into the Prerender.PagespeedHeader histogram. Public so it can be accessed
538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// by the unit test.
545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void GatherPagespeedData(const content::ResourceType resource_type,
558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                         const GURL& request_url,
568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                         const net::HttpResponseHeaders* response_headers);
578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Static method gathering stats about a URLRequest for which a response has
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// just started.
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void URLRequestResponseStarted(net::URLRequest* request);
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
62f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Report a URL was canceled due to trying to handle an external URL.
63f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void ReportPrerenderExternalURL();
64f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
65f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Report a URL was canceled due to unsupported prerender scheme.
66f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void ReportUnsupportedPrerenderScheme(const GURL& url);
67f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace prerender
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CHROME_BROWSER_PRERENDER_PRERENDER_UTIL_H_
71