Chromium Code Reviews| Index: base/metrics/field_trial.cc |
| diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc |
| index f11ef3535364ea609421842b99504373d36e0b52..58a9ae291d5e9a49fd26c85811a1322f4d7cc3ca 100644 |
| --- a/base/metrics/field_trial.cc |
| +++ b/base/metrics/field_trial.cc |
| @@ -10,7 +10,6 @@ |
| #include "base/base_switches.h" |
| #include "base/build_time.h" |
| #include "base/command_line.h" |
| -#include "base/feature_list.h" |
| #include "base/logging.h" |
| #include "base/metrics/field_trial_param_associator.h" |
| #include "base/pickle.h" |
| @@ -248,7 +247,19 @@ bool ParseFieldTrialsString(const std::string& trials_string, |
| return true; |
| } |
| -void AddForceFieldTrialsFlag(CommandLine* cmd_line) { |
| +void AddFeatureAndFieldTrialFlags(const char* enable_features_switch, |
| + const char* disable_features_switch, |
| + CommandLine* cmd_line) { |
| + std::string enabled_features; |
| + std::string disabled_features; |
| + FeatureList::GetInstance()->GetFeatureOverrides(&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); |
| + |
| std::string field_trial_states; |
| FieldTrialList::AllStatesToString(&field_trial_states); |
| if (!field_trial_states.empty()) { |
| @@ -805,6 +816,24 @@ void FieldTrialList::CreateTrialsFromCommandLine( |
| } |
| } |
| +// static |
| +void FieldTrialList::CreateFeaturesFromCommandLine( |
| + const base::CommandLine& command_line, |
| + const char* enable_features_switch, |
| + const char* disable_features_switch, |
| + FeatureList* feature_list) { |
| + // Fallback to command line if not using shared memory. |
| + if (!kUseSharedMemoryForFieldTrials || |
| + !global_->field_trial_allocator_.get()) { |
| + return feature_list->InitializeFromCommandLine( |
| + command_line.GetSwitchValueASCII(enable_features_switch), |
| + command_line.GetSwitchValueASCII(disable_features_switch)); |
| + } |
| + |
| + feature_list->InitializeFromSharedMemory( |
| + global_->field_trial_allocator_.get()); |
| +} |
| + |
| #if defined(POSIX_WITH_ZYGOTE) |
| // static |
| bool FieldTrialList::CreateTrialsFromDescriptor(int fd_key) { |
| @@ -854,12 +883,18 @@ int FieldTrialList::GetFieldTrialHandle() { |
| // static |
| void FieldTrialList::CopyFieldTrialStateToFlags( |
| const char* field_trial_handle_switch, |
| + const char* enable_features_switch, |
| + const char* disable_features_switch, |
| CommandLine* cmd_line) { |
| // TODO(lawrencewu): Ideally, having the global would be guaranteed. However, |
| // content browser tests currently don't create a FieldTrialList because they |
| // don't run ChromeBrowserMainParts code where it's done for Chrome. |
| - if (!global_) |
| - return; |
| + // Some tests depend on the enable and disable features flag switch, though, |
| + // so we can still add those even though AllStatesToString() will be a no-op. |
| + if (!global_) { |
| + return AddFeatureAndFieldTrialFlags(enable_features_switch, |
|
Alexei Svitkine (slow)
2016/12/02 20:14:28
The function return value is void - so don't retur
lawrencewu
2016/12/02 20:36:32
Done.
|
| + disable_features_switch, cmd_line); |
| + } |
| #if defined(OS_WIN) || defined(POSIX_WITH_ZYGOTE) |
| // Use shared memory to pass the state if the feature is enabled, otherwise |
| @@ -869,7 +904,8 @@ void FieldTrialList::CopyFieldTrialStateToFlags( |
| // If the readonly handle didn't get duplicated properly, then fallback to |
| // original behavior. |
| if (global_->readonly_allocator_handle_ == kInvalidPlatformFile) { |
| - AddForceFieldTrialsFlag(cmd_line); |
| + AddFeatureAndFieldTrialFlags(enable_features_switch, |
| + disable_features_switch, cmd_line); |
| return; |
| } |
| @@ -895,7 +931,8 @@ void FieldTrialList::CopyFieldTrialStateToFlags( |
| } |
| #endif |
| - AddForceFieldTrialsFlag(cmd_line); |
| + AddFeatureAndFieldTrialFlags(enable_features_switch, disable_features_switch, |
| + cmd_line); |
| } |
| // static |
| @@ -1171,6 +1208,10 @@ void FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded() { |
| AddToAllocatorWhileLocked(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. |