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. 4 5 #include "chrome/browser/net/predictor_tab_helper.h" 6 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 13 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::PredictorTabHelper); 14 15 namespace chrome_browser_net { 16 PredictorTabHelper(content::WebContents * web_contents)17PredictorTabHelper::PredictorTabHelper(content::WebContents* web_contents) 18 : content::WebContentsObserver(web_contents) { 19 } 20 ~PredictorTabHelper()21PredictorTabHelper::~PredictorTabHelper() { 22 } 23 DidStartNavigationToPendingEntry(const GURL & url,content::NavigationController::ReloadType reload_type)24void PredictorTabHelper::DidStartNavigationToPendingEntry( 25 const GURL& url, 26 content::NavigationController::ReloadType reload_type) { 27 Profile* profile = 28 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 29 chrome_browser_net::Predictor* predictor = profile->GetNetworkPredictor(); 30 if (!predictor) 31 return; 32 if (url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme)) 33 predictor->PreconnectUrlAndSubresources(url, GURL()); 34 } 35 36 } // namespace chrome_browser_net 37