| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/predictors/resource_prefetch_common.h" | 5 #include "chrome/browser/predictors/resource_prefetch_common.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <tuple> | 8 #include <tuple> |
| 9 | 9 |
| 10 #include "base/feature_list.h" | |
| 11 #include "base/metrics/field_trial_params.h" | 10 #include "base/metrics/field_trial_params.h" |
| 12 #include "chrome/browser/net/prediction_options.h" | 11 #include "chrome/browser/net/prediction_options.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/sessions/session_tab_helper.h" | 13 #include "chrome/browser/sessions/session_tab_helper.h" |
| 15 #include "components/prefs/pref_service.h" | 14 #include "components/prefs/pref_service.h" |
| 16 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 18 | 17 |
| 19 namespace predictors { | 18 namespace predictors { |
| 20 | 19 |
| 21 const char kSpeculativeResourcePrefetchingFeatureName[] = | 20 const char kSpeculativeResourcePrefetchingFeatureName[] = |
| 22 "SpeculativeResourcePrefetching"; | 21 "SpeculativeResourcePrefetching"; |
| 23 const char kModeParamName[] = "mode"; | 22 const char kModeParamName[] = "mode"; |
| 24 const char kLearningMode[] = "learning"; | 23 const char kLearningMode[] = "learning"; |
| 25 const char kExternalPrefetchingMode[] = "external-prefetching"; | 24 const char kExternalPrefetchingMode[] = "external-prefetching"; |
| 26 const char kPrefetchingMode[] = "prefetching"; | 25 const char kPrefetchingMode[] = "prefetching"; |
| 27 const char kEnableUrlLearningParamName[] = "enable-url-learning"; | 26 const char kEnableUrlLearningParamName[] = "enable-url-learning"; |
| 28 | 27 |
| 28 const base::Feature kSpeculativeResourcePrefetchingFeature = |
| 29 base::Feature(kSpeculativeResourcePrefetchingFeatureName, |
| 30 base::FEATURE_DISABLED_BY_DEFAULT); |
| 31 |
| 29 namespace { | 32 namespace { |
| 30 | 33 |
| 31 const base::Feature kSpeculativeResourcePrefetchingFeature{ | |
| 32 kSpeculativeResourcePrefetchingFeatureName, | |
| 33 base::FEATURE_DISABLED_BY_DEFAULT}; | |
| 34 | |
| 35 bool IsPrefetchingEnabledInternal(Profile* profile, int mode, int mask) { | 34 bool IsPrefetchingEnabledInternal(Profile* profile, int mode, int mask) { |
| 36 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 35 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 37 if ((mode & mask) == 0) | 36 if ((mode & mask) == 0) |
| 38 return false; | 37 return false; |
| 39 | 38 |
| 40 if (!profile || !profile->GetPrefs() || | 39 if (!profile || !profile->GetPrefs() || |
| 41 chrome_browser_net::CanPrefetchAndPrerenderUI(profile->GetPrefs()) != | 40 chrome_browser_net::CanPrefetchAndPrerenderUI(profile->GetPrefs()) != |
| 42 chrome_browser_net::NetworkPredictionStatus::ENABLED) { | 41 chrome_browser_net::NetworkPredictionStatus::ENABLED) { |
| 43 return false; | 42 return false; |
| 44 } | 43 } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 179 |
| 181 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { | 180 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { |
| 182 return max_resources_per_entry == 100; | 181 return max_resources_per_entry == 100; |
| 183 } | 182 } |
| 184 | 183 |
| 185 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { | 184 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { |
| 186 return max_urls_to_track == 200 && max_hosts_to_track == 100; | 185 return max_urls_to_track == 200 && max_hosts_to_track == 100; |
| 187 } | 186 } |
| 188 | 187 |
| 189 } // namespace predictors | 188 } // namespace predictors |
| OLD | NEW |