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

Unified Diff: components/variations/active_field_trials.h

Issue 286063004: Move active field trial API to variations component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 7 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/variations.gypi ('k') | components/variations/active_field_trials.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/variations/active_field_trials.h
===================================================================
--- components/variations/active_field_trials.h (revision 0)
+++ components/variations/active_field_trials.h (working copy)
@@ -0,0 +1,64 @@
+// Copyright 2013 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.
+
+#ifndef COMPONENTS_VARIATIONS_ACTIVE_FIELD_TRIALS_H_
+#define COMPONENTS_VARIATIONS_ACTIVE_FIELD_TRIALS_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/metrics/field_trial.h"
+
+namespace variations {
+
+// The Unique ID of a trial and its active group, where the name and group
+// identifiers are hashes of the trial and group name strings.
+struct ActiveGroupId {
+ uint32 name;
+ uint32 group;
+};
+
+// Returns an ActiveGroupId struct for the given trial and group names.
+ActiveGroupId MakeActiveGroupId(const std::string& trial_name,
+ const std::string& group_name);
+
+// We need to supply a Compare class for templates since ActiveGroupId is a
+// user-defined type.
+struct ActiveGroupIdCompare {
+ bool operator() (const ActiveGroupId& lhs, const ActiveGroupId& rhs) const {
+ // The group and name fields are just SHA-1 Hashes, so we just need to treat
+ // them as IDs and do a less-than comparison. We test group first, since
+ // name is more likely to collide.
+ if (lhs.group != rhs.group)
+ return lhs.group < rhs.group;
+ return lhs.name < rhs.name;
+ }
+};
+
+// Fills the supplied vector |name_group_ids| (which must be empty when called)
+// with unique ActiveGroupIds for each Field Trial that has a chosen group.
+// Field Trials for which a group has not been chosen yet are NOT returned in
+// this list.
+void GetFieldTrialActiveGroupIds(std::vector<ActiveGroupId>* name_group_ids);
+
+// Fills the supplied vector |output| (which must be empty when called) with
+// unique string representations of ActiveGroupIds for each Field Trial that
+// has a chosen group. The strings are formatted as "<TrialName>-<GroupName>",
+// with the names as hex strings. Field Trials for which a group has not been
+// chosen yet are NOT returned in this list.
+void GetFieldTrialActiveGroupIdsAsStrings(std::vector<std::string>* output);
+
+// Expose some functions for testing. These functions just wrap functionality
+// that is implemented above.
+namespace testing {
+
+void TestGetFieldTrialActiveGroupIds(
+ const base::FieldTrial::ActiveGroups& active_groups,
+ std::vector<ActiveGroupId>* name_group_ids);
+
+} // namespace testing
+
+} // namespace variations
+
+#endif // COMPONENTS_VARIATIONS_ACTIVE_FIELD_TRIALS_H_
« no previous file with comments | « components/variations.gypi ('k') | components/variations/active_field_trials.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698