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

Side by Side Diff: content/browser/child_process_launcher.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 unified diff | Download patch
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 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());
Alexei Svitkine (slow) 2016/10/03 15:28:05 Since both of these functions are const, please pa
lawrencewu 2016/10/03 21:36:11 Done.
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])));
161
Alexei Svitkine (slow) 2016/10/03 15:28:05 Nit: Remove extra added line.
lawrencewu 2016/10/03 21:36:11 Done.
158 launch_result = 162 launch_result =
159 StartSandboxedProcess(delegate, cmd_line, handles, &process); 163 StartSandboxedProcess(delegate, cmd_line, handles, &process);
160 } 164 }
161 #elif defined(OS_POSIX) 165 #elif defined(OS_POSIX)
162 std::string process_type = 166 std::string process_type =
163 cmd_line->GetSwitchValueASCII(switches::kProcessType); 167 cmd_line->GetSwitchValueASCII(switches::kProcessType);
164 std::unique_ptr<FileDescriptorInfo> files_to_register( 168 std::unique_ptr<FileDescriptorInfo> files_to_register(
165 FileDescriptorInfoImpl::Create()); 169 FileDescriptorInfoImpl::Create());
166 170
167 base::ScopedFD mojo_fd(client_handle.release().handle); 171 base::ScopedFD mojo_fd(client_handle.release().handle);
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 } 388 }
385 #if defined(OS_ANDROID) 389 #if defined(OS_ANDROID)
386 SetChildProcessInForeground(process.Handle(), !background); 390 SetChildProcessInForeground(process.Handle(), !background);
387 #endif 391 #endif
388 } 392 }
389 393
390 } // namespace 394 } // namespace
391 395
392 ChildProcessLauncher::ChildProcessLauncher( 396 ChildProcessLauncher::ChildProcessLauncher(
393 SandboxedProcessLauncherDelegate* delegate, 397 SandboxedProcessLauncherDelegate* delegate,
398 base::SharedMemory* field_trial_state,
Alexei Svitkine (slow) 2016/10/03 15:28:05 Suggest moving this further down - maybe after cli
lawrencewu 2016/10/03 21:36:11 Done.
394 base::CommandLine* cmd_line, 399 base::CommandLine* cmd_line,
395 int child_process_id, 400 int child_process_id,
396 Client* client, 401 Client* client,
397 const std::string& mojo_child_token, 402 const std::string& mojo_child_token,
398 const mojo::edk::ProcessErrorCallback& process_error_callback, 403 const mojo::edk::ProcessErrorCallback& process_error_callback,
399 bool terminate_on_shutdown) 404 bool terminate_on_shutdown)
400 : client_(client), 405 : client_(client),
401 termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION), 406 termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION),
402 exit_code_(RESULT_CODE_NORMAL_EXIT), 407 exit_code_(RESULT_CODE_NORMAL_EXIT),
403 zygote_(nullptr), 408 zygote_(nullptr),
404 starting_(true), 409 starting_(true),
405 process_error_callback_(process_error_callback), 410 process_error_callback_(process_error_callback),
406 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ 411 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \
407 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ 412 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \
408 defined(UNDEFINED_SANITIZER) 413 defined(UNDEFINED_SANITIZER)
409 terminate_child_on_shutdown_(false), 414 terminate_child_on_shutdown_(false),
410 #else 415 #else
411 terminate_child_on_shutdown_(terminate_on_shutdown), 416 terminate_child_on_shutdown_(terminate_on_shutdown),
412 #endif 417 #endif
413 mojo_child_token_(mojo_child_token), 418 mojo_child_token_(mojo_child_token),
414 weak_factory_(this) { 419 weak_factory_(this) {
415 DCHECK(CalledOnValidThread()); 420 DCHECK(CalledOnValidThread());
416 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); 421 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_));
417 Launch(delegate, cmd_line, child_process_id); 422 Launch(delegate, field_trial_state, cmd_line, child_process_id);
418 } 423 }
419 424
420 ChildProcessLauncher::~ChildProcessLauncher() { 425 ChildProcessLauncher::~ChildProcessLauncher() {
421 DCHECK(CalledOnValidThread()); 426 DCHECK(CalledOnValidThread());
422 if (process_.IsValid() && terminate_child_on_shutdown_) { 427 if (process_.IsValid() && terminate_child_on_shutdown_) {
423 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! So 428 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! So
424 // don't this on the UI/IO threads. 429 // don't this on the UI/IO threads.
425 BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE, 430 BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
426 base::Bind(&TerminateOnLauncherThread, zygote_, 431 base::Bind(&TerminateOnLauncherThread, zygote_,
427 base::Passed(&process_))); 432 base::Passed(&process_)));
428 } 433 }
429 } 434 }
430 435
431 void ChildProcessLauncher::Launch( 436 void ChildProcessLauncher::Launch(
432 SandboxedProcessLauncherDelegate* delegate, 437 SandboxedProcessLauncherDelegate* delegate,
438 base::SharedMemory* field_trial_state,
433 base::CommandLine* cmd_line, 439 base::CommandLine* cmd_line,
434 int child_process_id) { 440 int child_process_id) {
435 DCHECK(CalledOnValidThread()); 441 DCHECK(CalledOnValidThread());
436 442
437 #if defined(OS_ANDROID) 443 #if defined(OS_ANDROID)
438 // Android only supports renderer, sandboxed utility and gpu. 444 // Android only supports renderer, sandboxed utility and gpu.
439 std::string process_type = 445 std::string process_type =
440 cmd_line->GetSwitchValueASCII(switches::kProcessType); 446 cmd_line->GetSwitchValueASCII(switches::kProcessType);
441 CHECK(process_type == switches::kGpuProcess || 447 CHECK(process_type == switches::kGpuProcess ||
442 process_type == switches::kRendererProcess || 448 process_type == switches::kRendererProcess ||
(...skipping 30 matching lines...) Expand all
473 weak_factory_.GetWeakPtr(), 479 weak_factory_.GetWeakPtr(),
474 terminate_child_on_shutdown_, 480 terminate_child_on_shutdown_,
475 base::Passed(&server_handle))); 481 base::Passed(&server_handle)));
476 BrowserThread::PostTask( 482 BrowserThread::PostTask(
477 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, 483 BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
478 base::Bind(&LaunchOnLauncherThread, reply_callback, client_thread_id_, 484 base::Bind(&LaunchOnLauncherThread, reply_callback, client_thread_id_,
479 child_process_id, delegate, 485 child_process_id, delegate,
480 #if defined(OS_ANDROID) 486 #if defined(OS_ANDROID)
481 base::Passed(&ipcfd), 487 base::Passed(&ipcfd),
482 #endif 488 #endif
489 field_trial_state,
483 base::Passed(&client_handle), cmd_line)); 490 base::Passed(&client_handle), cmd_line));
484 } 491 }
485 492
486 void ChildProcessLauncher::UpdateTerminationStatus(bool known_dead) { 493 void ChildProcessLauncher::UpdateTerminationStatus(bool known_dead) {
487 DCHECK(CalledOnValidThread()); 494 DCHECK(CalledOnValidThread());
488 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 495 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
489 if (zygote_) { 496 if (zygote_) {
490 termination_status_ = zygote_->GetTerminationStatus( 497 termination_status_ = zygote_->GetTerminationStatus(
491 process_.Handle(), known_dead, &exit_code_); 498 process_.Handle(), known_dead, &exit_code_);
492 } else if (known_dead) { 499 } else if (known_dead) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 } 625 }
619 626
620 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( 627 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest(
621 Client* client) { 628 Client* client) {
622 Client* ret = client_; 629 Client* ret = client_;
623 client_ = client; 630 client_ = client;
624 return ret; 631 return ret;
625 } 632 }
626 633
627 } // namespace content 634 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698