diff options
author | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-30 23:18:29 +0000 |
---|---|---|
committer | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-30 23:18:29 +0000 |
commit | 7f2e792eec4293b56c6eb9a5d014cee9ed612841 (patch) | |
tree | 08f30bf750e13bbaff2c3871bb0622137883294c /chrome/browser/renderer_host | |
parent | e6d51160f9cf94237fdb2a25317c20c43eb14b6b (diff) | |
download | chromium_src-7f2e792eec4293b56c6eb9a5d014cee9ed612841.zip chromium_src-7f2e792eec4293b56c6eb9a5d014cee9ed612841.tar.gz chromium_src-7f2e792eec4293b56c6eb9a5d014cee9ed612841.tar.bz2 |
Revert 33344 - Relocate plugin list fetching to PluginService
We fetch the plugin list from three places. Previously, each location had
custom code to proxy the query to the file thread. This change moves
the query to the PluginService, which then internally manages posting to
the file thread and calling back.
I experimented with some different approaches to handling the lifetimes
of the requests and responses. The approach now is simple:
The PluginService plugin methods are called and respond on the IO
thread. Two of the three consumers of the plugin lists are already on
the IO thread, so they don't need any complicated thread handling.
None of the callers ever need to cancel their requests: one is a
singleton, and the other two always wait (in terms of holding a ref
on the object) for the requests to complete. This makes lifetime
management a lot simpler than it would otherwise be.
With this change in place, I can then look at refactoring the PluginService
implementation on Linux to do more complicated plugin loading as needed in
bug 17863.
BUG=17863
Review URL: http://codereview.chromium.org/437069
TBR=evan@chromium.org
Review URL: http://codereview.chromium.org/456012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33369 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/renderer_host')
4 files changed, 42 insertions, 54 deletions
diff --git a/chrome/browser/renderer_host/buffered_resource_handler.cc b/chrome/browser/renderer_host/buffered_resource_handler.cc index a72c54d..f3ca82f 100644 --- a/chrome/browser/renderer_host/buffered_resource_handler.cc +++ b/chrome/browser/renderer_host/buffered_resource_handler.cc @@ -10,7 +10,6 @@ #include "base/logging.h" #include "base/string_util.h" #include "chrome/browser/chrome_thread.h" -#include "chrome/browser/plugin_service.h" #include "chrome/browser/renderer_host/download_throttling_resource_handler.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" @@ -396,10 +395,10 @@ bool BufferedResourceHandler::ShouldWaitForPlugins() { ResourceDispatcherHost::InfoForRequest(request_); host_->PauseRequest(info->child_id(), info->request_id(), true); - // Schedule plugin loading. - this->AddRef(); // Balanced in OnGetPluginList. - PluginService::GetInstance()->GetPluginList(false, this); - + // Schedule plugin loading on the file thread. + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, + NewRunnableMethod(this, &BufferedResourceHandler::LoadPlugins)); return true; } @@ -467,18 +466,23 @@ bool BufferedResourceHandler::ShouldDownload(bool* need_plugin_list) { GURL(), type, allow_wildcard, &info, NULL); } -void BufferedResourceHandler::OnGetPluginList( - const std::vector<WebPluginInfo>& plugins) { - wait_for_plugins_ = false; +void BufferedResourceHandler::LoadPlugins() { + std::vector<WebPluginInfo> plugins; + NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins); - if (request_) { - ResourceDispatcherHostRequestInfo* info = - ResourceDispatcherHost::InfoForRequest(request_); - host_->PauseRequest(info->child_id(), info->request_id(), false); - if (!CompleteResponseStarted(info->request_id(), false)) - host_->CancelRequest(info->child_id(), info->request_id(), false); - } + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod(this, &BufferedResourceHandler::OnPluginsLoaded)); +} - // Drop the reference added before the GetPluginList call. - this->Release(); +void BufferedResourceHandler::OnPluginsLoaded() { + wait_for_plugins_ = false; + if (!request_) + return; + + ResourceDispatcherHostRequestInfo* info = + ResourceDispatcherHost::InfoForRequest(request_); + host_->PauseRequest(info->child_id(), info->request_id(), false); + if (!CompleteResponseStarted(info->request_id(), false)) + host_->CancelRequest(info->child_id(), info->request_id(), false); } diff --git a/chrome/browser/renderer_host/buffered_resource_handler.h b/chrome/browser/renderer_host/buffered_resource_handler.h index 3bed83a7..6bc34e1 100644 --- a/chrome/browser/renderer_host/buffered_resource_handler.h +++ b/chrome/browser/renderer_host/buffered_resource_handler.h @@ -7,7 +7,6 @@ #include <string> -#include "chrome/browser/plugin_service.h" #include "chrome/browser/renderer_host/resource_handler.h" class MessageLoop; @@ -15,8 +14,7 @@ class ResourceDispatcherHost; class URLRequest; // Used to buffer a request until enough data has been received. -class BufferedResourceHandler : public ResourceHandler, - public PluginService::GetPluginListClient { +class BufferedResourceHandler : public ResourceHandler { public: BufferedResourceHandler(ResourceHandler* handler, ResourceDispatcherHost* host, @@ -65,8 +63,11 @@ class BufferedResourceHandler : public ResourceHandler, // loaded. bool ShouldDownload(bool* need_plugin_list); + // Called on the file thread to load the list of plugins. + void LoadPlugins(); + // Called on the IO thread once the list of plugins has been loaded. - void OnGetPluginList(const std::vector<WebPluginInfo>& plugins); + void OnPluginsLoaded(); scoped_refptr<ResourceHandler> real_handler_; scoped_refptr<ResourceResponse> response_; diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index afc5007..8006960 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -582,32 +582,22 @@ void ResourceMessageFilter::OnLoadFont(LOGFONT font) { void ResourceMessageFilter::OnGetPlugins(bool refresh, IPC::Message* reply_msg) { - // Start the query to the plugin service, but only if we don't have another - // query already processing. - if (pending_getpluginlist_.empty()) { - PluginService::GetInstance()->GetPluginList(refresh, this); - this->AddRef(); - } - - // Put reply_msg into the queue of waiting responses. - pending_getpluginlist_.push(std::make_pair(refresh, reply_msg)); + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, + NewRunnableMethod( + this, &ResourceMessageFilter::OnGetPluginsOnFileThread, refresh, + reply_msg)); } -void ResourceMessageFilter::OnGetPluginList( - const std::vector<WebPluginInfo>& plugins) { - IPC::Message* msg = pending_getpluginlist_.front().second; - ViewHostMsg_GetPlugins::WriteReplyParams(msg, plugins); - Send(msg); - - pending_getpluginlist_.pop(); - if (!pending_getpluginlist_.empty()) { - // We have more pending requests; start the next one. - PluginService::GetInstance()->GetPluginList( - pending_getpluginlist_.front().first, this); - } else { - // Drop the reference grabbed in OnGetPlugins(). - this->Release(); - } +void ResourceMessageFilter::OnGetPluginsOnFileThread( + bool refresh, IPC::Message* reply_msg) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); + std::vector<WebPluginInfo> plugins; + NPAPI::PluginList::Singleton()->GetPlugins(refresh, &plugins); + ViewHostMsg_GetPlugins::WriteReplyParams(reply_msg, plugins); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod(this, &ResourceMessageFilter::Send, reply_msg)); } void ResourceMessageFilter::OnGetPluginPath(const GURL& url, diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h index 974abfc..53c78dd 100644 --- a/chrome/browser/renderer_host/resource_message_filter.h +++ b/chrome/browser/renderer_host/resource_message_filter.h @@ -24,7 +24,6 @@ #include "build/build_config.h" #include "chrome/browser/net/resolve_proxy_msg_helper.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" -#include "chrome/browser/plugin_service.h" #include "chrome/common/nacl_types.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/transport_dib.h" @@ -74,8 +73,7 @@ struct ViewHostMsg_DidPrintPage_Params; class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, public ResourceDispatcherHost::Receiver, public NotificationObserver, - public ResolveProxyMsgHelper::Delegate, - public PluginService::GetPluginListClient { + public ResolveProxyMsgHelper::Delegate { public: // Create the filter. // Note: because the lifecycle of the ResourceMessageFilter is not @@ -154,7 +152,7 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, void OnGetScreenInfo(gfx::NativeViewId window, IPC::Message* reply); #endif void OnGetPlugins(bool refresh, IPC::Message* reply_msg); - virtual void OnGetPluginList(const std::vector<WebPluginInfo>& plugins); + void OnGetPluginsOnFileThread(bool refresh, IPC::Message* reply_msg); void OnGetPluginPath(const GURL& url, const GURL& policy_url, const std::string& mime_type, @@ -400,11 +398,6 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, // A callback to create a routing id for the associated renderer process. scoped_ptr<CallbackWithReturnValue<int>::Type> next_route_id_callback_; - // A queue of pending GetPluginList calls. The bool is the |refresh| - // flag used to make the call, and the IPC::Message is the destination - // of the result of the call once the call completes. - std::queue<std::pair<bool, IPC::Message*> > pending_getpluginlist_; - DISALLOW_COPY_AND_ASSIGN(ResourceMessageFilter); }; |