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

Side by Side Diff: chrome/browser/net/predictor_tab_helper.cc

Issue 1813553004: Change net's predictor_tab_helper to use the new content Navigation API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: subframe / mainframe experiment Created 4 years, 9 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
OLDNEW
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/command_line.h" 7 #include "base/feature_list.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 "content/public/browser/navigation_handle.h"
12 13
13 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::PredictorTabHelper); 14 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::PredictorTabHelper);
14 15
15 namespace chrome_browser_net { 16 namespace chrome_browser_net {
16 17
18 namespace {
19
20 const base::Feature kPreconnectMore {
21 "PreconnectMore", base::FEATURE_DISABLED_BY_DEFAULT
22 };
23
24 const base::Feature kPreconnectMoreMainFrameOnly {
25 "PreconnectMoreMainFrameOnly", base::FEATURE_DISABLED_BY_DEFAULT
26 };
27
28 bool ShouldPreconnectMore() {
29 return base::FeatureList::IsEnabled(kPreconnectMore) ||
30 base::FeatureList::IsEnabled(kPreconnectMoreMainFrameOnly);
31 }
32
33 } // namespace
34
17 PredictorTabHelper::PredictorTabHelper(content::WebContents* web_contents) 35 PredictorTabHelper::PredictorTabHelper(content::WebContents* web_contents)
18 : content::WebContentsObserver(web_contents) { 36 : content::WebContentsObserver(web_contents) {
19 } 37 }
20 38
21 PredictorTabHelper::~PredictorTabHelper() { 39 PredictorTabHelper::~PredictorTabHelper() {
22 } 40 }
23 41
42 void PredictorTabHelper::DidStartNavigation(
43 content::NavigationHandle* navigation_handle) {
44 if (!ShouldPreconnectMore())
45 return;
46 if (!navigation_handle->IsInMainFrame() &&
47 !base::FeatureList::IsEnabled(kPreconnectMore)) {
48 return;
49 }
50 PreconnectUrl(navigation_handle->GetURL());
51 }
52
24 void PredictorTabHelper::DidStartNavigationToPendingEntry( 53 void PredictorTabHelper::DidStartNavigationToPendingEntry(
25 const GURL& url, 54 const GURL& url,
26 content::NavigationController::ReloadType reload_type) { 55 content::NavigationController::ReloadType reload_type) {
56 if (!ShouldPreconnectMore())
57 PreconnectUrl(url);
58 }
59
60 void PredictorTabHelper::PreconnectUrl(const GURL& url) {
27 Profile* profile = 61 Profile* profile =
28 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 62 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
29 chrome_browser_net::Predictor* predictor = profile->GetNetworkPredictor(); 63 chrome_browser_net::Predictor* predictor = profile->GetNetworkPredictor();
30 if (!predictor) 64 if (predictor && url.SchemeIsHTTPOrHTTPS())
31 return;
32 if (url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme))
33 predictor->PreconnectUrlAndSubresources(url, GURL()); 65 predictor->PreconnectUrlAndSubresources(url, GURL());
34 } 66 }
35 67
36 } // namespace chrome_browser_net 68 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698