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

Unified Diff: components/previews/previews_experiments.cc

Issue 2179863003: Adding a new component, Previews. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bengr comments Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/previews/previews_experiments.h ('k') | components/previews/previews_experiments_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/previews/previews_experiments.cc
diff --git a/components/previews/previews_experiments.cc b/components/previews/previews_experiments.cc
new file mode 100644
index 0000000000000000000000000000000000000000..be52481299417fb64c5707dd8699600edce6e8f9
--- /dev/null
+++ b/components/previews/previews_experiments.cc
@@ -0,0 +1,50 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/previews/previews_experiments.h"
+
+#include <map>
+#include <string>
+
+#include "base/metrics/field_trial.h"
+#include "base/strings/string_util.h"
+#include "components/variations/variations_associated_data.h"
+
+namespace {
+
+// The group of client-side previews experiments.
+const char kClientSidePreviewsFieldTrial[] = "ClientSidePreviews";
+
+const char kEnabled[] = "Enabled";
+
+// Allow offline pages to show for prohibitively slow networks.
+const char kOfflinePagesSlowNetwork[] = "show_offline_pages";
+
+} // namespace
+
+namespace previews {
+
+bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() {
+ // By convention, an experiment in the client-side previews study enables use
+ // of at least one client-side previews optimization if its name begins with
+ // "Enabled."
+ return base::StartsWith(
+ base::FieldTrialList::FindFullName(kClientSidePreviewsFieldTrial),
+ kEnabled, base::CompareCase::SENSITIVE);
+}
+
+bool IsOfflinePreviewsEnabled() {
+ if (!IsIncludedInClientSidePreviewsExperimentsFieldTrial())
+ return false;
+ std::map<std::string, std::string> experiment_params;
+ if (!variations::GetVariationParams(kClientSidePreviewsFieldTrial,
+ &experiment_params)) {
+ return false;
+ }
+ std::map<std::string, std::string>::const_iterator it =
+ experiment_params.find(kOfflinePagesSlowNetwork);
+ return it != experiment_params.end() && it->second == "true";
+}
+
+} // namespace previews
« no previous file with comments | « components/previews/previews_experiments.h ('k') | components/previews/previews_experiments_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698