OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 experiments_list->Clear(); | 321 experiments_list->Clear(); |
322 for (std::set<std::string>::const_iterator it = enabled_experiments.begin(); | 322 for (std::set<std::string>::const_iterator it = enabled_experiments.begin(); |
323 it != enabled_experiments.end(); | 323 it != enabled_experiments.end(); |
324 ++it) { | 324 ++it) { |
325 experiments_list->Append(new StringValue(*it)); | 325 experiments_list->Append(new StringValue(*it)); |
326 } | 326 } |
327 } | 327 } |
328 | 328 |
329 // Returns the name used in prefs for the choice at the specified index. | 329 // Returns the name used in prefs for the choice at the specified index. |
330 std::string NameForChoice(const Experiment& e, int index) { | 330 std::string NameForChoice(const Experiment& e, int index) { |
331 DCHECK(e.type == Experiment::MULTI_VALUE); | 331 DCHECK_EQ(e.type, Experiment::MULTI_VALUE); |
332 DCHECK(index < e.num_choices); | 332 DCHECK(index < e.num_choices); |
333 return std::string(e.internal_name) + about_flags::testing::kMultiSeparator + | 333 return std::string(e.internal_name) + about_flags::testing::kMultiSeparator + |
334 base::IntToString(index); | 334 base::IntToString(index); |
335 } | 335 } |
336 | 336 |
337 // Adds the internal names for the specified experiment to |names|. | 337 // Adds the internal names for the specified experiment to |names|. |
338 void AddInternalName(const Experiment& e, std::set<std::string>* names) { | 338 void AddInternalName(const Experiment& e, std::set<std::string>* names) { |
339 if (e.type == Experiment::SINGLE_VALUE) { | 339 if (e.type == Experiment::SINGLE_VALUE) { |
340 names->insert(e.internal_name); | 340 names->insert(e.internal_name); |
341 } else { | 341 } else { |
342 DCHECK(e.type == Experiment::MULTI_VALUE); | 342 DCHECK_EQ(e.type, Experiment::MULTI_VALUE); |
343 for (int i = 0; i < e.num_choices; ++i) | 343 for (int i = 0; i < e.num_choices; ++i) |
344 names->insert(NameForChoice(e, i)); | 344 names->insert(NameForChoice(e, i)); |
345 } | 345 } |
346 } | 346 } |
347 | 347 |
348 // Confirms that an experiment is valid, used in a DCHECK in | 348 // Confirms that an experiment is valid, used in a DCHECK in |
349 // SanitizeList below. | 349 // SanitizeList below. |
350 bool ValidateExperiment(const Experiment& e) { | 350 bool ValidateExperiment(const Experiment& e) { |
351 switch (e.type) { | 351 switch (e.type) { |
352 case Experiment::SINGLE_VALUE: | 352 case Experiment::SINGLE_VALUE: |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 platform_experiments.begin(), platform_experiments.end(), | 414 platform_experiments.begin(), platform_experiments.end(), |
415 result->begin(), result->end(), | 415 result->begin(), result->end(), |
416 std::inserter(new_enabled_experiments, new_enabled_experiments.begin())); | 416 std::inserter(new_enabled_experiments, new_enabled_experiments.begin())); |
417 | 417 |
418 result->swap(new_enabled_experiments); | 418 result->swap(new_enabled_experiments); |
419 } | 419 } |
420 | 420 |
421 // Returns the Value representing the choice data in the specified experiment. | 421 // Returns the Value representing the choice data in the specified experiment. |
422 Value* CreateChoiceData(const Experiment& experiment, | 422 Value* CreateChoiceData(const Experiment& experiment, |
423 const std::set<std::string>& enabled_experiments) { | 423 const std::set<std::string>& enabled_experiments) { |
424 DCHECK(experiment.type == Experiment::MULTI_VALUE); | 424 DCHECK_EQ(experiment.type, Experiment::MULTI_VALUE); |
425 ListValue* result = new ListValue; | 425 ListValue* result = new ListValue; |
426 for (int i = 0; i < experiment.num_choices; ++i) { | 426 for (int i = 0; i < experiment.num_choices; ++i) { |
427 const Experiment::Choice& choice = experiment.choices[i]; | 427 const Experiment::Choice& choice = experiment.choices[i]; |
428 DictionaryValue* value = new DictionaryValue; | 428 DictionaryValue* value = new DictionaryValue; |
429 std::string name = NameForChoice(experiment, i); | 429 std::string name = NameForChoice(experiment, i); |
430 value->SetString("description", | 430 value->SetString("description", |
431 l10n_util::GetStringUTF16(choice.description_id)); | 431 l10n_util::GetStringUTF16(choice.description_id)); |
432 value->SetString("internal_name", name); | 432 value->SetString("internal_name", name); |
433 value->SetBoolean("selected", enabled_experiments.count(name) > 0); | 433 value->SetBoolean("selected", enabled_experiments.count(name) > 0); |
434 result->Append(value); | 434 result->Append(value); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 } | 685 } |
686 | 686 |
687 const Experiment* GetExperiments(size_t* count) { | 687 const Experiment* GetExperiments(size_t* count) { |
688 *count = num_experiments; | 688 *count = num_experiments; |
689 return experiments; | 689 return experiments; |
690 } | 690 } |
691 | 691 |
692 } // namespace testing | 692 } // namespace testing |
693 | 693 |
694 } // namespace about_flags | 694 } // namespace about_flags |
OLD | NEW |