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

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

Issue 2166363003: Offline pages using NQE 2G Slow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: thestig comments Created 4 years, 4 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/previews_experiments.h" 5 #include "components/previews/previews_experiments.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "components/variations/variations_associated_data.h" 12 #include "components/variations/variations_associated_data.h"
13 13
14 namespace { 14 namespace {
15 15
16 // The group of client-side previews experiments. 16 // The group of client-side previews experiments.
17 const char kClientSidePreviewsFieldTrial[] = "ClientSidePreviews"; 17 const char kClientSidePreviewsFieldTrial[] = "ClientSidePreviews";
18 18
19 const char kEnabled[] = "Enabled"; 19 const char kEnabled[] = "Enabled";
20 20
21 // Allow offline pages to show for prohibitively slow networks. 21 // Allow offline pages to show for prohibitively slow networks.
22 const char kOfflinePagesSlowNetwork[] = "show_offline_pages"; 22 const char kOfflinePagesSlowNetwork[] = "show_offline_pages";
23 23
24 // The string that corresponds to enabled for the variation param experiments.
25 const char kExperimentEnabled[] = "true";
26
24 } // namespace 27 } // namespace
25 28
26 namespace previews { 29 namespace previews {
27 30
28 bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() { 31 bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() {
29 // By convention, an experiment in the client-side previews study enables use 32 // By convention, an experiment in the client-side previews study enables use
30 // of at least one client-side previews optimization if its name begins with 33 // of at least one client-side previews optimization if its name begins with
31 // "Enabled." 34 // "Enabled."
32 return base::StartsWith( 35 return base::StartsWith(
33 base::FieldTrialList::FindFullName(kClientSidePreviewsFieldTrial), 36 base::FieldTrialList::FindFullName(kClientSidePreviewsFieldTrial),
34 kEnabled, base::CompareCase::SENSITIVE); 37 kEnabled, base::CompareCase::SENSITIVE);
35 } 38 }
36 39
37 bool IsOfflinePreviewsEnabled() { 40 bool IsOfflinePreviewsEnabled() {
38 if (!IsIncludedInClientSidePreviewsExperimentsFieldTrial()) 41 if (!IsIncludedInClientSidePreviewsExperimentsFieldTrial())
39 return false; 42 return false;
40 std::map<std::string, std::string> experiment_params; 43 std::map<std::string, std::string> experiment_params;
41 if (!variations::GetVariationParams(kClientSidePreviewsFieldTrial, 44 if (!variations::GetVariationParams(kClientSidePreviewsFieldTrial,
42 &experiment_params)) { 45 &experiment_params)) {
43 return false; 46 return false;
44 } 47 }
45 std::map<std::string, std::string>::const_iterator it = 48 std::map<std::string, std::string>::const_iterator it =
46 experiment_params.find(kOfflinePagesSlowNetwork); 49 experiment_params.find(kOfflinePagesSlowNetwork);
47 return it != experiment_params.end() && it->second == "true"; 50 return it != experiment_params.end() && it->second == kExperimentEnabled;
51 }
52
53 bool EnableOfflinePreviewsForTesting() {
54 std::map<std::string, std::string> params;
55 params[kOfflinePagesSlowNetwork] = kExperimentEnabled;
56 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial,
57 kEnabled, params) &&
58 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial,
59 kEnabled);
48 } 60 }
49 61
50 } // namespace previews 62 } // namespace previews
OLDNEW
« no previous file with comments | « components/previews/previews_experiments.h ('k') | components/previews/previews_experiments_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698