| Index: components/previews/core/previews_experiments.cc
|
| diff --git a/components/previews/core/previews_experiments.cc b/components/previews/core/previews_experiments.cc
|
| index afd1fff87f1ee8db5d3751c94b842d02c69d94ed..8730a5df73f984ad181031c8b3eb41f364480622 100644
|
| --- a/components/previews/core/previews_experiments.cc
|
| +++ b/components/previews/core/previews_experiments.cc
|
| @@ -19,89 +19,135 @@ namespace {
|
| // The group of client-side previews experiments.
|
| const char kClientSidePreviewsFieldTrial[] = "ClientSidePreviews";
|
|
|
| const char kEnabled[] = "Enabled";
|
|
|
| // Allow offline pages to show for prohibitively slow networks.
|
| const char kOfflinePagesSlowNetwork[] = "show_offline_pages";
|
|
|
| // The maximum number of recent previews navigations the black list looks at to
|
| // determine if a host is blacklisted.
|
| -const char kMaxStoredHistoryLength[] = "stored_history_length";
|
| +const char kMaxStoredHistoryLengthPerHost[] =
|
| + "per_host_max_stored_history_length";
|
| +
|
| +// The maximum number of recent previews navigations the black list looks at to
|
| +// determine if all previews navigations should be disallowed.
|
| +const char kMaxStoredHistoryLengthHostIndifferent[] =
|
| + "host_indifferent_max_stored_history_length";
|
|
|
| // The maximum number of hosts allowed in the in memory black list.
|
| const char kMaxHostsInBlackList[] = "max_hosts_in_blacklist";
|
|
|
| // The number of recent navigations that were opted out of that would trigger
|
| // the host to be blacklisted.
|
| -const char kOptOutThreshold[] = "opt_out_threshold";
|
| +const char kPerHostOptOutThreshold[] = "per_host_opt_out_threshold";
|
| +
|
| +// The number of recent navigations that were opted out of that would trigger
|
| +// all previews navigations to be disallowed.
|
| +const char kHostIndifferentOptOutThreshold[] =
|
| + "host_indifferent_opt_out_threshold";
|
|
|
| // The amount of time a host remains blacklisted due to opt outs.
|
| -const char kBlackListDurationInDays[] = "black_list_duration_in_days";
|
| +const char kPerHostBlackListDurationInDays[] =
|
| + "per_host_black_list_duration_in_days";
|
| +
|
| +// The amount of time a host remains blacklisted due to opt outs.
|
| +const char kHostIndifferentBlackListDurationInDays[] =
|
| + "host_indifferent_black_list_duration_in_days";
|
|
|
| // The string that corresponds to enabled for the variation param experiments.
|
| const char kExperimentEnabled[] = "true";
|
|
|
| -// In seconds. Hosts are blacklisted for 30 days.
|
| -constexpr int kDefaultBlackListDurationInDays = 30;
|
| +// Hosts are blacklisted for 30 days.
|
| +const int kDefaultPerHostDurationInDays = 30;
|
| +
|
| +// Host indifferent previews navigations are disallowed for 100 years.
|
| +constexpr int kDefaultHostIndifferentDurationInDays = 365 * 100;
|
|
|
| // Returns the parameter value of |param| as a string. If there is no value for
|
| // |param|, returns an empty string.
|
| std::string ParamValue(const std::string& param) {
|
| if (!IsIncludedInClientSidePreviewsExperimentsFieldTrial())
|
| return std::string();
|
| std::map<std::string, std::string> experiment_params;
|
| if (!variations::GetVariationParams(kClientSidePreviewsFieldTrial,
|
| &experiment_params)) {
|
| return std::string();
|
| }
|
| std::map<std::string, std::string>::const_iterator it =
|
| experiment_params.find(param);
|
| return it == experiment_params.end() ? std::string() : it->second;
|
| }
|
|
|
| } // namespace
|
|
|
| namespace params {
|
|
|
| -size_t MaxStoredHistoryLengthForBlackList() {
|
| - std::string param_value = ParamValue(kMaxStoredHistoryLength);
|
| +size_t MaxStoredHistoryLengthForPerHostBlackList() {
|
| + std::string param_value = ParamValue(kMaxStoredHistoryLengthPerHost);
|
| size_t history_length;
|
| if (!base::StringToSizeT(param_value, &history_length)) {
|
| return 4;
|
| }
|
| return history_length;
|
| }
|
|
|
| +size_t MaxStoredHistoryLengthForHostIndifferentBlackList() {
|
| + std::string param_value = ParamValue(kMaxStoredHistoryLengthHostIndifferent);
|
| + size_t history_length;
|
| + if (!base::StringToSizeT(param_value, &history_length)) {
|
| + return 10;
|
| + }
|
| + return history_length;
|
| +}
|
| +
|
| size_t MaxInMemoryHostsInBlackList() {
|
| std::string param_value = ParamValue(kMaxHostsInBlackList);
|
| size_t max_hosts;
|
| if (!base::StringToSizeT(param_value, &max_hosts)) {
|
| return 100;
|
| }
|
| return max_hosts;
|
| }
|
|
|
| -int BlackListOptOutThreshold() {
|
| - std::string param_value = ParamValue(kOptOutThreshold);
|
| +int PerHostBlackListOptOutThreshold() {
|
| + std::string param_value = ParamValue(kPerHostOptOutThreshold);
|
| int opt_out_threshold;
|
| if (!base::StringToInt(param_value, &opt_out_threshold)) {
|
| return 2;
|
| }
|
| return opt_out_threshold;
|
| }
|
|
|
| -base::TimeDelta BlackListDuration() {
|
| - std::string param_value = ParamValue(kBlackListDurationInDays);
|
| +int HostIndifferentBlackListOptOutThreshold() {
|
| + std::string param_value = ParamValue(kHostIndifferentOptOutThreshold);
|
| + int opt_out_threshold;
|
| + if (!base::StringToInt(param_value, &opt_out_threshold)) {
|
| + return 4;
|
| + }
|
| + return opt_out_threshold;
|
| +}
|
| +
|
| +base::TimeDelta PerHostBlackListDuration() {
|
| + std::string param_value = ParamValue(kPerHostBlackListDurationInDays);
|
| + int duration;
|
| + if (!base::StringToInt(param_value, &duration)) {
|
| + return base::TimeDelta::FromDays(kDefaultPerHostDurationInDays);
|
| + }
|
| + return base::TimeDelta::FromDays(duration);
|
| +}
|
| +
|
| +base::TimeDelta HostIndifferentBlackListPerHostDuration() {
|
| + std::string param_value = ParamValue(kHostIndifferentBlackListDurationInDays);
|
| int duration;
|
| if (!base::StringToInt(param_value, &duration)) {
|
| - return base::TimeDelta::FromDays(kDefaultBlackListDurationInDays);
|
| + return base::TimeDelta::FromDays(kDefaultHostIndifferentDurationInDays);
|
| }
|
| return base::TimeDelta::FromDays(duration);
|
| }
|
|
|
| } // namespace params
|
|
|
| bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() {
|
| // By convention, an experiment in the client-side previews study enables use
|
| // of at least one client-side previews optimization if its name begins with
|
| // "Enabled."
|
|
|