Chromium Code Reviews| Index: base/metrics/field_trial.cc |
| diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc |
| index 911c8e5ee9842759c3c820929e268098e6a6dbd6..c0f046f534d6de29c7e643aad74959f02c040fc1 100644 |
| --- a/base/metrics/field_trial.cc |
| +++ b/base/metrics/field_trial.cc |
| @@ -309,7 +309,8 @@ FieldTrial::FieldTrial(const std::string& trial_name, |
| enable_field_trial_(true), |
| forced_(false), |
| group_reported_(false), |
| - trial_registered_(false) { |
| + trial_registered_(false), |
| + ref_(SharedPersistentMemoryAllocator::kReferenceNull) { |
| DCHECK_GT(total_probability, 0); |
| DCHECK(!trial_name_.empty()); |
| DCHECK(!default_group_name_.empty()); |
| @@ -340,6 +341,13 @@ void FieldTrial::FinalizeGroupChoice() { |
| // finalized. |
| DCHECK(!forced_); |
| SetGroupChoice(default_group_name_, kDefaultGroupNumber); |
| + |
| + // Add the field trial to shared memory. |
| + if (kUseSharedMemoryForFieldTrials) { |
| + SharedPersistentMemoryAllocator* allocator = |
| + FieldTrialList::GetFieldTrialAllocator(); |
|
Alexei Svitkine (slow)
2016/10/25 19:18:53
I'm not a fan of having a public getter for the al
lawrencewu
2016/10/25 20:27:33
I moved the AddToAllocatorWhileLocked function to
|
| + this->AddToAllocatorWhileLocked(allocator); |
| + } |
| } |
| bool FieldTrial::GetActiveGroup(ActiveGroup* active_group) const { |
| @@ -786,8 +794,18 @@ void FieldTrialList::NotifyFieldTrialGroupSelection(FieldTrial* field_trial) { |
| return; |
| if (kUseSharedMemoryForFieldTrials) { |
| - field_trial->AddToAllocatorWhileLocked( |
| - global_->field_trial_allocator_.get()); |
| + SharedPersistentMemoryAllocator* allocator = |
|
Alexei Svitkine (slow)
2016/10/25 19:18:53
Nit: Please make a helper function for this block
lawrencewu
2016/10/25 20:27:33
Done.
|
| + global_->field_trial_allocator_.get(); |
| + SharedPersistentMemoryAllocator::Reference ref = field_trial->ref_; |
| + if (ref == SharedPersistentMemoryAllocator::kReferenceNull) { |
| + // It's fine to do this even if the allocator hasn't been instantiated |
| + // yet -- it'll just return early. |
| + field_trial->AddToAllocatorWhileLocked(allocator); |
| + } else { |
| + FieldTrialEntry* entry = |
| + allocator->GetAsObject<FieldTrialEntry>(ref, kFieldTrialType); |
| + entry->activated = true; |
| + } |
| } |
| } |
| @@ -835,6 +853,10 @@ void FieldTrial::AddToAllocatorWhileLocked( |
| if (allocator == nullptr) |
| return; |
| + // Or if we've already added it. |
| + if (ref_ != SharedPersistentMemoryAllocator::kReferenceNull) |
| + return; |
| + |
| State trial_state; |
| if (!GetState(&trial_state)) |
| return; |
| @@ -869,6 +891,7 @@ void FieldTrial::AddToAllocatorWhileLocked( |
| group_name[trial_state.group_name.size()] = '\0'; |
| allocator->MakeIterable(ref); |
| + ref_ = ref; |
| } |
| // static |
| @@ -880,6 +903,11 @@ size_t FieldTrialList::GetFieldTrialCount() { |
| } |
| // static |
| +SharedPersistentMemoryAllocator* FieldTrialList::GetFieldTrialAllocator() { |
| + return global_->field_trial_allocator_.get(); |
| +} |
| + |
| +// static |
| const FieldTrial::EntropyProvider* |
| FieldTrialList::GetEntropyProviderForOneTimeRandomization() { |
| if (!global_) { |