| 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 <iterator> | 7 #include <iterator> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 2162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2173 #endif | 2173 #endif |
| 2174 } | 2174 } |
| 2175 | 2175 |
| 2176 std::set<std::string> new_enabled_experiments = | 2176 std::set<std::string> new_enabled_experiments = |
| 2177 base::STLSetIntersection<std::set<std::string> >( | 2177 base::STLSetIntersection<std::set<std::string> >( |
| 2178 platform_experiments, *result); | 2178 platform_experiments, *result); |
| 2179 | 2179 |
| 2180 result->swap(new_enabled_experiments); | 2180 result->swap(new_enabled_experiments); |
| 2181 } | 2181 } |
| 2182 | 2182 |
| 2183 // Returns true if none of this experiment's options have been enabled. |
| 2184 bool IsDefaultValue( |
| 2185 const Experiment& experiment, |
| 2186 const std::set<std::string>& enabled_experiments) { |
| 2187 switch (experiment.type) { |
| 2188 case Experiment::SINGLE_VALUE: |
| 2189 case Experiment::SINGLE_DISABLE_VALUE: |
| 2190 return enabled_experiments.count(experiment.internal_name) == 0; |
| 2191 case Experiment::MULTI_VALUE: |
| 2192 case Experiment::ENABLE_DISABLE_VALUE: |
| 2193 for (int i = 0; i < experiment.num_choices; ++i) { |
| 2194 if (enabled_experiments.count(experiment.NameForChoice(i)) > 0) |
| 2195 return false; |
| 2196 } |
| 2197 break; |
| 2198 default: |
| 2199 NOTREACHED(); |
| 2200 } |
| 2201 return true; |
| 2202 } |
| 2203 |
| 2183 // Returns the Value representing the choice data in the specified experiment. | 2204 // Returns the Value representing the choice data in the specified experiment. |
| 2184 base::Value* CreateChoiceData( | 2205 base::Value* CreateChoiceData( |
| 2185 const Experiment& experiment, | 2206 const Experiment& experiment, |
| 2186 const std::set<std::string>& enabled_experiments) { | 2207 const std::set<std::string>& enabled_experiments) { |
| 2187 DCHECK(experiment.type == Experiment::MULTI_VALUE || | 2208 DCHECK(experiment.type == Experiment::MULTI_VALUE || |
| 2188 experiment.type == Experiment::ENABLE_DISABLE_VALUE); | 2209 experiment.type == Experiment::ENABLE_DISABLE_VALUE); |
| 2189 base::ListValue* result = new base::ListValue; | 2210 base::ListValue* result = new base::ListValue; |
| 2190 for (int i = 0; i < experiment.num_choices; ++i) { | 2211 for (int i = 0; i < experiment.num_choices; ++i) { |
| 2191 base::DictionaryValue* value = new base::DictionaryValue; | 2212 base::DictionaryValue* value = new base::DictionaryValue; |
| 2192 const std::string name = experiment.NameForChoice(i); | 2213 const std::string name = experiment.NameForChoice(i); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2281 data->SetString("name", | 2302 data->SetString("name", |
| 2282 l10n_util::GetStringUTF16(experiment.visible_name_id)); | 2303 l10n_util::GetStringUTF16(experiment.visible_name_id)); |
| 2283 data->SetString("description", | 2304 data->SetString("description", |
| 2284 l10n_util::GetStringUTF16( | 2305 l10n_util::GetStringUTF16( |
| 2285 experiment.visible_description_id)); | 2306 experiment.visible_description_id)); |
| 2286 | 2307 |
| 2287 base::ListValue* supported_platforms = new base::ListValue(); | 2308 base::ListValue* supported_platforms = new base::ListValue(); |
| 2288 AddOsStrings(experiment.supported_platforms, supported_platforms); | 2309 AddOsStrings(experiment.supported_platforms, supported_platforms); |
| 2289 data->Set("supported_platforms", supported_platforms); | 2310 data->Set("supported_platforms", supported_platforms); |
| 2290 // True if the switch is not currently passed. | 2311 // True if the switch is not currently passed. |
| 2291 bool is_default_value = | 2312 bool is_default_value = IsDefaultValue(experiment, enabled_experiments); |
| 2292 enabled_experiments.count(experiment.internal_name) == 0; | 2313 data->SetBoolean("is_default", is_default_value); |
| 2293 | 2314 |
| 2294 switch (experiment.type) { | 2315 switch (experiment.type) { |
| 2295 case Experiment::SINGLE_VALUE: | 2316 case Experiment::SINGLE_VALUE: |
| 2296 case Experiment::SINGLE_DISABLE_VALUE: | 2317 case Experiment::SINGLE_DISABLE_VALUE: |
| 2297 data->SetBoolean("is_default", is_default_value); | |
| 2298 | |
| 2299 data->SetBoolean( | 2318 data->SetBoolean( |
| 2300 "enabled", | 2319 "enabled", |
| 2301 (!is_default_value && | 2320 (!is_default_value && |
| 2302 experiment.type == Experiment::SINGLE_VALUE) || | 2321 experiment.type == Experiment::SINGLE_VALUE) || |
| 2303 (is_default_value && | 2322 (is_default_value && |
| 2304 experiment.type == Experiment::SINGLE_DISABLE_VALUE)); | 2323 experiment.type == Experiment::SINGLE_DISABLE_VALUE)); |
| 2305 break; | 2324 break; |
| 2306 case Experiment::MULTI_VALUE: | 2325 case Experiment::MULTI_VALUE: |
| 2307 case Experiment::ENABLE_DISABLE_VALUE: | 2326 case Experiment::ENABLE_DISABLE_VALUE: |
| 2308 data->Set("choices", CreateChoiceData(experiment, enabled_experiments)); | 2327 data->Set("choices", CreateChoiceData(experiment, enabled_experiments)); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2602 } | 2621 } |
| 2603 | 2622 |
| 2604 const Experiment* GetExperiments(size_t* count) { | 2623 const Experiment* GetExperiments(size_t* count) { |
| 2605 *count = num_experiments; | 2624 *count = num_experiments; |
| 2606 return experiments; | 2625 return experiments; |
| 2607 } | 2626 } |
| 2608 | 2627 |
| 2609 } // namespace testing | 2628 } // namespace testing |
| 2610 | 2629 |
| 2611 } // namespace about_flags | 2630 } // namespace about_flags |
| OLD | NEW |