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" | |
8 #include "chrome/browser/net/predictor.h" | 7 #include "chrome/browser/net/predictor.h" |
9 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
11 #include "content/public/browser/navigation_handle.h" | 10 #include "content/public/browser/navigation_handle.h" |
12 #include "content/public/common/browser_side_navigation_policy.h" | 11 #include "content/public/common/browser_side_navigation_policy.h" |
13 | 12 |
14 #if defined(OS_CHROMEOS) | 13 #if defined(OS_CHROMEOS) |
15 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 14 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
16 #endif // defined(OS_CHROMEOS) | 15 #endif // defined(OS_CHROMEOS) |
17 | 16 |
18 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::PredictorTabHelper); | 17 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::PredictorTabHelper); |
19 | 18 |
20 namespace chrome_browser_net { | 19 namespace features { |
21 | |
22 namespace { | |
23 | 20 |
24 // Triggers the preconnector on renderer-initiated navigations. This captures | 21 // Triggers the preconnector on renderer-initiated navigations. This captures |
25 // more navigations. | 22 // more navigations. |
26 const base::Feature kPreconnectMore{"PreconnectMore", | 23 const base::Feature kPreconnectMore{"PreconnectMore", |
27 base::FEATURE_DISABLED_BY_DEFAULT}; | 24 base::FEATURE_DISABLED_BY_DEFAULT}; |
28 | 25 |
29 } // namespace | 26 } // namespace features |
| 27 |
| 28 namespace chrome_browser_net { |
30 | 29 |
31 PredictorTabHelper::PredictorTabHelper(content::WebContents* web_contents) | 30 PredictorTabHelper::PredictorTabHelper(content::WebContents* web_contents) |
32 : content::WebContentsObserver(web_contents), | 31 : content::WebContentsObserver(web_contents), |
33 predicted_from_pending_entry_(false) { | 32 predicted_from_pending_entry_(false) { |
34 } | 33 } |
35 | 34 |
36 PredictorTabHelper::~PredictorTabHelper() { | 35 PredictorTabHelper::~PredictorTabHelper() { |
37 } | 36 } |
38 | 37 |
39 void PredictorTabHelper::DidStartNavigation( | 38 void PredictorTabHelper::DidStartNavigation( |
40 content::NavigationHandle* navigation_handle) { | 39 content::NavigationHandle* navigation_handle) { |
41 if (!base::FeatureList::IsEnabled(kPreconnectMore) && | 40 if (!base::FeatureList::IsEnabled(features::kPreconnectMore) && |
42 (!content::IsBrowserSideNavigationEnabled() || | 41 (!content::IsBrowserSideNavigationEnabled() || |
43 navigation_handle->IsRendererInitiated())) | 42 navigation_handle->IsRendererInitiated())) |
44 return; | 43 return; |
45 // Subframe navigations are handled in WitnessURLRequest. | 44 // Subframe navigations are handled in WitnessURLRequest. |
46 if (!navigation_handle->IsInMainFrame()) | 45 if (!navigation_handle->IsInMainFrame()) |
47 return; | 46 return; |
48 if (predicted_from_pending_entry_) { | 47 if (predicted_from_pending_entry_) { |
49 predicted_from_pending_entry_ = false; | 48 predicted_from_pending_entry_ = false; |
50 return; | 49 return; |
51 } | 50 } |
(...skipping 27 matching lines...) Expand all Loading... |
79 | 78 |
80 void PredictorTabHelper::PreconnectUrl(const GURL& url) { | 79 void PredictorTabHelper::PreconnectUrl(const GURL& url) { |
81 Profile* profile = | 80 Profile* profile = |
82 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 81 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
83 Predictor* predictor(profile->GetNetworkPredictor()); | 82 Predictor* predictor(profile->GetNetworkPredictor()); |
84 if (predictor && url.SchemeIsHTTPOrHTTPS()) | 83 if (predictor && url.SchemeIsHTTPOrHTTPS()) |
85 predictor->PreconnectUrlAndSubresources(url, GURL()); | 84 predictor->PreconnectUrlAndSubresources(url, GURL()); |
86 } | 85 } |
87 | 86 |
88 } // namespace chrome_browser_net | 87 } // namespace chrome_browser_net |
OLD | NEW |