Chromium Code Reviews| Index: chrome/browser/nacl_host/nacl_process_host.cc |
| =================================================================== |
| --- chrome/browser/nacl_host/nacl_process_host.cc (revision 143037) |
| +++ chrome/browser/nacl_host/nacl_process_host.cc (working copy) |
| @@ -110,6 +110,7 @@ |
| struct NaClProcessHost::NaClInternal { |
| std::vector<nacl::Handle> sockets_for_renderer; |
| std::vector<nacl::Handle> sockets_for_sel_ldr; |
| + std::vector<nacl::FileDescriptor> handles_for_renderer; |
| }; |
| // ----------------------------------------------------------------------------- |
| @@ -537,6 +538,8 @@ |
| IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_AttachDebugExceptionHandler, |
| OnAttachDebugExceptionHandler) |
| #endif |
| + IPC_MESSAGE_HANDLER(NaClProcessHostMsg_PpapiChannelCreated, |
| + OnPpapiChannelCreated) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| return handled; |
| @@ -556,8 +559,7 @@ |
| } |
| } |
| -bool NaClProcessHost::ReplyToRenderer() { |
|
Mark Seaborn
2012/06/20 19:24:40
Why do you need to merge ReplyToRenderer() and Sta
bbudge
2012/06/21 00:00:46
I merged these because we now have to wait for the
Mark Seaborn
2012/06/21 15:30:03
I understand why you've done it, but I don't think
bbudge
2012/06/21 18:16:53
Done. Good idea, it's a much smaller change this w
|
| - std::vector<nacl::FileDescriptor> handles_for_renderer; |
| +bool NaClProcessHost::SendStart() { |
| for (size_t i = 0; i < internal_->sockets_for_renderer.size(); i++) { |
| #if defined(OS_WIN) |
| // Copy the handle into the renderer process. |
| @@ -573,7 +575,7 @@ |
| DLOG(ERROR) << "DuplicateHandle() failed"; |
| return false; |
| } |
| - handles_for_renderer.push_back( |
| + internal_->handles_for_renderer.push_back( |
| reinterpret_cast<nacl::FileDescriptor>(handle_in_renderer)); |
| #else |
| // No need to dup the imc_handle - we don't pass it anywhere else so |
| @@ -581,10 +583,11 @@ |
| nacl::FileDescriptor imc_handle; |
| imc_handle.fd = internal_->sockets_for_renderer[i]; |
| imc_handle.auto_close = true; |
| - handles_for_renderer.push_back(imc_handle); |
| + internal_->handles_for_renderer.push_back(imc_handle); |
| #endif |
| } |
| + const ChildProcessData& data = process_->GetData(); |
| #if defined(OS_WIN) |
| // If we are on 64-bit Windows, the NaCl process's sandbox is |
| // managed by a different process from the renderer's sandbox. We |
| @@ -592,23 +595,13 @@ |
| // that the renderer can send handles to the NaCl process using |
| // BrokerDuplicateHandle(). |
| if (RunningOnWOW64()) { |
| - if (!content::BrokerAddTargetPeer(process_->GetData().handle)) { |
| + if (!content::BrokerAddTargetPeer(data.handle)) { |
| DLOG(ERROR) << "Failed to add NaCl process PID"; |
| return false; |
| } |
| } |
| #endif |
| - ChromeViewHostMsg_LaunchNaCl::WriteReplyParams( |
| - reply_msg_, handles_for_renderer); |
| - chrome_render_message_filter_->Send(reply_msg_); |
| - chrome_render_message_filter_ = NULL; |
| - reply_msg_ = NULL; |
| - internal_->sockets_for_renderer.clear(); |
|
Mark Seaborn
2012/06/20 19:24:40
Removing this call isn't quite right. If NaClProc
bbudge
2012/06/21 00:00:46
I'm adding a TODO to fix this. I think we should c
|
| - return true; |
| -} |
| - |
| -bool NaClProcessHost::StartNaClExecution() { |
| NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); |
| nacl::NaClStartParams params; |
| @@ -618,11 +611,12 @@ |
| params.enable_exception_handling = enable_exception_handling_; |
| params.enable_debug_stub = |
| CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNaClDebug); |
| + params.enable_ipc_proxy = CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kEnableNaClIPCProxy); |
| base::PlatformFile irt_file = nacl_browser->IrtFile(); |
| CHECK_NE(irt_file, base::kInvalidPlatformFileValue); |
| - const ChildProcessData& data = process_->GetData(); |
| for (size_t i = 0; i < internal_->sockets_for_sel_ldr.size(); i++) { |
| if (!ShareHandleToSelLdr(data.handle, |
| internal_->sockets_for_sel_ldr[i], true, |
| @@ -658,14 +652,36 @@ |
| params.handles.push_back(memory_fd); |
| #endif |
| + // The start message should only be sent once we are sure we won't delete |
| + // ourselves. |
| process_->Send(new NaClProcessMsg_Start(params)); |
| internal_->sockets_for_sel_ldr.clear(); |
| + |
| + // If we aren't creating the IPC channel, send the reply message without |
| + // waiting for the NaCl process to signal that it's ready. |
| + // TODO(bbudge) remove this after we switch to the IPC proxy. |
| + if (!params.enable_ipc_proxy) { |
| + OnPpapiChannelCreated(IPC::ChannelHandle()); |
| + } |
| + |
| return true; |
| } |
| -bool NaClProcessHost::SendStart() { |
| - return ReplyToRenderer() && StartNaClExecution(); |
| +void NaClProcessHost::OnPpapiChannelCreated( |
| + const IPC::ChannelHandle& channel_handle) { |
| + // Now that the server end of the channel has been created, send the reply to |
| + // the renderer. |
| + base::ProcessId nacl_process_id = base::GetProcId(process_->GetData().handle); |
| + ChromeViewHostMsg_LaunchNaCl::WriteReplyParams( |
| + reply_msg_, internal_->handles_for_renderer, channel_handle, |
| + nacl_process_id); |
| + chrome_render_message_filter_->Send(reply_msg_); |
| + chrome_render_message_filter_ = NULL; |
| + reply_msg_ = NULL; |
| + |
| + internal_->sockets_for_renderer.clear(); |
| + internal_->handles_for_renderer.clear(); |
| } |
| bool NaClProcessHost::StartWithLaunchedProcess() { |