From eb415bf0e3fa41131a0f1f706e4f377d86206556 Mon Sep 17 00:00:00 2001 From: "ddorwin@chromium.org" Date: Thu, 14 Apr 2011 02:45:42 +0000 Subject: Asynchronously create the ppapi broker. BUG=none TEST=none Review URL: http://codereview.chromium.org/6822012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81525 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/plugins/ppapi/mock_plugin_delegate.cc | 1 - webkit/plugins/ppapi/mock_plugin_delegate.h | 3 +-- webkit/plugins/ppapi/plugin_delegate.h | 18 ++++++++++-------- webkit/plugins/ppapi/plugin_module.cc | 11 +++++++++++ webkit/plugins/ppapi/plugin_module.h | 6 ++++++ webkit/plugins/ppapi/ppb_broker_impl.cc | 4 ++-- webkit/plugins/ppapi/ppb_broker_impl.h | 2 +- 7 files changed, 31 insertions(+), 14 deletions(-) (limited to 'webkit/plugins') diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc index a9da765..e896bcd 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.cc +++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc @@ -53,7 +53,6 @@ MockPluginDelegate::PlatformAudio* MockPluginDelegate::CreateAudio( } MockPluginDelegate::PpapiBroker* MockPluginDelegate::ConnectToPpapiBroker( - PluginInstance* instance, PPB_Broker_Impl* client) { return NULL; } diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h index 78d59a2..101f788 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.h +++ b/webkit/plugins/ppapi/mock_plugin_delegate.h @@ -26,8 +26,7 @@ class MockPluginDelegate : public PluginDelegate { virtual PlatformAudio* CreateAudio(uint32_t sample_rate, uint32_t sample_count, PlatformAudio::Client* client); - virtual PpapiBroker* ConnectToPpapiBroker(PluginInstance* instance, - PPB_Broker_Impl* client); + virtual PpapiBroker* ConnectToPpapiBroker(PPB_Broker_Impl* client); virtual void NumberOfFindResultsChanged(int identifier, int total, bool final_result); diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h index 786e924..d986e95 100644 --- a/webkit/plugins/ppapi/plugin_delegate.h +++ b/webkit/plugins/ppapi/plugin_delegate.h @@ -210,15 +210,18 @@ class PluginDelegate { }; // Provides access to the ppapi broker. - class PpapiBroker { + class PpapiBroker : public base::RefCountedThreadSafe { public: - virtual ~PpapiBroker() {} + virtual void Connect(webkit::ppapi::PPB_Broker_Impl* client) = 0; - // Decrements the references to the broker for the instance. - // When the references reach 0 for all instances in this renderer, this - // object may be destroyed. When the references reach 0 for all instances - // using the same module, the broker may shut down. - virtual void Release(PluginInstance* instance) = 0; + // Decrements the references to the broker. + // When there are no more references, this renderer's dispatcher is + // destroyed, allowing the broker to shutdown if appropriate. + virtual void Disconnect(webkit::ppapi::PPB_Broker_Impl* client) = 0; + + protected: + friend class base::RefCountedThreadSafe; + ~PpapiBroker() {} }; // Notification that the given plugin has crashed. When a plugin crashes, all @@ -259,7 +262,6 @@ class PluginDelegate { // The caller is responsible for calling Release() on the returned pointer // to clean up the corresponding resources allocated during this call. virtual PpapiBroker* ConnectToPpapiBroker( - PluginInstance* instance, webkit::ppapi::PPB_Broker_Impl* client) = 0; // Notifies that the number of find results has changed. diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index d469860..6fc7f7c 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -389,6 +389,7 @@ PluginModule::PluginModule(const std::string& name, : lifetime_delegate_(lifetime_delegate), callback_tracker_(new CallbackTracker), is_crashed_(false), + broker_(NULL), library_(NULL), name_(name), path_(path), @@ -527,6 +528,16 @@ bool PluginModule::ReserveInstanceID(PP_Instance instance) { return true; // Instance ID is usable. } +void PluginModule::SetBroker( + scoped_refptr broker) { + DCHECK(!broker_.get()); + broker_ = broker; +} + +scoped_refptr PluginModule::GetBroker(){ + return broker_; +} + bool PluginModule::InitializeModule() { DCHECK(!out_of_process_proxy_.get()) << "Don't call for proxied modules."; int retval = entry_points_.initialize_module(pp_module(), &GetInterface); diff --git a/webkit/plugins/ppapi/plugin_module.h b/webkit/plugins/ppapi/plugin_module.h index dabd032..e462f3a 100644 --- a/webkit/plugins/ppapi/plugin_module.h +++ b/webkit/plugins/ppapi/plugin_module.h @@ -145,6 +145,9 @@ class PluginModule : public base::RefCounted, PP_Bool (*reserve)(PP_Module, PP_Instance)); bool ReserveInstanceID(PP_Instance instance); + void SetBroker(scoped_refptr broker); + scoped_refptr GetBroker(); + private: // Calls the InitializeModule entrypoint. The entrypoint must have been // set and the plugin must not be out of process (we don't maintain @@ -167,6 +170,9 @@ class PluginModule : public base::RefCounted, // entry_points_ aren't valid. scoped_ptr out_of_process_proxy_; + // Trusted broker for this plugin module. + scoped_refptr broker_; + // Holds a reference to the base::NativeLibrary handle if this PluginModule // instance wraps functions loaded from a library. Can be NULL. If // |library_| is non-NULL, PluginModule will attempt to unload the library diff --git a/webkit/plugins/ppapi/ppb_broker_impl.cc b/webkit/plugins/ppapi/ppb_broker_impl.cc index 9e0cb5c..83912c5 100644 --- a/webkit/plugins/ppapi/ppb_broker_impl.cc +++ b/webkit/plugins/ppapi/ppb_broker_impl.cc @@ -72,7 +72,7 @@ PPB_Broker_Impl::PPB_Broker_Impl(PluginInstance* instance) PPB_Broker_Impl::~PPB_Broker_Impl() { if (broker_) { - broker_->Release(instance()); + broker_->Disconnect(this); broker_ = NULL; } @@ -94,7 +94,7 @@ int32_t PPB_Broker_Impl::Connect( return PP_ERROR_FAILED; } - broker_ = plugin_delegate->ConnectToPpapiBroker(instance(), this); + broker_ = plugin_delegate->ConnectToPpapiBroker(this); if (!broker_) return PP_ERROR_FAILED; diff --git a/webkit/plugins/ppapi/ppb_broker_impl.h b/webkit/plugins/ppapi/ppb_broker_impl.h index f83d280..66454b9 100644 --- a/webkit/plugins/ppapi/ppb_broker_impl.h +++ b/webkit/plugins/ppapi/ppb_broker_impl.h @@ -38,7 +38,7 @@ class PPB_Broker_Impl : public Resource { private: // PluginDelegate ppapi broker object. // We don't own this pointer but are responsible for calling Release on it. - PluginDelegate::PpapiBroker* broker_; + scoped_refptr broker_; // Callback invoked from BrokerConnected. scoped_refptr connect_callback_; -- cgit v1.1