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

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

Issue 2504163005: Fix getting initially active trials with shared memory. (Closed)
Patch Set: Fix single process mode which is used by PhishingClassifierTest on Windows. Created 4 years, 1 month 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 SharedPersistentMemoryAllocator* allocator =
lawrencewu 2016/11/21 20:53:18 nit: use the FieldTrialAllocator typedef (and belo
Alexei Svitkine (slow) 2016/11/21 21:11:19 Done.
641 global_->field_trial_allocator_.get();
642 PersistentMemoryAllocator::Iterator mem_iter(allocator);
643 SharedPersistentMemoryAllocator::Reference ref;
lawrencewu 2016/11/21 20:53:18 FieldTrial::FieldTrialRef ref;
Alexei Svitkine (slow) 2016/11/21 21:11:19 Done.
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);
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
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
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
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