| OLD | NEW |
| 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/net/predictor_tab_helper.h" | 5 #include "chrome/browser/net/predictor_tab_helper.h" |
| 6 | 6 |
| 7 #include "base/feature_list.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/net/predictor.h" | 8 #include "chrome/browser/net/predictor.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
| 12 #include "components/variations/variations_associated_data.h" | |
| 13 #include "content/public/browser/navigation_handle.h" | |
| 14 | 12 |
| 15 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::PredictorTabHelper); | 13 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::PredictorTabHelper); |
| 16 | 14 |
| 17 namespace chrome_browser_net { | 15 namespace chrome_browser_net { |
| 18 | 16 |
| 19 namespace { | |
| 20 | |
| 21 // Triggers the preconnector on the new navigation api. This captures more | |
| 22 // navigations. | |
| 23 const base::Feature kPreconnectMore{"PreconnectMore", | |
| 24 base::FEATURE_DISABLED_BY_DEFAULT}; | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 PredictorTabHelper::PredictorTabHelper(content::WebContents* web_contents) | 17 PredictorTabHelper::PredictorTabHelper(content::WebContents* web_contents) |
| 29 : content::WebContentsObserver(web_contents) { | 18 : content::WebContentsObserver(web_contents) { |
| 30 } | 19 } |
| 31 | 20 |
| 32 PredictorTabHelper::~PredictorTabHelper() { | 21 PredictorTabHelper::~PredictorTabHelper() { |
| 33 } | 22 } |
| 34 | 23 |
| 35 void PredictorTabHelper::DidStartNavigation( | |
| 36 content::NavigationHandle* navigation_handle) { | |
| 37 if (!base::FeatureList::IsEnabled(kPreconnectMore)) | |
| 38 return; | |
| 39 // Subframe navigations require a param check. | |
| 40 if (!navigation_handle->IsInMainFrame() && | |
| 41 variations::GetVariationParamValue("PreconnectMore", | |
| 42 "preconnect_subframes") != "true") { | |
| 43 return; | |
| 44 } | |
| 45 PreconnectUrl(navigation_handle->GetURL()); | |
| 46 } | |
| 47 | |
| 48 void PredictorTabHelper::DidStartNavigationToPendingEntry( | 24 void PredictorTabHelper::DidStartNavigationToPendingEntry( |
| 49 const GURL& url, | 25 const GURL& url, |
| 50 content::NavigationController::ReloadType reload_type) { | 26 content::NavigationController::ReloadType reload_type) { |
| 51 // The standard way to preconnect based on navigation. | |
| 52 if (!base::FeatureList::IsEnabled(kPreconnectMore)) | |
| 53 PreconnectUrl(url); | |
| 54 } | |
| 55 | |
| 56 void PredictorTabHelper::PreconnectUrl(const GURL& url) { | |
| 57 Profile* profile = | 27 Profile* profile = |
| 58 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 28 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 59 chrome_browser_net::Predictor* predictor = profile->GetNetworkPredictor(); | 29 chrome_browser_net::Predictor* predictor = profile->GetNetworkPredictor(); |
| 60 if (predictor && url.SchemeIsHTTPOrHTTPS()) | 30 if (!predictor) |
| 31 return; |
| 32 if (url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme)) |
| 61 predictor->PreconnectUrlAndSubresources(url, GURL()); | 33 predictor->PreconnectUrlAndSubresources(url, GURL()); |
| 62 } | 34 } |
| 63 | 35 |
| 64 } // namespace chrome_browser_net | 36 } // namespace chrome_browser_net |
| OLD | NEW |