Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(575)

Unified Diff: ppapi/proxy/plugin_main.cc

Issue 140573003: Connect PPAPI IPC channels for non-SFI mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ppapi/proxy/plugin_main.cc
diff --git a/ppapi/proxy/plugin_main_nacl.cc b/ppapi/proxy/plugin_main.cc
similarity index 82%
rename from ppapi/proxy/plugin_main_nacl.cc
rename to ppapi/proxy/plugin_main.cc
index 90ebfd484874e18fe77da9f949eca9f187bd3e04..c10c0e1abb7acffb601f2e835b1655e7389eff6a 100644
--- a/ppapi/proxy/plugin_main_nacl.cc
+++ b/ppapi/proxy/plugin_main.cc
@@ -11,7 +11,17 @@
// IPC_MESSAGE_MACROS_LOG_ENABLED so ppapi_messages.h will generate the
// ViewMsgLog et al. functions.
+#ifndef __native_client__
+# if OS_LINUX
+# define NACL_LINUX 1
+# else
+# error "non-SFI mode is currently supported only on Linux."
dmichael (off chromium) 2014/02/13 19:00:34 Why are we changing the name of this file? Are we
hidehiko 2014/02/14 10:49:05 The main reason why I changed the file name is tha
+# endif
+#endif
+
+#include "base/at_exit.h"
#include "base/command_line.h"
+#include "base/lazy_instance.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/synchronization/waitable_event.h"
@@ -21,7 +31,6 @@
#include "ipc/ipc_logging.h"
#include "ipc/ipc_message.h"
#include "native_client/src/public/chrome_main.h"
-#include "native_client/src/shared/srpc/nacl_srpc.h"
#include "ppapi/c/ppp.h"
#include "ppapi/c/ppp_instance.h"
#include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h"
@@ -33,6 +42,10 @@
#include "ppapi/shared_impl/ppapi_switches.h"
#include "ppapi/shared_impl/ppb_audio_shared.h"
+#if defined(__native_client__)
+#include "native_client/src/shared/srpc/nacl_srpc.h"
+#endif
+
#if defined(IPC_MESSAGE_LOG_ENABLED)
#include "base/containers/hash_tables.h"
@@ -51,6 +64,44 @@ using ppapi::proxy::PluginProxyDelegate;
using ppapi::proxy::ProxyChannel;
using ppapi::proxy::SerializedHandle;
+namespace ppapi {
+namespace proxy {
+namespace {
+
+// On non-SFI mode, the FDs of IPC channels are different from the hard coded
+// ones. These values will be overwritten by SetIPCFileDescriptors() below.
+// The first FD (based on NACL_CHROME_DESC_BASE) is the IPC channel to the
+// browser, and the second one is to the renderer.
+int g_nacl_ipc_browser_fd = NACL_CHROME_DESC_BASE;
+int g_nacl_ipc_renderer_fd = NACL_CHROME_DESC_BASE + 1;
+
+// We cannot use the default traits for LazyInstance for the
+// base::WaitableEvent, because it doesn't have the default constructor.
+struct WaitableEventLazyInstanceTraits
+ : public base::DefaultLazyInstanceTraits<base::WaitableEvent> {
+ static base::WaitableEvent* New(void* instance) {
+ return new (instance) base::WaitableEvent(true, false);
+ }
+};
+base::LazyInstance<base::WaitableEvent, WaitableEventLazyInstanceTraits>
+ g_ppapi_start_event = LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+void SetIPCFileDescriptors(int ipc_browser_fd, int ipc_renderer_fd) {
dmichael (off chromium) 2014/02/13 19:00:34 This and WaitForPpapiStartEvent could maybe go in
hidehiko 2014/02/14 10:49:05 In the new file, I just moved this to the global f
+ // For non-SFI mode, the browser_ipc_fd and renderer_ipc_fd are different
+ // from the hard-coded numbers. So, this overwrites the values directly.
+ g_nacl_ipc_browser_fd = ipc_browser_fd;
+ g_nacl_ipc_renderer_fd = ipc_renderer_fd;
+}
+
+void WaitForPpapiStartEvent() {
+ g_ppapi_start_event.Pointer()->Wait();
+}
+
+} // namespace proxy
+} // namespace ppapi
+
namespace {
// This class manages communication between the plugin and the browser, and
@@ -107,7 +158,8 @@ PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop)
// The first FD (based on NACL_CHROME_DESC_BASE) is the IPC channel to the
// browser.
IPC::ChannelHandle channel_handle(
- "NaCl IPC", base::FileDescriptor(NACL_CHROME_DESC_BASE, false));
+ "NaCl IPC",
+ base::FileDescriptor(ppapi::proxy::g_nacl_ipc_browser_fd, false));
// We don't have/need a PID since handle sharing happens outside of the
// NaCl sandbox.
InitWithChannel(this, base::kNullProcessId, channel_handle,
@@ -232,7 +284,8 @@ void PpapiDispatcher::OnMsgInitializeNaClDispatcher(
// The second FD (based on NACL_CHROME_DESC_BASE) is the IPC channel to the
// renderer.
IPC::ChannelHandle channel_handle(
- "nacl", base::FileDescriptor(NACL_CHROME_DESC_BASE + 1, false));
+ "nacl",
+ base::FileDescriptor(ppapi::proxy::g_nacl_ipc_renderer_fd, false));
if (!dispatcher->InitPluginWithChannel(this, base::kNullProcessId,
channel_handle, false)) {
delete dispatcher;
@@ -240,6 +293,7 @@ void PpapiDispatcher::OnMsgInitializeNaClDispatcher(
}
// From here, the dispatcher will manage its own lifetime according to the
// lifetime of the attached channel.
+ ppapi::proxy::g_ppapi_start_event.Pointer()->Signal();
}
void PpapiDispatcher::OnPluginDispatcherMessageReceived(
@@ -273,22 +327,34 @@ void PpapiDispatcher::SetPpapiKeepAliveThrottleFromCommandLine() {
void PpapiPluginRegisterThreadCreator(
const struct PP_ThreadFunctions* thread_functions) {
+#if defined(__native_client__)
+ // TODO(hidehiko): The thread creation for the PPB_Audio is not yet
+ // implemented on non-SFI mode. Support this. Now, this function invocation
+ // is just ignored.
+
// Initialize all classes that need to create threads that call back into
// user code.
ppapi::PPB_Audio_Shared::SetThreadFunctions(thread_functions);
+#endif
}
int PpapiPluginMain() {
// Though it isn't referenced here, we must instantiate an AtExitManager.
base::AtExitManager exit_manager;
base::MessageLoop loop;
+#if defined(IPC_MESSAGE_LOG_ENABLED)
IPC::Logging::set_log_function_map(&g_log_function_mapping);
+#endif
ppapi::proxy::PluginGlobals plugin_globals;
base::Thread io_thread("Chrome_NaClIOThread");
base::Thread::Options options;
options.message_loop_type = base::MessageLoop::TYPE_IO;
io_thread.StartWithOptions(options);
+#if defined(__native_client__)
+ // Currently on non-SFI mode, we don't use SRPC server on plugin.
+ // TODO(hidehiko): Make sure this SRPC is actually used on SFI-mode.
+
// Start up the SRPC server on another thread. Otherwise, when it blocks
// on an RPC, the PPAPI proxy will hang. Do this before we initialize the
// module and start the PPAPI proxy so that the NaCl plugin can continue
@@ -297,6 +363,7 @@ int PpapiPluginMain() {
if (!NaClSrpcAcceptClientOnThread(srpc_methods)) {
return 1;
}
+#endif
PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy());
plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher);

Powered by Google App Engine
This is Rietveld 408576698