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

Side by Side Diff: components/previews/core/previews_experiments.cc

Issue 2537643005: Refactoring a code pattern in previews_experiments.cc (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/previews/core/previews_experiments.h" 5 #include "components/previews/core/previews_experiments.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 return it == experiment_params.end() ? std::string() : it->second; 82 return it == experiment_params.end() ? std::string() : it->second;
83 } 83 }
84 84
85 } // namespace 85 } // namespace
86 86
87 namespace params { 87 namespace params {
88 88
89 size_t MaxStoredHistoryLengthForPerHostBlackList() { 89 size_t MaxStoredHistoryLengthForPerHostBlackList() {
90 std::string param_value = ParamValue(kMaxStoredHistoryLengthPerHost); 90 std::string param_value = ParamValue(kMaxStoredHistoryLengthPerHost);
91 size_t history_length; 91 size_t history_length;
92 if (!base::StringToSizeT(param_value, &history_length)) { 92 if (!base::StringToSizeT(param_value, &history_length))
93 return 4; 93 history_length = 4;
94 }
95 return history_length; 94 return history_length;
96 } 95 }
97 96
98 size_t MaxStoredHistoryLengthForHostIndifferentBlackList() { 97 size_t MaxStoredHistoryLengthForHostIndifferentBlackList() {
99 std::string param_value = ParamValue(kMaxStoredHistoryLengthHostIndifferent); 98 std::string param_value = ParamValue(kMaxStoredHistoryLengthHostIndifferent);
100 size_t history_length; 99 size_t history_length;
101 if (!base::StringToSizeT(param_value, &history_length)) { 100 if (!base::StringToSizeT(param_value, &history_length))
102 return 10; 101 history_length = 10;
103 }
104 return history_length; 102 return history_length;
105 } 103 }
106 104
107 size_t MaxInMemoryHostsInBlackList() { 105 size_t MaxInMemoryHostsInBlackList() {
108 std::string param_value = ParamValue(kMaxHostsInBlackList); 106 std::string param_value = ParamValue(kMaxHostsInBlackList);
109 size_t max_hosts; 107 size_t max_hosts;
110 if (!base::StringToSizeT(param_value, &max_hosts)) { 108 if (!base::StringToSizeT(param_value, &max_hosts))
111 return 100; 109 max_hosts = 100;
112 }
113 return max_hosts; 110 return max_hosts;
114 } 111 }
115 112
116 int PerHostBlackListOptOutThreshold() { 113 int PerHostBlackListOptOutThreshold() {
117 std::string param_value = ParamValue(kPerHostOptOutThreshold); 114 std::string param_value = ParamValue(kPerHostOptOutThreshold);
118 int opt_out_threshold; 115 int opt_out_threshold;
119 if (!base::StringToInt(param_value, &opt_out_threshold)) { 116 if (!base::StringToInt(param_value, &opt_out_threshold))
120 return 2; 117 opt_out_threshold = 2;
121 }
122 return opt_out_threshold; 118 return opt_out_threshold;
123 } 119 }
124 120
125 int HostIndifferentBlackListOptOutThreshold() { 121 int HostIndifferentBlackListOptOutThreshold() {
126 std::string param_value = ParamValue(kHostIndifferentOptOutThreshold); 122 std::string param_value = ParamValue(kHostIndifferentOptOutThreshold);
127 int opt_out_threshold; 123 int opt_out_threshold;
128 if (!base::StringToInt(param_value, &opt_out_threshold)) { 124 if (!base::StringToInt(param_value, &opt_out_threshold))
129 return 4; 125 opt_out_threshold = 4;
130 }
131 return opt_out_threshold; 126 return opt_out_threshold;
132 } 127 }
133 128
134 base::TimeDelta PerHostBlackListDuration() { 129 base::TimeDelta PerHostBlackListDuration() {
135 std::string param_value = ParamValue(kPerHostBlackListDurationInDays); 130 std::string param_value = ParamValue(kPerHostBlackListDurationInDays);
136 int duration; 131 int duration;
137 if (!base::StringToInt(param_value, &duration)) { 132 if (!base::StringToInt(param_value, &duration))
138 return base::TimeDelta::FromDays(30); 133 duration = 30;
139 }
140 return base::TimeDelta::FromDays(duration); 134 return base::TimeDelta::FromDays(duration);
141 } 135 }
142 136
143 base::TimeDelta HostIndifferentBlackListPerHostDuration() { 137 base::TimeDelta HostIndifferentBlackListPerHostDuration() {
144 std::string param_value = ParamValue(kHostIndifferentBlackListDurationInDays); 138 std::string param_value = ParamValue(kHostIndifferentBlackListDurationInDays);
145 int duration; 139 int duration;
146 if (!base::StringToInt(param_value, &duration)) { 140 if (!base::StringToInt(param_value, &duration))
147 return base::TimeDelta::FromDays(365 * 100); 141 duration = 365 * 100;
148 }
149 return base::TimeDelta::FromDays(duration); 142 return base::TimeDelta::FromDays(duration);
150 } 143 }
151 144
152 base::TimeDelta SingleOptOutDuration() { 145 base::TimeDelta SingleOptOutDuration() {
153 std::string param_value = ParamValue(kSingleOptOutDurationInSeconds); 146 std::string param_value = ParamValue(kSingleOptOutDurationInSeconds);
154 int duration; 147 int duration;
155 if (!base::StringToInt(param_value, &duration)) { 148 if (!base::StringToInt(param_value, &duration))
156 return base::TimeDelta::FromSeconds(60 * 5); 149 duration = 60 * 5;
157 }
158 return base::TimeDelta::FromSeconds(duration); 150 return base::TimeDelta::FromSeconds(duration);
159 } 151 }
160 152
161 base::TimeDelta OfflinePreviewFreshnessDuration() { 153 base::TimeDelta OfflinePreviewFreshnessDuration() {
162 std::string param_value = ParamValue(kOfflinePreviewFreshnessDurationInDays); 154 std::string param_value = ParamValue(kOfflinePreviewFreshnessDurationInDays);
163 int duration; 155 int duration;
164 if (!base::StringToInt(param_value, &duration)) { 156 if (!base::StringToInt(param_value, &duration))
165 return base::TimeDelta::FromDays(7); 157 duration = 7;
166 }
167 return base::TimeDelta::FromDays(duration); 158 return base::TimeDelta::FromDays(duration);
168 } 159 }
169 160
170 } // namespace params 161 } // namespace params
171 162
172 bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() { 163 bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() {
173 // By convention, an experiment in the client-side previews study enables use 164 // By convention, an experiment in the client-side previews study enables use
174 // of at least one client-side previews optimization if its name begins with 165 // of at least one client-side previews optimization if its name begins with
175 // "Enabled." 166 // "Enabled."
176 return base::StartsWith( 167 return base::StartsWith(
(...skipping 14 matching lines...) Expand all
191 bool EnableOfflinePreviewsForTesting() { 182 bool EnableOfflinePreviewsForTesting() {
192 std::map<std::string, std::string> params; 183 std::map<std::string, std::string> params;
193 params[kOfflinePagesSlowNetwork] = kExperimentEnabled; 184 params[kOfflinePagesSlowNetwork] = kExperimentEnabled;
194 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial, 185 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial,
195 kEnabled, params) && 186 kEnabled, params) &&
196 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial, 187 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial,
197 kEnabled); 188 kEnabled);
198 } 189 }
199 190
200 } // namespace previews 191 } // namespace previews
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698