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

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

Issue 2640023007: Adds PreviewsType version mechanism for clearing blacklist entries. (Closed)
Patch Set: Missed a change in last upload Created 3 years, 11 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 bool IsPreviewsTypeEnabled(PreviewsType type) { 175 bool IsPreviewsTypeEnabled(PreviewsType type) {
173 switch (type) { 176 switch (type) {
174 case PreviewsType::OFFLINE: 177 case PreviewsType::OFFLINE:
175 return ParamValue(kOfflinePagesSlowNetwork) == kExperimentEnabled; 178 return ParamValue(kOfflinePagesSlowNetwork) == kExperimentEnabled;
176 default: 179 default:
177 NOTREACHED(); 180 NOTREACHED();
178 return false; 181 return false;
179 } 182 }
180 } 183 }
181 184
185 bool GetPreviewsTypeVersion(PreviewsType type) {
186 DCHECK(IsPreviewsTypeEnabled(type));
187 int version = 0; // default
188 switch (type) {
189 case PreviewsType::OFFLINE:
190 base::StringToInt(ParamValue(kOfflinePagesSlowNetworkVersion), &version);
191 return version;
tbansal1 2017/01/26 00:59:14 I think the switch-case can be rewritten to get co
dougarnett 2017/02/07 21:15:02 Done.
192 default:
193 NOTREACHED();
194 }
195 return version;
196 }
197
198 std::unique_ptr<std::vector<std::pair<PreviewsType, int>>>
199 GetEnabledPreviews() {
200 std::unique_ptr<std::vector<std::pair<PreviewsType, int>>> enabled_previews(
201 new std::vector<std::pair<PreviewsType, int>>());
202
203 if (IsPreviewsTypeEnabled(PreviewsType::OFFLINE)) {
204 enabled_previews->push_back(
205 {PreviewsType::OFFLINE, GetPreviewsTypeVersion(PreviewsType::OFFLINE)});
206 }
207 return enabled_previews;
208 }
209
182 bool EnableOfflinePreviewsForTesting() { 210 bool EnableOfflinePreviewsForTesting() {
183 std::map<std::string, std::string> params; 211 std::map<std::string, std::string> params;
184 params[kOfflinePagesSlowNetwork] = kExperimentEnabled; 212 params[kOfflinePagesSlowNetwork] = kExperimentEnabled;
185 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial, 213 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial,
186 kEnabled, params) && 214 kEnabled, params) &&
187 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial, 215 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial,
188 kEnabled); 216 kEnabled);
189 } 217 }
190 218
191 } // namespace previews 219 } // namespace previews
OLDNEW
« no previous file with comments | « components/previews/core/previews_experiments.h ('k') | components/previews/core/previews_opt_out_store_sql.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698