Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: components/previews/core/previews_experiments.cc

Issue 2640023007: Adds PreviewsType version mechanism for clearing blacklist entries. (Closed)
Patch Set: Cleaned up commented include Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/metrics/field_trial.h" 11 #include "base/metrics/field_trial.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "components/variations/variations_associated_data.h" 14 #include "components/variations/variations_associated_data.h"
15 15
16 namespace previews { 16 namespace previews {
17 17
18 namespace { 18 namespace {
19 19
20 // The group of client-side previews experiments. 20 // The group of client-side previews experiments.
21 const char kClientSidePreviewsFieldTrial[] = "ClientSidePreviews"; 21 const char kClientSidePreviewsFieldTrial[] = "ClientSidePreviews";
22 22
23 const char kEnabled[] = "Enabled"; 23 const char kEnabled[] = "Enabled";
24 24
25 // Allow offline pages to show for prohibitively slow networks. 25 // Allow offline pages to show for prohibitively slow networks.
26 const char kOfflinePagesSlowNetwork[] = "show_offline_pages"; 26 const char kOfflinePagesSlowNetwork[] = "show_offline_pages";
27 27
28 // Version of treatment for showing offline pages, if enabled.
29 const char kOfflinePagesSlowNetworkVersion[] = "show_offline_pages.version";
30
28 // The maximum number of recent previews navigations the black list looks at to 31 // The maximum number of recent previews navigations the black list looks at to
29 // determine if a host is blacklisted. 32 // determine if a host is blacklisted.
30 const char kMaxStoredHistoryLengthPerHost[] = 33 const char kMaxStoredHistoryLengthPerHost[] =
31 "per_host_max_stored_history_length"; 34 "per_host_max_stored_history_length";
32 35
33 // The maximum number of recent previews navigations the black list looks at to 36 // The maximum number of recent previews navigations the black list looks at to
34 // determine if all previews navigations should be disallowed. 37 // determine if all previews navigations should be disallowed.
35 const char kMaxStoredHistoryLengthHostIndifferent[] = 38 const char kMaxStoredHistoryLengthHostIndifferent[] =
36 "host_indifferent_max_stored_history_length"; 39 "host_indifferent_max_stored_history_length";
37 40
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 bool IsPreviewsTypeEnabled(PreviewsType type) { 191 bool IsPreviewsTypeEnabled(PreviewsType type) {
189 switch (type) { 192 switch (type) {
190 case PreviewsType::OFFLINE: 193 case PreviewsType::OFFLINE:
191 return ParamValue(kOfflinePagesSlowNetwork) == kExperimentEnabled; 194 return ParamValue(kOfflinePagesSlowNetwork) == kExperimentEnabled;
192 default: 195 default:
193 NOTREACHED(); 196 NOTREACHED();
194 return false; 197 return false;
195 } 198 }
196 } 199 }
197 200
201 int GetPreviewsTypeVersion(PreviewsType type) {
202 DCHECK(IsPreviewsTypeEnabled(type));
203 int version = 0; // default
204 switch (type) {
205 case PreviewsType::OFFLINE:
206 base::StringToInt(ParamValue(kOfflinePagesSlowNetworkVersion), &version);
207 return version;
208 // List remaining enum cases vs. default to catch when new one is added.
209 case PreviewsType::NONE:
210 break;
211 case PreviewsType::LAST:
RyanSturm 2017/02/08 23:51:00 nit: change "case PreviewsType::LAST: break;" to "
dougarnett 2017/02/09 17:46:59 Tarun asked for explicit cases instead of default
tbansal1 2017/02/09 17:48:58 ryansturm@: What are the advantages of using tests
RyanSturm 2017/02/09 17:54:38 If this will cause GCC to complain when a new valu
dougarnett 2017/02/13 17:56:17 Here is example compile time error from warning: e
212 break;
213 }
214 NOTREACHED();
215 return -1;
216 }
217
218 std::unique_ptr<std::vector<std::pair<PreviewsType, int>>>
219 GetEnabledPreviews() {
220 std::unique_ptr<std::vector<std::pair<PreviewsType, int>>> enabled_previews(
221 new std::vector<std::pair<PreviewsType, int>>());
222
223 if (IsPreviewsTypeEnabled(PreviewsType::OFFLINE)) {
bengr 2017/02/09 17:33:46 I'd add the loop between NONE and LAST now, even t
dougarnett 2017/02/13 17:56:17 Done.
224 enabled_previews->push_back(
225 {PreviewsType::OFFLINE, GetPreviewsTypeVersion(PreviewsType::OFFLINE)});
226 }
227 return enabled_previews;
228 }
229
198 bool EnableOfflinePreviewsForTesting() { 230 bool EnableOfflinePreviewsForTesting() {
199 std::map<std::string, std::string> params; 231 std::map<std::string, std::string> params;
200 params[kOfflinePagesSlowNetwork] = kExperimentEnabled; 232 params[kOfflinePagesSlowNetwork] = kExperimentEnabled;
201 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial, 233 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial,
202 kEnabled, params) && 234 kEnabled, params) &&
203 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial, 235 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial,
204 kEnabled); 236 kEnabled);
205 } 237 }
206 238
207 } // namespace previews 239 } // namespace previews
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698