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

Side by Side Diff: content/browser/browser_child_process_host_impl.cc

Issue 2365273004: Initial implementation for sharing field trial state (win) (Closed)
Patch Set: Fix unit test and remove macro 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/browser_child_process_host_impl.h" 5 #include "content/browser/browser_child_process_host_impl.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/dump_without_crashing.h" 10 #include "base/debug/dump_without_crashing.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 // list. 201 // list.
202 BrowserChildProcessList copy = g_child_process_list.Get(); 202 BrowserChildProcessList copy = g_child_process_list.Get();
203 for (BrowserChildProcessList::iterator it = copy.begin(); 203 for (BrowserChildProcessList::iterator it = copy.begin();
204 it != copy.end(); ++it) { 204 it != copy.end(); ++it) {
205 delete (*it)->delegate(); // ~*HostDelegate deletes *HostImpl. 205 delete (*it)->delegate(); // ~*HostDelegate deletes *HostImpl.
206 } 206 }
207 } 207 }
208 208
209 // static 209 // static
210 void BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags( 210 void BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags(
211 base::CommandLine* cmd_line) { 211 base::CommandLine* cmd_line,
212 base::SharedMemory* shared_memory) {
212 std::string enabled_features; 213 std::string enabled_features;
213 std::string disabled_features; 214 std::string disabled_features;
214 base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features, 215 base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features,
215 &disabled_features); 216 &disabled_features);
216 if (!enabled_features.empty()) 217 if (!enabled_features.empty())
217 cmd_line->AppendSwitchASCII(switches::kEnableFeatures, enabled_features); 218 cmd_line->AppendSwitchASCII(switches::kEnableFeatures, enabled_features);
218 if (!disabled_features.empty()) 219 if (!disabled_features.empty())
219 cmd_line->AppendSwitchASCII(switches::kDisableFeatures, disabled_features); 220 cmd_line->AppendSwitchASCII(switches::kDisableFeatures, disabled_features);
220 221
221 // If we run base::FieldTrials, we want to pass to their state to the 222 // If we run base::FieldTrials, we want to pass to their state to the
222 // child process so that it can act in accordance with each state. 223 // child process so that it can act in accordance with each state.
223 std::string field_trial_states; 224 std::string field_trial_states;
224 base::FieldTrialList::AllStatesToString(&field_trial_states); 225 base::FieldTrialList::AllStatesToString(&field_trial_states);
225 if (!field_trial_states.empty()) { 226 if (!field_trial_states.empty()) {
226 cmd_line->AppendSwitchASCII(switches::kForceFieldTrials, 227 // Use shared memory to pass field_trial_states if we can, otherwise
227 field_trial_states); 228 // fallback to the command line.
229 if (shared_memory) {
230 size_t length = field_trial_states.size() + 1;
231 shared_memory->CreateAndMapAnonymous(length);
232 memcpy(shared_memory->memory(), field_trial_states.c_str(), length);
233
234 // HANDLE is just typedef'd to void *
235 auto uintptr_handle =
236 reinterpret_cast<std::uintptr_t>(shared_memory->handle().GetHandle());
237 std::string field_trial_handle =
238 std::to_string(uintptr_handle) + "," + std::to_string(length);
239
240 cmd_line->AppendSwitchASCII(switches::kFieldTrialHandle,
241 field_trial_handle);
242 } else {
243 cmd_line->AppendSwitchASCII(switches::kForceFieldTrials,
244 field_trial_states);
245 }
228 } 246 }
229 } 247 }
230 248
231 void BrowserChildProcessHostImpl::Launch( 249 void BrowserChildProcessHostImpl::Launch(
232 SandboxedProcessLauncherDelegate* delegate, 250 SandboxedProcessLauncherDelegate* delegate,
233 base::CommandLine* cmd_line, 251 base::CommandLine* cmd_line,
252 const base::SharedMemory* field_trial_state,
234 bool terminate_on_shutdown) { 253 bool terminate_on_shutdown) {
235 DCHECK_CURRENTLY_ON(BrowserThread::IO); 254 DCHECK_CURRENTLY_ON(BrowserThread::IO);
236 255
237 GetContentClient()->browser()->AppendExtraCommandLineSwitches( 256 GetContentClient()->browser()->AppendExtraCommandLineSwitches(
238 cmd_line, data_.id); 257 cmd_line, data_.id);
239 258
240 const base::CommandLine& browser_command_line = 259 const base::CommandLine& browser_command_line =
241 *base::CommandLine::ForCurrentProcess(); 260 *base::CommandLine::ForCurrentProcess();
242 static const char* const kForwardSwitches[] = { 261 static const char* const kForwardSwitches[] = {
243 switches::kDisableLogging, 262 switches::kDisableLogging,
244 switches::kEnableLogging, 263 switches::kEnableLogging,
245 switches::kIPCConnectionTimeout, 264 switches::kIPCConnectionTimeout,
246 switches::kLoggingLevel, 265 switches::kLoggingLevel,
247 switches::kTraceToConsole, 266 switches::kTraceToConsole,
248 switches::kV, 267 switches::kV,
249 switches::kVModule, 268 switches::kVModule,
250 }; 269 };
251 cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches, 270 cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches,
252 arraysize(kForwardSwitches)); 271 arraysize(kForwardSwitches));
253 272
254 if (child_connection_) { 273 if (child_connection_) {
255 cmd_line->AppendSwitchASCII(switches::kMojoApplicationChannelToken, 274 cmd_line->AppendSwitchASCII(switches::kMojoApplicationChannelToken,
256 child_connection_->service_token()); 275 child_connection_->service_token());
257 } 276 }
258 277
259 notify_child_disconnected_ = true; 278 notify_child_disconnected_ = true;
260 child_process_.reset(new ChildProcessLauncher( 279 child_process_.reset(new ChildProcessLauncher(
261 delegate, 280 delegate, cmd_line, data_.id, this, field_trial_state, child_token_,
262 cmd_line,
263 data_.id,
264 this,
265 child_token_,
266 base::Bind(&BrowserChildProcessHostImpl::OnMojoError, 281 base::Bind(&BrowserChildProcessHostImpl::OnMojoError,
267 weak_factory_.GetWeakPtr(), 282 weak_factory_.GetWeakPtr(),
268 base::ThreadTaskRunnerHandle::Get()), 283 base::ThreadTaskRunnerHandle::Get()),
269 terminate_on_shutdown)); 284 terminate_on_shutdown));
270 } 285 }
271 286
272 const ChildProcessData& BrowserChildProcessHostImpl::GetData() const { 287 const ChildProcessData& BrowserChildProcessHostImpl::GetData() const {
273 DCHECK_CURRENTLY_ON(BrowserThread::IO); 288 DCHECK_CURRENTLY_ON(BrowserThread::IO);
274 return data_; 289 return data_;
275 } 290 }
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 617
603 #if defined(OS_WIN) 618 #if defined(OS_WIN)
604 619
605 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) { 620 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) {
606 OnChildDisconnected(); 621 OnChildDisconnected();
607 } 622 }
608 623
609 #endif 624 #endif
610 625
611 } // namespace content 626 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698