James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
James Robinson | b4b7af2 | 2014-12-05 11:21:01 -0800 | [diff] [blame] | 5 | #include "shell/child_process.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 6 | |
| 7 | #include "base/command_line.h" |
| 8 | #include "base/logging.h" |
| 9 | #include "base/strings/string_number_conversions.h" |
| 10 | #include "mojo/edk/embedder/platform_channel_pair.h" |
James Robinson | b4b7af2 | 2014-12-05 11:21:01 -0800 | [diff] [blame] | 11 | #include "shell/app_child_process.h" |
| 12 | #include "shell/switches.h" |
| 13 | #include "shell/test_child_process.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 14 | |
| 15 | namespace mojo { |
| 16 | namespace shell { |
| 17 | |
| 18 | ChildProcess::~ChildProcess() { |
| 19 | } |
| 20 | |
| 21 | // static |
| 22 | scoped_ptr<ChildProcess> ChildProcess::Create( |
| 23 | const base::CommandLine& command_line) { |
| 24 | if (!command_line.HasSwitch(switches::kChildProcessType)) |
| 25 | return scoped_ptr<ChildProcess>(); |
| 26 | |
| 27 | int type_as_int; |
James Robinson | b4b7af2 | 2014-12-05 11:21:01 -0800 | [diff] [blame] | 28 | CHECK(base::StringToInt( |
| 29 | command_line.GetSwitchValueASCII(switches::kChildProcessType), |
| 30 | &type_as_int)); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 31 | |
| 32 | scoped_ptr<ChildProcess> rv; |
| 33 | switch (type_as_int) { |
| 34 | case TYPE_TEST: |
| 35 | rv.reset(new TestChildProcess()); |
| 36 | break; |
| 37 | case TYPE_APP: |
| 38 | rv.reset(new AppChildProcess()); |
| 39 | break; |
| 40 | default: |
| 41 | CHECK(false) << "Invalid child process type"; |
| 42 | break; |
| 43 | } |
| 44 | |
| 45 | if (rv) { |
| 46 | rv->platform_channel_ = |
| 47 | embedder::PlatformChannelPair::PassClientHandleFromParentProcess( |
| 48 | command_line); |
| 49 | CHECK(rv->platform_channel_.is_valid()); |
| 50 | } |
| 51 | |
| 52 | return rv.Pass(); |
| 53 | } |
| 54 | |
| 55 | ChildProcess::ChildProcess() { |
| 56 | } |
| 57 | |
| 58 | } // namespace shell |
| 59 | } // namespace mojo |