blob: 0f62928ae16b881521b478f5d2869d1a0c576f47 [file] [log] [blame]
droger09a79c42015-10-27 12:02:321// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "components/version_ui/version_handler_helper.h"
6
dcheng51ace48a2015-12-26 22:45:177#include <utility>
droger09a79c42015-10-27 12:02:328#include <vector>
9
Gayane Petrosyan5efebf12018-02-05 17:25:4810#include "base/base_switches.h"
droger09a79c42015-10-27 12:02:3211#include "base/metrics/field_trial.h"
Robert Kaplow42e265f72017-07-19 17:43:2212#include "base/strings/string_piece.h"
droger09a79c42015-10-27 12:02:3213#include "base/strings/string_util.h"
14#include "base/values.h"
15#include "components/variations/active_field_trials.h"
Gayane Petrosyan5efebf12018-02-05 17:25:4816#include "components/variations/net/variations_command_line.h"
droger09a79c42015-10-27 12:02:3217
18namespace version_ui {
19
dcheng3f767dc32016-04-25 22:54:2220std::unique_ptr<base::Value> GetVariationsList() {
droger09a79c42015-10-27 12:02:3221 std::vector<std::string> variations;
22#if !defined(NDEBUG)
23 base::FieldTrial::ActiveGroups active_groups;
24 base::FieldTrialList::GetActiveFieldTrialGroups(&active_groups);
25
26 const unsigned char kNonBreakingHyphenUTF8[] = {0xE2, 0x80, 0x91, '\0'};
27 const std::string kNonBreakingHyphenUTF8String(
28 reinterpret_cast<const char*>(kNonBreakingHyphenUTF8));
29 for (const auto& group : active_groups) {
30 std::string line = group.trial_name + ":" + group.group_name;
31 base::ReplaceChars(line, "-", kNonBreakingHyphenUTF8String, &line);
32 variations.push_back(line);
33 }
34#else
35 // In release mode, display the hashes only.
Robert Kaplow42e265f72017-07-19 17:43:2236 variations::GetFieldTrialActiveGroupIdsAsStrings(base::StringPiece(),
37 &variations);
droger09a79c42015-10-27 12:02:3238#endif
39
dcheng3f767dc32016-04-25 22:54:2240 std::unique_ptr<base::ListValue> variations_list(new base::ListValue);
droger09a79c42015-10-27 12:02:3241 for (std::vector<std::string>::const_iterator it = variations.begin();
42 it != variations.end(); ++it) {
dcheng58241a812016-06-03 18:18:4243 variations_list->AppendString(*it);
droger09a79c42015-10-27 12:02:3244 }
45
dcheng51ace48a2015-12-26 22:45:1746 return std::move(variations_list);
droger09a79c42015-10-27 12:02:3247}
48
Gayane Petrosyan5efebf12018-02-05 17:25:4849base::Value GetVariationsCommandLineAsValue() {
50 return base::Value(variations::GetVariationsCommandLine());
51}
52
droger09a79c42015-10-27 12:02:3253} // namespace version_ui