Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
|
dmichael (off chromium)
2012/06/14 03:12:41
I don't really like the name "plugin_globals_nacl.
bbudge
2012/06/15 01:07:32
This was inspired by the naming in the SRPC proxy.
| |
| 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 <map> | |
| 6 #include <set> | |
| 7 | |
| 8 #include "build/build_config.h" | |
| 9 // Need to include this before most other files because it defines | |
| 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 | |
| 12 // ViewMsgLog et al. functions. | |
| 13 | |
| 14 #include "base/message_loop.h" | |
| 15 #include "base/synchronization/waitable_event.h" | |
| 16 #include "base/threading/thread.h" | |
| 17 #include "ipc/ipc_channel_handle.h" | |
| 18 #include "ipc/ipc_logging.h" | |
| 19 #include "ipc/ipc_message.h" | |
| 20 #include "native_client/src/untrusted/irt/irt_ppapi.h" | |
| 21 #include "ppapi/c/ppp.h" | |
| 22 #include "ppapi/c/ppp_instance.h" | |
| 23 #include "ppapi/proxy/plugin_dispatcher.h" | |
| 24 #include "ppapi/proxy/plugin_globals.h" | |
| 25 | |
| 26 #if defined(IPC_MESSAGE_LOG_ENABLED) | |
| 27 #define IPC_MESSAGE_MACROS_LOG_ENABLED | |
| 28 #include "ppapi/proxy/ppapi_messages.h" | |
| 29 #endif | |
| 30 | |
| 31 #define NACL_IPC_FD 6 // TODO(use API constant) | |
| 32 | |
| 33 using ppapi::proxy::PluginDispatcher; | |
| 34 using ppapi::proxy::PluginGlobals; | |
| 35 | |
| 36 namespace { | |
| 37 | |
| 38 struct PP_ThreadFunctions thread_funcs; | |
| 39 | |
| 40 // Copied from src/content/ppapi_plugin/ppapi_thread. This is a minimal | |
| 41 // implementation to get us started. | |
| 42 class PluginDispatcherDelegate : public PluginDispatcher::PluginDelegate { | |
| 43 public: | |
| 44 explicit PluginDispatcherDelegate( | |
| 45 scoped_refptr<base::MessageLoopProxy> io_loop) | |
| 46 : message_loop_(io_loop), | |
| 47 shutdown_event_(true, false) { | |
| 48 } | |
| 49 | |
| 50 virtual base::MessageLoopProxy* GetIPCMessageLoop() OVERRIDE { | |
| 51 return message_loop_.get(); | |
| 52 } | |
| 53 | |
| 54 virtual base::WaitableEvent* GetShutdownEvent() OVERRIDE { | |
| 55 return &shutdown_event_; | |
| 56 } | |
| 57 | |
| 58 virtual IPC::PlatformFileForTransit ShareHandleWithRemote( | |
| 59 base::PlatformFile handle, | |
| 60 const IPC::SyncChannel& channel, | |
| 61 bool should_close_source) OVERRIDE { | |
| 62 return IPC::InvalidPlatformFileForTransit(); | |
| 63 } | |
| 64 | |
| 65 virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() OVERRIDE { | |
| 66 return &instances_; | |
| 67 } | |
| 68 | |
| 69 virtual uint32 Register(PluginDispatcher* plugin_dispatcher) OVERRIDE { | |
| 70 if (!plugin_dispatcher || | |
| 71 plugin_dispatchers_.size() >= std::numeric_limits<uint32>::max()) { | |
| 72 return 0; | |
| 73 } | |
| 74 | |
| 75 uint32 id = 0; | |
| 76 do { | |
| 77 // Although it is unlikely, make sure that we won't cause any trouble when | |
| 78 // the counter overflows. | |
| 79 id = next_plugin_dispatcher_id_++; | |
| 80 } while (id == 0 || | |
| 81 plugin_dispatchers_.find(id) != plugin_dispatchers_.end()); | |
| 82 plugin_dispatchers_[id] = plugin_dispatcher; | |
| 83 return id; | |
| 84 } | |
| 85 | |
| 86 virtual void Unregister(uint32 plugin_dispatcher_id) OVERRIDE { | |
| 87 plugin_dispatchers_.erase(plugin_dispatcher_id); | |
| 88 } | |
| 89 | |
| 90 private: | |
| 91 std::set<PP_Instance> instances_; | |
| 92 std::map<uint32, PluginDispatcher*> plugin_dispatchers_; | |
| 93 uint32 next_plugin_dispatcher_id_; | |
| 94 scoped_refptr<base::MessageLoopProxy> message_loop_; | |
| 95 base::WaitableEvent shutdown_event_; | |
| 96 }; | |
| 97 | |
| 98 } // namespace | |
| 99 | |
| 100 extern "C" { | |
|
brettw
2012/06/14 20:01:04
I'd put a blank line after this and before the } b
Mark Seaborn
2012/06/14 21:49:20
Rather than using 'extern "C"' here, can you do '#
bbudge
2012/06/15 01:07:32
The style checker complains, but I like your way b
bbudge
2012/06/15 01:07:32
Done.
| |
| 101 void PpapiPluginRegisterThreadCreator( | |
| 102 const struct PP_ThreadFunctions* new_funcs) { | |
| 103 thread_funcs = *new_funcs; | |
| 104 } | |
| 105 | |
| 106 int IrtInit() { | |
| 107 return 0; | |
| 108 } | |
| 109 | |
| 110 int PpapiPluginMain() { | |
| 111 base::AtExitManager exit_manager; | |
| 112 MessageLoop loop; | |
| 113 IPC::Logging::set_log_function_map(&g_log_function_mapping); | |
| 114 ppapi::proxy::PluginGlobals plugin_globals; | |
| 115 base::Thread io_thread("Chrome_NaClIOThread"); | |
| 116 base::Thread::Options options; | |
| 117 options.message_loop_type = MessageLoop::TYPE_IO; | |
| 118 io_thread.StartWithOptions(options); | |
| 119 | |
| 120 int32_t error = ::PPP_InitializeModule( | |
| 121 0 /* module */, | |
| 122 &ppapi::proxy::PluginDispatcher::GetBrowserInterface); | |
| 123 // TODO(dmichael): Handle other error conditions, like failure to connect? | |
| 124 if (error) | |
| 125 return error; | |
| 126 | |
| 127 PluginDispatcherDelegate delegate(io_thread.message_loop_proxy()); | |
| 128 | |
| 129 // TODO(dmichael) Figure out how to determine if we're in incognito | |
| 130 PluginDispatcher dispatcher(::PPP_GetInterface, false /* incognito */); | |
| 131 IPC::ChannelHandle channel_handle("NaCl IPC", | |
| 132 base::FileDescriptor(NACL_IPC_FD, false)); | |
| 133 dispatcher.InitPluginWithChannel(&delegate, channel_handle, false); | |
| 134 | |
| 135 loop.Run(); | |
| 136 return 0; | |
| 137 } | |
| 138 } // extern "C" | |
| 139 | |
| OLD | NEW |