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

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

Issue 1857573002: [reland] 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: Update finch test config on chromeos Created 4 years, 7 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"
11 #include "chrome/common/url_constants.h" 10 #include "chrome/common/url_constants.h"
11 #include "content/public/browser/navigation_handle.h"
12 12
13 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::PredictorTabHelper); 13 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::PredictorTabHelper);
14 14
15 namespace chrome_browser_net { 15 namespace chrome_browser_net {
16 16
17 namespace {
18
19 // Triggers the preconnector on the new navigation api. This captures more
20 // navigations.
21 const base::Feature kPreconnectMore{"PreconnectMore",
22 base::FEATURE_DISABLED_BY_DEFAULT};
23
24 } // namespace
25
17 PredictorTabHelper::PredictorTabHelper(content::WebContents* web_contents) 26 PredictorTabHelper::PredictorTabHelper(content::WebContents* web_contents)
18 : content::WebContentsObserver(web_contents) { 27 : content::WebContentsObserver(web_contents),
28 predicted_from_pending_entry_(false) {
19 } 29 }
20 30
21 PredictorTabHelper::~PredictorTabHelper() { 31 PredictorTabHelper::~PredictorTabHelper() {
22 } 32 }
23 33
34 void PredictorTabHelper::DidStartNavigation(
35 content::NavigationHandle* navigation_handle) {
36 if (!base::FeatureList::IsEnabled(kPreconnectMore))
37 return;
38 // Subframe navigations are handled in WitnessURLRequest.
39 if (!navigation_handle->IsInMainFrame())
40 return;
41 if (predicted_from_pending_entry_) {
42 predicted_from_pending_entry_ = false;
43 return;
44 }
45 PreconnectUrl(navigation_handle->GetURL());
46 }
47
24 void PredictorTabHelper::DidStartNavigationToPendingEntry( 48 void PredictorTabHelper::DidStartNavigationToPendingEntry(
25 const GURL& url, 49 const GURL& url,
26 content::NavigationController::ReloadType reload_type) { 50 content::NavigationController::ReloadType reload_type) {
51 // The standard way to preconnect based on navigation.
52 PreconnectUrl(url);
53 predicted_from_pending_entry_ = true;
54 }
55
56 void PredictorTabHelper::PreconnectUrl(const GURL& url) {
27 Profile* profile = 57 Profile* profile =
28 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 58 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
29 chrome_browser_net::Predictor* predictor = profile->GetNetworkPredictor(); 59 chrome_browser_net::Predictor* predictor = profile->GetNetworkPredictor();
30 if (!predictor) 60 if (predictor && url.SchemeIsHTTPOrHTTPS())
31 return;
32 if (url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme))
33 predictor->PreconnectUrlAndSubresources(url, GURL()); 61 predictor->PreconnectUrlAndSubresources(url, GURL());
34 } 62 }
35 63
36 } // namespace chrome_browser_net 64 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/predictor_tab_helper.h ('k') | testing/variations/fieldtrial_testing_config_android.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698