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

Side by Side Diff: mojo/runner/host/child_process.cc

Issue 1538823002: Convert Pass()→std::move() in mojo/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 | « mojo/runner/context.cc ('k') | mojo/runner/host/child_process_host.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/runner/host/child_process.h" 5 #include "mojo/runner/host/child_process.h"
6 6
7 #include <utility>
8
7 #include "base/base_switches.h" 9 #include "base/base_switches.h"
8 #include "base/bind.h" 10 #include "base/bind.h"
9 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
10 #include "base/command_line.h" 12 #include "base/command_line.h"
11 #include "base/debug/stack_trace.h" 13 #include "base/debug/stack_trace.h"
12 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
13 #include "base/i18n/icu_util.h" 15 #include "base/i18n/icu_util.h"
14 #include "base/location.h" 16 #include "base/location.h"
15 #include "base/logging.h" 17 #include "base/logging.h"
16 #include "base/macros.h" 18 #include "base/macros.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 151
150 base::SingleThreadTaskRunner* io_runner() const { return io_runner_.get(); } 152 base::SingleThreadTaskRunner* io_runner() const { return io_runner_.get(); }
151 153
152 base::SingleThreadTaskRunner* controller_runner() const { 154 base::SingleThreadTaskRunner* controller_runner() const {
153 return controller_runner_.get(); 155 return controller_runner_.get();
154 } 156 }
155 157
156 ChildControllerImpl* controller() const { return controller_.get(); } 158 ChildControllerImpl* controller() const { return controller_.get(); }
157 159
158 void set_controller(scoped_ptr<ChildControllerImpl> controller) { 160 void set_controller(scoped_ptr<ChildControllerImpl> controller) {
159 controller_ = controller.Pass(); 161 controller_ = std::move(controller);
160 } 162 }
161 163
162 private: 164 private:
163 void ShutdownOnControllerThread() { 165 void ShutdownOnControllerThread() {
164 // First, destroy the controller. 166 // First, destroy the controller.
165 controller_.reset(); 167 controller_.reset();
166 168
167 // Next shutdown IPC. We'll unblock the main thread in OnShutdownComplete(). 169 // Next shutdown IPC. We'll unblock the main thread in OnShutdownComplete().
168 embedder::ShutdownIPCSupport(); 170 embedder::ShutdownIPCSupport();
169 } 171 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 ScopedMessagePipeHandle host_message_pipe, 208 ScopedMessagePipeHandle host_message_pipe,
207 const Blocker::Unblocker& unblocker) { 209 const Blocker::Unblocker& unblocker) {
208 DCHECK(app_context); 210 DCHECK(app_context);
209 DCHECK(host_message_pipe.is_valid()); 211 DCHECK(host_message_pipe.is_valid());
210 212
211 DCHECK(!app_context->controller()); 213 DCHECK(!app_context->controller());
212 214
213 scoped_ptr<ChildControllerImpl> impl( 215 scoped_ptr<ChildControllerImpl> impl(
214 new ChildControllerImpl(app_context, app_library, unblocker)); 216 new ChildControllerImpl(app_context, app_library, unblocker));
215 217
216 impl->Bind(host_message_pipe.Pass()); 218 impl->Bind(std::move(host_message_pipe));
217 219
218 app_context->set_controller(impl.Pass()); 220 app_context->set_controller(std::move(impl));
219 } 221 }
220 222
221 void Bind(ScopedMessagePipeHandle handle) { 223 void Bind(ScopedMessagePipeHandle handle) {
222 binding_.Bind(handle.Pass()); 224 binding_.Bind(std::move(handle));
223 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); 225 binding_.set_connection_error_handler([this]() { OnConnectionError(); });
224 } 226 }
225 227
226 void OnConnectionError() { 228 void OnConnectionError() {
227 // A connection error means the connection to the shell is lost. This is not 229 // A connection error means the connection to the shell is lost. This is not
228 // recoverable. 230 // recoverable.
229 LOG(ERROR) << "Connection error to the shell."; 231 LOG(ERROR) << "Connection error to the shell.";
230 _exit(1); 232 _exit(1);
231 } 233 }
232 234
(...skipping 19 matching lines...) Expand all
252 const Blocker::Unblocker& unblocker) 254 const Blocker::Unblocker& unblocker)
253 : app_context_(app_context), 255 : app_context_(app_context),
254 app_library_(app_library), 256 app_library_(app_library),
255 unblocker_(unblocker), 257 unblocker_(unblocker),
256 channel_info_(nullptr), 258 channel_info_(nullptr),
257 binding_(this) {} 259 binding_(this) {}
258 260
259 static void StartAppOnMainThread( 261 static void StartAppOnMainThread(
260 base::NativeLibrary app_library, 262 base::NativeLibrary app_library,
261 InterfaceRequest<Application> application_request) { 263 InterfaceRequest<Application> application_request) {
262 if (!RunNativeApplication(app_library, application_request.Pass())) { 264 if (!RunNativeApplication(app_library, std::move(application_request))) {
263 LOG(ERROR) << "Failure to RunNativeApplication()"; 265 LOG(ERROR) << "Failure to RunNativeApplication()";
264 } 266 }
265 } 267 }
266 268
267 base::ThreadChecker thread_checker_; 269 base::ThreadChecker thread_checker_;
268 AppContext* const app_context_; 270 AppContext* const app_context_;
269 base::NativeLibrary app_library_; 271 base::NativeLibrary app_library_;
270 Blocker::Unblocker unblocker_; 272 Blocker::Unblocker unblocker_;
271 StartAppCallback on_app_complete_; 273 StartAppCallback on_app_complete_;
272 274
(...skipping 18 matching lines...) Expand all
291 // support integrated into mojo. 293 // support integrated into mojo.
292 std::vector<BrokerFilePermission> permissions; 294 std::vector<BrokerFilePermission> permissions;
293 permissions.push_back( 295 permissions.push_back(
294 BrokerFilePermission::ReadWriteCreateUnlinkRecursive("/dev/shm/")); 296 BrokerFilePermission::ReadWriteCreateUnlinkRecursive("/dev/shm/"));
295 scoped_ptr<mojo::runner::LinuxSandbox> sandbox( 297 scoped_ptr<mojo::runner::LinuxSandbox> sandbox(
296 new mojo::runner::LinuxSandbox(permissions)); 298 new mojo::runner::LinuxSandbox(permissions));
297 sandbox->Warmup(); 299 sandbox->Warmup();
298 sandbox->EngageNamespaceSandbox(); 300 sandbox->EngageNamespaceSandbox();
299 sandbox->EngageSeccompSandbox(); 301 sandbox->EngageSeccompSandbox();
300 sandbox->Seal(); 302 sandbox->Seal();
301 return sandbox.Pass(); 303 return sandbox;
302 } 304 }
303 #endif 305 #endif
304 306
305 ScopedMessagePipeHandle InitializeHostMessagePipe( 307 ScopedMessagePipeHandle InitializeHostMessagePipe(
306 embedder::ScopedPlatformHandle platform_channel, 308 embedder::ScopedPlatformHandle platform_channel,
307 scoped_refptr<base::TaskRunner> io_task_runner) { 309 scoped_refptr<base::TaskRunner> io_task_runner) {
308 ScopedMessagePipeHandle host_message_pipe(embedder::CreateChannel( 310 ScopedMessagePipeHandle host_message_pipe(
309 platform_channel.Pass(), base::Bind(&DidCreateChannel), io_task_runner)); 311 embedder::CreateChannel(std::move(platform_channel),
312 base::Bind(&DidCreateChannel), io_task_runner));
310 313
311 if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) { 314 if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) {
312 // When using the new Mojo EDK, each message pipe is backed by a platform 315 // When using the new Mojo EDK, each message pipe is backed by a platform
313 // handle. The one platform handle that comes on the command line is used 316 // handle. The one platform handle that comes on the command line is used
314 // to bind to the ChildController interface. However we also want a 317 // to bind to the ChildController interface. However we also want a
315 // platform handle to setup the communication channel by which we exchange 318 // platform handle to setup the communication channel by which we exchange
316 // handles to/from tokens, which is needed for sandboxed Windows 319 // handles to/from tokens, which is needed for sandboxed Windows
317 // processes. 320 // processes.
318 char broker_handle[10]; 321 char broker_handle[10];
319 MojoHandleSignalsState state; 322 MojoHandleSignalsState state;
320 MojoResult rv = 323 MojoResult rv =
321 MojoWait(host_message_pipe.get().value(), MOJO_HANDLE_SIGNAL_READABLE, 324 MojoWait(host_message_pipe.get().value(), MOJO_HANDLE_SIGNAL_READABLE,
322 MOJO_DEADLINE_INDEFINITE, &state); 325 MOJO_DEADLINE_INDEFINITE, &state);
323 CHECK_EQ(MOJO_RESULT_OK, rv); 326 CHECK_EQ(MOJO_RESULT_OK, rv);
324 uint32_t num_bytes = arraysize(broker_handle); 327 uint32_t num_bytes = arraysize(broker_handle);
325 rv = MojoReadMessage(host_message_pipe.get().value(), 328 rv = MojoReadMessage(host_message_pipe.get().value(),
326 broker_handle, &num_bytes, nullptr, 0, 329 broker_handle, &num_bytes, nullptr, 0,
327 MOJO_READ_MESSAGE_FLAG_NONE); 330 MOJO_READ_MESSAGE_FLAG_NONE);
328 CHECK_EQ(MOJO_RESULT_OK, rv); 331 CHECK_EQ(MOJO_RESULT_OK, rv);
329 332
330 edk::ScopedPlatformHandle broker_channel = 333 edk::ScopedPlatformHandle broker_channel =
331 edk::PlatformChannelPair::PassClientHandleFromParentProcessFromString( 334 edk::PlatformChannelPair::PassClientHandleFromParentProcessFromString(
332 std::string(broker_handle, num_bytes)); 335 std::string(broker_handle, num_bytes));
333 CHECK(broker_channel.is_valid()); 336 CHECK(broker_channel.is_valid());
334 embedder::SetParentPipeHandle( 337 embedder::SetParentPipeHandle(
335 mojo::embedder::ScopedPlatformHandle(mojo::embedder::PlatformHandle( 338 mojo::embedder::ScopedPlatformHandle(mojo::embedder::PlatformHandle(
336 broker_channel.release().handle))); 339 broker_channel.release().handle)));
337 } 340 }
338 341
339 return host_message_pipe.Pass(); 342 return host_message_pipe;
340 } 343 }
341 344
342 } // namespace 345 } // namespace
343 346
344 int ChildProcessMain() { 347 int ChildProcessMain() {
345 DVLOG(2) << "ChildProcessMain()"; 348 DVLOG(2) << "ChildProcessMain()";
346 const base::CommandLine& command_line = 349 const base::CommandLine& command_line =
347 *base::CommandLine::ForCurrentProcess(); 350 *base::CommandLine::ForCurrentProcess();
348 351
349 #if defined(OS_LINUX) && !defined(OS_ANDROID) 352 #if defined(OS_LINUX) && !defined(OS_ANDROID)
(...skipping 19 matching lines...) Expand all
369 embedder::ScopedPlatformHandle platform_channel = 372 embedder::ScopedPlatformHandle platform_channel =
370 embedder::PlatformChannelPair::PassClientHandleFromParentProcess( 373 embedder::PlatformChannelPair::PassClientHandleFromParentProcess(
371 command_line); 374 command_line);
372 CHECK(platform_channel.is_valid()); 375 CHECK(platform_channel.is_valid());
373 376
374 DCHECK(!base::MessageLoop::current()); 377 DCHECK(!base::MessageLoop::current());
375 378
376 AppContext app_context; 379 AppContext app_context;
377 app_context.Init(); 380 app_context.Init();
378 ScopedMessagePipeHandle host_message_pipe = InitializeHostMessagePipe( 381 ScopedMessagePipeHandle host_message_pipe = InitializeHostMessagePipe(
379 platform_channel.Pass(), app_context.io_runner()); 382 std::move(platform_channel), app_context.io_runner());
380 app_context.StartControllerThread(); 383 app_context.StartControllerThread();
381 Blocker blocker; 384 Blocker blocker;
382 app_context.controller_runner()->PostTask( 385 app_context.controller_runner()->PostTask(
383 FROM_HERE, 386 FROM_HERE,
384 base::Bind(&ChildControllerImpl::Init, base::Unretained(&app_context), 387 base::Bind(&ChildControllerImpl::Init, base::Unretained(&app_context),
385 base::Unretained(app_library), 388 base::Unretained(app_library),
386 base::Passed(&host_message_pipe), blocker.GetUnblocker())); 389 base::Passed(&host_message_pipe), blocker.GetUnblocker()));
387 // This will block, then run whatever the controller wants. 390 // This will block, then run whatever the controller wants.
388 blocker.Block(); 391 blocker.Block();
389 392
390 app_context.Shutdown(); 393 app_context.Shutdown();
391 394
392 return 0; 395 return 0;
393 } 396 }
394 397
395 } // namespace runner 398 } // namespace runner
396 } // namespace mojo 399 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/runner/context.cc ('k') | mojo/runner/host/child_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698