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

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

Issue 2748033002: Revert of Moving previews code from components/ to chrome/ (Closed)
Patch Set: Created 3 years, 9 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 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 std::string param_value = 182 std::string param_value =
183 ClientSidePreviewsParamValue(kEffectiveConnectionTypeThreshold); 183 ClientSidePreviewsParamValue(kEffectiveConnectionTypeThreshold);
184 net::EffectiveConnectionType effective_connection_type; 184 net::EffectiveConnectionType effective_connection_type;
185 if (!net::GetEffectiveConnectionTypeForName(param_value, 185 if (!net::GetEffectiveConnectionTypeForName(param_value,
186 &effective_connection_type)) { 186 &effective_connection_type)) {
187 effective_connection_type = net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G; 187 effective_connection_type = net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G;
188 } 188 }
189 return effective_connection_type; 189 return effective_connection_type;
190 } 190 }
191 191
192 bool IsOfflinePreviewsEnabled() {
193 // Check if "show_offline_pages" is set to "true".
194 return ClientSidePreviewsParamValue(kOfflinePagesSlowNetwork) ==
195 kExperimentEnabled;
196 }
197
198 int OfflinePreviewsVersion() {
199 int version;
200 if (!base::StringToInt(ClientSidePreviewsParamValue(kVersion), &version))
201 version = 0;
202 return version;
203 }
204
205 } // namespace params 192 } // namespace params
206 193
207 bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() { 194 bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() {
208 // By convention, an experiment in the client-side previews study enables use 195 // By convention, an experiment in the client-side previews study enables use
209 // of at least one client-side previews optimization if its name begins with 196 // of at least one client-side previews optimization if its name begins with
210 // "Enabled." 197 // "Enabled."
211 return base::StartsWith( 198 return base::StartsWith(
212 base::FieldTrialList::FindFullName(kClientSidePreviewsFieldTrial), 199 base::FieldTrialList::FindFullName(kClientSidePreviewsFieldTrial),
213 kEnabled, base::CompareCase::SENSITIVE); 200 kEnabled, base::CompareCase::SENSITIVE);
214 } 201 }
215 202
203 bool IsPreviewsTypeEnabled(PreviewsType type) {
204 switch (type) {
205 case PreviewsType::OFFLINE:
206 return ClientSidePreviewsParamValue(kOfflinePagesSlowNetwork) ==
207 kExperimentEnabled;
208 default:
209 NOTREACHED();
210 return false;
211 }
212 }
213
214 int GetPreviewsTypeVersion(PreviewsType type) {
215 int version = 0; // default
216 switch (type) {
217 case PreviewsType::OFFLINE:
218 base::StringToInt(ClientSidePreviewsParamValue(kVersion), &version);
219 return version;
220 // List remaining enum cases vs. default to catch when new one is added.
221 case PreviewsType::NONE:
222 break;
223 case PreviewsType::LAST:
224 break;
225 }
226 NOTREACHED();
227 return -1;
228 }
229
230 std::unique_ptr<PreviewsTypeList> GetEnabledPreviews() {
231 std::unique_ptr<PreviewsTypeList> enabled_previews(new PreviewsTypeList());
232
233 // Loop across all previews types (relies on sequential enum values).
234 for (int i = static_cast<int>(PreviewsType::NONE) + 1;
235 i < static_cast<int>(PreviewsType::LAST); ++i) {
236 PreviewsType type = static_cast<PreviewsType>(i);
237 if (IsPreviewsTypeEnabled(type)) {
238 enabled_previews->push_back({type, GetPreviewsTypeVersion(type)});
239 }
240 }
241 return enabled_previews;
242 }
243
216 bool EnableOfflinePreviewsForTesting() { 244 bool EnableOfflinePreviewsForTesting() {
217 std::map<std::string, std::string> params; 245 std::map<std::string, std::string> params;
218 params[kOfflinePagesSlowNetwork] = kExperimentEnabled; 246 params[kOfflinePagesSlowNetwork] = kExperimentEnabled;
219 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial, 247 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial,
220 kEnabled, params) && 248 kEnabled, params) &&
221 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial, 249 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial,
222 kEnabled); 250 kEnabled);
223 } 251 }
224 252
225 } // namespace previews 253 } // namespace previews
OLDNEW
« no previous file with comments | « components/previews/core/previews_experiments.h ('k') | components/previews/core/previews_experiments_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698