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

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

Issue 2439203002: Adding a short blacklist period after every previews opt out (Closed)
Patch Set: tbansal commetns Created 4 years, 1 month 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 | « components/previews/core/previews_experiments.h ('k') | 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 21 matching lines...) Expand all
32 // The maximum number of hosts allowed in the in memory black list. 32 // The maximum number of hosts allowed in the in memory black list.
33 const char kMaxHostsInBlackList[] = "max_hosts_in_blacklist"; 33 const char kMaxHostsInBlackList[] = "max_hosts_in_blacklist";
34 34
35 // The number of recent navigations that were opted out of that would trigger 35 // The number of recent navigations that were opted out of that would trigger
36 // the host to be blacklisted. 36 // the host to be blacklisted.
37 const char kOptOutThreshold[] = "opt_out_threshold"; 37 const char kOptOutThreshold[] = "opt_out_threshold";
38 38
39 // The amount of time a host remains blacklisted due to opt outs. 39 // The amount of time a host remains blacklisted due to opt outs.
40 const char kBlackListDurationInDays[] = "black_list_duration_in_days"; 40 const char kBlackListDurationInDays[] = "black_list_duration_in_days";
41 41
42 // The amount of time after any opt out that no previews should be shown.
43 const char kSingleOptOutDurationInSeconds[] =
44 "single_opt_out_duration_in_seconds";
45
42 // The string that corresponds to enabled for the variation param experiments. 46 // The string that corresponds to enabled for the variation param experiments.
43 const char kExperimentEnabled[] = "true"; 47 const char kExperimentEnabled[] = "true";
44 48
45 // In seconds. Hosts are blacklisted for 30 days. 49 // In seconds. Hosts are blacklisted for 30 days.
46 constexpr int kDefaultBlackListDurationInDays = 30; 50 const int kDefaultBlackListDurationInDays = 30;
51
52 // In seconds. Previews are not shown for 5 minutes after an opt out.
53 constexpr int kDefaultSingleOptOutDurationInSeconds = 60 * 5;
47 54
48 // Returns the parameter value of |param| as a string. If there is no value for 55 // Returns the parameter value of |param| as a string. If there is no value for
49 // |param|, returns an empty string. 56 // |param|, returns an empty string.
50 std::string ParamValue(const std::string& param) { 57 std::string ParamValue(const std::string& param) {
51 if (!IsIncludedInClientSidePreviewsExperimentsFieldTrial()) 58 if (!IsIncludedInClientSidePreviewsExperimentsFieldTrial())
52 return std::string(); 59 return std::string();
53 std::map<std::string, std::string> experiment_params; 60 std::map<std::string, std::string> experiment_params;
54 if (!variations::GetVariationParams(kClientSidePreviewsFieldTrial, 61 if (!variations::GetVariationParams(kClientSidePreviewsFieldTrial,
55 &experiment_params)) { 62 &experiment_params)) {
56 return std::string(); 63 return std::string();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 100
94 base::TimeDelta BlackListDuration() { 101 base::TimeDelta BlackListDuration() {
95 std::string param_value = ParamValue(kBlackListDurationInDays); 102 std::string param_value = ParamValue(kBlackListDurationInDays);
96 int duration; 103 int duration;
97 if (!base::StringToInt(param_value, &duration)) { 104 if (!base::StringToInt(param_value, &duration)) {
98 return base::TimeDelta::FromDays(kDefaultBlackListDurationInDays); 105 return base::TimeDelta::FromDays(kDefaultBlackListDurationInDays);
99 } 106 }
100 return base::TimeDelta::FromDays(duration); 107 return base::TimeDelta::FromDays(duration);
101 } 108 }
102 109
110 base::TimeDelta SingleOptOutDuration() {
111 std::string param_value = ParamValue(kSingleOptOutDurationInSeconds);
112 int duration;
113 if (!base::StringToInt(param_value, &duration)) {
114 return base::TimeDelta::FromSeconds(kDefaultSingleOptOutDurationInSeconds);
115 }
116 return base::TimeDelta::FromSeconds(duration);
117 }
118
103 } // namespace params 119 } // namespace params
104 120
105 bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() { 121 bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() {
106 // By convention, an experiment in the client-side previews study enables use 122 // By convention, an experiment in the client-side previews study enables use
107 // of at least one client-side previews optimization if its name begins with 123 // of at least one client-side previews optimization if its name begins with
108 // "Enabled." 124 // "Enabled."
109 return base::StartsWith( 125 return base::StartsWith(
110 base::FieldTrialList::FindFullName(kClientSidePreviewsFieldTrial), 126 base::FieldTrialList::FindFullName(kClientSidePreviewsFieldTrial),
111 kEnabled, base::CompareCase::SENSITIVE); 127 kEnabled, base::CompareCase::SENSITIVE);
112 } 128 }
(...skipping 11 matching lines...) Expand all
124 bool EnableOfflinePreviewsForTesting() { 140 bool EnableOfflinePreviewsForTesting() {
125 std::map<std::string, std::string> params; 141 std::map<std::string, std::string> params;
126 params[kOfflinePagesSlowNetwork] = kExperimentEnabled; 142 params[kOfflinePagesSlowNetwork] = kExperimentEnabled;
127 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial, 143 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial,
128 kEnabled, params) && 144 kEnabled, params) &&
129 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial, 145 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial,
130 kEnabled); 146 kEnabled);
131 } 147 }
132 148
133 } // namespace previews 149 } // namespace previews
OLDNEW
« no previous file with comments | « components/previews/core/previews_experiments.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698