diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-04 22:31:21 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-04 22:31:21 +0000 |
commit | ece8f0bfe21498928a4a352e7c318efcdae06b18 (patch) | |
tree | d5cca4f46344bb9e82782bcf2109ef67d11ce7ce /webkit | |
parent | 9a861cc490008122943d4e3df06ddda1f9c5dab1 (diff) | |
download | chromium_src-ece8f0bfe21498928a4a352e7c318efcdae06b18.zip chromium_src-ece8f0bfe21498928a4a352e7c318efcdae06b18.tar.gz chromium_src-ece8f0bfe21498928a4a352e7c318efcdae06b18.tar.bz2 |
Re-use existing out-of-process plugins if one is already loaded. Otherwise
sites with multiple plugins will load that many child processes, which is bad.
This works by having creators of out-of-process plugins add it to a list in the
PepperPluginRegistry. The items are deleted from this list by a new delegate
implementation for the module to tell the registry that it's being destroyed.
It's a little awkward since the PluginModule can't know about the
PepperPluginRegistry, and all other pepper "delegates" are associated with the
Instance/RenderView, so by definition can't be used when the module is being
torn down since there are no instances.
It might have been nice to have an Add function on the lifetime delegate so
that the module will add itself to the list. But the plugin path name is
currently not available in all code paths, and it seemed messy to add.
TEST=manual
BUG=none
Review URL: http://codereview.chromium.org/6085007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70457 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/plugins/ppapi/plugin_delegate.h | 19 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_module.cc | 6 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_module.h | 12 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_unittest.cc | 6 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_unittest.h | 7 |
5 files changed, 43 insertions, 7 deletions
diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h index fef6cff..9feff6d 100644 --- a/webkit/plugins/ppapi/plugin_delegate.h +++ b/webkit/plugins/ppapi/plugin_delegate.h @@ -63,12 +63,31 @@ namespace ppapi { class FileIO; class PluginInstance; +class PluginModule; class FullscreenContainer; // Virtual interface that the browser implements to implement features for // PPAPI plugins. class PluginDelegate { public: + // This interface is used for the PluginModule to tell the code in charge of + // re-using modules which modules currently exist. + // + // It is different than the other interfaces, which are scoped to the + // lifetime of the plugin instance. The implementor of this interface must + // outlive all plugin modules, and is in practice a singleton + // (PepperPluginRegistry). This requirement means we can't do the obvious + // thing and just have a PluginDelegate call for this purpose (when the + // module is being deleted, we know there are no more PluginInstances that + // have PluginDelegates). + class ModuleLifetime { + public: + // Notification that the given plugin object has been deleted. This is + // called from the module's destructor, so you should not dereference the + // given pointer. + virtual void PluginModuleDestroyed(PluginModule* destroyed_module) = 0; + }; + // This class is implemented by the PluginDelegate implementation and is // designed to manage the lifetime and communicatin with the proxy's // HostDispatcher for out-of-process PPAPI plugins. diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index 250261b..6fb24cc 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -348,8 +348,9 @@ PluginModule::EntryPoints::EntryPoints() // PluginModule ---------------------------------------------------------------- -PluginModule::PluginModule() - : callback_tracker_(new CallbackTracker), +PluginModule::PluginModule(PluginDelegate::ModuleLifetime* lifetime_delegate) + : lifetime_delegate_(lifetime_delegate), + callback_tracker_(new CallbackTracker), library_(NULL) { pp_module_ = ResourceTracker::Get()->AddModule(this); GetMainThreadMessageLoop(); // Initialize the main thread message loop. @@ -383,6 +384,7 @@ PluginModule::~PluginModule() { base::UnloadNativeLibrary(library_); ResourceTracker::Get()->ModuleDeleted(pp_module_); + lifetime_delegate_->PluginModuleDestroyed(this); } bool PluginModule::InitAsInternalPlugin(const EntryPoints& entry_points) { diff --git a/webkit/plugins/ppapi/plugin_module.h b/webkit/plugins/ppapi/plugin_module.h index d4096c61..913b003 100644 --- a/webkit/plugins/ppapi/plugin_module.h +++ b/webkit/plugins/ppapi/plugin_module.h @@ -68,9 +68,13 @@ class PluginModule : public base::RefCounted<PluginModule>, PPP_ShutdownModuleFunc shutdown_module; // Optional, may be NULL. }; - // You must call one of the Init functions to create a module of the type - // you desire. - PluginModule(); + // You must call one of the Init functions after the constructor to create a + // module of the type you desire. + // + // The module lifetime delegate is a non-owning pointer that must outlive + // all plugin modules. In practice it will be a global singleton that + // tracks which modules are alive. + PluginModule(PluginDelegate::ModuleLifetime* lifetime_delegate); ~PluginModule(); @@ -142,6 +146,8 @@ class PluginModule : public base::RefCounted<PluginModule>, // entrypoints in that case). bool InitializeModule(); + PluginDelegate::ModuleLifetime* lifetime_delegate_; + // Tracker for completion callbacks, used mainly to ensure that all callbacks // are properly aborted on module shutdown. scoped_refptr<CallbackTracker> callback_tracker_; diff --git a/webkit/plugins/ppapi/ppapi_unittest.cc b/webkit/plugins/ppapi/ppapi_unittest.cc index 479871b..bc3039d 100644 --- a/webkit/plugins/ppapi/ppapi_unittest.cc +++ b/webkit/plugins/ppapi/ppapi_unittest.cc @@ -87,7 +87,7 @@ void PpapiUnittest::SetUp() { delegate_.reset(new MockPluginDelegate); // Initialize the mock module. - module_ = new PluginModule; + module_ = new PluginModule(this); PluginModule::EntryPoints entry_points; entry_points.get_interface = &MockGetInterface; entry_points.initialize_module = &MockInitializeModule; @@ -115,5 +115,9 @@ void PpapiUnittest::ShutdownModule() { module_ = NULL; } +void PpapiUnittest::PluginModuleDestroyed(PluginModule* destroyed_module) { + // Nothing needed (this is necessary to make the module compile). +} + } // namespace ppapi } // namespace webkit diff --git a/webkit/plugins/ppapi/ppapi_unittest.h b/webkit/plugins/ppapi/ppapi_unittest.h index b9ccf5e..c18af87 100644 --- a/webkit/plugins/ppapi/ppapi_unittest.h +++ b/webkit/plugins/ppapi/ppapi_unittest.h @@ -9,6 +9,7 @@ #include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "testing/gtest/include/gtest/gtest.h" +#include "webkit/plugins/ppapi/plugin_delegate.h" namespace webkit { namespace ppapi { @@ -17,7 +18,8 @@ class MockPluginDelegate; class PluginInstance; class PluginModule; -class PpapiUnittest : public testing::Test { +class PpapiUnittest : public testing::Test, + public webkit::ppapi::PluginDelegate::ModuleLifetime { public: PpapiUnittest(); virtual ~PpapiUnittest(); @@ -42,6 +44,9 @@ class PpapiUnittest : public testing::Test { scoped_refptr<PluginModule> module_; scoped_refptr<PluginInstance> instance_; + // ModuleLifetime implementation. + virtual void PluginModuleDestroyed(PluginModule* destroyed_module); + DISALLOW_COPY_AND_ASSIGN(PpapiUnittest); }; |