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

Side by Side Diff: chrome/common/metrics/variations/variations_util.cc

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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/common/metrics/variations/variations_util.h" 5 #include "chrome/common/metrics/variations/variations_util.h"
6 6
7 #include <vector>
8
9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/common/child_process_logging.h" 7 #include "chrome/common/child_process_logging.h"
12 #include "chrome/common/crash_keys.h" 8 #include "chrome/common/crash_keys.h"
9 #include "components/variations/active_field_trials.h"
13 10
14 namespace chrome_variations { 11 namespace chrome_variations {
15 12
16 namespace {
17
18 // Populates |name_group_ids| based on |active_groups|.
19 void GetFieldTrialActiveGroupIdsForActiveGroups(
20 const base::FieldTrial::ActiveGroups& active_groups,
21 std::vector<ActiveGroupId>* name_group_ids) {
22 DCHECK(name_group_ids->empty());
23 for (base::FieldTrial::ActiveGroups::const_iterator it =
24 active_groups.begin(); it != active_groups.end(); ++it) {
25 name_group_ids->push_back(MakeActiveGroupId(it->trial_name,
26 it->group_name));
27 }
28 }
29
30 } // namespace
31
32 void GetFieldTrialActiveGroupIds(
33 std::vector<ActiveGroupId>* name_group_ids) {
34 DCHECK(name_group_ids->empty());
35 // A note on thread safety: Since GetActiveFieldTrialGroups() is thread
36 // safe, and we operate on a separate list of that data, this function is
37 // technically thread safe as well, with respect to the FieldTrialList data.
38 base::FieldTrial::ActiveGroups active_groups;
39 base::FieldTrialList::GetActiveFieldTrialGroups(&active_groups);
40 GetFieldTrialActiveGroupIdsForActiveGroups(active_groups,
41 name_group_ids);
42 }
43
44 void GetFieldTrialActiveGroupIdsAsStrings(
45 std::vector<std::string>* output) {
46 DCHECK(output->empty());
47 std::vector<ActiveGroupId> name_group_ids;
48 GetFieldTrialActiveGroupIds(&name_group_ids);
49 for (size_t i = 0; i < name_group_ids.size(); ++i) {
50 output->push_back(base::StringPrintf(
51 "%x-%x", name_group_ids[i].name, name_group_ids[i].group));
52 }
53 }
54
55 void SetChildProcessLoggingVariationList() { 13 void SetChildProcessLoggingVariationList() {
56 std::vector<std::string> experiment_strings; 14 std::vector<std::string> experiment_strings;
57 GetFieldTrialActiveGroupIdsAsStrings(&experiment_strings); 15 variations::GetFieldTrialActiveGroupIdsAsStrings(&experiment_strings);
58 crash_keys::SetVariationsList(experiment_strings); 16 crash_keys::SetVariationsList(experiment_strings);
59 } 17 }
60 18
61 // Functions below are exposed for testing explicitly behind this namespace.
62 // They simply wrap existing functions in this file.
63 namespace testing {
64
65 void TestGetFieldTrialActiveGroupIds(
66 const base::FieldTrial::ActiveGroups& active_groups,
67 std::vector<ActiveGroupId>* name_group_ids) {
68 GetFieldTrialActiveGroupIdsForActiveGroups(active_groups,
69 name_group_ids);
70 }
71
72 } // namespace testing
73
74 } // namespace chrome_variations 19 } // namespace chrome_variations
OLDNEW
« no previous file with comments | « chrome/common/metrics/variations/variations_util.h ('k') | chrome/common/metrics/variations/variations_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698