Chromium Code Reviews| Index: ppapi/proxy/plugin_globals_nacl.cc |
| =================================================================== |
| --- ppapi/proxy/plugin_globals_nacl.cc (revision 0) |
| +++ ppapi/proxy/plugin_globals_nacl.cc (revision 0) |
| @@ -0,0 +1,148 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <map> |
| +#include <set> |
| + |
| +#include "build/build_config.h" |
| +// Need to include this before most other files because it defines |
| +// IPC_MESSAGE_LOG_ENABLED. We need to use it to define |
| +// IPC_MESSAGE_MACROS_LOG_ENABLED so ppapi_messages.h will generate the |
| +// ViewMsgLog et al. functions. |
| + |
| +#include "base/message_loop.h" |
| +#include "base/synchronization/waitable_event.h" |
| +#include "base/threading/thread.h" |
| +#include "ipc/ipc_channel_handle.h" |
| +#include "ipc/ipc_logging.h" |
| +#include "ipc/ipc_message.h" |
| +#include "native_client/src/include/portability.h" |
|
Mark Seaborn
2012/06/13 20:27:37
Are you just #including this for EXTERN_C_BEGIN?
bbudge
2012/06/14 02:45:10
Done.
|
| +#include "native_client/src/untrusted/irt/irt_ppapi.h" |
| +#include "ppapi/c/ppp.h" |
| +#include "ppapi/c/ppp_instance.h" |
| +#include "ppapi/proxy/plugin_dispatcher.h" |
| +#include "ppapi/proxy/plugin_globals.h" |
| + |
| +#if defined(IPC_MESSAGE_LOG_ENABLED) |
| +#define IPC_MESSAGE_MACROS_LOG_ENABLED |
| +#include "ppapi/proxy/ppapi_messages.h" |
| +#endif |
| + |
| +#define NACL_IPC_FD 6 // TODO(use API constant) |
|
Mark Seaborn
2012/06/13 20:27:37
Please add a comment that this must match up with
bbudge
2012/06/14 02:45:10
Done.
Mark Seaborn
2012/06/14 21:49:20
I don't see a different comment in the new version
bbudge
2012/06/15 01:07:32
Oops. Good catch. Done.
On 2012/06/14 21:49:20, Ma
|
| + |
| +using ppapi::proxy::PluginDispatcher; |
| +using ppapi::proxy::PluginGlobals; |
| + |
| +namespace { |
| + |
| +struct PP_ThreadFunctions thread_funcs; |
| + |
| +// Copied from src/content/ppapi_plugin/ppapi_thread. This is a minimal |
| +// implementation to get us started. |
| +class PluginDispatcherDelegate : public PluginDispatcher::PluginDelegate { |
| + public: |
| + explicit PluginDispatcherDelegate( |
| + scoped_refptr<base::MessageLoopProxy> io_loop) |
| + : message_loop_(io_loop), |
| + shutdown_event_(true, false) { |
| + } |
| + |
| + virtual base::MessageLoopProxy* GetIPCMessageLoop() OVERRIDE { |
| + return message_loop_.get(); |
| + } |
| + |
| + virtual base::WaitableEvent* GetShutdownEvent() OVERRIDE { |
| + return &shutdown_event_; |
| + } |
| + |
| + virtual IPC::PlatformFileForTransit ShareHandleWithRemote( |
| + base::PlatformFile handle, |
| + const IPC::SyncChannel& channel, |
| + bool should_close_source) OVERRIDE { |
| + return IPC::InvalidPlatformFileForTransit(); |
| + } |
| + |
| + virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() OVERRIDE { |
| + return &instances_; |
| + } |
| + |
| + virtual uint32 Register(PluginDispatcher* plugin_dispatcher) OVERRIDE { |
| + if (!plugin_dispatcher || |
| + plugin_dispatchers_.size() >= std::numeric_limits<uint32>::max()) { |
| + return 0; |
| + } |
| + |
| + uint32 id = 0; |
| + do { |
| + // Although it is unlikely, make sure that we won't cause any trouble when |
| + // the counter overflows. |
| + id = next_plugin_dispatcher_id_++; |
| + } while (id == 0 || |
| + plugin_dispatchers_.find(id) != plugin_dispatchers_.end()); |
| + plugin_dispatchers_[id] = plugin_dispatcher; |
| + return id; |
| + } |
| + |
| + virtual void Unregister(uint32 plugin_dispatcher_id) OVERRIDE { |
| + plugin_dispatchers_.erase(plugin_dispatcher_id); |
| + } |
| + |
| + private: |
| + std::set<PP_Instance> instances_; |
| + std::map<uint32, PluginDispatcher*> plugin_dispatchers_; |
| + uint32 next_plugin_dispatcher_id_; |
| + scoped_refptr<base::MessageLoopProxy> message_loop_; |
| + base::WaitableEvent shutdown_event_; |
| +}; |
| + |
| +} // namespace |
| + |
| +EXTERN_C_BEGIN |
| + |
| +void PpapiPluginRegisterThreadCreator( |
| + const struct PP_ThreadFunctions* new_funcs) { |
| + thread_funcs = *new_funcs; |
| +} |
| + |
| +int IrtInit() { |
| + static int initialized = 0; |
|
Mark Seaborn
2012/06/13 20:27:37
This function body doesn't do anything, so this ca
bbudge
2012/06/14 02:45:10
Done.
|
| + if (initialized) { |
| + return 0; |
| + } |
| + |
| + initialized = 1; |
| + return 0; |
| +} |
| + |
| +int PpapiPluginMain() { |
| + base::AtExitManager exit_manager; |
| + MessageLoop loop; |
| + IPC::Logging::set_log_function_map(&g_log_function_mapping); |
| + ppapi::proxy::PluginGlobals plugin_globals; |
| + base::Thread io_thread("Chrome_NaClIOThread"); |
| + base::Thread::Options options; |
| + options.message_loop_type = MessageLoop::TYPE_IO; |
| + io_thread.StartWithOptions(options); |
| + |
| + int32_t ok = ::PPP_InitializeModule( |
| + 0 /* module */, |
| + &ppapi::proxy::PluginDispatcher::GetBrowserInterface); |
| + // TODO(dmichael): Handle other error canditions, like failure to connect? |
|
Mark Seaborn
2012/06/13 20:27:37
'conditions'
bbudge
2012/06/14 02:45:10
Done.
|
| + // if (!ok) |
| + // return ok; |
| + |
| + PluginDispatcherDelegate delegate(io_thread.message_loop_proxy()); |
| + |
| + // TODO(dmichael) Figure out how to determine if we're in incognito |
|
Mark Seaborn
2012/06/13 20:27:37
This does not seem appropriate to the untrusted pr
|
| + PluginDispatcher dispatcher(::PPP_GetInterface, false /* incognito */); |
| + IPC::ChannelHandle channel_handle("NaCl IPC", |
| + base::FileDescriptor(NACL_IPC_FD, false)); |
| + dispatcher.InitPluginWithChannel(&delegate, channel_handle, false); |
| + |
| + loop.Run(); |
| + return 0; |
| +} |
| + |
| +EXTERN_C_END |
| + |
| Property changes on: ppapi/proxy/plugin_globals_nacl.cc |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |