Chromium Code Reviews| Index: base/metrics/field_trial.cc |
| diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc |
| index 63f549e5729d69b3587de96dbef7ad61764bac26..a568b78118ba7ebc55cfbdec22e70cad7a564836 100644 |
| --- a/base/metrics/field_trial.cc |
| +++ b/base/metrics/field_trial.cc |
| @@ -823,15 +823,17 @@ size_t FieldTrialList::GetFieldTrialCount() { |
| // static |
| void FieldTrialList::CreateTrialsFromSharedMemory( |
| std::unique_ptr<SharedMemory> shm) { |
| - const SharedPersistentMemoryAllocator shalloc(std::move(shm), 0, |
| - kAllocatorName, true); |
| - PersistentMemoryAllocator::Iterator mem_iter(&shalloc); |
| + global_->field_trial_allocator_.reset(new SharedPersistentMemoryAllocator( |
| + std::move(shm), 0, kAllocatorName, true)); |
| + SharedPersistentMemoryAllocator* shalloc = |
| + global_->field_trial_allocator_.get(); |
| + PersistentMemoryAllocator::Iterator mem_iter(shalloc); |
| SharedPersistentMemoryAllocator::Reference ref; |
| while ((ref = mem_iter.GetNextOfType(kFieldTrialType)) != |
| SharedPersistentMemoryAllocator::kReferenceNull) { |
| const FieldTrialEntry* entry = |
| - shalloc.GetAsObject<const FieldTrialEntry>(ref, kFieldTrialType); |
| + shalloc->GetAsObject<const FieldTrialEntry>(ref, kFieldTrialType); |
| StringPiece trial_name; |
| StringPiece group_name; |
| @@ -845,6 +847,7 @@ void FieldTrialList::CreateTrialsFromSharedMemory( |
| FieldTrial* trial = |
| CreateFieldTrial(trial_name.as_string(), group_name.as_string()); |
| + trial->ref_ = ref; |
| if (entry->activated) { |
| // Call |group()| to mark the trial as "used" and notify observers, if |
| // any. This is useful to ensure that field trials created in child |
| @@ -895,6 +898,11 @@ void FieldTrialList::AddToAllocatorWhileLocked(FieldTrial* field_trial) { |
| if (allocator == nullptr) |
| return; |
| + // Or if the allocator is read only, which means we are in a child process and |
| + // shouldn't be writing to it. |
| + if (allocator->IsReadonly()) |
| + return; |
| + |
| // Or if we've already added it. |
| if (field_trial->ref_ != SharedPersistentMemoryAllocator::kReferenceNull) |
| return; |
| @@ -932,6 +940,10 @@ void FieldTrialList::ActivateFieldTrialEntryWhileLocked( |
| FieldTrial* field_trial) { |
| SharedPersistentMemoryAllocator* allocator = |
| global_->field_trial_allocator_.get(); |
| + |
| + if (allocator && allocator->IsReadonly()) |
|
Alexei Svitkine (slow)
2016/11/07 18:31:33
This is needed because now the child process actua
lawrencewu
2016/11/07 19:11:37
Yes, that's correct. Added comments to both places
|
| + return; |
| + |
| SharedPersistentMemoryAllocator::Reference ref = field_trial->ref_; |
| if (ref == SharedPersistentMemoryAllocator::kReferenceNull) { |
| // It's fine to do this even if the allocator hasn't been instantiated |