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

Unified Diff: base/metrics/field_trial.cc

Issue 2484773002: Store ref in field trial in child processes (Closed)
Patch Set: add comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/metrics/field_trial.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/field_trial.cc
diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc
index 63f549e5729d69b3587de96dbef7ad61764bac26..dec24c9663b19d5577b6739abb67571acf54607f 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,11 @@ void FieldTrialList::ActivateFieldTrialEntryWhileLocked(
FieldTrial* field_trial) {
SharedPersistentMemoryAllocator* allocator =
global_->field_trial_allocator_.get();
+
+ // Check if we're in the child process and return early if so.
+ if (allocator && allocator->IsReadonly())
+ 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
« no previous file with comments | « base/metrics/field_trial.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698