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

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

Issue 2365273004: Initial implementation for sharing field trial state (win) (Closed)
Patch Set: rebase + gclient sync 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
« no previous file with comments | « content/browser/child_process_launcher.h ('k') | content/browser/gpu/gpu_process_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/child_process_launcher.h" 5 #include "content/browser/child_process_launcher.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 114 }
115 #endif 115 #endif
116 116
117 void LaunchOnLauncherThread(const NotifyCallback& callback, 117 void LaunchOnLauncherThread(const NotifyCallback& callback,
118 BrowserThread::ID client_thread_id, 118 BrowserThread::ID client_thread_id,
119 int child_process_id, 119 int child_process_id,
120 SandboxedProcessLauncherDelegate* delegate, 120 SandboxedProcessLauncherDelegate* delegate,
121 #if defined(OS_ANDROID) 121 #if defined(OS_ANDROID)
122 base::ScopedFD ipcfd, 122 base::ScopedFD ipcfd,
123 #endif 123 #endif
124 const base::SharedMemory* field_trial_state,
124 mojo::edk::ScopedPlatformHandle client_handle, 125 mojo::edk::ScopedPlatformHandle client_handle,
125 base::CommandLine* cmd_line) { 126 base::CommandLine* cmd_line) {
126 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); 127 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
127 std::unique_ptr<SandboxedProcessLauncherDelegate> delegate_deleter(delegate); 128 std::unique_ptr<SandboxedProcessLauncherDelegate> delegate_deleter(delegate);
128 #if !defined(OS_ANDROID) 129 #if !defined(OS_ANDROID)
129 ZygoteHandle zygote = nullptr; 130 ZygoteHandle zygote = nullptr;
130 int launch_result = LAUNCH_RESULT_FAILURE; 131 int launch_result = LAUNCH_RESULT_FAILURE;
131 #endif 132 #endif
132 #if defined(OS_WIN) 133 #if defined(OS_WIN)
133 bool launch_elevated = delegate->ShouldLaunchElevated(); 134 bool launch_elevated = delegate->ShouldLaunchElevated();
(...skipping 11 matching lines...) Expand all
145 #if defined(OS_WIN) 146 #if defined(OS_WIN)
146 if (launch_elevated) { 147 if (launch_elevated) {
147 // When establishing a Mojo connection, the pipe path has already been added 148 // When establishing a Mojo connection, the pipe path has already been added
148 // to the command line. 149 // to the command line.
149 base::LaunchOptions options; 150 base::LaunchOptions options;
150 options.start_hidden = true; 151 options.start_hidden = true;
151 process = base::LaunchElevatedProcess(*cmd_line, options); 152 process = base::LaunchElevatedProcess(*cmd_line, options);
152 } else { 153 } else {
153 base::HandlesToInheritVector handles; 154 base::HandlesToInheritVector handles;
154 handles.push_back(client_handle.get().handle); 155 handles.push_back(client_handle.get().handle);
156 if (field_trial_state)
157 handles.push_back(field_trial_state->handle().GetHandle());
155 cmd_line->AppendSwitchASCII( 158 cmd_line->AppendSwitchASCII(
156 mojo::edk::PlatformChannelPair::kMojoPlatformChannelHandleSwitch, 159 mojo::edk::PlatformChannelPair::kMojoPlatformChannelHandleSwitch,
157 base::UintToString(base::win::HandleToUint32(handles[0]))); 160 base::UintToString(base::win::HandleToUint32(handles[0])));
158 launch_result = 161 launch_result =
159 StartSandboxedProcess(delegate, cmd_line, handles, &process); 162 StartSandboxedProcess(delegate, cmd_line, handles, &process);
160 } 163 }
161 #elif defined(OS_POSIX) 164 #elif defined(OS_POSIX)
162 std::string process_type = 165 std::string process_type =
163 cmd_line->GetSwitchValueASCII(switches::kProcessType); 166 cmd_line->GetSwitchValueASCII(switches::kProcessType);
164 std::unique_ptr<FileDescriptorInfo> files_to_register( 167 std::unique_ptr<FileDescriptorInfo> files_to_register(
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 #endif 393 #endif
391 } 394 }
392 395
393 } // namespace 396 } // namespace
394 397
395 ChildProcessLauncher::ChildProcessLauncher( 398 ChildProcessLauncher::ChildProcessLauncher(
396 SandboxedProcessLauncherDelegate* delegate, 399 SandboxedProcessLauncherDelegate* delegate,
397 base::CommandLine* cmd_line, 400 base::CommandLine* cmd_line,
398 int child_process_id, 401 int child_process_id,
399 Client* client, 402 Client* client,
403 const base::SharedMemory* field_trial_state,
400 const std::string& mojo_child_token, 404 const std::string& mojo_child_token,
401 const mojo::edk::ProcessErrorCallback& process_error_callback, 405 const mojo::edk::ProcessErrorCallback& process_error_callback,
402 bool terminate_on_shutdown) 406 bool terminate_on_shutdown)
403 : client_(client), 407 : client_(client),
404 termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION), 408 termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION),
405 exit_code_(RESULT_CODE_NORMAL_EXIT), 409 exit_code_(RESULT_CODE_NORMAL_EXIT),
406 zygote_(nullptr), 410 zygote_(nullptr),
407 starting_(true), 411 starting_(true),
408 process_error_callback_(process_error_callback), 412 process_error_callback_(process_error_callback),
409 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ 413 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \
410 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ 414 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \
411 defined(UNDEFINED_SANITIZER) 415 defined(UNDEFINED_SANITIZER)
412 terminate_child_on_shutdown_(false), 416 terminate_child_on_shutdown_(false),
413 #else 417 #else
414 terminate_child_on_shutdown_(terminate_on_shutdown), 418 terminate_child_on_shutdown_(terminate_on_shutdown),
415 #endif 419 #endif
416 mojo_child_token_(mojo_child_token), 420 mojo_child_token_(mojo_child_token),
417 weak_factory_(this) { 421 weak_factory_(this) {
418 DCHECK(CalledOnValidThread()); 422 DCHECK(CalledOnValidThread());
419 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); 423 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_));
420 Launch(delegate, cmd_line, child_process_id); 424 Launch(delegate, cmd_line, child_process_id, field_trial_state);
421 } 425 }
422 426
423 ChildProcessLauncher::~ChildProcessLauncher() { 427 ChildProcessLauncher::~ChildProcessLauncher() {
424 DCHECK(CalledOnValidThread()); 428 DCHECK(CalledOnValidThread());
425 if (process_.IsValid() && terminate_child_on_shutdown_) { 429 if (process_.IsValid() && terminate_child_on_shutdown_) {
426 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! So 430 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! So
427 // don't this on the UI/IO threads. 431 // don't this on the UI/IO threads.
428 BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE, 432 BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
429 base::Bind(&TerminateOnLauncherThread, zygote_, 433 base::Bind(&TerminateOnLauncherThread, zygote_,
430 base::Passed(&process_))); 434 base::Passed(&process_)));
431 } 435 }
432 } 436 }
433 437
434 void ChildProcessLauncher::Launch( 438 void ChildProcessLauncher::Launch(SandboxedProcessLauncherDelegate* delegate,
435 SandboxedProcessLauncherDelegate* delegate, 439 base::CommandLine* cmd_line,
436 base::CommandLine* cmd_line, 440 int child_process_id,
437 int child_process_id) { 441 const base::SharedMemory* field_trial_state) {
438 DCHECK(CalledOnValidThread()); 442 DCHECK(CalledOnValidThread());
439 443
440 #if defined(OS_ANDROID) 444 #if defined(OS_ANDROID)
441 // Android only supports renderer, sandboxed utility and gpu. 445 // Android only supports renderer, sandboxed utility and gpu.
442 std::string process_type = 446 std::string process_type =
443 cmd_line->GetSwitchValueASCII(switches::kProcessType); 447 cmd_line->GetSwitchValueASCII(switches::kProcessType);
444 CHECK(process_type == switches::kGpuProcess || 448 CHECK(process_type == switches::kGpuProcess ||
445 process_type == switches::kRendererProcess || 449 process_type == switches::kRendererProcess ||
446 #if defined(ENABLE_PLUGINS) 450 #if defined(ENABLE_PLUGINS)
447 process_type == switches::kPpapiPluginProcess || 451 process_type == switches::kPpapiPluginProcess ||
(...skipping 28 matching lines...) Expand all
476 weak_factory_.GetWeakPtr(), 480 weak_factory_.GetWeakPtr(),
477 terminate_child_on_shutdown_, 481 terminate_child_on_shutdown_,
478 base::Passed(&server_handle))); 482 base::Passed(&server_handle)));
479 BrowserThread::PostTask( 483 BrowserThread::PostTask(
480 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, 484 BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
481 base::Bind(&LaunchOnLauncherThread, reply_callback, client_thread_id_, 485 base::Bind(&LaunchOnLauncherThread, reply_callback, client_thread_id_,
482 child_process_id, delegate, 486 child_process_id, delegate,
483 #if defined(OS_ANDROID) 487 #if defined(OS_ANDROID)
484 base::Passed(&ipcfd), 488 base::Passed(&ipcfd),
485 #endif 489 #endif
486 base::Passed(&client_handle), cmd_line)); 490 field_trial_state, base::Passed(&client_handle), cmd_line));
487 } 491 }
488 492
489 void ChildProcessLauncher::UpdateTerminationStatus(bool known_dead) { 493 void ChildProcessLauncher::UpdateTerminationStatus(bool known_dead) {
490 DCHECK(CalledOnValidThread()); 494 DCHECK(CalledOnValidThread());
491 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 495 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
492 if (zygote_) { 496 if (zygote_) {
493 termination_status_ = zygote_->GetTerminationStatus( 497 termination_status_ = zygote_->GetTerminationStatus(
494 process_.Handle(), known_dead, &exit_code_); 498 process_.Handle(), known_dead, &exit_code_);
495 } else if (known_dead) { 499 } else if (known_dead) {
496 termination_status_ = 500 termination_status_ =
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 } 625 }
622 626
623 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( 627 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest(
624 Client* client) { 628 Client* client) {
625 Client* ret = client_; 629 Client* ret = client_;
626 client_ = client; 630 client_ = client;
627 return ret; 631 return ret;
628 } 632 }
629 633
630 } // namespace content 634 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/child_process_launcher.h ('k') | content/browser/gpu/gpu_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698