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/feature_list.h" |
8 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 8 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
9 #include "chrome/browser/net/predictor.h" | 9 #include "chrome/browser/net/predictor.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
12 #include "content/public/browser/navigation_handle.h" | 12 #include "content/public/browser/navigation_handle.h" |
13 #include "content/public/common/browser_side_navigation_policy.h" | |
13 | 14 |
14 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::PredictorTabHelper); | 15 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::PredictorTabHelper); |
15 | 16 |
16 namespace chrome_browser_net { | 17 namespace chrome_browser_net { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 // Triggers the preconnector on the new navigation api. This captures more | 21 // Triggers the preconnector on renderer-initiated navigations. This captures |
21 // navigations. | 22 // more navigations. |
22 const base::Feature kPreconnectMore{"PreconnectMore", | 23 const base::Feature kPreconnectMore{"PreconnectMore", |
23 base::FEATURE_DISABLED_BY_DEFAULT}; | 24 base::FEATURE_DISABLED_BY_DEFAULT}; |
24 | 25 |
25 } // namespace | 26 } // namespace |
26 | 27 |
27 PredictorTabHelper::PredictorTabHelper(content::WebContents* web_contents) | 28 PredictorTabHelper::PredictorTabHelper(content::WebContents* web_contents) |
28 : content::WebContentsObserver(web_contents), | 29 : content::WebContentsObserver(web_contents), |
29 predicted_from_pending_entry_(false) { | 30 predicted_from_pending_entry_(false) { |
30 } | 31 } |
31 | 32 |
32 PredictorTabHelper::~PredictorTabHelper() { | 33 PredictorTabHelper::~PredictorTabHelper() { |
33 } | 34 } |
34 | 35 |
35 void PredictorTabHelper::DidStartNavigation( | 36 void PredictorTabHelper::DidStartNavigation( |
36 content::NavigationHandle* navigation_handle) { | 37 content::NavigationHandle* navigation_handle) { |
37 if (!base::FeatureList::IsEnabled(kPreconnectMore)) | 38 if (!base::FeatureList::IsEnabled(kPreconnectMore) && |
39 (!content::IsBrowserSideNavigationEnabled() || | |
40 navigation_handle->IsRendererInitiated())) | |
Charlie Harrison
2016/12/09 17:23:10
Note: IsRendererInitiated is a flaky api (crbug.co
| |
38 return; | 41 return; |
39 // Subframe navigations are handled in WitnessURLRequest. | 42 // Subframe navigations are handled in WitnessURLRequest. |
40 if (!navigation_handle->IsInMainFrame()) | 43 if (!navigation_handle->IsInMainFrame()) |
41 return; | 44 return; |
42 if (predicted_from_pending_entry_) { | 45 if (predicted_from_pending_entry_) { |
43 predicted_from_pending_entry_ = false; | 46 predicted_from_pending_entry_ = false; |
44 return; | 47 return; |
45 } | 48 } |
46 PreconnectUrl(navigation_handle->GetURL()); | 49 PreconnectUrl(navigation_handle->GetURL()); |
47 } | 50 } |
48 | 51 |
49 void PredictorTabHelper::DidStartNavigationToPendingEntry( | 52 void PredictorTabHelper::DidStartNavigationToPendingEntry( |
50 const GURL& url, | 53 const GURL& url, |
51 content::ReloadType reload_type) { | 54 content::ReloadType reload_type) { |
55 // This method isn't needed with PlzNavigate (see comment in header for | |
56 // predicted_from_pending_entry_) | |
57 if (content::IsBrowserSideNavigationEnabled()) | |
Charlie Harrison
2016/12/09 17:23:10
Is the method still called in PlzNavigate mode? If
jam
2016/12/09 17:28:48
Yes it is, but it's planned to be removed.
| |
58 return; | |
59 | |
52 // The standard way to preconnect based on navigation. | 60 // The standard way to preconnect based on navigation. |
53 PreconnectUrl(url); | 61 PreconnectUrl(url); |
54 predicted_from_pending_entry_ = true; | 62 predicted_from_pending_entry_ = true; |
55 } | 63 } |
56 | 64 |
57 void PredictorTabHelper::DocumentOnLoadCompletedInMainFrame() { | 65 void PredictorTabHelper::DocumentOnLoadCompletedInMainFrame() { |
58 Profile* profile = | 66 Profile* profile = |
59 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 67 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
60 Predictor* predictor = profile->GetNetworkPredictor(); | 68 Predictor* predictor = profile->GetNetworkPredictor(); |
61 #if defined(OS_CHROMEOS) | 69 #if defined(OS_CHROMEOS) |
62 if (chromeos::ProfileHelper::IsSigninProfile(profile)) | 70 if (chromeos::ProfileHelper::IsSigninProfile(profile)) |
63 return; | 71 return; |
64 #endif | 72 #endif |
65 if (predictor) | 73 if (predictor) |
66 predictor->SaveStateForNextStartup(); | 74 predictor->SaveStateForNextStartup(); |
67 } | 75 } |
68 | 76 |
69 void PredictorTabHelper::PreconnectUrl(const GURL& url) { | 77 void PredictorTabHelper::PreconnectUrl(const GURL& url) { |
70 Profile* profile = | 78 Profile* profile = |
71 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 79 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
72 Predictor* predictor(profile->GetNetworkPredictor()); | 80 Predictor* predictor(profile->GetNetworkPredictor()); |
73 if (predictor && url.SchemeIsHTTPOrHTTPS()) | 81 if (predictor && url.SchemeIsHTTPOrHTTPS()) |
74 predictor->PreconnectUrlAndSubresources(url, GURL()); | 82 predictor->PreconnectUrlAndSubresources(url, GURL()); |
75 } | 83 } |
76 | 84 |
77 } // namespace chrome_browser_net | 85 } // namespace chrome_browser_net |
OLD | NEW |