| OLD | NEW |
| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 "per_host_black_list_duration_in_days"; | 52 "per_host_black_list_duration_in_days"; |
| 53 | 53 |
| 54 // The amount of time a host remains blacklisted due to opt outs. | 54 // The amount of time a host remains blacklisted due to opt outs. |
| 55 const char kHostIndifferentBlackListDurationInDays[] = | 55 const char kHostIndifferentBlackListDurationInDays[] = |
| 56 "host_indifferent_black_list_duration_in_days"; | 56 "host_indifferent_black_list_duration_in_days"; |
| 57 | 57 |
| 58 // 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. |
| 59 const char kSingleOptOutDurationInSeconds[] = | 59 const char kSingleOptOutDurationInSeconds[] = |
| 60 "single_opt_out_duration_in_seconds"; | 60 "single_opt_out_duration_in_seconds"; |
| 61 | 61 |
| 62 // The amount of time that an offline page is considered fresh enough to be |
| 63 // shown as a preview. |
| 64 const char kOfflinePreviewFreshnessDurationInDays[] = |
| 65 "offline_preview_freshness_duration_in_days"; |
| 66 |
| 62 // The string that corresponds to enabled for the variation param experiments. | 67 // The string that corresponds to enabled for the variation param experiments. |
| 63 const char kExperimentEnabled[] = "true"; | 68 const char kExperimentEnabled[] = "true"; |
| 64 | 69 |
| 65 // Returns the parameter value of |param| as a string. If there is no value for | 70 // Returns the parameter value of |param| as a string. If there is no value for |
| 66 // |param|, returns an empty string. | 71 // |param|, returns an empty string. |
| 67 std::string ParamValue(const std::string& param) { | 72 std::string ParamValue(const std::string& param) { |
| 68 if (!IsIncludedInClientSidePreviewsExperimentsFieldTrial()) | 73 if (!IsIncludedInClientSidePreviewsExperimentsFieldTrial()) |
| 69 return std::string(); | 74 return std::string(); |
| 70 std::map<std::string, std::string> experiment_params; | 75 std::map<std::string, std::string> experiment_params; |
| 71 if (!variations::GetVariationParams(kClientSidePreviewsFieldTrial, | 76 if (!variations::GetVariationParams(kClientSidePreviewsFieldTrial, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 151 |
| 147 base::TimeDelta SingleOptOutDuration() { | 152 base::TimeDelta SingleOptOutDuration() { |
| 148 std::string param_value = ParamValue(kSingleOptOutDurationInSeconds); | 153 std::string param_value = ParamValue(kSingleOptOutDurationInSeconds); |
| 149 int duration; | 154 int duration; |
| 150 if (!base::StringToInt(param_value, &duration)) { | 155 if (!base::StringToInt(param_value, &duration)) { |
| 151 return base::TimeDelta::FromSeconds(60 * 5); | 156 return base::TimeDelta::FromSeconds(60 * 5); |
| 152 } | 157 } |
| 153 return base::TimeDelta::FromSeconds(duration); | 158 return base::TimeDelta::FromSeconds(duration); |
| 154 } | 159 } |
| 155 | 160 |
| 161 base::TimeDelta OfflinePreviewFreshnessDuration() { |
| 162 std::string param_value = ParamValue(kOfflinePreviewFreshnessDurationInDays); |
| 163 int duration; |
| 164 if (!base::StringToInt(param_value, &duration)) { |
| 165 return base::TimeDelta::FromDays(7); |
| 166 } |
| 167 return base::TimeDelta::FromDays(duration); |
| 168 } |
| 169 |
| 156 } // namespace params | 170 } // namespace params |
| 157 | 171 |
| 158 bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() { | 172 bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() { |
| 159 // By convention, an experiment in the client-side previews study enables use | 173 // By convention, an experiment in the client-side previews study enables use |
| 160 // of at least one client-side previews optimization if its name begins with | 174 // of at least one client-side previews optimization if its name begins with |
| 161 // "Enabled." | 175 // "Enabled." |
| 162 return base::StartsWith( | 176 return base::StartsWith( |
| 163 base::FieldTrialList::FindFullName(kClientSidePreviewsFieldTrial), | 177 base::FieldTrialList::FindFullName(kClientSidePreviewsFieldTrial), |
| 164 kEnabled, base::CompareCase::SENSITIVE); | 178 kEnabled, base::CompareCase::SENSITIVE); |
| 165 } | 179 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 177 bool EnableOfflinePreviewsForTesting() { | 191 bool EnableOfflinePreviewsForTesting() { |
| 178 std::map<std::string, std::string> params; | 192 std::map<std::string, std::string> params; |
| 179 params[kOfflinePagesSlowNetwork] = kExperimentEnabled; | 193 params[kOfflinePagesSlowNetwork] = kExperimentEnabled; |
| 180 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial, | 194 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial, |
| 181 kEnabled, params) && | 195 kEnabled, params) && |
| 182 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial, | 196 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial, |
| 183 kEnabled); | 197 kEnabled); |
| 184 } | 198 } |
| 185 | 199 |
| 186 } // namespace previews | 200 } // namespace previews |
| OLD | NEW |