Commit 4428eafa authored by Alexei Svitkine's avatar Alexei Svitkine Committed by Commit Bot

[Cleanup] Remove kUseSharedMemoryForFieldTrials in field_trial.c.

This constant was only set to false on OS_FUCHSIA and has been
shipping as true for several years on all other platforms.

Cleans up the code to not need this constant in most places and
adds a OS_FUCHSIA ifdef around InstantiateFieldTrialAllocatorIfNeeded()
which is the only place that needed custom logic to disable it for
Fuchsia.

Bug: 867558
Change-Id: Idbf49ce571a50d67debeafe2cdacee086ebca537
Reviewed-on: https://chromium-review.googlesource.com/c/1343020
Commit-Queue: Alexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609922}
parent c5d65c1e
...@@ -45,20 +45,6 @@ const char kPersistentStringSeparator = '/'; // Currently a slash. ...@@ -45,20 +45,6 @@ const char kPersistentStringSeparator = '/'; // Currently a slash.
// command line which forces its activation. // command line which forces its activation.
const char kActivationMarker = '*'; const char kActivationMarker = '*';
// Use shared memory to communicate field trial (experiment) state. Set to false
// for now while the implementation is fleshed out (e.g. data format, single
// shared memory segment). See https://codereview.chromium.org/2365273004/ and
// crbug.com/653874
// The browser is the only process that has write access to the shared memory.
// This is safe from race conditions because MakeIterable is a release operation
// and GetNextOfType is an acquire operation, so memory writes before
// MakeIterable happen before memory reads after GetNextOfType.
#if defined(OS_FUCHSIA) // TODO(752368): Not yet supported on Fuchsia.
const bool kUseSharedMemoryForFieldTrials = false;
#else
const bool kUseSharedMemoryForFieldTrials = true;
#endif
// Constants for the field trial allocator. // Constants for the field trial allocator.
const char kAllocatorName[] = "FieldTrialAllocator"; const char kAllocatorName[] = "FieldTrialAllocator";
...@@ -242,10 +228,10 @@ SharedMemoryHandle GetSharedMemoryReadOnlyHandle(SharedMemory* shared_memory) { ...@@ -242,10 +228,10 @@ SharedMemoryHandle GetSharedMemoryReadOnlyHandle(SharedMemory* shared_memory) {
// writable mapping attempts, but the original one in |shm| survives // writable mapping attempts, but the original one in |shm| survives
// and is still usable in the current process. // and is still usable in the current process.
result.SetRegionReadOnly(); result.SetRegionReadOnly();
#endif // OS_ANDROID #endif // defined(OS_ANDROID)
return result; return result;
} }
#endif // !OS_NACL #endif // !defined(OS_NACL)
} // namespace } // namespace
...@@ -459,7 +445,7 @@ void FieldTrial::FinalizeGroupChoiceImpl(bool is_locked) { ...@@ -459,7 +445,7 @@ void FieldTrial::FinalizeGroupChoiceImpl(bool is_locked) {
SetGroupChoice(default_group_name_, kDefaultGroupNumber); SetGroupChoice(default_group_name_, kDefaultGroupNumber);
// Add the field trial to shared memory. // Add the field trial to shared memory.
if (kUseSharedMemoryForFieldTrials && trial_registered_) if (trial_registered_)
FieldTrialList::OnGroupFinalized(is_locked, this); FieldTrialList::OnGroupFinalized(is_locked, this);
} }
...@@ -872,8 +858,7 @@ void FieldTrialList::CreateFeaturesFromCommandLine( ...@@ -872,8 +858,7 @@ void FieldTrialList::CreateFeaturesFromCommandLine(
const char* disable_features_switch, const char* disable_features_switch,
FeatureList* feature_list) { FeatureList* feature_list) {
// Fallback to command line if not using shared memory. // Fallback to command line if not using shared memory.
if (!kUseSharedMemoryForFieldTrials || if (!global_->field_trial_allocator_.get()) {
!global_->field_trial_allocator_.get()) {
return feature_list->InitializeFromCommandLine( return feature_list->InitializeFromCommandLine(
command_line.GetSwitchValueASCII(enable_features_switch), command_line.GetSwitchValueASCII(enable_features_switch),
command_line.GetSwitchValueASCII(disable_features_switch)); command_line.GetSwitchValueASCII(disable_features_switch));
...@@ -889,18 +874,16 @@ void FieldTrialList::AppendFieldTrialHandleIfNeeded( ...@@ -889,18 +874,16 @@ void FieldTrialList::AppendFieldTrialHandleIfNeeded(
HandlesToInheritVector* handles) { HandlesToInheritVector* handles) {
if (!global_) if (!global_)
return; return;
if (kUseSharedMemoryForFieldTrials) { InstantiateFieldTrialAllocatorIfNeeded();
InstantiateFieldTrialAllocatorIfNeeded(); if (global_->readonly_allocator_handle_.IsValid())
if (global_->readonly_allocator_handle_.IsValid()) handles->push_back(global_->readonly_allocator_handle_.GetHandle());
handles->push_back(global_->readonly_allocator_handle_.GetHandle());
}
} }
#elif defined(OS_FUCHSIA) #elif defined(OS_FUCHSIA)
// TODO(fuchsia): Implement shared-memory configuration (crbug.com/752368). // TODO(fuchsia): Implement shared-memory configuration (crbug.com/752368).
#elif defined(OS_MACOSX) && !defined(OS_IOS) #elif defined(OS_MACOSX) && !defined(OS_IOS)
// static // static
FieldTrialMemoryServer* FieldTrialList::GetFieldTrialMemoryServer() { FieldTrialMemoryServer* FieldTrialList::GetFieldTrialMemoryServer() {
if (global_ && kUseSharedMemoryForFieldTrials) { if (global_) {
InstantiateFieldTrialAllocatorIfNeeded(); InstantiateFieldTrialAllocatorIfNeeded();
return global_->field_trial_server_.get(); return global_->field_trial_server_.get();
} }
...@@ -909,7 +892,7 @@ FieldTrialMemoryServer* FieldTrialList::GetFieldTrialMemoryServer() { ...@@ -909,7 +892,7 @@ FieldTrialMemoryServer* FieldTrialList::GetFieldTrialMemoryServer() {
#elif defined(OS_POSIX) && !defined(OS_NACL) #elif defined(OS_POSIX) && !defined(OS_NACL)
// static // static
SharedMemoryHandle FieldTrialList::GetFieldTrialHandle() { SharedMemoryHandle FieldTrialList::GetFieldTrialHandle() {
if (global_ && kUseSharedMemoryForFieldTrials) { if (global_) {
InstantiateFieldTrialAllocatorIfNeeded(); InstantiateFieldTrialAllocatorIfNeeded();
// We check for an invalid handle where this gets called. // We check for an invalid handle where this gets called.
return global_->readonly_allocator_handle_; return global_->readonly_allocator_handle_;
...@@ -924,53 +907,37 @@ void FieldTrialList::CopyFieldTrialStateToFlags( ...@@ -924,53 +907,37 @@ void FieldTrialList::CopyFieldTrialStateToFlags(
const char* enable_features_switch, const char* enable_features_switch,
const char* disable_features_switch, const char* disable_features_switch,
CommandLine* cmd_line) { CommandLine* cmd_line) {
// TODO(lawrencewu): Ideally, having the global would be guaranteed. However, #if !defined(OS_FUCHSIA) // TODO(752368): Not yet supported on Fuchsia.
// content browser tests currently don't create a FieldTrialList because they // Use shared memory to communicate field trial state to child processes.
// don't run ChromeBrowserMainParts code where it's done for Chrome. // The browser is the only process that has write access to the shared memory.
// Some tests depend on the enable and disable features flag switch, though, InstantiateFieldTrialAllocatorIfNeeded();
// so we can still add those even though AllStatesToString() will be a no-op. #endif // !defined(OS_FUCHSIA)
if (!global_) {
// If the readonly handle did not get created, fall back to flags.
if (!global_ || !global_->readonly_allocator_handle_.IsValid()) {
AddFeatureAndFieldTrialFlags(enable_features_switch, AddFeatureAndFieldTrialFlags(enable_features_switch,
disable_features_switch, cmd_line); disable_features_switch, cmd_line);
return; return;
} }
// Use shared memory to pass the state if the feature is enabled, otherwise global_->field_trial_allocator_->UpdateTrackingHistograms();
// fallback to passing it via the command line as a string. std::string switch_value =
if (kUseSharedMemoryForFieldTrials) { SerializeSharedMemoryHandleMetadata(global_->readonly_allocator_handle_);
InstantiateFieldTrialAllocatorIfNeeded(); cmd_line->AppendSwitchASCII(field_trial_handle_switch, switch_value);
// If the readonly handle didn't get duplicated properly, then fallback to
// original behavior.
if (!global_->readonly_allocator_handle_.IsValid()) {
AddFeatureAndFieldTrialFlags(enable_features_switch,
disable_features_switch, cmd_line);
return;
}
global_->field_trial_allocator_->UpdateTrackingHistograms();
std::string switch_value = SerializeSharedMemoryHandleMetadata(
global_->readonly_allocator_handle_);
cmd_line->AppendSwitchASCII(field_trial_handle_switch, switch_value);
// Append --enable-features and --disable-features switches corresponding
// to the features enabled on the command-line, so that child and browser
// process command lines match and clearly show what has been specified
// explicitly by the user.
std::string enabled_features;
std::string disabled_features;
FeatureList::GetInstance()->GetCommandLineFeatureOverrides(
&enabled_features, &disabled_features);
if (!enabled_features.empty())
cmd_line->AppendSwitchASCII(enable_features_switch, enabled_features);
if (!disabled_features.empty())
cmd_line->AppendSwitchASCII(disable_features_switch, disabled_features);
return; // Append --enable-features and --disable-features switches corresponding
} // to the features enabled on the command-line, so that child and browser
// process command lines match and clearly show what has been specified
// explicitly by the user.
std::string enabled_features;
std::string disabled_features;
FeatureList::GetInstance()->GetCommandLineFeatureOverrides(
&enabled_features, &disabled_features);
AddFeatureAndFieldTrialFlags(enable_features_switch, disable_features_switch, if (!enabled_features.empty())
cmd_line); cmd_line->AppendSwitchASCII(enable_features_switch, enabled_features);
if (!disabled_features.empty())
cmd_line->AppendSwitchASCII(disable_features_switch, disabled_features);
} }
// static // static
...@@ -1054,8 +1021,7 @@ void FieldTrialList::NotifyFieldTrialGroupSelection(FieldTrial* field_trial) { ...@@ -1054,8 +1021,7 @@ void FieldTrialList::NotifyFieldTrialGroupSelection(FieldTrial* field_trial) {
if (!field_trial->enable_field_trial_) if (!field_trial->enable_field_trial_)
return; return;
if (kUseSharedMemoryForFieldTrials) ActivateFieldTrialEntryWhileLocked(field_trial);
ActivateFieldTrialEntryWhileLocked(field_trial);
} }
// Recording for stability debugging has to be done inline as a task posted // Recording for stability debugging has to be done inline as a task posted
...@@ -1274,7 +1240,7 @@ SharedMemoryHandle FieldTrialList::DeserializeSharedMemoryHandleMetadata( ...@@ -1274,7 +1240,7 @@ SharedMemoryHandle FieldTrialList::DeserializeSharedMemoryHandleMetadata(
FieldTrialMemoryClient::AcquireMemoryObject(); FieldTrialMemoryClient::AcquireMemoryObject();
if (scoped_handle == MACH_PORT_NULL) if (scoped_handle == MACH_PORT_NULL)
return SharedMemoryHandle(); return SharedMemoryHandle();
#endif // defined(OS_WIN) #endif
base::UnguessableToken guid; base::UnguessableToken guid;
if (!DeserializeGUIDFromStringPieces(tokens[1], tokens[2], &guid)) if (!DeserializeGUIDFromStringPieces(tokens[1], tokens[2], &guid))
...@@ -1333,9 +1299,6 @@ bool FieldTrialList::CreateTrialsFromSwitchValue( ...@@ -1333,9 +1299,6 @@ bool FieldTrialList::CreateTrialsFromSwitchValue(
bool FieldTrialList::CreateTrialsFromDescriptor( bool FieldTrialList::CreateTrialsFromDescriptor(
int fd_key, int fd_key,
const std::string& switch_value) { const std::string& switch_value) {
if (!kUseSharedMemoryForFieldTrials)
return false;
if (fd_key == -1) if (fd_key == -1)
return false; return false;
...@@ -1402,6 +1365,7 @@ bool FieldTrialList::CreateTrialsFromSharedMemory( ...@@ -1402,6 +1365,7 @@ bool FieldTrialList::CreateTrialsFromSharedMemory(
void FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded() { void FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded() {
if (!global_) if (!global_)
return; return;
AutoLock auto_lock(global_->lock_); AutoLock auto_lock(global_->lock_);
// Create the allocator if not already created and add all existing trials. // Create the allocator if not already created and add all existing trials.
if (global_->field_trial_allocator_ != nullptr) if (global_->field_trial_allocator_ != nullptr)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment