NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / net / predictor_tab_helper.cc
blob43792819786f0966642c8b630358baf3a47bc136
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
3 // found in the LICENSE file.
5 #include "chrome/browser/net/predictor_tab_helper.h"
7 #include "base/command_line.h"
8 #include "chrome/browser/net/predictor.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/url_constants.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/common/frame_navigate_params.h"
15 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::PredictorTabHelper);
17 using content::BrowserThread;
19 namespace {
21 bool IsUserLinkNavigationRequest(content::PageTransition page_transition) {
22 bool is_link = (content::PageTransitionStripQualifier(page_transition) ==
23 content::PAGE_TRANSITION_LINK);
24 bool is_forward_back = (page_transition &
25 content::PAGE_TRANSITION_FORWARD_BACK) != 0;
26 // Tracking navigation session including client-side redirect
27 // is currently not supported.
28 bool is_client_redirect = (page_transition &
29 content::PAGE_TRANSITION_CLIENT_REDIRECT) != 0;
30 return is_link && !is_forward_back && !is_client_redirect;
33 } // namespace
35 namespace chrome_browser_net {
37 PredictorTabHelper::PredictorTabHelper(content::WebContents* web_contents)
38 : content::WebContentsObserver(web_contents) {
41 PredictorTabHelper::~PredictorTabHelper() {
44 void PredictorTabHelper::DidStartNavigationToPendingEntry(
45 const GURL& url,
46 content::NavigationController::ReloadType reload_type) {
47 Profile* profile =
48 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
49 chrome_browser_net::Predictor* predictor = profile->GetNetworkPredictor();
50 if (!predictor)
51 return;
52 if (url.SchemeIs(content::kHttpScheme) || url.SchemeIs(content::kHttpsScheme))
53 predictor->PreconnectUrlAndSubresources(url, GURL());
56 void PredictorTabHelper::DidNavigateMainFrame(
57 const content::LoadCommittedDetails& details,
58 const content::FrameNavigateParams& params) {
59 if (!IsUserLinkNavigationRequest(params.transition) ||
60 !(params.url.SchemeIsHTTPOrHTTPS()))
61 return;
63 Profile* profile = Profile::FromBrowserContext(
64 web_contents()->GetBrowserContext());
65 Predictor* predictor = profile->GetNetworkPredictor();
66 if (predictor) {
67 BrowserThread::PostTask(
68 BrowserThread::IO,
69 FROM_HERE,
70 base::Bind(&Predictor::RecordLinkNavigation,
71 base::Unretained(predictor),
72 params.url));
76 } // namespace chrome_browser_net