droger | 09a79c4 | 2015-10-27 12:02:32 | [diff] [blame] | 1 | // 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 | |
dcheng | 51ace48a | 2015-12-26 22:45:17 | [diff] [blame] | 7 | #include <utility> |
droger | 09a79c4 | 2015-10-27 12:02:32 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
Gayane Petrosyan | 5efebf1 | 2018-02-05 17:25:48 | [diff] [blame^] | 10 | #include "base/base_switches.h" |
droger | 09a79c4 | 2015-10-27 12:02:32 | [diff] [blame] | 11 | #include "base/metrics/field_trial.h" |
Robert Kaplow | 42e265f7 | 2017-07-19 17:43:22 | [diff] [blame] | 12 | #include "base/strings/string_piece.h" |
droger | 09a79c4 | 2015-10-27 12:02:32 | [diff] [blame] | 13 | #include "base/strings/string_util.h" |
| 14 | #include "base/values.h" |
| 15 | #include "components/variations/active_field_trials.h" |
Gayane Petrosyan | 5efebf1 | 2018-02-05 17:25:48 | [diff] [blame^] | 16 | #include "components/variations/net/variations_command_line.h" |
droger | 09a79c4 | 2015-10-27 12:02:32 | [diff] [blame] | 17 | |
| 18 | namespace version_ui { |
| 19 | |
dcheng | 3f767dc3 | 2016-04-25 22:54:22 | [diff] [blame] | 20 | std::unique_ptr<base::Value> GetVariationsList() { |
droger | 09a79c4 | 2015-10-27 12:02:32 | [diff] [blame] | 21 | 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 Kaplow | 42e265f7 | 2017-07-19 17:43:22 | [diff] [blame] | 36 | variations::GetFieldTrialActiveGroupIdsAsStrings(base::StringPiece(), |
| 37 | &variations); |
droger | 09a79c4 | 2015-10-27 12:02:32 | [diff] [blame] | 38 | #endif |
| 39 | |
dcheng | 3f767dc3 | 2016-04-25 22:54:22 | [diff] [blame] | 40 | std::unique_ptr<base::ListValue> variations_list(new base::ListValue); |
droger | 09a79c4 | 2015-10-27 12:02:32 | [diff] [blame] | 41 | for (std::vector<std::string>::const_iterator it = variations.begin(); |
| 42 | it != variations.end(); ++it) { |
dcheng | 58241a81 | 2016-06-03 18:18:42 | [diff] [blame] | 43 | variations_list->AppendString(*it); |
droger | 09a79c4 | 2015-10-27 12:02:32 | [diff] [blame] | 44 | } |
| 45 | |
dcheng | 51ace48a | 2015-12-26 22:45:17 | [diff] [blame] | 46 | return std::move(variations_list); |
droger | 09a79c4 | 2015-10-27 12:02:32 | [diff] [blame] | 47 | } |
| 48 | |
Gayane Petrosyan | 5efebf1 | 2018-02-05 17:25:48 | [diff] [blame^] | 49 | base::Value GetVariationsCommandLineAsValue() { |
| 50 | return base::Value(variations::GetVariationsCommandLine()); |
| 51 | } |
| 52 | |
droger | 09a79c4 | 2015-10-27 12:02:32 | [diff] [blame] | 53 | } // namespace version_ui |