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

Unified Diff: content/browser/browser_child_process_host_impl.cc

Issue 2365273004: Initial implementation for sharing field trial state (win) (Closed)
Patch Set: Address comments 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..4601cc7e04a6f5a0e34073ba534e86d1c16351ed 100644
--- a/content/browser/browser_child_process_host_impl.cc
+++ b/content/browser/browser_child_process_host_impl.cc
@@ -38,6 +38,7 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_data.h"
#include "content/public/browser/content_browser_client.h"
+#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/mojo_channel_switches.h"
#include "content/public/common/process_type.h"
@@ -207,7 +208,8 @@ void BrowserChildProcessHostImpl::TerminateAll() {
}
// static
-void BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags(
+std::unique_ptr<base::SharedMemory>
+BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags(
base::CommandLine* cmd_line) {
std::string enabled_features;
std::string disabled_features;
@@ -219,18 +221,28 @@ void BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags(
cmd_line->AppendSwitchASCII(switches::kDisableFeatures, disabled_features);
// If we run base::FieldTrials, we want to pass to their state to the
- // child process so that it can act in accordance with each state.
- std::string field_trial_states;
- base::FieldTrialList::AllStatesToString(&field_trial_states);
- if (!field_trial_states.empty()) {
- cmd_line->AppendSwitchASCII(switches::kForceFieldTrials,
- field_trial_states);
+ // child process so that it can act in accordance with each state. Use shared
+ // memory to pass the state if the feature is enabled, otherwise fallback to
+ // passing it via the command line as a string.
+ if (base::FeatureList::IsEnabled(
Alexei Svitkine (slow) 2016/10/06 13:45:30 Can this whole logic live in the helper function (
lawrencewu 2016/10/06 20:14:57 Done.
+ features::kShareFieldTrialStateViaSharedMemory)) {
+ return base::FieldTrialList::CopyFieldTrialStateToSharedMemory(
+ cmd_line, switches::kFieldTrialHandle);
+ } else {
+ std::string field_trial_states;
+ base::FieldTrialList::AllStatesToString(&field_trial_states);
+ if (!field_trial_states.empty()) {
+ cmd_line->AppendSwitchASCII(switches::kForceFieldTrials,
+ field_trial_states);
+ }
+ return std::unique_ptr<base::SharedMemory>(nullptr);
}
}
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 +270,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