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

Unified Diff: ppapi/proxy/plugin_main.cc

Issue 139993009: [WIP] Yet another demo for BMM NaCl ppapi connection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 79%
rename from ppapi/proxy/plugin_main_nacl.cc
rename to ppapi/proxy/plugin_main.cc
index a128f638ee5c1bfb6c572bf888655060b2296637..32cf71099b7b9929b988a08fc341d92a254ba2c6 100644
--- a/ppapi/proxy/plugin_main_nacl.cc
+++ b/ppapi/proxy/plugin_main.cc
@@ -11,16 +11,15 @@
// IPC_MESSAGE_MACROS_LOG_ENABLED so ppapi_messages.h will generate the
// ViewMsgLog et al. functions.
+#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/thread.h"
-#include "components/tracing/child_trace_message_filter.h"
#include "ipc/ipc_channel_handle.h"
#include "ipc/ipc_logging.h"
#include "ipc/ipc_message.h"
-#include "native_client/src/shared/srpc/nacl_srpc.h"
#include "native_client/src/untrusted/irt/irt_ppapi.h"
#include "ppapi/c/ppp.h"
#include "ppapi/c/ppp_instance.h"
@@ -33,6 +32,11 @@
#include "ppapi/shared_impl/ppapi_switches.h"
#include "ppapi/shared_impl/ppb_audio_shared.h"
+#if defined(__native_client__)
+#include "components/tracing/child_trace_message_filter.h"
+#include "native_client/src/shared/srpc/nacl_srpc.h"
+#endif
+
#if defined(IPC_MESSAGE_LOG_ENABLED)
#include "base/containers/hash_tables.h"
@@ -45,16 +49,43 @@ LogFunctionMap g_log_function_mapping;
#endif
#include "ppapi/proxy/ppapi_messages.h"
-// This must match up with NACL_CHROME_INITIAL_IPC_DESC,
-// defined in sel_main_chrome.h
-#define NACL_IPC_FD 6
-
using ppapi::proxy::PluginDispatcher;
using ppapi::proxy::PluginGlobals;
using ppapi::proxy::PluginProxyDelegate;
using ppapi::proxy::ProxyChannel;
using ppapi::proxy::SerializedHandle;
+namespace ppapi {
+namespace proxy {
+// This must match up with NACL_CHROME_INITIAL_IPC_DESC,
+// defined in sel_main_chrome.h
+int g_nacl_browser_ipc_fd = 6;
+
+// This must match up with NACL_CHROME_RENDERER_INITIAL_IPC_DESC,
+// defined in sel_main_chrome.h
+int g_nacl_renderer_ipc_fd = 7;
+
+base::WaitableEvent* g_ppapi_start_event = NULL;
+
+// 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.
+void SetIPCFileDescriptors(int browser_ipc_fd, int renderer_ipc_fd) {
+ g_nacl_browser_ipc_fd = browser_ipc_fd;
+ g_nacl_renderer_ipc_fd = renderer_ipc_fd;
+}
+
+// For non-SFI mode, we need to wait returning LoadModule SRPC until the
+// MessageLoop on the plugin's main thread starts to run. This is the signal
+// of the synchronization. Note that this setter must be called before the
+// main thread starts, otherwise it would have a timing issue.
+void SetPpapiStartEvent(base::WaitableEvent* ppapi_start_event) {
+ DCHECK(g_ppapi_start_event == NULL);
+ g_ppapi_start_event = ppapi_start_event;
+}
+
+} // namespace proxy
+} // namespace ppapi
+
namespace {
// This class manages communication between the plugin and the browser, and
@@ -110,15 +141,18 @@ PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop)
message_loop_(io_loop),
shutdown_event_(true, false) {
IPC::ChannelHandle channel_handle(
- "NaCl IPC", base::FileDescriptor(NACL_IPC_FD, false));
+ "NaCl IPC",
+ base::FileDescriptor(ppapi::proxy::g_nacl_browser_ipc_fd, false));
// We don't have/need a PID since handle sharing happens outside of the
// NaCl sandbox.
InitWithChannel(this, base::kNullProcessId, channel_handle,
false); // Channel is server.
channel()->AddFilter(new ppapi::proxy::PluginMessageFilter(
NULL, PluginGlobals::Get()->resource_reply_thread_registrar()));
+#if defined(__native_client__)
channel()->AddFilter(
new tracing::ChildTraceMessageFilter(message_loop_.get()));
+#endif
}
base::MessageLoopProxy* PpapiDispatcher::GetIPCMessageLoop() {
@@ -199,43 +233,7 @@ bool PpapiDispatcher::OnMessageReceived(const IPC::Message& msg) {
void PpapiDispatcher::OnMsgCreateNaClChannel(
const ppapi::PpapiNaClChannelArgs& args,
SerializedHandle handle) {
- static bool command_line_and_logging_initialized = false;
- if (!command_line_and_logging_initialized) {
- CommandLine::Init(0, NULL);
- for (size_t i = 0; i < args.switch_names.size(); ++i) {
- DCHECK(i < args.switch_values.size());
- CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- args.switch_names[i], args.switch_values[i]);
- }
- logging::LoggingSettings settings;
- settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
- logging::InitLogging(settings);
- SetPpapiKeepAliveThrottleFromCommandLine();
- command_line_and_logging_initialized = true;
- }
- // Tell the process-global GetInterface which interfaces it can return to the
- // plugin.
- ppapi::proxy::InterfaceList::SetProcessGlobalPermissions(
- args.permissions);
-
- int32_t error = ::PPP_InitializeModule(
- 0 /* module */,
- &ppapi::proxy::PluginDispatcher::GetBrowserInterface);
- if (error)
- ::exit(error);
-
- PluginDispatcher* dispatcher =
- new PluginDispatcher(::PPP_GetInterface, args.permissions,
- args.off_the_record);
- // The channel handle's true name is not revealed here.
- IPC::ChannelHandle channel_handle("nacl", handle.descriptor());
- if (!dispatcher->InitPluginWithChannel(this, base::kNullProcessId,
- channel_handle, false)) {
- delete dispatcher;
- return;
- }
- // From here, the dispatcher will manage its own lifetime according to the
- // lifetime of the attached channel.
+ LOG(FATAL) << "OnMsgCreateNaClChannel";
}
void PpapiDispatcher::OnPluginDispatcherMessageReceived(
@@ -265,26 +263,47 @@ void PpapiDispatcher::SetPpapiKeepAliveThrottleFromCommandLine() {
}
}
+void SetPpapiKeepAliveThrottleFromCommandLine() {
+ unsigned keepalive_throttle_interval_milliseconds = 0;
+ if (base::StringToUint(
+ CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kPpapiKeepAliveThrottle),
+ &keepalive_throttle_interval_milliseconds)) {
+ ppapi::proxy::PluginGlobals::Get()->
+ set_keepalive_throttle_interval_milliseconds(
+ keepalive_throttle_interval_milliseconds);
+ }
+}
+
} // namespace
void PpapiPluginRegisterThreadCreator(
const struct PP_ThreadFunctions* thread_functions) {
+#if defined(__native_client__)
+ // Note: Currently, PPB_Audio_Shared::SetThreadFunctions is not available
+ // on non-SFI mode, just because it is still under development.
+
// Initialize all classes that need to create threads that call back into
// user code.
ppapi::PPB_Audio_Shared::SetThreadFunctions(thread_functions);
+#endif
}
int PpapiPluginMain() {
+ LOG(ERROR) << "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__)
// 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
@@ -293,10 +312,64 @@ int PpapiPluginMain() {
if (!NaClSrpcAcceptClientOnThread(srpc_methods)) {
return 1;
}
+#endif
+
+ // TODO fix me.
+ ppapi::PpapiNaClChannelArgs args;
+ args.permissions = ppapi::PpapiPermissions(33);
+
+ static bool command_line_and_logging_initialized = false;
+ if (!command_line_and_logging_initialized) {
+ CommandLine::Init(0, NULL);
+ for (size_t i = 0; i < args.switch_names.size(); ++i) {
+ DCHECK(i < args.switch_values.size());
+ CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ args.switch_names[i], args.switch_values[i]);
+ }
+ logging::LoggingSettings settings;
+ settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
+ logging::InitLogging(settings);
+ SetPpapiKeepAliveThrottleFromCommandLine();
+ command_line_and_logging_initialized = true;
+ }
+
+ // Tell the process-global GetInterface which interfaces it can return to the
+ // plugin.
+ ppapi::proxy::InterfaceList::SetProcessGlobalPermissions(
+ args.permissions);
PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy());
plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher);
+ PluginDispatcher* plugin_dispatcher =
+ new PluginDispatcher(::PPP_GetInterface, args.permissions,
+ args.off_the_record);
+
+ // The channel handle's true name is not revealed here.
+ IPC::ChannelHandle channel_handle(
+ "nacl",
+ base::FileDescriptor(ppapi::proxy::g_nacl_renderer_ipc_fd, false));
+ if (!plugin_dispatcher->InitPluginWithChannel(
+ &ppapi_dispatcher, base::kNullProcessId,
+ channel_handle, false)) {
+ delete plugin_dispatcher;
+ return 1;
+ }
+
+ // From here, the dispatcher will manage its own lifetime according to the
+ // lifetime of the attached channel.
+
+ int32_t error = ::PPP_InitializeModule(
+ 0 /* module */,
+ &ppapi::proxy::PluginDispatcher::GetBrowserInterface);
+ if (error)
+ ::exit(error);
+
+ if (ppapi::proxy::g_ppapi_start_event) {
+ ppapi::proxy::g_ppapi_start_event->Signal();
+ ppapi::proxy::g_ppapi_start_event = NULL;
+ }
+
loop.Run();
return 0;

Powered by Google App Engine
This is Rietveld 408576698