blob: e53ac0af2abf6d1140aac6cc692d4775976ba3ad [file] [log] [blame]
James Robinson646469d2014-10-03 15:33:28 -07001// 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 Robinsonb4b7af22014-12-05 11:21:01 -08005#include "shell/child_process.h"
James Robinson646469d2014-10-03 15:33:28 -07006
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 Robinsonb4b7af22014-12-05 11:21:01 -080011#include "shell/app_child_process.h"
12#include "shell/switches.h"
13#include "shell/test_child_process.h"
James Robinson646469d2014-10-03 15:33:28 -070014
15namespace mojo {
16namespace shell {
17
18ChildProcess::~ChildProcess() {
19}
20
21// static
22scoped_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 Robinsonb4b7af22014-12-05 11:21:01 -080028 CHECK(base::StringToInt(
29 command_line.GetSwitchValueASCII(switches::kChildProcessType),
30 &type_as_int));
James Robinson646469d2014-10-03 15:33:28 -070031
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
55ChildProcess::ChildProcess() {
56}
57
58} // namespace shell
59} // namespace mojo