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

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

Issue 2442013003: Add non-host functionality to the previews blacklist (Closed)
Patch Set: rebase 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
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"
11 #include "base/metrics/field_trial.h" 11 #include "base/metrics/field_trial.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "components/variations/variations_associated_data.h" 14 #include "components/variations/variations_associated_data.h"
15 15
16 namespace previews { 16 namespace previews {
17 17
18 namespace { 18 namespace {
19 19
20 // The group of client-side previews experiments. 20 // The group of client-side previews experiments.
21 const char kClientSidePreviewsFieldTrial[] = "ClientSidePreviews"; 21 const char kClientSidePreviewsFieldTrial[] = "ClientSidePreviews";
22 22
23 const char kEnabled[] = "Enabled"; 23 const char kEnabled[] = "Enabled";
24 24
25 // Allow offline pages to show for prohibitively slow networks. 25 // Allow offline pages to show for prohibitively slow networks.
26 const char kOfflinePagesSlowNetwork[] = "show_offline_pages"; 26 const char kOfflinePagesSlowNetwork[] = "show_offline_pages";
27 27
28 // The maximum number of recent previews navigations the black list looks at to 28 // The maximum number of recent previews navigations the black list looks at to
29 // determine if a host is blacklisted. 29 // determine if a host is blacklisted.
30 const char kMaxStoredHistoryLength[] = "stored_history_length"; 30 const char kMaxStoredHistoryLengthPerHost[] =
31 "per_host_max_stored_history_length";
32
33 // The maximum number of recent previews navigations the black list looks at to
34 // determine if all previews navigations should be disallowed.
35 const char kMaxStoredHistoryLengthHostIndifferent[] =
36 "host_indifferent_max_stored_history_length";
31 37
32 // The maximum number of hosts allowed in the in memory black list. 38 // The maximum number of hosts allowed in the in memory black list.
33 const char kMaxHostsInBlackList[] = "max_hosts_in_blacklist"; 39 const char kMaxHostsInBlackList[] = "max_hosts_in_blacklist";
34 40
35 // The number of recent navigations that were opted out of that would trigger 41 // The number of recent navigations that were opted out of that would trigger
36 // the host to be blacklisted. 42 // the host to be blacklisted.
37 const char kOptOutThreshold[] = "opt_out_threshold"; 43 const char kPerHostOptOutThreshold[] = "per_host_opt_out_threshold";
44
45 // The number of recent navigations that were opted out of that would trigger
46 // all previews navigations to be disallowed.
47 const char kHostIndifferentOptOutThreshold[] =
48 "host_indifferent_opt_out_threshold";
38 49
39 // The amount of time a host remains blacklisted due to opt outs. 50 // The amount of time a host remains blacklisted due to opt outs.
40 const char kBlackListDurationInDays[] = "black_list_duration_in_days"; 51 const char kPerHostBlackListDurationInDays[] =
52 "per_host_black_list_duration_in_days";
53
54 // The amount of time a host remains blacklisted due to opt outs.
55 const char kHostIndifferentBlackListDurationInDays[] =
56 "host_indifferent_black_list_duration_in_days";
41 57
42 // The amount of time after any opt out that no previews should be shown. 58 // The amount of time after any opt out that no previews should be shown.
43 const char kSingleOptOutDurationInSeconds[] = 59 const char kSingleOptOutDurationInSeconds[] =
44 "single_opt_out_duration_in_seconds"; 60 "single_opt_out_duration_in_seconds";
45 61
46 // The string that corresponds to enabled for the variation param experiments. 62 // The string that corresponds to enabled for the variation param experiments.
47 const char kExperimentEnabled[] = "true"; 63 const char kExperimentEnabled[] = "true";
48 64
49 // In seconds. Hosts are blacklisted for 30 days. 65 // Hosts are blacklisted for 30 days.
50 const int kDefaultBlackListDurationInDays = 30; 66 const int kDefaultPerHostDurationInDays = 30;
67
68 // Host indifferent previews navigations are disallowed for 100 years.
69 constexpr int kDefaultHostIndifferentDurationInDays = 365 * 100;
51 70
52 // In seconds. Previews are not shown for 5 minutes after an opt out. 71 // In seconds. Previews are not shown for 5 minutes after an opt out.
53 constexpr int kDefaultSingleOptOutDurationInSeconds = 60 * 5; 72 constexpr int kDefaultSingleOptOutDurationInSeconds = 60 * 5;
54 73
55 // Returns the parameter value of |param| as a string. If there is no value for 74 // Returns the parameter value of |param| as a string. If there is no value for
56 // |param|, returns an empty string. 75 // |param|, returns an empty string.
57 std::string ParamValue(const std::string& param) { 76 std::string ParamValue(const std::string& param) {
58 if (!IsIncludedInClientSidePreviewsExperimentsFieldTrial()) 77 if (!IsIncludedInClientSidePreviewsExperimentsFieldTrial())
59 return std::string(); 78 return std::string();
60 std::map<std::string, std::string> experiment_params; 79 std::map<std::string, std::string> experiment_params;
61 if (!variations::GetVariationParams(kClientSidePreviewsFieldTrial, 80 if (!variations::GetVariationParams(kClientSidePreviewsFieldTrial,
62 &experiment_params)) { 81 &experiment_params)) {
63 return std::string(); 82 return std::string();
64 } 83 }
65 std::map<std::string, std::string>::const_iterator it = 84 std::map<std::string, std::string>::const_iterator it =
66 experiment_params.find(param); 85 experiment_params.find(param);
67 return it == experiment_params.end() ? std::string() : it->second; 86 return it == experiment_params.end() ? std::string() : it->second;
68 } 87 }
69 88
70 } // namespace 89 } // namespace
71 90
72 namespace params { 91 namespace params {
73 92
74 size_t MaxStoredHistoryLengthForBlackList() { 93 size_t MaxStoredHistoryLengthForPerHostBlackList() {
75 std::string param_value = ParamValue(kMaxStoredHistoryLength); 94 std::string param_value = ParamValue(kMaxStoredHistoryLengthPerHost);
76 size_t history_length; 95 size_t history_length;
77 if (!base::StringToSizeT(param_value, &history_length)) { 96 if (!base::StringToSizeT(param_value, &history_length)) {
78 return 4; 97 return 4;
79 } 98 }
80 return history_length; 99 return history_length;
81 } 100 }
82 101
102 size_t MaxStoredHistoryLengthForHostIndifferentBlackList() {
103 std::string param_value = ParamValue(kMaxStoredHistoryLengthHostIndifferent);
104 size_t history_length;
105 if (!base::StringToSizeT(param_value, &history_length)) {
106 return 10;
107 }
108 return history_length;
109 }
110
83 size_t MaxInMemoryHostsInBlackList() { 111 size_t MaxInMemoryHostsInBlackList() {
84 std::string param_value = ParamValue(kMaxHostsInBlackList); 112 std::string param_value = ParamValue(kMaxHostsInBlackList);
85 size_t max_hosts; 113 size_t max_hosts;
86 if (!base::StringToSizeT(param_value, &max_hosts)) { 114 if (!base::StringToSizeT(param_value, &max_hosts)) {
87 return 100; 115 return 100;
88 } 116 }
89 return max_hosts; 117 return max_hosts;
90 } 118 }
91 119
92 int BlackListOptOutThreshold() { 120 int PerHostBlackListOptOutThreshold() {
93 std::string param_value = ParamValue(kOptOutThreshold); 121 std::string param_value = ParamValue(kPerHostOptOutThreshold);
94 int opt_out_threshold; 122 int opt_out_threshold;
95 if (!base::StringToInt(param_value, &opt_out_threshold)) { 123 if (!base::StringToInt(param_value, &opt_out_threshold)) {
96 return 2; 124 return 2;
97 } 125 }
98 return opt_out_threshold; 126 return opt_out_threshold;
99 } 127 }
100 128
101 base::TimeDelta BlackListDuration() { 129 int HostIndifferentBlackListOptOutThreshold() {
102 std::string param_value = ParamValue(kBlackListDurationInDays); 130 std::string param_value = ParamValue(kHostIndifferentOptOutThreshold);
131 int opt_out_threshold;
132 if (!base::StringToInt(param_value, &opt_out_threshold)) {
133 return 4;
134 }
135 return opt_out_threshold;
136 }
137
138 base::TimeDelta PerHostBlackListDuration() {
139 std::string param_value = ParamValue(kPerHostBlackListDurationInDays);
103 int duration; 140 int duration;
104 if (!base::StringToInt(param_value, &duration)) { 141 if (!base::StringToInt(param_value, &duration)) {
105 return base::TimeDelta::FromDays(kDefaultBlackListDurationInDays); 142 return base::TimeDelta::FromDays(kDefaultPerHostDurationInDays);
143 }
144 return base::TimeDelta::FromDays(duration);
145 }
146
147 base::TimeDelta HostIndifferentBlackListPerHostDuration() {
148 std::string param_value = ParamValue(kHostIndifferentBlackListDurationInDays);
149 int duration;
150 if (!base::StringToInt(param_value, &duration)) {
151 return base::TimeDelta::FromDays(kDefaultHostIndifferentDurationInDays);
tbansal1 2016/10/28 21:59:34 why not just use 365*100 directly like other funct
RyanSturm 2016/11/02 19:52:30 Done.
106 } 152 }
107 return base::TimeDelta::FromDays(duration); 153 return base::TimeDelta::FromDays(duration);
108 } 154 }
109 155
110 base::TimeDelta SingleOptOutDuration() { 156 base::TimeDelta SingleOptOutDuration() {
111 std::string param_value = ParamValue(kSingleOptOutDurationInSeconds); 157 std::string param_value = ParamValue(kSingleOptOutDurationInSeconds);
112 int duration; 158 int duration;
113 if (!base::StringToInt(param_value, &duration)) { 159 if (!base::StringToInt(param_value, &duration)) {
114 return base::TimeDelta::FromSeconds(kDefaultSingleOptOutDurationInSeconds); 160 return base::TimeDelta::FromSeconds(kDefaultSingleOptOutDurationInSeconds);
115 } 161 }
(...skipping 24 matching lines...) Expand all
140 bool EnableOfflinePreviewsForTesting() { 186 bool EnableOfflinePreviewsForTesting() {
141 std::map<std::string, std::string> params; 187 std::map<std::string, std::string> params;
142 params[kOfflinePagesSlowNetwork] = kExperimentEnabled; 188 params[kOfflinePagesSlowNetwork] = kExperimentEnabled;
143 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial, 189 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial,
144 kEnabled, params) && 190 kEnabled, params) &&
145 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial, 191 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial,
146 kEnabled); 192 kEnabled);
147 } 193 }
148 194
149 } // namespace previews 195 } // namespace previews
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698