Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/nacl/browser/nacl_process_host.h" | 5 #include "components/nacl/browser/nacl_process_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate, | 612 IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate, |
| 613 OnSetKnownToValidate) | 613 OnSetKnownToValidate) |
| 614 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_ResolveFileToken, | 614 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_ResolveFileToken, |
| 615 OnResolveFileToken) | 615 OnResolveFileToken) |
| 616 #if defined(OS_WIN) | 616 #if defined(OS_WIN) |
| 617 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_AttachDebugExceptionHandler, | 617 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_AttachDebugExceptionHandler, |
| 618 OnAttachDebugExceptionHandler) | 618 OnAttachDebugExceptionHandler) |
| 619 #endif | 619 #endif |
| 620 IPC_MESSAGE_HANDLER(NaClProcessHostMsg_PpapiChannelsCreated, | 620 IPC_MESSAGE_HANDLER(NaClProcessHostMsg_PpapiChannelsCreated, |
| 621 OnPpapiChannelsCreated) | 621 OnPpapiChannelsCreated) |
| 622 IPC_MESSAGE_HANDLER(NaClProcessHostMsg_DebugStubPortSelected, | |
| 623 OnDebugStubPortSelected) | |
| 622 IPC_MESSAGE_UNHANDLED(handled = false) | 624 IPC_MESSAGE_UNHANDLED(handled = false) |
| 623 IPC_END_MESSAGE_MAP() | 625 IPC_END_MESSAGE_MAP() |
| 624 return handled; | 626 return handled; |
| 625 } | 627 } |
| 626 | 628 |
| 627 void NaClProcessHost::OnProcessLaunched() { | 629 void NaClProcessHost::OnProcessLaunched() { |
| 628 if (!StartWithLaunchedProcess()) | 630 if (!StartWithLaunchedProcess()) |
| 629 delete this; | 631 delete this; |
| 630 } | 632 } |
| 631 | 633 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 710 reply_msg_, result, error_message); | 712 reply_msg_, result, error_message); |
| 711 nacl_host_message_filter_->Send(reply_msg_); | 713 nacl_host_message_filter_->Send(reply_msg_); |
| 712 nacl_host_message_filter_ = NULL; | 714 nacl_host_message_filter_ = NULL; |
| 713 reply_msg_ = NULL; | 715 reply_msg_ = NULL; |
| 714 } | 716 } |
| 715 } | 717 } |
| 716 | 718 |
| 717 // TCP port we chose for NaCl debug stub. It can be any other number. | 719 // TCP port we chose for NaCl debug stub. It can be any other number. |
| 718 static const int kInitialDebugStubPort = 4014; | 720 static const int kInitialDebugStubPort = 4014; |
| 719 | 721 |
| 722 void NaClProcessHost::ChangeDebugStubPort(int port) { | |
| 723 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); | |
| 724 if (nacl_browser->HasGdbDebugStubPortListener()) { | |
| 725 nacl_browser->FireGdbDebugStubPortOpened(port); | |
| 726 } | |
| 727 // Set debug stub port on the process object. | |
| 728 process_->SetNaClDebugStubPort(port); | |
| 729 } | |
| 730 | |
| 720 #if defined(OS_POSIX) | 731 #if defined(OS_POSIX) |
| 721 net::SocketDescriptor NaClProcessHost::GetDebugStubSocketHandle() { | 732 net::SocketDescriptor NaClProcessHost::GetDebugStubSocketHandle() { |
| 722 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); | |
| 723 net::SocketDescriptor s = net::kInvalidSocket; | 733 net::SocketDescriptor s = net::kInvalidSocket; |
| 724 // We always try to allocate the default port first. If this fails, we then | 734 // We always try to allocate the default port first. If this fails, we then |
| 725 // allocate any available port. | 735 // allocate any available port. |
| 726 // On success, if the test system has register a handler | 736 // On success, if the test system has register a handler |
| 727 // (GdbDebugStubPortListener), we fire a notification. | 737 // (GdbDebugStubPortListener), we fire a notification. |
| 728 int port = kInitialDebugStubPort; | 738 int port = kInitialDebugStubPort; |
| 729 s = net::TCPListenSocket::CreateAndBind("127.0.0.1", port); | 739 s = net::TCPListenSocket::CreateAndBind("127.0.0.1", port); |
| 730 if (s == net::kInvalidSocket) { | 740 if (s == net::kInvalidSocket) { |
| 731 s = net::TCPListenSocket::CreateAndBindAnyPort("127.0.0.1", &port); | 741 s = net::TCPListenSocket::CreateAndBindAnyPort("127.0.0.1", &port); |
| 732 } | 742 } |
| 733 if (s != net::kInvalidSocket) { | 743 if (s != net::kInvalidSocket) { |
| 734 if (nacl_browser->HasGdbDebugStubPortListener()) { | 744 ChangeDebugStubPort(port); |
| 735 nacl_browser->FireGdbDebugStubPortOpened(port); | |
| 736 } | |
| 737 } | 745 } |
| 738 // Set debug stub port on the process object. | |
| 739 process_->SetNaClDebugStubPort(port); | |
| 740 if (s == net::kInvalidSocket) { | 746 if (s == net::kInvalidSocket) { |
| 741 LOG(ERROR) << "failed to open socket for debug stub"; | 747 LOG(ERROR) << "failed to open socket for debug stub"; |
| 742 return net::kInvalidSocket; | 748 return net::kInvalidSocket; |
| 743 } else { | 749 } else { |
| 744 LOG(WARNING) << "debug stub on port " << port; | 750 LOG(WARNING) << "debug stub on port " << port; |
| 745 } | 751 } |
| 746 if (listen(s, 1)) { | 752 if (listen(s, 1)) { |
| 747 LOG(ERROR) << "listen() failed on debug stub socket"; | 753 LOG(ERROR) << "listen() failed on debug stub socket"; |
| 748 if (IGNORE_EINTR(close(s)) < 0) | 754 if (IGNORE_EINTR(close(s)) < 0) |
| 749 PLOG(ERROR) << "failed to close debug stub socket"; | 755 PLOG(ERROR) << "failed to close debug stub socket"; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 897 // Let the renderer know that the IPC channels are established. | 903 // Let the renderer know that the IPC channels are established. |
| 898 ReplyToRenderer(ppapi_renderer_channel_handle, | 904 ReplyToRenderer(ppapi_renderer_channel_handle, |
| 899 trusted_renderer_channel_handle); | 905 trusted_renderer_channel_handle); |
| 900 } else { | 906 } else { |
| 901 // Attempt to open more than 1 browser channel is not supported. | 907 // Attempt to open more than 1 browser channel is not supported. |
| 902 // Shut down the NaCl process. | 908 // Shut down the NaCl process. |
| 903 process_->GetHost()->ForceShutdown(); | 909 process_->GetHost()->ForceShutdown(); |
| 904 } | 910 } |
| 905 } | 911 } |
| 906 | 912 |
| 913 // This method is called when NaClProcessHostMsg_OnDebugStubPortSelected is | |
|
Mark Seaborn
2014/03/26 23:34:04
It's NaClProcessHostMsg_DebugStubPortSelected. No
bradn
2014/05/05 18:46:07
Dropped comment, but the name is this way for cons
| |
| 914 // received. | |
| 915 void NaClProcessHost::OnDebugStubPortSelected(uint16_t debug_stub_port) { | |
| 916 ChangeDebugStubPort(debug_stub_port); | |
| 917 } | |
| 918 | |
| 907 bool NaClProcessHost::StartWithLaunchedProcess() { | 919 bool NaClProcessHost::StartWithLaunchedProcess() { |
| 908 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); | 920 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); |
| 909 | 921 |
| 910 if (nacl_browser->IsReady()) { | 922 if (nacl_browser->IsReady()) { |
| 911 return StartNaClExecution(); | 923 return StartNaClExecution(); |
| 912 } else if (nacl_browser->IsOk()) { | 924 } else if (nacl_browser->IsOk()) { |
| 913 nacl_browser->WaitForResources( | 925 nacl_browser->WaitForResources( |
| 914 base::Bind(&NaClProcessHost::OnResourcesReady, | 926 base::Bind(&NaClProcessHost::OnResourcesReady, |
| 915 weak_factory_.GetWeakPtr())); | 927 weak_factory_.GetWeakPtr())); |
| 916 return true; | 928 return true; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1070 process_handle.Take(), info, | 1082 process_handle.Take(), info, |
| 1071 base::MessageLoopProxy::current(), | 1083 base::MessageLoopProxy::current(), |
| 1072 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 1084 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
| 1073 weak_factory_.GetWeakPtr())); | 1085 weak_factory_.GetWeakPtr())); |
| 1074 return true; | 1086 return true; |
| 1075 } | 1087 } |
| 1076 } | 1088 } |
| 1077 #endif | 1089 #endif |
| 1078 | 1090 |
| 1079 } // namespace nacl | 1091 } // namespace nacl |
| OLD | NEW |