• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "ppapi/nacl_irt/plugin_main.h"
6 
7 #include "build/build_config.h"
8 // Need to include this before most other files because it defines
9 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define
10 // IPC_MESSAGE_MACROS_LOG_ENABLED so ppapi_messages.h will generate the
11 // ViewMsgLog et al. functions.
12 
13 #include "base/message_loop/message_loop.h"
14 #include "base/threading/thread.h"
15 #include "ipc/ipc_logging.h"
16 #include "ppapi/nacl_irt/plugin_startup.h"
17 #include "ppapi/nacl_irt/ppapi_dispatcher.h"
18 #include "ppapi/proxy/plugin_globals.h"
19 #include "ppapi/shared_impl/ppb_audio_shared.h"
20 
21 #if defined(__native_client__)
22 #include "native_client/src/shared/srpc/nacl_srpc.h"
23 #endif
24 
PpapiPluginRegisterThreadCreator(const struct PP_ThreadFunctions * thread_functions)25 void PpapiPluginRegisterThreadCreator(
26     const struct PP_ThreadFunctions* thread_functions) {
27   // Initialize all classes that need to create threads that call back into
28   // user code.
29   ppapi::PPB_Audio_Shared::SetThreadFunctions(thread_functions);
30 }
31 
PpapiPluginMain()32 int PpapiPluginMain() {
33   base::MessageLoop loop;
34   ppapi::proxy::PluginGlobals plugin_globals;
35 
36 #if defined(__native_client__)
37   // Currently on non-SFI mode, we don't use SRPC server on plugin.
38   // TODO(hidehiko): Make sure this SRPC is actually used on SFI-mode.
39 
40   // Start up the SRPC server on another thread. Otherwise, when it blocks
41   // on an RPC, the PPAPI proxy will hang. Do this before we initialize the
42   // module and start the PPAPI proxy so that the NaCl plugin can continue
43   // loading the app.
44   static struct NaClSrpcHandlerDesc srpc_methods[] = { { NULL, NULL } };
45   if (!NaClSrpcAcceptClientOnThread(srpc_methods)) {
46     return 1;
47   }
48 #endif
49 
50   ppapi::PpapiDispatcher ppapi_dispatcher(
51       ppapi::GetIOThread()->message_loop_proxy(),
52       ppapi::GetShutdownEvent(),
53       ppapi::GetBrowserIPCFileDescriptor(),
54       ppapi::GetRendererIPCFileDescriptor());
55   plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher);
56 
57   loop.Run();
58 
59   return 0;
60 }
61