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

Unified Diff: content/browser/browser_child_process_host_impl.cc

Issue 2365273004: Initial implementation for sharing field trial state (win) (Closed)
Patch Set: Remove windows macro causing compilation issue 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..060ac6915589d80d8ca839febf79f27a1c1b59da 100644
--- a/content/browser/browser_child_process_host_impl.cc
+++ b/content/browser/browser_child_process_host_impl.cc
@@ -207,8 +207,13 @@ void BrowserChildProcessHostImpl::TerminateAll() {
}
// static
+#if defined(OS_WIN)
+void BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags(
+ base::CommandLine* cmd_line, base::SharedMemory* shared_memory) {
+#else
void BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags(
base::CommandLine* cmd_line) {
+#endif
std::string enabled_features;
std::string disabled_features;
base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features,
@@ -223,13 +228,29 @@ void BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags(
std::string field_trial_states;
base::FieldTrialList::AllStatesToString(&field_trial_states);
if (!field_trial_states.empty()) {
+ // Use shared memory to pass field_trial_states if we're on Windows,
+ // otherwise fallback to the command line.
+#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 *
+ HANDLE handle = shared_memory->handle().GetHandle();
+ auto uintptr_handle = reinterpret_cast<std::uintptr_t>(handle);
+ std::string string_handle = std::to_string(uintptr_handle);
+ cmd_line->AppendSwitchASCII("field_trial_handle", string_handle);
+ cmd_line->AppendSwitchASCII("field_trial_length", std::to_string(length));
+#else
cmd_line->AppendSwitchASCII(switches::kForceFieldTrials,
field_trial_states);
+#endif
}
}
void BrowserChildProcessHostImpl::Launch(
SandboxedProcessLauncherDelegate* delegate,
+ base::SharedMemory* field_trial_state,
base::CommandLine* cmd_line,
bool terminate_on_shutdown) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -259,6 +280,7 @@ void BrowserChildProcessHostImpl::Launch(
notify_child_disconnected_ = true;
child_process_.reset(new ChildProcessLauncher(
delegate,
+ field_trial_state,
cmd_line,
data_.id,
this,

Powered by Google App Engine
This is Rietveld 408576698