Chromium Code Reviews| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 | 62 // The amount of time that an offline page is considered fresh enough to be |
| 63 // shown as a preview. | 63 // shown as a preview. |
| 64 const char kOfflinePreviewFreshnessDurationInDays[] = | 64 const char kOfflinePreviewFreshnessDurationInDays[] = |
| 65 "offline_preview_freshness_duration_in_days"; | 65 "offline_preview_freshness_duration_in_days"; |
| 66 | 66 |
| 67 // The threshold of EffectiveConnectionType above which previews will not be | |
| 68 // served. | |
| 69 // See net/nqe/effective_connection_type.h for mapping from int to value. | |
| 70 const char kEffectiveConnectionTypeThreshold[] = | |
| 71 "max_allowed_effective_connection_type"; | |
| 72 | |
| 67 // The string that corresponds to enabled for the variation param experiments. | 73 // The string that corresponds to enabled for the variation param experiments. |
| 68 const char kExperimentEnabled[] = "true"; | 74 const char kExperimentEnabled[] = "true"; |
| 69 | 75 |
| 70 // Returns the parameter value of |param| as a string. If there is no value for | 76 // Returns the parameter value of |param| as a string. If there is no value for |
| 71 // |param|, returns an empty string. | 77 // |param|, returns an empty string. |
| 72 std::string ParamValue(const std::string& param) { | 78 std::string ParamValue(const std::string& param) { |
| 73 if (!IsIncludedInClientSidePreviewsExperimentsFieldTrial()) | 79 if (!IsIncludedInClientSidePreviewsExperimentsFieldTrial()) |
| 74 return std::string(); | 80 return std::string(); |
| 75 std::map<std::string, std::string> experiment_params; | 81 std::map<std::string, std::string> experiment_params; |
| 76 if (!variations::GetVariationParams(kClientSidePreviewsFieldTrial, | 82 if (!variations::GetVariationParams(kClientSidePreviewsFieldTrial, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 } | 157 } |
| 152 | 158 |
| 153 base::TimeDelta OfflinePreviewFreshnessDuration() { | 159 base::TimeDelta OfflinePreviewFreshnessDuration() { |
| 154 std::string param_value = ParamValue(kOfflinePreviewFreshnessDurationInDays); | 160 std::string param_value = ParamValue(kOfflinePreviewFreshnessDurationInDays); |
| 155 int duration; | 161 int duration; |
| 156 if (!base::StringToInt(param_value, &duration)) | 162 if (!base::StringToInt(param_value, &duration)) |
| 157 duration = 7; | 163 duration = 7; |
| 158 return base::TimeDelta::FromDays(duration); | 164 return base::TimeDelta::FromDays(duration); |
| 159 } | 165 } |
| 160 | 166 |
| 167 net::EffectiveConnectionType EffectiveConnectionTypeThreshold() { | |
| 168 std::string param_value = ParamValue(kEffectiveConnectionTypeThreshold); | |
| 169 int effective_type_value; | |
| 170 if (!base::StringToInt(param_value, &effective_type_value)) { | |
|
tbansal1
2017/02/02 00:13:40
You may want to use this function:
https://cs.chro
RyanSturm
2017/02/02 00:22:28
Done. Thanks.
| |
| 171 effective_type_value = | |
|
tbansal1
2017/02/02 00:13:40
Instead of 2 static casts, may be just return E_C_
RyanSturm
2017/02/02 00:22:28
Acknowledged.
| |
| 172 static_cast<int>(net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); | |
| 173 } | |
| 174 return static_cast<net::EffectiveConnectionType>(effective_type_value); | |
| 175 } | |
| 176 | |
| 161 } // namespace params | 177 } // namespace params |
| 162 | 178 |
| 163 bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() { | 179 bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() { |
| 164 // By convention, an experiment in the client-side previews study enables use | 180 // By convention, an experiment in the client-side previews study enables use |
| 165 // of at least one client-side previews optimization if its name begins with | 181 // of at least one client-side previews optimization if its name begins with |
| 166 // "Enabled." | 182 // "Enabled." |
| 167 return base::StartsWith( | 183 return base::StartsWith( |
| 168 base::FieldTrialList::FindFullName(kClientSidePreviewsFieldTrial), | 184 base::FieldTrialList::FindFullName(kClientSidePreviewsFieldTrial), |
| 169 kEnabled, base::CompareCase::SENSITIVE); | 185 kEnabled, base::CompareCase::SENSITIVE); |
| 170 } | 186 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 182 bool EnableOfflinePreviewsForTesting() { | 198 bool EnableOfflinePreviewsForTesting() { |
| 183 std::map<std::string, std::string> params; | 199 std::map<std::string, std::string> params; |
| 184 params[kOfflinePagesSlowNetwork] = kExperimentEnabled; | 200 params[kOfflinePagesSlowNetwork] = kExperimentEnabled; |
| 185 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial, | 201 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial, |
| 186 kEnabled, params) && | 202 kEnabled, params) && |
| 187 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial, | 203 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial, |
| 188 kEnabled); | 204 kEnabled); |
| 189 } | 205 } |
| 190 | 206 |
| 191 } // namespace previews | 207 } // namespace previews |
| OLD | NEW |