diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-13 17:50:20 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-13 17:50:20 +0000 |
commit | a08ebeaea39acfe007d9ee9b25b28efd04011e5a (patch) | |
tree | c878b32554af650294155ab21491dc086cff0939 /ppapi/proxy/plugin_dispatcher.cc | |
parent | 9d7557f78d893c56afcf65f2e6317feabb9af796 (diff) | |
download | chromium_src-a08ebeaea39acfe007d9ee9b25b28efd04011e5a.zip chromium_src-a08ebeaea39acfe007d9ee9b25b28efd04011e5a.tar.gz chromium_src-a08ebeaea39acfe007d9ee9b25b28efd04011e5a.tar.bz2 |
Share PPAPI out-of-process plugins between renderer processes.
This provides the hook-up for plugin sharing but not shutdown or cleanup from
errors. There is still a lot of work to do cleaning up in the plugin and the
browser when a renderer dies, or cleaning up in the renderer and browser when a
plugin dies. Currently, even the normal exit case crashes in the browser. But
fixing it in this patch would be too complicated to write or review, so I'm
going to do shutdown & error handling in a followup.
Review URL: http://codereview.chromium.org/6486034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74766 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy/plugin_dispatcher.cc')
-rw-r--r-- | ppapi/proxy/plugin_dispatcher.cc | 76 |
1 files changed, 49 insertions, 27 deletions
diff --git a/ppapi/proxy/plugin_dispatcher.cc b/ppapi/proxy/plugin_dispatcher.cc index b30f6da..1f4454c 100644 --- a/ppapi/proxy/plugin_dispatcher.cc +++ b/ppapi/proxy/plugin_dispatcher.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -16,6 +16,11 @@ #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppp_class_proxy.h" +#if defined(OS_POSIX) +#include "base/eintr_wrapper.h" +#include "ipc/ipc_channel_posix.h" +#endif + namespace pp { namespace proxy { @@ -24,23 +29,15 @@ namespace { typedef std::map<PP_Instance, PluginDispatcher*> InstanceToDispatcherMap; InstanceToDispatcherMap* g_instance_to_dispatcher = NULL; -const void* GetInterfaceFromDispatcher(const char* interface) { - // All interfaces the plugin requests of the browser are "PPB". - const InterfaceProxy::Info* info = Dispatcher::GetPPBInterfaceInfo(interface); - if (!info) - return NULL; - return info->interface; -} - } // namespace PluginDispatcher::PluginDispatcher(base::ProcessHandle remote_process_handle, - GetInterfaceFunc get_interface, - InitModuleFunc init_module, - ShutdownModuleFunc shutdown_module) - : Dispatcher(remote_process_handle, get_interface), - init_module_(init_module), - shutdown_module_(shutdown_module) { + GetInterfaceFunc get_interface) + : Dispatcher(remote_process_handle, get_interface) +#if defined(OS_POSIX) + , renderer_fd_(-1) +#endif + { SetSerializationRules(new PluginVarSerializationRules); // As a plugin, we always support the PPP_Class interface. There's no @@ -49,8 +46,9 @@ PluginDispatcher::PluginDispatcher(base::ProcessHandle remote_process_handle, } PluginDispatcher::~PluginDispatcher() { - if (shutdown_module_) - shutdown_module_(); +#if defined(OS_POSIX) + CloseRendererFD(); +#endif } // static @@ -64,6 +62,16 @@ PluginDispatcher* PluginDispatcher::GetForInstance(PP_Instance instance) { return found->second; } +// static +const void* PluginDispatcher::GetInterfaceFromDispatcher( + const char* interface) { + // All interfaces the plugin requests of the browser are "PPB". + const InterfaceProxy::Info* info = GetPPBInterfaceInfo(interface); + if (!info) + return NULL; + return info->interface; +} + bool PluginDispatcher::IsPlugin() const { return true; } @@ -78,8 +86,6 @@ bool PluginDispatcher::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PluginDispatcher, msg) IPC_MESSAGE_HANDLER(PpapiMsg_SupportsInterface, OnMsgSupportsInterface) - IPC_MESSAGE_HANDLER(PpapiMsg_InitializeModule, OnMsgInitializeModule) - IPC_MESSAGE_HANDLER(PpapiMsg_Shutdown, OnMsgShutdown) IPC_END_MESSAGE_MAP() return handled; } @@ -122,6 +128,14 @@ bool PluginDispatcher::OnMessageReceived(const IPC::Message& msg) { return proxy->OnMessageReceived(msg); } +void PluginDispatcher::OnChannelError() { + // The renderer has crashed. This channel and all instances associated with + // it are no longer valid. + ForceFreeAllInstances(); + // TODO(brettw) free resources too! + delete this; +} + void PluginDispatcher::DidCreateInstance(PP_Instance instance) { if (!g_instance_to_dispatcher) g_instance_to_dispatcher = new InstanceToDispatcherMap; @@ -152,16 +166,24 @@ InstanceData* PluginDispatcher::GetInstanceData(PP_Instance instance) { return (it == instance_map_.end()) ? NULL : &it->second; } -void PluginDispatcher::OnMsgInitializeModule(PP_Module pp_module, - bool* result) { - set_pp_module(pp_module); - *result = init_module_(pp_module, &GetInterfaceFromDispatcher) == PP_OK; +#if defined(OS_POSIX) +int PluginDispatcher::GetRendererFD() { + if (renderer_fd_ == -1) + renderer_fd_ = channel()->GetClientFileDescriptor(); + return renderer_fd_; +} + +void PluginDispatcher::CloseRendererFD() { + if (renderer_fd_ != -1) { + if (HANDLE_EINTR(close(renderer_fd_)) < 0) + PLOG(ERROR) << "close"; + renderer_fd_ = -1; + } } +#endif -void PluginDispatcher::OnMsgShutdown() { - if (shutdown_module_) - shutdown_module_(); - MessageLoop::current()->Quit(); +void PluginDispatcher::ForceFreeAllInstances() { + // TODO(brettw) implement freeing instances on crash. } void PluginDispatcher::OnMsgSupportsInterface( |