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

Unified Diff: content/browser/browser_child_process_host_impl.cc

Issue 2365273004: Initial implementation for sharing field trial state (win) (Closed)
Patch Set: add feature logic for sharing field trials Created 4 years, 2 months 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: content/browser/browser_child_process_host_impl.cc
diff --git a/content/browser/browser_child_process_host_impl.cc b/content/browser/browser_child_process_host_impl.cc
index e3eacd3ce01dead3132bee37df83760295395796..8cb7c71ad83ea1c25830ba3dc3057d1a82b39bf4 100644
--- a/content/browser/browser_child_process_host_impl.cc
+++ b/content/browser/browser_child_process_host_impl.cc
@@ -208,7 +208,8 @@ void BrowserChildProcessHostImpl::TerminateAll() {
// static
void BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags(
- base::CommandLine* cmd_line) {
+ base::CommandLine* cmd_line,
+ base::SharedMemory* shared_memory) {
std::string enabled_features;
std::string disabled_features;
base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features,
@@ -223,14 +224,34 @@ void BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags(
std::string field_trial_states;
base::FieldTrialList::AllStatesToString(&field_trial_states);
if (!field_trial_states.empty()) {
- cmd_line->AppendSwitchASCII(switches::kForceFieldTrials,
- field_trial_states);
+ // Use shared memory to pass field_trial_states if we can, otherwise
+ // fallback to the command line.
+ if (shared_memory) {
Alexei Svitkine (slow) 2016/10/04 18:49:35 I also suggest putting this code in base/metrics a
lawrencewu 2016/10/05 20:57:56 Done.
+#if defined(OS_WIN)
+ size_t length = field_trial_states.size() + 1;
+ shared_memory->CreateAndMapAnonymous(length);
+ memcpy(shared_memory->memory(), field_trial_states.c_str(), length);
+
+ // HANDLE is just typedef'd to void *
+ auto uintptr_handle =
+ reinterpret_cast<std::uintptr_t>(shared_memory->handle().GetHandle());
+ std::string field_trial_handle =
+ std::to_string(uintptr_handle) + "," + std::to_string(length);
+
+ cmd_line->AppendSwitchASCII(switches::kFieldTrialHandle,
+ field_trial_handle);
+#endif
+ } else {
+ cmd_line->AppendSwitchASCII(switches::kForceFieldTrials,
+ field_trial_states);
+ }
}
}
void BrowserChildProcessHostImpl::Launch(
SandboxedProcessLauncherDelegate* delegate,
base::CommandLine* cmd_line,
+ const base::SharedMemory* field_trial_state,
bool terminate_on_shutdown) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -258,11 +279,7 @@ void BrowserChildProcessHostImpl::Launch(
notify_child_disconnected_ = true;
child_process_.reset(new ChildProcessLauncher(
- delegate,
- cmd_line,
- data_.id,
- this,
- child_token_,
+ delegate, cmd_line, data_.id, this, field_trial_state, child_token_,
base::Bind(&BrowserChildProcessHostImpl::OnMojoError,
weak_factory_.GetWeakPtr(),
base::ThreadTaskRunnerHandle::Get()),

Powered by Google App Engine
This is Rietveld 408576698