Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: base/metrics/field_trial.cc

Issue 2504163005: Fix getting initially active trials with shared memory. (Closed)
Patch Set: Use typedefs Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 return false; 160 return false;
161 next_item++; 161 next_item++;
162 entry.activated = true; 162 entry.activated = true;
163 } 163 }
164 entry.trial_name = 164 entry.trial_name =
165 trials_string_piece.substr(next_item, name_end - next_item); 165 trials_string_piece.substr(next_item, name_end - next_item);
166 entry.group_name = 166 entry.group_name =
167 trials_string_piece.substr(name_end + 1, group_name_end - name_end - 1); 167 trials_string_piece.substr(name_end + 1, group_name_end - name_end - 1);
168 next_item = group_name_end + 1; 168 next_item = group_name_end + 1;
169 169
170 entries->push_back(entry); 170 entries->push_back(std::move(entry));
171 } 171 }
172 return true; 172 return true;
173 } 173 }
174 174
175 void AddForceFieldTrialsFlag(CommandLine* cmd_line) { 175 void AddForceFieldTrialsFlag(CommandLine* cmd_line) {
176 std::string field_trial_states; 176 std::string field_trial_states;
177 FieldTrialList::AllStatesToString(&field_trial_states); 177 FieldTrialList::AllStatesToString(&field_trial_states);
178 if (!field_trial_states.empty()) { 178 if (!field_trial_states.empty()) {
179 cmd_line->AppendSwitchASCII(switches::kForceFieldTrials, 179 cmd_line->AppendSwitchASCII(switches::kForceFieldTrials,
180 field_trial_states); 180 field_trial_states);
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_);
632
633 if (!global_->field_trial_allocator_) {
634 GetActiveFieldTrialGroupsFromString(
635 command_line.GetSwitchValueASCII(switches::kForceFieldTrials),
636 active_groups);
637 return;
638 }
639
640 FieldTrialAllocator* allocator = global_->field_trial_allocator_.get();
641 FieldTrialAllocator::Iterator mem_iter(allocator);
642 FieldTrial::FieldTrialRef ref;
643 while ((ref = mem_iter.GetNextOfType(kFieldTrialType)) !=
644 SharedPersistentMemoryAllocator::kReferenceNull) {
645 const FieldTrialEntry* entry =
646 allocator->GetAsObject<const FieldTrialEntry>(ref, kFieldTrialType);
647
648 StringPiece trial_name;
649 StringPiece group_name;
650 if (entry->activated &&
651 entry->GetTrialAndGroupName(&trial_name, &group_name)) {
652 FieldTrial::ActiveGroup group;
653 group.trial_name = trial_name.as_string();
654 group.group_name = group_name.as_string();
655 active_groups->push_back(group);
656 }
657 }
658 }
659
660 // static
628 bool FieldTrialList::CreateTrialsFromString( 661 bool FieldTrialList::CreateTrialsFromString(
629 const std::string& trials_string, 662 const std::string& trials_string,
630 const std::set<std::string>& ignored_trial_names) { 663 const std::set<std::string>& ignored_trial_names) {
631 DCHECK(global_); 664 DCHECK(global_);
632 if (trials_string.empty() || !global_) 665 if (trials_string.empty() || !global_)
633 return true; 666 return true;
634 667
635 std::vector<FieldTrial::State> entries; 668 std::vector<FieldTrial::State> entries;
636 if (!ParseFieldTrialsString(trials_string, &entries)) 669 if (!ParseFieldTrialsString(trials_string, &entries))
637 return false; 670 return false;
(...skipping 15 matching lines...) Expand all
653 trial->group(); 686 trial->group();
654 } 687 }
655 } 688 }
656 return true; 689 return true;
657 } 690 }
658 691
659 // static 692 // static
660 void FieldTrialList::CreateTrialsFromCommandLine( 693 void FieldTrialList::CreateTrialsFromCommandLine(
661 const CommandLine& cmd_line, 694 const CommandLine& cmd_line,
662 const char* field_trial_handle_switch) { 695 const char* field_trial_handle_switch) {
663 DCHECK(global_); 696 global_->create_trials_from_command_line_called_ = true;
664 697
665 #if defined(OS_WIN) && !defined(OS_NACL) 698 #if defined(OS_WIN) && !defined(OS_NACL)
666 if (cmd_line.HasSwitch(field_trial_handle_switch)) { 699 if (cmd_line.HasSwitch(field_trial_handle_switch)) {
667 std::string arg = cmd_line.GetSwitchValueASCII(field_trial_handle_switch); 700 std::string arg = cmd_line.GetSwitchValueASCII(field_trial_handle_switch);
668 int field_trial_handle = std::stoi(arg); 701 int field_trial_handle = std::stoi(arg);
669 HANDLE handle = reinterpret_cast<HANDLE>(field_trial_handle); 702 HANDLE handle = reinterpret_cast<HANDLE>(field_trial_handle);
670 bool result = CreateTrialsFromWindowsHandle(handle); 703 bool result = CreateTrialsFromWindowsHandle(handle);
671 DCHECK(result); 704 DCHECK(result);
672 } 705 }
673 #endif 706 #endif
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 return; 1043 return;
1011 } 1044 }
1012 AutoLock auto_lock(global_->lock_); 1045 AutoLock auto_lock(global_->lock_);
1013 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name(); 1046 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name();
1014 trial->AddRef(); 1047 trial->AddRef();
1015 trial->SetTrialRegistered(); 1048 trial->SetTrialRegistered();
1016 global_->registered_[trial->trial_name()] = trial; 1049 global_->registered_[trial->trial_name()] = trial;
1017 } 1050 }
1018 1051
1019 } // namespace base 1052 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/field_trial.h ('k') | chrome/common/variations/child_process_field_trial_syncer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698