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

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

Issue 2686983003: Avoid a thread hop when initializing IPC to new processes (Closed)
Patch Set: . Created 3 years, 10 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/i18n/icu_util.h" 10 #include "base/i18n/icu_util.h"
(...skipping 12 matching lines...) Expand all
23 std::unique_ptr<base::CommandLine> command_line, 23 std::unique_ptr<base::CommandLine> command_line,
24 int child_process_id, 24 int child_process_id,
25 Client* client, 25 Client* client,
26 std::unique_ptr<mojo::edk::PendingProcessConnection> pending_connection, 26 std::unique_ptr<mojo::edk::PendingProcessConnection> pending_connection,
27 const mojo::edk::ProcessErrorCallback& process_error_callback, 27 const mojo::edk::ProcessErrorCallback& process_error_callback,
28 bool terminate_on_shutdown) 28 bool terminate_on_shutdown)
29 : client_(client), 29 : client_(client),
30 termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION), 30 termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION),
31 exit_code_(RESULT_CODE_NORMAL_EXIT), 31 exit_code_(RESULT_CODE_NORMAL_EXIT),
32 starting_(true), 32 starting_(true),
33 pending_connection_(std::move(pending_connection)),
34 process_error_callback_(process_error_callback), 33 process_error_callback_(process_error_callback),
35 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ 34 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \
36 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ 35 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \
37 defined(UNDEFINED_SANITIZER) 36 defined(UNDEFINED_SANITIZER)
38 terminate_child_on_shutdown_(false), 37 terminate_child_on_shutdown_(false),
39 #else 38 #else
40 terminate_child_on_shutdown_(terminate_on_shutdown), 39 terminate_child_on_shutdown_(terminate_on_shutdown),
41 #endif 40 #endif
42 weak_factory_(this) { 41 weak_factory_(this) {
43 DCHECK(CalledOnValidThread()); 42 DCHECK(CalledOnValidThread());
44 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); 43 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_));
45 44
46 helper_ = new ChildProcessLauncherHelper( 45 helper_ = new ChildProcessLauncherHelper(
47 child_process_id, client_thread_id_, 46 child_process_id, client_thread_id_, std::move(command_line),
48 std::move(command_line), std::move(delegate), 47 std::move(delegate), std::move(pending_connection),
49 weak_factory_.GetWeakPtr(), terminate_on_shutdown); 48 process_error_callback_, weak_factory_.GetWeakPtr(),
49 terminate_on_shutdown);
50 helper_->StartLaunchOnClientThread(); 50 helper_->StartLaunchOnClientThread();
51 } 51 }
52 52
53 ChildProcessLauncher::~ChildProcessLauncher() { 53 ChildProcessLauncher::~ChildProcessLauncher() {
54 DCHECK(CalledOnValidThread()); 54 DCHECK(CalledOnValidThread());
55 if (process_.process.IsValid() && terminate_child_on_shutdown_) { 55 if (process_.process.IsValid() && terminate_child_on_shutdown_) {
56 // Client has gone away, so just kill the process. 56 // Client has gone away, so just kill the process.
57 ChildProcessLauncherHelper::ForceNormalProcessTerminationAsync( 57 ChildProcessLauncherHelper::ForceNormalProcessTerminationAsync(
58 std::move(process_)); 58 std::move(process_));
59 } 59 }
60 } 60 }
61 61
62 void ChildProcessLauncher::SetProcessBackgrounded(bool background) { 62 void ChildProcessLauncher::SetProcessBackgrounded(bool background) {
63 DCHECK(CalledOnValidThread()); 63 DCHECK(CalledOnValidThread());
64 base::Process to_pass = process_.process.Duplicate(); 64 base::Process to_pass = process_.process.Duplicate();
65 BrowserThread::PostTask( 65 BrowserThread::PostTask(
66 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, 66 BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
67 base::Bind( 67 base::Bind(
68 &ChildProcessLauncherHelper::SetProcessBackgroundedOnLauncherThread, 68 &ChildProcessLauncherHelper::SetProcessBackgroundedOnLauncherThread,
69 base::Passed(&to_pass), 69 base::Passed(&to_pass),
70 background)); 70 background));
71 } 71 }
72 72
73 void ChildProcessLauncher::Notify( 73 void ChildProcessLauncher::Notify(ChildProcessLauncherHelper::Process process,
74 ChildProcessLauncherHelper::Process process, 74 int error_code) {
75 mojo::edk::ScopedPlatformHandle server_handle,
76 int error_code) {
77 DCHECK(CalledOnValidThread()); 75 DCHECK(CalledOnValidThread());
78 starting_ = false; 76 starting_ = false;
79 process_ = std::move(process); 77 process_ = std::move(process);
80 78
81 // Take ownership of the pending connection here so it's destroyed when 79 // Take ownership of the pending connection here so it's destroyed when
82 // we go out of scope regardless of the outcome below. 80 // we go out of scope regardless of the outcome below.
83 std::unique_ptr<mojo::edk::PendingProcessConnection> pending_connection =
84 std::move(pending_connection_);
85 if (process_.process.IsValid()) { 81 if (process_.process.IsValid()) {
86 // Set up Mojo IPC to the new process.
87 DCHECK(pending_connection);
88 pending_connection->Connect(process_.process.Handle(),
89 std::move(server_handle),
90 process_error_callback_);
91 client_->OnProcessLaunched(); 82 client_->OnProcessLaunched();
92 } else { 83 } else {
93 termination_status_ = base::TERMINATION_STATUS_LAUNCH_FAILED; 84 termination_status_ = base::TERMINATION_STATUS_LAUNCH_FAILED;
94 85
95 // NOTE: May delete |this|. 86 // NOTE: May delete |this|.
96 client_->OnProcessLaunchFailed(error_code); 87 client_->OnProcessLaunchFailed(error_code);
97 } 88 }
98 } 89 }
99 90
100 bool ChildProcessLauncher::IsStarting() { 91 bool ChildProcessLauncher::IsStarting() {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 } 142 }
152 143
153 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( 144 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest(
154 Client* client) { 145 Client* client) {
155 Client* ret = client_; 146 Client* ret = client_;
156 client_ = client; 147 client_ = client;
157 return ret; 148 return ret;
158 } 149 }
159 150
160 } // namespace content 151 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/child_process_launcher.h ('k') | content/browser/child_process_launcher_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698