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

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

Issue 2680973006: Mojo EDK: Add safe process connection API (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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/process/launch.h" 12 #include "base/process/launch.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "content/public/common/result_codes.h" 14 #include "content/public/common/result_codes.h"
15 #include "content/public/common/sandboxed_process_launcher_delegate.h" 15 #include "content/public/common/sandboxed_process_launcher_delegate.h"
16 16
17 namespace content { 17 namespace content {
18 18
19 using internal::ChildProcessLauncherHelper; 19 using internal::ChildProcessLauncherHelper;
20 20
21 ChildProcessLauncher::ChildProcessLauncher( 21 ChildProcessLauncher::ChildProcessLauncher(
22 std::unique_ptr<SandboxedProcessLauncherDelegate> delegate, 22 std::unique_ptr<SandboxedProcessLauncherDelegate> delegate,
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 const std::string& mojo_child_token, 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)),
33 process_error_callback_(process_error_callback), 34 process_error_callback_(process_error_callback),
34 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ 35 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \
35 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ 36 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \
36 defined(UNDEFINED_SANITIZER) 37 defined(UNDEFINED_SANITIZER)
37 terminate_child_on_shutdown_(false), 38 terminate_child_on_shutdown_(false),
38 #else 39 #else
39 terminate_child_on_shutdown_(terminate_on_shutdown), 40 terminate_child_on_shutdown_(terminate_on_shutdown),
40 #endif 41 #endif
41 mojo_child_token_(mojo_child_token),
42 weak_factory_(this) { 42 weak_factory_(this) {
43 DCHECK(CalledOnValidThread()); 43 DCHECK(CalledOnValidThread());
44 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); 44 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_));
45 45
46 helper_ = new ChildProcessLauncherHelper( 46 helper_ = new ChildProcessLauncherHelper(
47 child_process_id, client_thread_id_, 47 child_process_id, client_thread_id_,
48 std::move(command_line), std::move(delegate), 48 std::move(command_line), std::move(delegate),
49 weak_factory_.GetWeakPtr(), terminate_on_shutdown); 49 weak_factory_.GetWeakPtr(), terminate_on_shutdown);
50 helper_->StartLaunchOnClientThread(); 50 helper_->StartLaunchOnClientThread();
51 } 51 }
(...skipping 19 matching lines...) Expand all
71 } 71 }
72 72
73 void ChildProcessLauncher::Notify( 73 void ChildProcessLauncher::Notify(
74 ChildProcessLauncherHelper::Process process, 74 ChildProcessLauncherHelper::Process process,
75 mojo::edk::ScopedPlatformHandle server_handle, 75 mojo::edk::ScopedPlatformHandle server_handle,
76 int error_code) { 76 int error_code) {
77 DCHECK(CalledOnValidThread()); 77 DCHECK(CalledOnValidThread());
78 starting_ = false; 78 starting_ = false;
79 process_ = std::move(process); 79 process_ = std::move(process);
80 80
81 // Take ownership of the pending connection here so it's destroyed when
82 // we go out of scope regardless of the outcome below.
83 std::unique_ptr<mojo::edk::PendingProcessConnection> pending_connection =
84 std::move(pending_connection_);
81 if (process_.process.IsValid()) { 85 if (process_.process.IsValid()) {
82 // Set up Mojo IPC to the new process. 86 // Set up Mojo IPC to the new process.
83 mojo::edk::ChildProcessLaunched(process_.process.Handle(), 87 DCHECK(pending_connection);
84 std::move(server_handle), 88 pending_connection->Connect(process_.process.Handle(),
85 mojo_child_token_, 89 std::move(server_handle),
86 process_error_callback_); 90 process_error_callback_);
87 client_->OnProcessLaunched(); 91 client_->OnProcessLaunched();
88 } else { 92 } else {
89 mojo::edk::ChildProcessLaunchFailed(mojo_child_token_);
90 termination_status_ = base::TERMINATION_STATUS_LAUNCH_FAILED; 93 termination_status_ = base::TERMINATION_STATUS_LAUNCH_FAILED;
94
95 // NOTE: May delete |this|.
91 client_->OnProcessLaunchFailed(error_code); 96 client_->OnProcessLaunchFailed(error_code);
92 } 97 }
93 } 98 }
94 99
95 bool ChildProcessLauncher::IsStarting() { 100 bool ChildProcessLauncher::IsStarting() {
96 // TODO(crbug.com/469248): This fails in some tests. 101 // TODO(crbug.com/469248): This fails in some tests.
97 // DCHECK(CalledOnValidThread()); 102 // DCHECK(CalledOnValidThread());
98 return starting_; 103 return starting_;
99 } 104 }
100 105
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 151 }
147 152
148 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( 153 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest(
149 Client* client) { 154 Client* client) {
150 Client* ret = client_; 155 Client* ret = client_;
151 client_ = client; 156 client_ = client;
152 return ret; 157 return ret;
153 } 158 }
154 159
155 } // namespace content 160 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/child_process_launcher.h ('k') | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698