| 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/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/metrics/field_trial.h" |
| 11 #include "chrome/browser/net/prediction_options.h" | 12 #include "chrome/browser/net/prediction_options.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/sessions/session_tab_helper.h" | 14 #include "chrome/browser/sessions/session_tab_helper.h" |
| 14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 15 #include "components/prefs/pref_service.h" | 16 #include "components/prefs/pref_service.h" |
| 17 #include "components/variations/variations_associated_data.h" |
| 16 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 18 | 20 |
| 19 namespace predictors { | 21 namespace predictors { |
| 20 | 22 |
| 23 const char kSpeculativeResourcePrefetchingFeatureName[] = |
| 24 "SpeculativeResourcePrefetching"; |
| 25 const char kModeParamName[] = "mode"; |
| 26 const char kLearningMode[] = "learning"; |
| 27 const char kExternalPrefetchingMode[] = "external-prefetching"; |
| 28 const char kPrefetchingMode[] = "prefetching"; |
| 29 |
| 21 namespace { | 30 namespace { |
| 22 | 31 |
| 32 const base::Feature kSpeculativeResourcePrefetchingFeature{ |
| 33 kSpeculativeResourcePrefetchingFeatureName, |
| 34 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 35 |
| 23 bool IsPrefetchingEnabledInternal(Profile* profile, int mode, int mask) { | 36 bool IsPrefetchingEnabledInternal(Profile* profile, int mode, int mask) { |
| 24 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 37 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 25 if ((mode & mask) == 0) | 38 if ((mode & mask) == 0) |
| 26 return false; | 39 return false; |
| 27 | 40 |
| 28 if (!profile || !profile->GetPrefs() || | 41 if (!profile || !profile->GetPrefs() || |
| 29 chrome_browser_net::CanPrefetchAndPrerenderUI(profile->GetPrefs()) != | 42 chrome_browser_net::CanPrefetchAndPrerenderUI(profile->GetPrefs()) != |
| 30 chrome_browser_net::NetworkPredictionStatus::ENABLED) { | 43 chrome_browser_net::NetworkPredictionStatus::ENABLED) { |
| 31 return false; | 44 return false; |
| 32 } | 45 } |
| 33 | 46 |
| 34 return true; | 47 return true; |
| 35 } | 48 } |
| 36 | 49 |
| 37 } // namespace | 50 } // namespace |
| 38 | 51 |
| 39 bool IsSpeculativeResourcePrefetchingEnabled( | 52 bool IsSpeculativeResourcePrefetchingEnabled( |
| 40 Profile* profile, | 53 Profile* profile, |
| 41 ResourcePrefetchPredictorConfig* config) { | 54 ResourcePrefetchPredictorConfig* config) { |
| 42 DCHECK(config); | 55 DCHECK(config); |
| 43 | 56 |
| 44 // Off the record - disabled. | 57 // Disabled for of-the-record. Policy choice, not a technical limitation. |
| 45 if (!profile || profile->IsOffTheRecord()) | 58 if (!profile || profile->IsOffTheRecord()) |
| 46 return false; | 59 return false; |
| 47 | 60 |
| 48 // Enabled by command line switch. The config has the default params already | 61 if (!base::FeatureList::IsEnabled(kSpeculativeResourcePrefetchingFeature)) |
| 49 // set. The command line with just enable them with the default params. | 62 return false; |
| 50 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 51 switches::kSpeculativeResourcePrefetching)) { | |
| 52 const std::string value = | |
| 53 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 54 switches::kSpeculativeResourcePrefetching); | |
| 55 | 63 |
| 56 if (value == switches::kSpeculativeResourcePrefetchingDisabled) { | 64 std::string mode_value = variations::GetVariationParamValueByFeature( |
| 57 return false; | 65 kSpeculativeResourcePrefetchingFeature, kModeParamName); |
| 58 } else if (value == switches::kSpeculativeResourcePrefetchingLearning) { | 66 if (mode_value == kLearningMode) { |
| 59 config->mode |= ResourcePrefetchPredictorConfig::LEARNING; | 67 config->mode |= ResourcePrefetchPredictorConfig::LEARNING; |
| 60 return true; | 68 return true; |
| 61 } else if (value == | 69 } else if (mode_value == kExternalPrefetchingMode) { |
| 62 switches::kSpeculativeResourcePrefetchingEnabledExternal) { | 70 config->mode |= ResourcePrefetchPredictorConfig::LEARNING | |
| 63 config->mode |= ResourcePrefetchPredictorConfig::LEARNING | | 71 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL; |
| 64 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL; | 72 return true; |
| 65 return true; | 73 } else if (mode_value == kPrefetchingMode) { |
| 66 } else if (value == switches::kSpeculativeResourcePrefetchingEnabled) { | 74 config->mode |= ResourcePrefetchPredictorConfig::LEARNING | |
| 67 config->mode |= | 75 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL | |
| 68 ResourcePrefetchPredictorConfig::LEARNING | | 76 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_NAVIGATION; |
| 69 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_NAVIGATION | | 77 return true; |
| 70 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL; | |
| 71 return true; | |
| 72 } | |
| 73 } | 78 } |
| 74 | 79 |
| 75 return false; | 80 return false; |
| 76 } | 81 } |
| 77 | 82 |
| 78 NavigationID::NavigationID() : tab_id(-1) {} | 83 NavigationID::NavigationID() : tab_id(-1) {} |
| 79 | 84 |
| 80 NavigationID::NavigationID(const NavigationID& other) | 85 NavigationID::NavigationID(const NavigationID& other) |
| 81 : tab_id(other.tab_id), | 86 : tab_id(other.tab_id), |
| 82 main_frame_url(other.main_frame_url), | 87 main_frame_url(other.main_frame_url), |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 173 |
| 169 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { | 174 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { |
| 170 return max_resources_per_entry == 100; | 175 return max_resources_per_entry == 100; |
| 171 } | 176 } |
| 172 | 177 |
| 173 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { | 178 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { |
| 174 return max_urls_to_track == 200 && max_hosts_to_track == 100; | 179 return max_urls_to_track == 200 && max_hosts_to_track == 100; |
| 175 } | 180 } |
| 176 | 181 |
| 177 } // namespace predictors | 182 } // namespace predictors |
| OLD | NEW |