OLD | NEW |
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 "shell/child_process_host.h" | 5 #include "shell/child_process_host.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 : context_(context), channel_info_(nullptr) { | 28 : context_(context), channel_info_(nullptr) { |
29 } | 29 } |
30 | 30 |
31 ChildProcessHost::~ChildProcessHost() { | 31 ChildProcessHost::~ChildProcessHost() { |
32 DCHECK(!child_process_.IsValid()); | 32 DCHECK(!child_process_.IsValid()); |
33 } | 33 } |
34 | 34 |
35 void ChildProcessHost::Start() { | 35 void ChildProcessHost::Start() { |
36 DCHECK(!child_process_.IsValid()); | 36 DCHECK(!child_process_.IsValid()); |
37 | 37 |
| 38 // TODO(vtl): Add something for |slave_info|. |
| 39 mojo::embedder::ScopedPlatformHandle platform_handle_for_channel; |
| 40 std::string child_connection_id; |
| 41 mojo::embedder::ConnectToSlave( |
| 42 nullptr, platform_channel_pair_.PassServerHandle(), |
| 43 &platform_handle_for_channel, &child_connection_id); |
| 44 |
38 mojo::ScopedMessagePipeHandle handle(mojo::embedder::CreateChannel( | 45 mojo::ScopedMessagePipeHandle handle(mojo::embedder::CreateChannel( |
39 platform_channel_pair_.PassServerHandle(), | 46 platform_handle_for_channel.Pass(), context_->task_runners()->io_runner(), |
40 context_->task_runners()->io_runner(), | |
41 base::Bind(&ChildProcessHost::DidCreateChannel, base::Unretained(this)), | 47 base::Bind(&ChildProcessHost::DidCreateChannel, base::Unretained(this)), |
42 base::MessageLoop::current()->message_loop_proxy())); | 48 base::MessageLoop::current()->message_loop_proxy())); |
43 | 49 |
44 controller_.Bind(mojo::InterfacePtrInfo<ChildController>(handle.Pass(), 0u)); | 50 controller_.Bind(mojo::InterfacePtrInfo<ChildController>(handle.Pass(), 0u)); |
45 controller_.set_error_handler(this); | 51 controller_.set_error_handler(this); |
46 | 52 |
47 CHECK(base::PostTaskAndReplyWithResult( | 53 CHECK(base::PostTaskAndReplyWithResult( |
48 context_->task_runners()->blocking_pool(), FROM_HERE, | 54 context_->task_runners()->blocking_pool(), FROM_HERE, |
49 base::Bind(&ChildProcessHost::DoLaunch, base::Unretained(this)), | 55 base::Bind(&ChildProcessHost::DoLaunch, base::Unretained(this), |
| 56 child_connection_id), |
50 base::Bind(&ChildProcessHost::DidStart, base::Unretained(this)))); | 57 base::Bind(&ChildProcessHost::DidStart, base::Unretained(this)))); |
51 } | 58 } |
52 | 59 |
53 int ChildProcessHost::Join() { | 60 int ChildProcessHost::Join() { |
54 DCHECK(child_process_.IsValid()); | 61 DCHECK(child_process_.IsValid()); |
55 int rv = -1; | 62 int rv = -1; |
56 LOG_IF(ERROR, !child_process_.WaitForExit(&rv)) | 63 LOG_IF(ERROR, !child_process_.WaitForExit(&rv)) |
57 << "Failed to wait for child process"; | 64 << "Failed to wait for child process"; |
58 child_process_.Close(); | 65 child_process_.Close(); |
59 return rv; | 66 return rv; |
(...skipping 29 matching lines...) Expand all Loading... |
89 | 96 |
90 // Callback for |mojo::embedder::CreateChannel()|. | 97 // Callback for |mojo::embedder::CreateChannel()|. |
91 void ChildProcessHost::DidCreateChannel( | 98 void ChildProcessHost::DidCreateChannel( |
92 mojo::embedder::ChannelInfo* channel_info) { | 99 mojo::embedder::ChannelInfo* channel_info) { |
93 DVLOG(2) << "ChildProcessHost::DidCreateChannel()"; | 100 DVLOG(2) << "ChildProcessHost::DidCreateChannel()"; |
94 | 101 |
95 CHECK(channel_info); | 102 CHECK(channel_info); |
96 channel_info_ = channel_info; | 103 channel_info_ = channel_info; |
97 } | 104 } |
98 | 105 |
99 bool ChildProcessHost::DoLaunch() { | 106 bool ChildProcessHost::DoLaunch(const std::string& child_connection_id) { |
100 static const char* kForwardSwitches[] = { | 107 static const char* kForwardSwitches[] = { |
101 switches::kTraceToConsole, switches::kV, switches::kVModule, | 108 switches::kTraceToConsole, switches::kV, switches::kVModule, |
102 }; | 109 }; |
103 | 110 |
104 base::CommandLine child_command_line(context_->mojo_shell_child_path()); | 111 base::CommandLine child_command_line(context_->mojo_shell_child_path()); |
105 child_command_line.CopySwitchesFrom(*base::CommandLine::ForCurrentProcess(), | 112 child_command_line.CopySwitchesFrom(*base::CommandLine::ForCurrentProcess(), |
106 kForwardSwitches, | 113 kForwardSwitches, |
107 arraysize(kForwardSwitches)); | 114 arraysize(kForwardSwitches)); |
108 child_command_line.AppendSwitch(switches::kChildProcess); | 115 child_command_line.AppendSwitchASCII(switches::kChildConnectionId, |
| 116 child_connection_id); |
109 | 117 |
110 mojo::embedder::HandlePassingInformation handle_passing_info; | 118 mojo::embedder::HandlePassingInformation handle_passing_info; |
111 platform_channel_pair_.PrepareToPassClientHandleToChildProcess( | 119 platform_channel_pair_.PrepareToPassClientHandleToChildProcess( |
112 &child_command_line, &handle_passing_info); | 120 &child_command_line, &handle_passing_info); |
113 | 121 |
114 base::LaunchOptions options; | 122 base::LaunchOptions options; |
115 options.fds_to_remap = &handle_passing_info; | 123 options.fds_to_remap = &handle_passing_info; |
116 DVLOG(2) << "Launching child with command line: " | 124 DVLOG(2) << "Launching child with command line: " |
117 << child_command_line.GetCommandLineString(); | 125 << child_command_line.GetCommandLineString(); |
118 child_process_ = base::LaunchProcess(child_command_line, options); | 126 child_process_ = base::LaunchProcess(child_command_line, options); |
(...skipping 10 matching lines...) Expand all Loading... |
129 on_app_complete_.reset(); | 137 on_app_complete_.reset(); |
130 on_app_complete.Run(result); | 138 on_app_complete.Run(result); |
131 } | 139 } |
132 } | 140 } |
133 | 141 |
134 void ChildProcessHost::OnConnectionError() { | 142 void ChildProcessHost::OnConnectionError() { |
135 AppCompleted(MOJO_RESULT_UNKNOWN); | 143 AppCompleted(MOJO_RESULT_UNKNOWN); |
136 } | 144 } |
137 | 145 |
138 } // namespace shell | 146 } // namespace shell |
OLD | NEW |