OLD | NEW |
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/browser/about_flags.h" | 5 #include "chrome/browser/about_flags.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 #define MULTI_VALUE_TYPE(choices) \ | 72 #define MULTI_VALUE_TYPE(choices) \ |
73 Experiment::MULTI_VALUE, NULL, NULL, NULL, NULL, choices, arraysize(choices) | 73 Experiment::MULTI_VALUE, NULL, NULL, NULL, NULL, choices, arraysize(choices) |
74 | 74 |
75 namespace { | 75 namespace { |
76 | 76 |
77 const unsigned kOsAll = kOsMac | kOsWin | kOsLinux | kOsCrOS | kOsAndroid; | 77 const unsigned kOsAll = kOsMac | kOsWin | kOsLinux | kOsCrOS | kOsAndroid; |
78 const unsigned kOsDesktop = kOsMac | kOsWin | kOsLinux | kOsCrOS; | 78 const unsigned kOsDesktop = kOsMac | kOsWin | kOsLinux | kOsCrOS; |
79 | 79 |
80 // Adds a |StringValue| to |list| for each platform where |bitmask| indicates | 80 // Adds a |StringValue| to |list| for each platform where |bitmask| indicates |
81 // whether the experiment is available on that platform. | 81 // whether the experiment is available on that platform. |
82 void AddOsStrings(unsigned bitmask, ListValue* list) { | 82 void AddOsStrings(unsigned bitmask, base::ListValue* list) { |
83 struct { | 83 struct { |
84 unsigned bit; | 84 unsigned bit; |
85 const char* const name; | 85 const char* const name; |
86 } kBitsToOs[] = { | 86 } kBitsToOs[] = { |
87 {kOsMac, "Mac"}, | 87 {kOsMac, "Mac"}, |
88 {kOsWin, "Windows"}, | 88 {kOsWin, "Windows"}, |
89 {kOsLinux, "Linux"}, | 89 {kOsLinux, "Linux"}, |
90 {kOsCrOS, "Chrome OS"}, | 90 {kOsCrOS, "Chrome OS"}, |
91 {kOsAndroid, "Android"}, | 91 {kOsAndroid, "Android"}, |
92 {kOsCrOSOwnerOnly, "Chrome OS (owner only)"}, | 92 {kOsCrOSOwnerOnly, "Chrome OS (owner only)"}, |
93 }; | 93 }; |
94 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kBitsToOs); ++i) | 94 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kBitsToOs); ++i) |
95 if (bitmask & kBitsToOs[i].bit) | 95 if (bitmask & kBitsToOs[i].bit) |
96 list->Append(new StringValue(kBitsToOs[i].name)); | 96 list->Append(new base::StringValue(kBitsToOs[i].name)); |
97 } | 97 } |
98 | 98 |
99 // Convert switch constants to proper CommandLine::StringType strings. | 99 // Convert switch constants to proper CommandLine::StringType strings. |
100 CommandLine::StringType GetSwitchString(const std::string& flag) { | 100 CommandLine::StringType GetSwitchString(const std::string& flag) { |
101 CommandLine cmd_line(CommandLine::NO_PROGRAM); | 101 CommandLine cmd_line(CommandLine::NO_PROGRAM); |
102 cmd_line.AppendSwitch(flag); | 102 cmd_line.AppendSwitch(flag); |
103 DCHECK(cmd_line.argv().size() == 2); | 103 DCHECK(cmd_line.argv().size() == 2); |
104 return cmd_line.argv()[1]; | 104 return cmd_line.argv()[1]; |
105 } | 105 } |
106 | 106 |
(...skipping 1977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2084 std::set<std::string> new_enabled_experiments; | 2084 std::set<std::string> new_enabled_experiments; |
2085 std::set_intersection( | 2085 std::set_intersection( |
2086 platform_experiments.begin(), platform_experiments.end(), | 2086 platform_experiments.begin(), platform_experiments.end(), |
2087 result->begin(), result->end(), | 2087 result->begin(), result->end(), |
2088 std::inserter(new_enabled_experiments, new_enabled_experiments.begin())); | 2088 std::inserter(new_enabled_experiments, new_enabled_experiments.begin())); |
2089 | 2089 |
2090 result->swap(new_enabled_experiments); | 2090 result->swap(new_enabled_experiments); |
2091 } | 2091 } |
2092 | 2092 |
2093 // Returns the Value representing the choice data in the specified experiment. | 2093 // Returns the Value representing the choice data in the specified experiment. |
2094 Value* CreateChoiceData(const Experiment& experiment, | 2094 base::Value* CreateChoiceData( |
2095 const std::set<std::string>& enabled_experiments) { | 2095 const Experiment& experiment, |
| 2096 const std::set<std::string>& enabled_experiments) { |
2096 DCHECK(experiment.type == Experiment::MULTI_VALUE || | 2097 DCHECK(experiment.type == Experiment::MULTI_VALUE || |
2097 experiment.type == Experiment::ENABLE_DISABLE_VALUE); | 2098 experiment.type == Experiment::ENABLE_DISABLE_VALUE); |
2098 ListValue* result = new ListValue; | 2099 base::ListValue* result = new base::ListValue; |
2099 for (int i = 0; i < experiment.num_choices; ++i) { | 2100 for (int i = 0; i < experiment.num_choices; ++i) { |
2100 DictionaryValue* value = new DictionaryValue; | 2101 base::DictionaryValue* value = new base::DictionaryValue; |
2101 const std::string name = experiment.NameForChoice(i); | 2102 const std::string name = experiment.NameForChoice(i); |
2102 value->SetString("internal_name", name); | 2103 value->SetString("internal_name", name); |
2103 value->SetString("description", experiment.DescriptionForChoice(i)); | 2104 value->SetString("description", experiment.DescriptionForChoice(i)); |
2104 value->SetBoolean("selected", enabled_experiments.count(name) > 0); | 2105 value->SetBoolean("selected", enabled_experiments.count(name) > 0); |
2105 result->Append(value); | 2106 result->Append(value); |
2106 } | 2107 } |
2107 return result; | 2108 return result; |
2108 } | 2109 } |
2109 | 2110 |
2110 } // namespace | 2111 } // namespace |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2164 std::set<std::string> enabled_experiments; | 2165 std::set<std::string> enabled_experiments; |
2165 GetSanitizedEnabledFlags(flags_storage, &enabled_experiments); | 2166 GetSanitizedEnabledFlags(flags_storage, &enabled_experiments); |
2166 | 2167 |
2167 int current_platform = GetCurrentPlatform(); | 2168 int current_platform = GetCurrentPlatform(); |
2168 | 2169 |
2169 for (size_t i = 0; i < num_experiments; ++i) { | 2170 for (size_t i = 0; i < num_experiments; ++i) { |
2170 const Experiment& experiment = experiments[i]; | 2171 const Experiment& experiment = experiments[i]; |
2171 if (SkipConditionalExperiment(experiment)) | 2172 if (SkipConditionalExperiment(experiment)) |
2172 continue; | 2173 continue; |
2173 | 2174 |
2174 DictionaryValue* data = new DictionaryValue(); | 2175 base::DictionaryValue* data = new base::DictionaryValue(); |
2175 data->SetString("internal_name", experiment.internal_name); | 2176 data->SetString("internal_name", experiment.internal_name); |
2176 data->SetString("name", | 2177 data->SetString("name", |
2177 l10n_util::GetStringUTF16(experiment.visible_name_id)); | 2178 l10n_util::GetStringUTF16(experiment.visible_name_id)); |
2178 data->SetString("description", | 2179 data->SetString("description", |
2179 l10n_util::GetStringUTF16( | 2180 l10n_util::GetStringUTF16( |
2180 experiment.visible_description_id)); | 2181 experiment.visible_description_id)); |
2181 | 2182 |
2182 ListValue* supported_platforms = new ListValue(); | 2183 base::ListValue* supported_platforms = new base::ListValue(); |
2183 AddOsStrings(experiment.supported_platforms, supported_platforms); | 2184 AddOsStrings(experiment.supported_platforms, supported_platforms); |
2184 data->Set("supported_platforms", supported_platforms); | 2185 data->Set("supported_platforms", supported_platforms); |
2185 | 2186 |
2186 switch (experiment.type) { | 2187 switch (experiment.type) { |
2187 case Experiment::SINGLE_VALUE: | 2188 case Experiment::SINGLE_VALUE: |
2188 data->SetBoolean( | 2189 data->SetBoolean( |
2189 "enabled", | 2190 "enabled", |
2190 enabled_experiments.count(experiment.internal_name) > 0); | 2191 enabled_experiments.count(experiment.internal_name) > 0); |
2191 break; | 2192 break; |
2192 case Experiment::MULTI_VALUE: | 2193 case Experiment::MULTI_VALUE: |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2454 } | 2455 } |
2455 | 2456 |
2456 const Experiment* GetExperiments(size_t* count) { | 2457 const Experiment* GetExperiments(size_t* count) { |
2457 *count = num_experiments; | 2458 *count = num_experiments; |
2458 return experiments; | 2459 return experiments; |
2459 } | 2460 } |
2460 | 2461 |
2461 } // namespace testing | 2462 } // namespace testing |
2462 | 2463 |
2463 } // namespace about_flags | 2464 } // namespace about_flags |
OLD | NEW |