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

Unified Diff: base/metrics/field_trial_param_associator.cc

Issue 2456723004: Move VariationsParamAssociator to base (Closed)
Patch Set: Created 4 years, 2 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
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..b9781018fc8bc29c8bfa621f1cacb2b714e65f93
--- /dev/null
+++ b/base/metrics/field_trial_param_associator.cc
@@ -0,0 +1,51 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
Alexei Svitkine (slow) 2016/10/28 15:39:16 No (c)
lawrencewu 2016/10/28 16:54:29 Done.
+// 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"
+
+namespace base {
+
+// 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

Powered by Google App Engine
This is Rietveld 408576698