| 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 <string> | |
| 8 | |
| 9 #include "base/logging.h" | 7 #include "base/logging.h" |
| 10 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 11 #include "base/metrics/field_trial_params.h" | 9 #include "base/metrics/field_trial_params.h" |
| 12 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 14 | 12 |
| 15 namespace previews { | 13 namespace previews { |
| 16 | 14 |
| 17 namespace { | 15 namespace { |
| 18 | 16 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 GetParamValueAsInt(kClientSidePreviewsFieldTrial, | 119 GetParamValueAsInt(kClientSidePreviewsFieldTrial, |
| 122 "single_opt_out_duration_in_seconds", 60 * 5)); | 120 "single_opt_out_duration_in_seconds", 60 * 5)); |
| 123 } | 121 } |
| 124 | 122 |
| 125 base::TimeDelta OfflinePreviewFreshnessDuration() { | 123 base::TimeDelta OfflinePreviewFreshnessDuration() { |
| 126 return base::TimeDelta::FromDays( | 124 return base::TimeDelta::FromDays( |
| 127 GetParamValueAsInt(kClientSidePreviewsFieldTrial, | 125 GetParamValueAsInt(kClientSidePreviewsFieldTrial, |
| 128 "offline_preview_freshness_duration_in_days", 7)); | 126 "offline_preview_freshness_duration_in_days", 7)); |
| 129 } | 127 } |
| 130 | 128 |
| 131 net::EffectiveConnectionType EffectiveConnectionTypeThresholdForOffline() { | 129 net::EffectiveConnectionType EffectiveConnectionTypeThreshold() { |
| 132 return GetParamValueAsECT(kClientSidePreviewsFieldTrial, | 130 return GetParamValueAsECT(kClientSidePreviewsFieldTrial, |
| 133 kEffectiveConnectionTypeThreshold, | 131 kEffectiveConnectionTypeThreshold, |
| 134 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); | 132 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); |
| 135 } | 133 } |
| 136 | 134 |
| 137 bool IsOfflinePreviewsEnabled() { | 135 bool IsOfflinePreviewsEnabled() { |
| 138 // Check if "show_offline_pages" is set to "true". | 136 // Check if "show_offline_pages" is set to "true". |
| 139 return IsIncludedInClientSidePreviewsExperimentsFieldTrial() && | 137 return IsIncludedInClientSidePreviewsExperimentsFieldTrial() && |
| 140 base::GetFieldTrialParamValue(kClientSidePreviewsFieldTrial, | 138 base::GetFieldTrialParamValue(kClientSidePreviewsFieldTrial, |
| 141 kOfflinePagesSlowNetwork) == | 139 kOfflinePagesSlowNetwork) == |
| 142 kExperimentEnabled; | 140 kExperimentEnabled; |
| 143 } | 141 } |
| 144 | 142 |
| 145 int OfflinePreviewsVersion() { | 143 int OfflinePreviewsVersion() { |
| 146 return GetParamValueAsInt(kClientSidePreviewsFieldTrial, kVersion, 0); | 144 return GetParamValueAsInt(kClientSidePreviewsFieldTrial, kVersion, 0); |
| 147 } | 145 } |
| 148 | 146 |
| 149 bool IsClientLoFiEnabled() { | 147 bool IsClientLoFiEnabled() { |
| 150 return base::StartsWith( | 148 return base::StartsWith( |
| 151 base::FieldTrialList::FindFullName(kClientLoFiExperimentName), kEnabled, | 149 base::FieldTrialList::FindFullName(kClientLoFiExperimentName), kEnabled, |
| 152 base::CompareCase::SENSITIVE); | 150 base::CompareCase::SENSITIVE); |
| 153 } | 151 } |
| 154 | 152 |
| 155 int ClientLoFiVersion() { | 153 int LoFiVersion() { |
| 156 return GetParamValueAsInt(kClientLoFiExperimentName, kVersion, 0); | 154 return GetParamValueAsInt(kClientLoFiExperimentName, kVersion, 0); |
| 157 } | 155 } |
| 158 | 156 |
| 159 net::EffectiveConnectionType EffectiveConnectionTypeThresholdForClientLoFi() { | 157 net::EffectiveConnectionType EffectiveConnectionTypeThresholdForLoFi() { |
| 160 return GetParamValueAsECT(kClientLoFiExperimentName, | 158 return GetParamValueAsECT(kClientLoFiExperimentName, |
| 161 kEffectiveConnectionTypeThreshold, | 159 kEffectiveConnectionTypeThreshold, |
| 162 net::EFFECTIVE_CONNECTION_TYPE_2G); | 160 net::EFFECTIVE_CONNECTION_TYPE_2G); |
| 163 } | 161 } |
| 164 | 162 |
| 165 } // namespace params | 163 } // namespace params |
| 166 | 164 |
| 167 bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() { | 165 bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() { |
| 168 // By convention, an experiment in the client-side previews study enables use | 166 // By convention, an experiment in the client-side previews study enables use |
| 169 // of at least one client-side previews optimization if its name begins with | 167 // of at least one client-side previews optimization if its name begins with |
| 170 // "Enabled." | 168 // "Enabled." |
| 171 return base::StartsWith( | 169 return base::StartsWith( |
| 172 base::FieldTrialList::FindFullName(kClientSidePreviewsFieldTrial), | 170 base::FieldTrialList::FindFullName(kClientSidePreviewsFieldTrial), |
| 173 kEnabled, base::CompareCase::SENSITIVE); | 171 kEnabled, base::CompareCase::SENSITIVE); |
| 174 } | 172 } |
| 175 | 173 |
| 174 std::string GetStringNameForType(PreviewsType type) { |
| 175 switch (type) { |
| 176 case PreviewsType::OFFLINE: |
| 177 return "Offline"; |
| 178 case PreviewsType::LOFI: |
| 179 return "LoFi"; |
| 180 case PreviewsType::LITE_PAGE: |
| 181 return "LitePage"; |
| 182 case PreviewsType::NONE: |
| 183 case PreviewsType::LAST: |
| 184 break; |
| 185 } |
| 186 NOTREACHED(); |
| 187 return std::string(); |
| 188 } |
| 189 |
| 176 } // namespace previews | 190 } // namespace previews |
| OLD | NEW |