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

Side by Side Diff: services/service_manager/runner/host/service_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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "services/service_manager/runner/host/service_process_launcher.h" 5 #include "services/service_manager/runner/host/service_process_launcher.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 29 matching lines...) Expand all
40 namespace service_manager { 40 namespace service_manager {
41 41
42 ServiceProcessLauncher::ServiceProcessLauncher( 42 ServiceProcessLauncher::ServiceProcessLauncher(
43 base::TaskRunner* launch_process_runner, 43 base::TaskRunner* launch_process_runner,
44 Delegate* delegate, 44 Delegate* delegate,
45 const base::FilePath& service_path) 45 const base::FilePath& service_path)
46 : launch_process_runner_(launch_process_runner), 46 : launch_process_runner_(launch_process_runner),
47 delegate_(delegate), 47 delegate_(delegate),
48 start_sandboxed_(false), 48 start_sandboxed_(false),
49 service_path_(service_path), 49 service_path_(service_path),
50 child_token_(mojo::edk::GenerateRandomToken()),
51 start_child_process_event_( 50 start_child_process_event_(
52 base::WaitableEvent::ResetPolicy::AUTOMATIC, 51 base::WaitableEvent::ResetPolicy::AUTOMATIC,
53 base::WaitableEvent::InitialState::NOT_SIGNALED), 52 base::WaitableEvent::InitialState::NOT_SIGNALED),
54 weak_factory_(this) { 53 weak_factory_(this) {
55 if (service_path_.empty()) 54 if (service_path_.empty())
56 service_path_ = base::CommandLine::ForCurrentProcess()->GetProgram(); 55 service_path_ = base::CommandLine::ForCurrentProcess()->GetProgram();
57 } 56 }
58 57
59 ServiceProcessLauncher::~ServiceProcessLauncher() { 58 ServiceProcessLauncher::~ServiceProcessLauncher() {
60 Join(); 59 Join();
(...skipping 22 matching lines...) Expand all
83 child_command_line->AppendSwitchASCII("u", target.user_id()); 82 child_command_line->AppendSwitchASCII("u", target.user_id());
84 #endif 83 #endif
85 84
86 if (start_sandboxed_) 85 if (start_sandboxed_)
87 child_command_line->AppendSwitch(::switches::kEnableSandbox); 86 child_command_line->AppendSwitch(::switches::kEnableSandbox);
88 87
89 mojo_ipc_channel_.reset(new mojo::edk::PlatformChannelPair); 88 mojo_ipc_channel_.reset(new mojo::edk::PlatformChannelPair);
90 mojo_ipc_channel_->PrepareToPassClientHandleToChildProcess( 89 mojo_ipc_channel_->PrepareToPassClientHandleToChildProcess(
91 child_command_line.get(), &handle_passing_info_); 90 child_command_line.get(), &handle_passing_info_);
92 91
93 mojom::ServicePtr client = 92 mojom::ServicePtr client = PassServiceRequestOnCommandLine(
94 PassServiceRequestOnCommandLine(child_command_line.get(), child_token_); 93 &process_connection_, child_command_line.get());
95 launch_process_runner_->PostTaskAndReply( 94 launch_process_runner_->PostTaskAndReply(
96 FROM_HERE, 95 FROM_HERE,
97 base::Bind(&ServiceProcessLauncher::DoLaunch, base::Unretained(this), 96 base::Bind(&ServiceProcessLauncher::DoLaunch, base::Unretained(this),
98 base::Passed(&child_command_line)), 97 base::Passed(&child_command_line)),
99 base::Bind(&ServiceProcessLauncher::DidStart, 98 base::Bind(&ServiceProcessLauncher::DidStart,
100 weak_factory_.GetWeakPtr(), callback)); 99 weak_factory_.GetWeakPtr(), callback));
101 return client; 100 return client;
102 } 101 }
103 102
104 void ServiceProcessLauncher::Join() { 103 void ServiceProcessLauncher::Join() {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 189 }
191 190
192 if (child_process_.IsValid()) { 191 if (child_process_.IsValid()) {
193 DVLOG(0) << "Launched child process pid=" << child_process_.Pid() 192 DVLOG(0) << "Launched child process pid=" << child_process_.Pid()
194 << ", instance=" << target_.instance() 193 << ", instance=" << target_.instance()
195 << ", name=" << target_.name() 194 << ", name=" << target_.name()
196 << ", user_id=" << target_.user_id(); 195 << ", user_id=" << target_.user_id();
197 196
198 if (mojo_ipc_channel_.get()) { 197 if (mojo_ipc_channel_.get()) {
199 mojo_ipc_channel_->ChildProcessLaunched(); 198 mojo_ipc_channel_->ChildProcessLaunched();
200 mojo::edk::ChildProcessLaunched( 199 process_connection_.Connect(child_process_.Handle(),
201 child_process_.Handle(), 200 mojo_ipc_channel_->PassServerHandle());
202 mojo::edk::ScopedPlatformHandle(mojo::edk::PlatformHandle(
203 mojo_ipc_channel_->PassServerHandle().release().handle)),
204 child_token_);
205 } 201 }
206 } 202 }
207 start_child_process_event_.Signal(); 203 start_child_process_event_.Signal();
208 } 204 }
209 205
210 } // namespace service_manager 206 } // namespace service_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698