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

Unified Diff: base/metrics/field_trial_param_associator.cc

Issue 2456723004: Move VariationsParamAssociator to base (Closed)
Patch Set: rebase-update Created 4 years, 1 month 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 | « base/metrics/field_trial_param_associator.h ('k') | components/variations/variations_associated_data.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/field_trial_param_associator.cc
diff --git a/base/metrics/field_trial_param_associator.cc b/base/metrics/field_trial_param_associator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0ba26ef34b4bb5f292bd020eb5383778b7bdfc4d
--- /dev/null
+++ b/base/metrics/field_trial_param_associator.cc
@@ -0,0 +1,56 @@
+// 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 "base/metrics/field_trial_param_associator.h"
+
+#include "base/metrics/field_trial.h"
+
+namespace base {
+
+FieldTrialParamAssociator::FieldTrialParamAssociator() {}
+FieldTrialParamAssociator::~FieldTrialParamAssociator() {}
+
+// static
+FieldTrialParamAssociator* FieldTrialParamAssociator::GetInstance() {
+ return Singleton<FieldTrialParamAssociator,
+ LeakySingletonTraits<FieldTrialParamAssociator>>::get();
+}
+
+bool FieldTrialParamAssociator::AssociateFieldTrialParams(
+ const std::string& trial_name,
+ const std::string& group_name,
+ const FieldTrialParams& params) {
+ AutoLock scoped_lock(lock_);
+
+ if (FieldTrialList::IsTrialActive(trial_name))
+ return false;
+
+ const FieldTrialKey key(trial_name, group_name);
+ if (ContainsKey(field_trial_params_, key))
+ return false;
+
+ field_trial_params_[key] = params;
+ return true;
+}
+
+bool FieldTrialParamAssociator::GetFieldTrialParams(
+ const std::string& trial_name,
+ FieldTrialParams* params) {
+ AutoLock scoped_lock(lock_);
+
+ const std::string group_name = FieldTrialList::FindFullName(trial_name);
+ const FieldTrialKey key(trial_name, group_name);
+ if (!ContainsKey(field_trial_params_, key))
+ return false;
+
+ *params = field_trial_params_[key];
+ return true;
+}
+
+void FieldTrialParamAssociator::ClearAllParamsForTesting() {
+ AutoLock scoped_lock(lock_);
+ field_trial_params_.clear();
+}
+
+} // namespace base
« no previous file with comments | « base/metrics/field_trial_param_associator.h ('k') | components/variations/variations_associated_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698