Chromium Code Reviews| 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 "base/metrics/field_trial.h" | 5 #include "base/metrics/field_trial.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/base_switches.h" | 10 #include "base/base_switches.h" |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 618 if (entry.activated) { | 618 if (entry.activated) { |
| 619 FieldTrial::ActiveGroup group; | 619 FieldTrial::ActiveGroup group; |
| 620 group.trial_name = entry.trial_name.as_string(); | 620 group.trial_name = entry.trial_name.as_string(); |
| 621 group.group_name = entry.group_name.as_string(); | 621 group.group_name = entry.group_name.as_string(); |
| 622 active_groups->push_back(group); | 622 active_groups->push_back(group); |
| 623 } | 623 } |
| 624 } | 624 } |
| 625 } | 625 } |
| 626 | 626 |
| 627 // static | 627 // static |
| 628 void FieldTrialList::GetInitiallyActiveFieldTrials( | |
| 629 const base::CommandLine& command_line, | |
| 630 FieldTrial::ActiveGroups* active_groups) { | |
| 631 DCHECK(global_->create_trials_from_command_line_called_); | |
|
lawrencewu
2016/11/18 16:33:10
This function is called or can be called before Cr
Alexei Svitkine (slow)
2016/11/18 16:35:47
If it's called before it, then the field_trial_all
| |
| 632 | |
| 633 if (!global_->field_trial_allocator_) { | |
| 634 GetActiveFieldTrialGroupsFromString( | |
| 635 command_line.GetSwitchValueASCII(switches::kForceFieldTrials), | |
| 636 active_groups); | |
| 637 return; | |
| 638 } | |
| 639 | |
| 640 SharedPersistentMemoryAllocator* allocator = | |
| 641 global_->field_trial_allocator_.get(); | |
| 642 PersistentMemoryAllocator::Iterator mem_iter(allocator); | |
| 643 SharedPersistentMemoryAllocator::Reference ref; | |
| 644 while ((ref = mem_iter.GetNextOfType(kFieldTrialType)) != | |
| 645 SharedPersistentMemoryAllocator::kReferenceNull) { | |
| 646 const FieldTrialEntry* entry = | |
| 647 allocator->GetAsObject<const FieldTrialEntry>(ref, kFieldTrialType); | |
| 648 | |
| 649 StringPiece trial_name; | |
| 650 StringPiece group_name; | |
| 651 if (entry->activated && | |
| 652 entry->GetTrialAndGroupName(&trial_name, &group_name)) { | |
| 653 FieldTrial::ActiveGroup group; | |
| 654 group.trial_name = trial_name.as_string(); | |
| 655 group.group_name = group_name.as_string(); | |
| 656 active_groups->push_back(group); | |
|
bcwhite
2016/11/21 15:56:22
push_back(std::move(group))
Alexei Svitkine (slow)
2016/11/21 20:47:11
Done.
| |
| 657 } | |
| 658 } | |
| 659 } | |
| 660 | |
| 661 // static | |
| 628 bool FieldTrialList::CreateTrialsFromString( | 662 bool FieldTrialList::CreateTrialsFromString( |
| 629 const std::string& trials_string, | 663 const std::string& trials_string, |
| 630 const std::set<std::string>& ignored_trial_names) { | 664 const std::set<std::string>& ignored_trial_names) { |
| 631 DCHECK(global_); | 665 DCHECK(global_); |
| 632 if (trials_string.empty() || !global_) | 666 if (trials_string.empty() || !global_) |
| 633 return true; | 667 return true; |
| 634 | 668 |
| 635 std::vector<FieldTrial::State> entries; | 669 std::vector<FieldTrial::State> entries; |
| 636 if (!ParseFieldTrialsString(trials_string, &entries)) | 670 if (!ParseFieldTrialsString(trials_string, &entries)) |
| 637 return false; | 671 return false; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 653 trial->group(); | 687 trial->group(); |
| 654 } | 688 } |
| 655 } | 689 } |
| 656 return true; | 690 return true; |
| 657 } | 691 } |
| 658 | 692 |
| 659 // static | 693 // static |
| 660 void FieldTrialList::CreateTrialsFromCommandLine( | 694 void FieldTrialList::CreateTrialsFromCommandLine( |
| 661 const CommandLine& cmd_line, | 695 const CommandLine& cmd_line, |
| 662 const char* field_trial_handle_switch) { | 696 const char* field_trial_handle_switch) { |
| 663 DCHECK(global_); | 697 global_->create_trials_from_command_line_called_ = true; |
| 664 | 698 |
| 665 #if defined(OS_WIN) && !defined(OS_NACL) | 699 #if defined(OS_WIN) && !defined(OS_NACL) |
| 666 if (cmd_line.HasSwitch(field_trial_handle_switch)) { | 700 if (cmd_line.HasSwitch(field_trial_handle_switch)) { |
| 667 std::string arg = cmd_line.GetSwitchValueASCII(field_trial_handle_switch); | 701 std::string arg = cmd_line.GetSwitchValueASCII(field_trial_handle_switch); |
| 668 size_t token = arg.find(","); | 702 size_t token = arg.find(","); |
| 669 int field_trial_handle = std::stoi(arg.substr(0, token)); | 703 int field_trial_handle = std::stoi(arg.substr(0, token)); |
| 670 size_t field_trial_length = std::stoi(arg.substr(token + 1, arg.length())); | 704 size_t field_trial_length = std::stoi(arg.substr(token + 1, arg.length())); |
| 671 | 705 |
| 672 HANDLE handle = reinterpret_cast<HANDLE>(field_trial_handle); | 706 HANDLE handle = reinterpret_cast<HANDLE>(field_trial_handle); |
| 673 SharedMemoryHandle shm_handle = | 707 SharedMemoryHandle shm_handle = |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1015 return; | 1049 return; |
| 1016 } | 1050 } |
| 1017 AutoLock auto_lock(global_->lock_); | 1051 AutoLock auto_lock(global_->lock_); |
| 1018 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name(); | 1052 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name(); |
| 1019 trial->AddRef(); | 1053 trial->AddRef(); |
| 1020 trial->SetTrialRegistered(); | 1054 trial->SetTrialRegistered(); |
| 1021 global_->registered_[trial->trial_name()] = trial; | 1055 global_->registered_[trial->trial_name()] = trial; |
| 1022 } | 1056 } |
| 1023 | 1057 |
| 1024 } // namespace base | 1058 } // namespace base |
| OLD | NEW |