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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
Mark Seaborn 2014/02/07 23:54:10 Can you keep this file named as plugin_main_nacl.c
hidehiko 2014/02/10 08:18:34 We need to remove _nacl.cc suffix, because we need
Mark Seaborn 2014/02/10 18:57:35 OK, I see. Can you explain that in the commit mes
hidehiko 2014/02/12 15:00:38 Done.
5 #include <map> 5 #include <map>
6 #include <set> 6 #include <set>
7 7
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 // Need to include this before most other files because it defines 9 // Need to include this before most other files because it defines
10 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define 10 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define
11 // IPC_MESSAGE_MACROS_LOG_ENABLED so ppapi_messages.h will generate the 11 // IPC_MESSAGE_MACROS_LOG_ENABLED so ppapi_messages.h will generate the
12 // ViewMsgLog et al. functions. 12 // ViewMsgLog et al. functions.
13 13
14 #include "base/at_exit.h"
14 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/lazy_instance.h"
15 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
16 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
17 #include "base/synchronization/waitable_event.h" 19 #include "base/synchronization/waitable_event.h"
18 #include "base/threading/thread.h" 20 #include "base/threading/thread.h"
19 #include "components/tracing/child_trace_message_filter.h"
20 #include "ipc/ipc_channel_handle.h" 21 #include "ipc/ipc_channel_handle.h"
21 #include "ipc/ipc_logging.h" 22 #include "ipc/ipc_logging.h"
22 #include "ipc/ipc_message.h" 23 #include "ipc/ipc_message.h"
23 #include "native_client/src/shared/srpc/nacl_srpc.h"
24 #include "native_client/src/untrusted/irt/irt_ppapi.h" 24 #include "native_client/src/untrusted/irt/irt_ppapi.h"
25 #include "ppapi/c/ppp.h" 25 #include "ppapi/c/ppp.h"
26 #include "ppapi/c/ppp_instance.h" 26 #include "ppapi/c/ppp_instance.h"
27 #include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h" 27 #include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h"
28 #include "ppapi/proxy/plugin_dispatcher.h" 28 #include "ppapi/proxy/plugin_dispatcher.h"
29 #include "ppapi/proxy/plugin_globals.h" 29 #include "ppapi/proxy/plugin_globals.h"
30 #include "ppapi/proxy/plugin_message_filter.h" 30 #include "ppapi/proxy/plugin_message_filter.h"
31 #include "ppapi/proxy/plugin_proxy_delegate.h" 31 #include "ppapi/proxy/plugin_proxy_delegate.h"
32 #include "ppapi/proxy/resource_reply_thread_registrar.h" 32 #include "ppapi/proxy/resource_reply_thread_registrar.h"
33 #include "ppapi/shared_impl/ppapi_switches.h" 33 #include "ppapi/shared_impl/ppapi_switches.h"
34 #include "ppapi/shared_impl/ppb_audio_shared.h" 34 #include "ppapi/shared_impl/ppb_audio_shared.h"
35 35
36 #if defined(__native_client__)
37 #include "components/tracing/child_trace_message_filter.h"
38 #include "native_client/src/shared/srpc/nacl_srpc.h"
39 #endif
40
36 #if defined(IPC_MESSAGE_LOG_ENABLED) 41 #if defined(IPC_MESSAGE_LOG_ENABLED)
37 #include "base/containers/hash_tables.h" 42 #include "base/containers/hash_tables.h"
38 43
39 LogFunctionMap g_log_function_mapping; 44 LogFunctionMap g_log_function_mapping;
40 45
41 #define IPC_MESSAGE_MACROS_LOG_ENABLED 46 #define IPC_MESSAGE_MACROS_LOG_ENABLED
42 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \ 47 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \
43 g_log_function_mapping[msg_id] = logger 48 g_log_function_mapping[msg_id] = logger
44 49
45 #endif 50 #endif
46 #include "ppapi/proxy/ppapi_messages.h" 51 #include "ppapi/proxy/ppapi_messages.h"
47 52
48 // This value must be sync'ed with the one defined in the sel_main_chrome.h. 53 // This value must be sync'ed with the one defined in the sel_main_chrome.h.
49 #define NACL_CHROME_DESC_BASE 6 54 #define NACL_CHROME_DESC_BASE 6
50 55
51 using ppapi::proxy::PluginDispatcher; 56 using ppapi::proxy::PluginDispatcher;
52 using ppapi::proxy::PluginGlobals; 57 using ppapi::proxy::PluginGlobals;
53 using ppapi::proxy::PluginProxyDelegate; 58 using ppapi::proxy::PluginProxyDelegate;
54 using ppapi::proxy::ProxyChannel; 59 using ppapi::proxy::ProxyChannel;
55 using ppapi::proxy::SerializedHandle; 60 using ppapi::proxy::SerializedHandle;
56 61
62 namespace ppapi {
63 namespace proxy {
64 namespace {
65
66 // On non-SFI mode, the FDs of IPC channels are different from the hard coded
67 // ones. These values will be overwritten by SetIPCFileDescriptors() below.
68 // The first FD (based on NACL_CHROME_DESC_BASE) is the IPC channel to the
69 // browser, and the second one is to the renderer.
70 int g_nacl_ipc_browser_fd = NACL_CHROME_DESC_BASE;
71 int g_nacl_ipc_renderer_fd = NACL_CHROME_DESC_BASE + 1;
72
73 // We cannot use the default traits for LazyInstance for the
74 // base::WaitableEvent, because it doesn't have the default constructor.
75 struct WaitableEventLazyInstanceTraits
76 : public base::DefaultLazyInstanceTraits<base::WaitableEvent> {
77 static base::WaitableEvent* New(void* instance) {
78 return new (instance) base::WaitableEvent(true, false);
79 }
80 };
81 base::LazyInstance<base::WaitableEvent, WaitableEventLazyInstanceTraits>
82 g_ppapi_start_event = LAZY_INSTANCE_INITIALIZER;
83
84 } // namespace
85
86 // For non-SFI mode, the browser_ipc_fd and renderer_ipc_fd are different from
87 // the hard-coded numbers. So, this overwrites the values directly.
88 void SetIPCFileDescriptors(int ipc_browser_fd, int ipc_renderer_fd) {
89 g_nacl_ipc_browser_fd = ipc_browser_fd;
90 g_nacl_ipc_renderer_fd = ipc_renderer_fd;
91 }
92
93 void WaitForPpapiStartEvent() {
94 g_ppapi_start_event.Pointer()->Wait();
95 }
96
97 } // namespace proxy
98 } // namespace ppapi
99
100
57 namespace { 101 namespace {
58 102
59 // This class manages communication between the plugin and the browser, and 103 // This class manages communication between the plugin and the browser, and
60 // manages the PluginDispatcher instances for communication between the plugin 104 // manages the PluginDispatcher instances for communication between the plugin
61 // and the renderer. 105 // and the renderer.
62 class PpapiDispatcher : public ProxyChannel, 106 class PpapiDispatcher : public ProxyChannel,
63 public PluginDispatcher::PluginDelegate, 107 public PluginDispatcher::PluginDelegate,
64 public PluginProxyDelegate { 108 public PluginProxyDelegate {
65 public: 109 public:
66 explicit PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop); 110 explicit PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 base::WaitableEvent shutdown_event_; 147 base::WaitableEvent shutdown_event_;
104 }; 148 };
105 149
106 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop) 150 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop)
107 : next_plugin_dispatcher_id_(0), 151 : next_plugin_dispatcher_id_(0),
108 message_loop_(io_loop), 152 message_loop_(io_loop),
109 shutdown_event_(true, false) { 153 shutdown_event_(true, false) {
110 // The first FD (based on NACL_CHROME_DESC_BASE) is the IPC channel to the 154 // The first FD (based on NACL_CHROME_DESC_BASE) is the IPC channel to the
111 // browser. 155 // browser.
112 IPC::ChannelHandle channel_handle( 156 IPC::ChannelHandle channel_handle(
113 "NaCl IPC", base::FileDescriptor(NACL_CHROME_DESC_BASE, false)); 157 "NaCl IPC",
158 base::FileDescriptor(ppapi::proxy::g_nacl_ipc_browser_fd, false));
114 // We don't have/need a PID since handle sharing happens outside of the 159 // We don't have/need a PID since handle sharing happens outside of the
115 // NaCl sandbox. 160 // NaCl sandbox.
116 InitWithChannel(this, base::kNullProcessId, channel_handle, 161 InitWithChannel(this, base::kNullProcessId, channel_handle,
117 false); // Channel is server. 162 false); // Channel is server.
118 channel()->AddFilter(new ppapi::proxy::PluginMessageFilter( 163 channel()->AddFilter(new ppapi::proxy::PluginMessageFilter(
119 NULL, PluginGlobals::Get()->resource_reply_thread_registrar())); 164 NULL, PluginGlobals::Get()->resource_reply_thread_registrar()));
165 #if defined(__native_client_)
Mark Seaborn 2014/02/07 23:54:10 Can you comment why this is conditional?
hidehiko 2014/02/10 08:18:34 Oops sorry, I don't think we need this ifdef guard
120 channel()->AddFilter( 166 channel()->AddFilter(
121 new tracing::ChildTraceMessageFilter(message_loop_.get())); 167 new tracing::ChildTraceMessageFilter(message_loop_.get()));
168 #endif
122 } 169 }
123 170
124 base::MessageLoopProxy* PpapiDispatcher::GetIPCMessageLoop() { 171 base::MessageLoopProxy* PpapiDispatcher::GetIPCMessageLoop() {
125 return message_loop_.get(); 172 return message_loop_.get();
126 } 173 }
127 174
128 base::WaitableEvent* PpapiDispatcher::GetShutdownEvent() { 175 base::WaitableEvent* PpapiDispatcher::GetShutdownEvent() {
129 return &shutdown_event_; 176 return &shutdown_event_;
130 } 177 }
131 178
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 if (error) 275 if (error)
229 ::exit(error); 276 ::exit(error);
230 277
231 PluginDispatcher* dispatcher = 278 PluginDispatcher* dispatcher =
232 new PluginDispatcher(::PPP_GetInterface, args.permissions, 279 new PluginDispatcher(::PPP_GetInterface, args.permissions,
233 args.off_the_record); 280 args.off_the_record);
234 // The channel handle's true name is not revealed here. 281 // The channel handle's true name is not revealed here.
235 // The second FD (based on NACL_CHROME_DESC_BASE) is the IPC channel to the 282 // The second FD (based on NACL_CHROME_DESC_BASE) is the IPC channel to the
236 // renderer. 283 // renderer.
237 IPC::ChannelHandle channel_handle( 284 IPC::ChannelHandle channel_handle(
238 "nacl", base::FileDescriptor(NACL_CHROME_DESC_BASE + 1, false)); 285 "nacl",
286 base::FileDescriptor(ppapi::proxy::g_nacl_ipc_renderer_fd, false));
239 if (!dispatcher->InitPluginWithChannel(this, base::kNullProcessId, 287 if (!dispatcher->InitPluginWithChannel(this, base::kNullProcessId,
240 channel_handle, false)) { 288 channel_handle, false)) {
241 delete dispatcher; 289 delete dispatcher;
242 return; 290 return;
243 } 291 }
244 // From here, the dispatcher will manage its own lifetime according to the 292 // From here, the dispatcher will manage its own lifetime according to the
245 // lifetime of the attached channel. 293 // lifetime of the attached channel.
246 } 294 }
247 295
248 void PpapiDispatcher::OnPluginDispatcherMessageReceived( 296 void PpapiDispatcher::OnPluginDispatcherMessageReceived(
(...skipping 20 matching lines...) Expand all
269 ppapi::proxy::PluginGlobals::Get()-> 317 ppapi::proxy::PluginGlobals::Get()->
270 set_keepalive_throttle_interval_milliseconds( 318 set_keepalive_throttle_interval_milliseconds(
271 keepalive_throttle_interval_milliseconds); 319 keepalive_throttle_interval_milliseconds);
272 } 320 }
273 } 321 }
274 322
275 } // namespace 323 } // namespace
276 324
277 void PpapiPluginRegisterThreadCreator( 325 void PpapiPluginRegisterThreadCreator(
278 const struct PP_ThreadFunctions* thread_functions) { 326 const struct PP_ThreadFunctions* thread_functions) {
327 #if defined(__native_client__)
Mark Seaborn 2014/02/07 23:54:10 Can you add a comment explaining why, with a TODO?
hidehiko 2014/02/10 08:18:34 This is just not yet implemented on non-SFI mode.
279 // Initialize all classes that need to create threads that call back into 328 // Initialize all classes that need to create threads that call back into
280 // user code. 329 // user code.
281 ppapi::PPB_Audio_Shared::SetThreadFunctions(thread_functions); 330 ppapi::PPB_Audio_Shared::SetThreadFunctions(thread_functions);
331 #endif
282 } 332 }
283 333
284 int PpapiPluginMain() { 334 int PpapiPluginMain() {
285 // Though it isn't referenced here, we must instantiate an AtExitManager. 335 // Though it isn't referenced here, we must instantiate an AtExitManager.
286 base::AtExitManager exit_manager; 336 base::AtExitManager exit_manager;
287 base::MessageLoop loop; 337 base::MessageLoop loop;
338 #if defined(IPC_MESSAGE_LOG_ENABLED)
288 IPC::Logging::set_log_function_map(&g_log_function_mapping); 339 IPC::Logging::set_log_function_map(&g_log_function_mapping);
340 #endif
289 ppapi::proxy::PluginGlobals plugin_globals; 341 ppapi::proxy::PluginGlobals plugin_globals;
290 base::Thread io_thread("Chrome_NaClIOThread"); 342 base::Thread io_thread("Chrome_NaClIOThread");
291 base::Thread::Options options; 343 base::Thread::Options options;
292 options.message_loop_type = base::MessageLoop::TYPE_IO; 344 options.message_loop_type = base::MessageLoop::TYPE_IO;
293 io_thread.StartWithOptions(options); 345 io_thread.StartWithOptions(options);
294 346
347 #if defined(__native_client__)
Mark Seaborn 2014/02/07 23:54:10 Can you add a comment saying why this is condition
hidehiko 2014/02/10 08:18:34 IIUC, this SRPC is for open_resource, and it will
Mark Seaborn 2014/02/10 18:57:35 Actually, the SRPC server launched by this call pr
hidehiko 2014/02/12 15:00:38 Done.
295 // Start up the SRPC server on another thread. Otherwise, when it blocks 348 // Start up the SRPC server on another thread. Otherwise, when it blocks
296 // on an RPC, the PPAPI proxy will hang. Do this before we initialize the 349 // on an RPC, the PPAPI proxy will hang. Do this before we initialize the
297 // module and start the PPAPI proxy so that the NaCl plugin can continue 350 // module and start the PPAPI proxy so that the NaCl plugin can continue
298 // loading the app. 351 // loading the app.
299 static struct NaClSrpcHandlerDesc srpc_methods[] = { { NULL, NULL } }; 352 static struct NaClSrpcHandlerDesc srpc_methods[] = { { NULL, NULL } };
300 if (!NaClSrpcAcceptClientOnThread(srpc_methods)) { 353 if (!NaClSrpcAcceptClientOnThread(srpc_methods)) {
301 return 1; 354 return 1;
302 } 355 }
356 #endif
303 357
304 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy()); 358 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy());
305 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher); 359 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher);
306 360
361 ppapi::proxy::g_ppapi_start_event.Pointer()->Signal();
Mark Seaborn 2014/02/07 23:54:10 As I commented on https://codereview.chromium.org/
hidehiko 2014/02/10 08:18:34 I think there is a circular dependency again here.
Mark Seaborn 2014/02/10 18:57:35 That should be OK because, as you say, the message
hidehiko 2014/02/12 15:00:38 I still think we have the problem as I wrote in th
362
307 loop.Run(); 363 loop.Run();
308 364
309 return 0; 365 return 0;
310 } 366 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698