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

Side by Side Diff: chrome/browser/predictors/resource_prefetch_common.cc

Issue 2652313002: predictors: Move the configuration of speculative prefetch to field trials. (Closed)
Patch Set: Created 3 years, 10 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
OLDNEW
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 } else if (mode_value == kExternalPrefetchingMode) {
61 } else if (value == 69 config->mode |= ResourcePrefetchPredictorConfig::LEARNING |
62 switches::kSpeculativeResourcePrefetchingEnabledExternal) { 70 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL;
63 config->mode |= ResourcePrefetchPredictorConfig::LEARNING | 71 } else if (mode_value == kPrefetchingMode) {
64 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL; 72 config->mode |= ResourcePrefetchPredictorConfig::LEARNING |
65 return true; 73 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL |
66 } else if (value == switches::kSpeculativeResourcePrefetchingEnabled) { 74 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_NAVIGATION;
67 config->mode |= 75 } else {
68 ResourcePrefetchPredictorConfig::LEARNING | 76 return false;
droger 2017/01/25 17:27:11 Nit: For readability it may be better to have a re
Benoit L 2017/01/26 09:58:15 Done.
69 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_NAVIGATION |
70 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL;
71 return true;
72 }
73 } 77 }
74 78
75 return false; 79 return true;
76 } 80 }
77 81
78 NavigationID::NavigationID() : tab_id(-1) {} 82 NavigationID::NavigationID() : tab_id(-1) {}
79 83
80 NavigationID::NavigationID(const NavigationID& other) 84 NavigationID::NavigationID(const NavigationID& other)
81 : tab_id(other.tab_id), 85 : tab_id(other.tab_id),
82 main_frame_url(other.main_frame_url), 86 main_frame_url(other.main_frame_url),
83 creation_time(other.creation_time) {} 87 creation_time(other.creation_time) {}
84 88
85 NavigationID::NavigationID(content::WebContents* web_contents) 89 NavigationID::NavigationID(content::WebContents* web_contents)
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 172
169 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { 173 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const {
170 return max_resources_per_entry == 100; 174 return max_resources_per_entry == 100;
171 } 175 }
172 176
173 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { 177 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const {
174 return max_urls_to_track == 200 && max_hosts_to_track == 100; 178 return max_urls_to_track == 200 && max_hosts_to_track == 100;
175 } 179 }
176 180
177 } // namespace predictors 181 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698