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

Unified Diff: base/metrics/field_trial.cc

Issue 2546653002: Store and retrieve features from shared memory (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: base/metrics/field_trial.cc
diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc
index ee1629c2e55c40bf343f1e5f9db48f598c95e36d..831239835fe23c729bb128d4135eb269948c7865 100644
--- a/base/metrics/field_trial.cc
+++ b/base/metrics/field_trial.cc
@@ -66,9 +66,9 @@ const size_t kFieldTrialAllocationSize = 128 << 10; // 128 KiB
#endif
// We create one FieldTrialEntry per field trial in shared memory, via
-// AddToAllocatorWhileLocked. The FieldTrialEntry is followed by a base::Pickle
-// object that we unpickle and read from. Any changes to this structure requires
-// a bump in kFieldTrialType id defined above.
+// AddTrialToAllocatorWhileLocked. The FieldTrialEntry is followed by a
+// base::Pickle object that we unpickle and read from. Any changes to this
+// structure requires a bump in kFieldTrialType id defined above.
struct FieldTrialEntry {
// Expected size for 32/64-bit check.
static constexpr size_t kExpectedInstanceSize = 8;
@@ -739,6 +739,11 @@ void FieldTrialList::CreateTrialsFromCommandLine(
std::set<std::string>());
DCHECK(result);
}
+
+ // TODO(lawrencewu): rename CreateTrialsFromCommandLine to
+ // CreateTrialsAndFeaturesFromCommandLine, cause that's what we're doing.
+ FeatureList::GetInstance()->InitializeFromSharedMemory(
+ global_->field_trial_allocator_.get());
}
#if defined(POSIX_WITH_ZYGOTE)
@@ -879,10 +884,10 @@ void FieldTrialList::OnGroupFinalized(bool is_locked, FieldTrial* field_trial) {
if (!global_)
return;
if (is_locked) {
- AddToAllocatorWhileLocked(field_trial);
+ AddTrialToAllocatorWhileLocked(field_trial);
} else {
AutoLock auto_lock(global_->lock_);
- AddToAllocatorWhileLocked(field_trial);
+ AddTrialToAllocatorWhileLocked(field_trial);
}
}
@@ -1004,9 +1009,13 @@ void FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded() {
// Add all existing field trials.
for (const auto& registered : global_->registered_) {
- AddToAllocatorWhileLocked(registered.second);
+ AddTrialToAllocatorWhileLocked(registered.second);
}
+ // Add all existing features.
+ FeatureList::GetInstance()->AddFeaturesToAllocator(
+ global_->field_trial_allocator_.get());
+
#if defined(OS_WIN) || defined(POSIX_WITH_ZYGOTE)
// Set |readonly_allocator_handle_| so we can pass it to be inherited and
// via the command line.
@@ -1017,7 +1026,7 @@ void FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded() {
#endif
// static
-void FieldTrialList::AddToAllocatorWhileLocked(FieldTrial* field_trial) {
+void FieldTrialList::AddTrialToAllocatorWhileLocked(FieldTrial* field_trial) {
FieldTrialAllocator* allocator = global_->field_trial_allocator_.get();
// Don't do anything if the allocator hasn't been instantiated yet.
@@ -1075,7 +1084,7 @@ void FieldTrialList::ActivateFieldTrialEntryWhileLocked(
if (ref == FieldTrialAllocator::kReferenceNull) {
// It's fine to do this even if the allocator hasn't been instantiated
// yet -- it'll just return early.
- AddToAllocatorWhileLocked(field_trial);
+ AddTrialToAllocatorWhileLocked(field_trial);
} else {
// It's also okay to do this even though the callee doesn't have a lock --
// the only thing that happens on a stale read here is a slight performance

Powered by Google App Engine
This is Rietveld 408576698