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

Unified Diff: base/metrics/field_trial.cc

Issue 2546653002: Store and retrieve features from shared memory (Closed)
Patch Set: Address comments and write unittest 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
« no previous file with comments | « base/metrics/field_trial.h ('k') | base/metrics/field_trial_unittest.cc » ('j') | 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 ee1629c2e55c40bf343f1e5f9db48f598c95e36d..6f251c0fb7ffc0724e968f07d47e3e2c3276b758 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/pickle.h"
#include "base/process/memory.h"
@@ -184,7 +183,19 @@ bool ParseFieldTrialsString(const std::string& trials_string,
return true;
}
-void AddForceFieldTrialsFlag(CommandLine* cmd_line) {
+void AddFeatureAndFieldTrialFlags(CommandLine* cmd_line,
Alexei Svitkine (slow) 2016/12/01 19:39:22 Nit: Non-const params should be last.
lawrencewu 2016/12/02 19:24:46 Done.
+ const char* enable_features_switch,
+ const char* disable_features_switch) {
+ 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()) {
@@ -741,6 +752,22 @@ void FieldTrialList::CreateTrialsFromCommandLine(
}
}
+// static
+void FieldTrialList::CreateFeaturesFromCommandLine(
+ const base::CommandLine& command_line,
+ const char* enable_features_switch,
+ const char* disable_features_switch,
+ std::unique_ptr<FeatureList>& feature_list) {
Alexei Svitkine (slow) 2016/12/01 19:39:22 Don't pass non const refs. You can pass as a Feat
lawrencewu 2016/12/02 19:24:46 Done.
+ // Fallback to command line if not using shared memory.
+ if (!kUseSharedMemoryForFieldTrials || !global_->field_trial_allocator_.get())
Alexei Svitkine (slow) 2016/12/01 19:39:22 Nit: {}'s
+ 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) {
@@ -790,6 +817,8 @@ 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
@@ -805,7 +834,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(cmd_line, enable_features_switch,
+ disable_features_switch);
return;
}
@@ -831,7 +861,8 @@ void FieldTrialList::CopyFieldTrialStateToFlags(
}
#endif
- AddForceFieldTrialsFlag(cmd_line);
+ AddFeatureAndFieldTrialFlags(cmd_line, enable_features_switch,
+ disable_features_switch);
}
// static
@@ -1007,6 +1038,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.
« no previous file with comments | « base/metrics/field_trial.h ('k') | base/metrics/field_trial_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698