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

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

Issue 2907263002: [Not for review] Add TRACE_EVENTs and chrome://flags for preconnect
Patch Set: Created 3 years, 6 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
« no previous file with comments | « chrome/browser/net/predictor.cc ('k') | content/public/common/content_features.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/feature_list.h" 7 #include "base/feature_list.h"
8 #include "base/trace_event/trace_event.h"
8 #include "chrome/browser/net/predictor.h" 9 #include "chrome/browser/net/predictor.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
11 #include "content/public/browser/navigation_handle.h" 12 #include "content/public/browser/navigation_handle.h"
12 #include "content/public/common/browser_side_navigation_policy.h" 13 #include "content/public/common/browser_side_navigation_policy.h"
14 #include "content/public/common/content_features.h"
13 15
14 #if defined(OS_CHROMEOS) 16 #if defined(OS_CHROMEOS)
15 #include "chrome/browser/chromeos/profiles/profile_helper.h" 17 #include "chrome/browser/chromeos/profiles/profile_helper.h"
16 #endif // defined(OS_CHROMEOS) 18 #endif // defined(OS_CHROMEOS)
17 19
18 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::PredictorTabHelper); 20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::PredictorTabHelper);
19 21
20 namespace chrome_browser_net { 22 namespace chrome_browser_net {
21 23
22 namespace { 24 namespace {
23 25
24 // Triggers the preconnector on renderer-initiated navigations. This captures 26 // Triggers the preconnector on renderer-initiated navigations. This captures
25 // more navigations. 27 // more navigations.
26 const base::Feature kPreconnectMore{"PreconnectMore", 28 const base::Feature kPreconnectMore{"PreconnectMore",
27 base::FEATURE_DISABLED_BY_DEFAULT}; 29 base::FEATURE_DISABLED_BY_DEFAULT};
28 30
29 } // namespace 31 } // namespace
30 32
31 PredictorTabHelper::PredictorTabHelper(content::WebContents* web_contents) 33 PredictorTabHelper::PredictorTabHelper(content::WebContents* web_contents)
32 : content::WebContentsObserver(web_contents), 34 : content::WebContentsObserver(web_contents),
33 predicted_from_pending_entry_(false) { 35 predicted_from_pending_entry_(false) {
34 } 36 }
35 37
36 PredictorTabHelper::~PredictorTabHelper() { 38 PredictorTabHelper::~PredictorTabHelper() {
37 } 39 }
38 40
39 void PredictorTabHelper::DidStartNavigation( 41 void PredictorTabHelper::DidStartNavigation(
40 content::NavigationHandle* navigation_handle) { 42 content::NavigationHandle* navigation_handle) {
43 if (!base::FeatureList::IsEnabled(features::kPredictorPreconnect))
44 return;
41 if (!base::FeatureList::IsEnabled(kPreconnectMore) && 45 if (!base::FeatureList::IsEnabled(kPreconnectMore) &&
42 (!content::IsBrowserSideNavigationEnabled() || 46 (!content::IsBrowserSideNavigationEnabled() ||
43 navigation_handle->IsRendererInitiated())) 47 navigation_handle->IsRendererInitiated()))
44 return; 48 return;
45 // Subframe navigations are handled in WitnessURLRequest. 49 // Subframe navigations are handled in WitnessURLRequest.
46 if (!navigation_handle->IsInMainFrame()) 50 if (!navigation_handle->IsInMainFrame())
47 return; 51 return;
48 if (predicted_from_pending_entry_) { 52 if (predicted_from_pending_entry_) {
49 predicted_from_pending_entry_ = false; 53 predicted_from_pending_entry_ = false;
50 return; 54 return;
51 } 55 }
52 PreconnectUrl(navigation_handle->GetURL()); 56 PreconnectUrl(navigation_handle->GetURL());
53 } 57 }
54 58
55 void PredictorTabHelper::DidStartNavigationToPendingEntry( 59 void PredictorTabHelper::DidStartNavigationToPendingEntry(
56 const GURL& url, 60 const GURL& url,
57 content::ReloadType reload_type) { 61 content::ReloadType reload_type) {
62 if (!base::FeatureList::IsEnabled(features::kPredictorPreconnect))
63 return;
58 // This method isn't needed with PlzNavigate (see comment in header for 64 // This method isn't needed with PlzNavigate (see comment in header for
59 // predicted_from_pending_entry_) 65 // predicted_from_pending_entry_)
60 if (content::IsBrowserSideNavigationEnabled()) 66 if (content::IsBrowserSideNavigationEnabled())
61 return; 67 return;
62 68
63 // The standard way to preconnect based on navigation. 69 // The standard way to preconnect based on navigation.
64 PreconnectUrl(url); 70 PreconnectUrl(url);
65 predicted_from_pending_entry_ = true; 71 predicted_from_pending_entry_ = true;
66 } 72 }
67 73
68 void PredictorTabHelper::DocumentOnLoadCompletedInMainFrame() { 74 void PredictorTabHelper::DocumentOnLoadCompletedInMainFrame() {
69 Profile* profile = 75 Profile* profile =
70 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 76 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
71 Predictor* predictor = profile->GetNetworkPredictor(); 77 Predictor* predictor = profile->GetNetworkPredictor();
72 #if defined(OS_CHROMEOS) 78 #if defined(OS_CHROMEOS)
73 if (chromeos::ProfileHelper::IsSigninProfile(profile)) 79 if (chromeos::ProfileHelper::IsSigninProfile(profile))
74 return; 80 return;
75 #endif 81 #endif
76 if (predictor) 82 if (predictor)
77 predictor->SaveStateForNextStartup(); 83 predictor->SaveStateForNextStartup();
78 } 84 }
79 85
80 void PredictorTabHelper::PreconnectUrl(const GURL& url) { 86 void PredictorTabHelper::PreconnectUrl(const GURL& url) {
87 TRACE_EVENT1("net", "PredictorTabHelper::PreconnectUrl", "url", url.spec());
81 Profile* profile = 88 Profile* profile =
82 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 89 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
83 Predictor* predictor(profile->GetNetworkPredictor()); 90 Predictor* predictor(profile->GetNetworkPredictor());
84 if (predictor && url.SchemeIsHTTPOrHTTPS()) 91 if (predictor && url.SchemeIsHTTPOrHTTPS())
85 predictor->PreconnectUrlAndSubresources(url, GURL()); 92 predictor->PreconnectUrlAndSubresources(url, GURL());
86 } 93 }
87 94
88 } // namespace chrome_browser_net 95 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/predictor.cc ('k') | content/public/common/content_features.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698