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

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: Created 4 years, 2 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/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 20 matching lines...) Expand all
31 // The maximum number of hosts allowed in the in memory black list. 31 // The maximum number of hosts allowed in the in memory black list.
32 const char kMaxHostsInBlackList[] = "max_hosts_in_blacklist"; 32 const char kMaxHostsInBlackList[] = "max_hosts_in_blacklist";
33 33
34 // The number of recent navigations that were opted out of that would trigger 34 // The number of recent navigations that were opted out of that would trigger
35 // the host to be blacklisted. 35 // the host to be blacklisted.
36 const char kOptOutThreshold[] = "opt_out_threshold"; 36 const char kOptOutThreshold[] = "opt_out_threshold";
37 37
38 // The amount of time a host remains blacklisted due to opt outs. 38 // The amount of time a host remains blacklisted due to opt outs.
39 const char kBlackListDurationInDays[] = "black_list_duration_in_days"; 39 const char kBlackListDurationInDays[] = "black_list_duration_in_days";
40 40
41 // The amount of time after any opt out that no previews should be shown.
42 const char kSingleOptOutDurationInSeconds[] =
43 "single_opt_out_duration_in_seconds";
44
41 // The string that corresponds to enabled for the variation param experiments. 45 // The string that corresponds to enabled for the variation param experiments.
42 const char kExperimentEnabled[] = "true"; 46 const char kExperimentEnabled[] = "true";
43 47
44 // In seconds. Hosts are blacklisted for 30 days. 48 // In seconds. Hosts are blacklisted for 30 days.
45 constexpr int kDefaultBlackListDurationInDays = 30; 49 const int kDefaultBlackListDurationInDays = 30;
50
51 // In seconds. Previews are not show for 5 minutes after an opt out.
tbansal1 2016/10/21 23:15:34 s/show/shown/
RyanSturm 2016/10/24 21:18:25 Done.
52 constexpr int kDefaultSingleOptOutDurationInSeconds = 60 * 5;
46 53
47 // Returns the parameter value of |param| as a string. If there is no value for 54 // Returns the parameter value of |param| as a string. If there is no value for
48 // |param|, returns an empty string. 55 // |param|, returns an empty string.
49 std::string ParamValue(const std::string& param) { 56 std::string ParamValue(const std::string& param) {
50 if (!IsIncludedInClientSidePreviewsExperimentsFieldTrial()) 57 if (!IsIncludedInClientSidePreviewsExperimentsFieldTrial())
51 return std::string(); 58 return std::string();
52 std::map<std::string, std::string> experiment_params; 59 std::map<std::string, std::string> experiment_params;
53 if (!variations::GetVariationParams(kClientSidePreviewsFieldTrial, 60 if (!variations::GetVariationParams(kClientSidePreviewsFieldTrial,
54 &experiment_params)) { 61 &experiment_params)) {
55 return std::string(); 62 return std::string();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 99
93 base::TimeDelta BlackListDuration() { 100 base::TimeDelta BlackListDuration() {
94 std::string param_value = ParamValue(kBlackListDurationInDays); 101 std::string param_value = ParamValue(kBlackListDurationInDays);
95 int duration; 102 int duration;
96 if (!base::StringToInt(param_value, &duration)) { 103 if (!base::StringToInt(param_value, &duration)) {
97 return base::TimeDelta::FromDays(kDefaultBlackListDurationInDays); 104 return base::TimeDelta::FromDays(kDefaultBlackListDurationInDays);
98 } 105 }
99 return base::TimeDelta::FromDays(duration); 106 return base::TimeDelta::FromDays(duration);
100 } 107 }
101 108
109 base::TimeDelta SingleOptOutBlackOutDuration() {
110 std::string param_value = ParamValue(kSingleOptOutDurationInSeconds);
111 int duration;
112 if (!base::StringToInt(param_value, &duration)) {
113 return base::TimeDelta::FromSeconds(kDefaultSingleOptOutDurationInSeconds);
114 }
115 return base::TimeDelta::FromSeconds(duration);
116 }
117
102 } // namespace params 118 } // namespace params
103 119
104 bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() { 120 bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() {
105 // By convention, an experiment in the client-side previews study enables use 121 // By convention, an experiment in the client-side previews study enables use
106 // of at least one client-side previews optimization if its name begins with 122 // of at least one client-side previews optimization if its name begins with
107 // "Enabled." 123 // "Enabled."
108 return base::StartsWith( 124 return base::StartsWith(
109 base::FieldTrialList::FindFullName(kClientSidePreviewsFieldTrial), 125 base::FieldTrialList::FindFullName(kClientSidePreviewsFieldTrial),
110 kEnabled, base::CompareCase::SENSITIVE); 126 kEnabled, base::CompareCase::SENSITIVE);
111 } 127 }
112 128
113 bool IsOfflinePreviewsEnabled() { 129 bool IsOfflinePreviewsEnabled() {
114 return ParamValue(kOfflinePagesSlowNetwork) == kExperimentEnabled; 130 return ParamValue(kOfflinePagesSlowNetwork) == kExperimentEnabled;
115 } 131 }
116 132
117 bool EnableOfflinePreviewsForTesting() { 133 bool EnableOfflinePreviewsForTesting() {
118 std::map<std::string, std::string> params; 134 std::map<std::string, std::string> params;
119 params[kOfflinePagesSlowNetwork] = kExperimentEnabled; 135 params[kOfflinePagesSlowNetwork] = kExperimentEnabled;
120 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial, 136 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial,
121 kEnabled, params) && 137 kEnabled, params) &&
122 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial, 138 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial,
123 kEnabled); 139 kEnabled);
124 } 140 }
125 141
126 } // namespace previews 142 } // namespace previews
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698