Index: components/previews/core/previews_experiments.cc |
diff --git a/components/previews/core/previews_experiments.cc b/components/previews/core/previews_experiments.cc |
index a236ab0bbdfffc7c2f59a14c87718880435567ad..9c9d765802448a4a74efadf8273428b0a6a96cc3 100644 |
--- a/components/previews/core/previews_experiments.cc |
+++ b/components/previews/core/previews_experiments.cc |
@@ -1,60 +1,124 @@ |
// Copyright 2016 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
#include "components/previews/core/previews_experiments.h" |
#include <map> |
#include <string> |
#include "base/metrics/field_trial.h" |
+#include "base/strings/string_number_conversions.h" |
#include "base/strings/string_util.h" |
#include "components/variations/variations_associated_data.h" |
+namespace previews { |
+ |
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 domain is blacklisted. |
tbansal1
2016/09/22 21:12:28
s/domain/host/
and everywhere else.
RyanSturm
2016/09/23 17:23:25
Done.
|
+const char kMaxStoredHistoryLength[] = "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 domain to be blacklisted. |
+const char kOptOutThreshold[] = "opt_out_threshold"; |
+ |
+// The amount of time a domain remains blacklisted due to opt outs. |
+const char kBlackListDurationInDays[] = "black_list_duration_in_days"; |
+ |
// The string that corresponds to enabled for the variation param experiments. |
const char kExperimentEnabled[] = "true"; |
+// In seconds. Domains are blacklisted for 30 days. |
+constexpr int kDefaultBlackListDurationInDays = 30; |
+ |
+// 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 previews { |
+namespace params { |
+ |
+size_t MaxStoredHistoryLengthForBlackList() { |
+ std::string param_value = ParamValue(kMaxStoredHistoryLength); |
+ size_t history_length; |
+ if (!base::StringToSizeT(param_value, &history_length)) { |
+ return 4; |
+ } |
+ 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 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 duration; |
+ if (!base::StringToInt(param_value, &duration)) { |
+ return base::TimeDelta::FromDays(kDefaultBlackListDurationInDays); |
+ } |
+ 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." |
return base::StartsWith( |
base::FieldTrialList::FindFullName(kClientSidePreviewsFieldTrial), |
kEnabled, base::CompareCase::SENSITIVE); |
} |
bool IsOfflinePreviewsEnabled() { |
- if (!IsIncludedInClientSidePreviewsExperimentsFieldTrial()) |
- return false; |
- std::map<std::string, std::string> experiment_params; |
- if (!variations::GetVariationParams(kClientSidePreviewsFieldTrial, |
- &experiment_params)) { |
- return false; |
- } |
- std::map<std::string, std::string>::const_iterator it = |
- experiment_params.find(kOfflinePagesSlowNetwork); |
- return it != experiment_params.end() && it->second == kExperimentEnabled; |
+ return ParamValue(kOfflinePagesSlowNetwork) == kExperimentEnabled; |
} |
bool EnableOfflinePreviewsForTesting() { |
std::map<std::string, std::string> params; |
params[kOfflinePagesSlowNetwork] = kExperimentEnabled; |
return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial, |
kEnabled, params) && |
base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial, |
kEnabled); |
} |