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

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: groups 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 // Run the preconnect predictor on all main frame and subframe navigations.
21 const base::Feature kPreconnectMore{"PreconnectMoreAllFrames",
22 base::FEATURE_DISABLED_BY_DEFAULT};
23
24 // Run the preconnect predictor on all main frame navigations. When this feature
25 // is off the predictor is only run for some browser initiated navigations.
26 const base::Feature kPreconnectMoreMainFrameOnly{
27 "PreconnectMoreMainFrameOnly", base::FEATURE_DISABLED_BY_DEFAULT};
Alexei Svitkine (slow) 2016/03/21 19:42:12 I think it would be better to use a top-level feat
Charlie Harrison 2016/03/22 16:26:36 Thanks for the suggestion. I was unsure of relatio
28
29 bool ShouldPreconnectMore() {
30 return base::FeatureList::IsEnabled(kPreconnectMore) ||
31 base::FeatureList::IsEnabled(kPreconnectMoreMainFrameOnly);
32 }
33
34 } // namespace
35
17 PredictorTabHelper::PredictorTabHelper(content::WebContents* web_contents) 36 PredictorTabHelper::PredictorTabHelper(content::WebContents* web_contents)
18 : content::WebContentsObserver(web_contents) { 37 : content::WebContentsObserver(web_contents) {
19 } 38 }
20 39
21 PredictorTabHelper::~PredictorTabHelper() { 40 PredictorTabHelper::~PredictorTabHelper() {
22 } 41 }
23 42
43 void PredictorTabHelper::DidStartNavigation(
44 content::NavigationHandle* navigation_handle) {
45 if (!ShouldPreconnectMore())
46 return;
47 if (!navigation_handle->IsInMainFrame() &&
48 !base::FeatureList::IsEnabled(kPreconnectMore)) {
49 return;
50 }
51 PreconnectUrl(navigation_handle->GetURL());
52 }
53
24 void PredictorTabHelper::DidStartNavigationToPendingEntry( 54 void PredictorTabHelper::DidStartNavigationToPendingEntry(
25 const GURL& url, 55 const GURL& url,
26 content::NavigationController::ReloadType reload_type) { 56 content::NavigationController::ReloadType reload_type) {
57 if (!ShouldPreconnectMore())
58 PreconnectUrl(url);
59 }
60
61 void PredictorTabHelper::PreconnectUrl(const GURL& url) {
27 Profile* profile = 62 Profile* profile =
28 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 63 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
29 chrome_browser_net::Predictor* predictor = profile->GetNetworkPredictor(); 64 chrome_browser_net::Predictor* predictor = profile->GetNetworkPredictor();
30 if (!predictor) 65 if (predictor && url.SchemeIsHTTPOrHTTPS())
31 return;
32 if (url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme))
33 predictor->PreconnectUrlAndSubresources(url, GURL()); 66 predictor->PreconnectUrlAndSubresources(url, GURL());
34 } 67 }
35 68
36 } // namespace chrome_browser_net 69 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698