summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorddorwin@chromium.org <ddorwin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-16 22:12:45 +0000
committerddorwin@chromium.org <ddorwin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-16 22:12:45 +0000
commite2614c60e3bab6cc1b949ecd8101189d285da17f (patch)
treef664f4e27974b7dee547aba035abef48e27c167c /content
parent64a2958841eb968837a90c9a738d9b68e33abb70 (diff)
downloadchromium_src-e2614c60e3bab6cc1b949ecd8101189d285da17f.zip
chromium_src-e2614c60e3bab6cc1b949ecd8101189d285da17f.tar.gz
chromium_src-e2614c60e3bab6cc1b949ecd8101189d285da17f.tar.bz2
Refactored ppapi Dispatcher to share common code between the plugin and broker dispatchers.
Common code is in DispatcherBase. The base of the dispatcher for plugins remains Dispatcher. The base of the dispatcher for Brokers is BrokerDispatcher. BUG=none TEST=ppapi out-of-process plugins Review URL: http://codereview.chromium.org/6859003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81883 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/content_ppapi_plugin.gypi2
-rw-r--r--content/ppapi_plugin/broker_process_dispatcher.cc38
-rw-r--r--content/ppapi_plugin/broker_process_dispatcher.h24
-rw-r--r--content/ppapi_plugin/ppapi_thread.cc34
-rw-r--r--content/ppapi_plugin/ppapi_thread.h6
-rw-r--r--content/renderer/pepper_plugin_delegate_impl.cc4
6 files changed, 90 insertions, 18 deletions
diff --git a/content/content_ppapi_plugin.gypi b/content/content_ppapi_plugin.gypi
index c586705..e62050b 100644
--- a/content/content_ppapi_plugin.gypi
+++ b/content/content_ppapi_plugin.gypi
@@ -12,6 +12,8 @@
'../ppapi/ppapi.gyp:ppapi_proxy',
],
'sources': [
+ 'ppapi_plugin/broker_process_dispatcher.cc',
+ 'ppapi_plugin/broker_process_dispatcher.h',
'ppapi_plugin/plugin_process_dispatcher.cc',
'ppapi_plugin/plugin_process_dispatcher.h',
'ppapi_plugin/ppapi_broker_main.cc',
diff --git a/content/ppapi_plugin/broker_process_dispatcher.cc b/content/ppapi_plugin/broker_process_dispatcher.cc
new file mode 100644
index 0000000..68e56e7
--- /dev/null
+++ b/content/ppapi_plugin/broker_process_dispatcher.cc
@@ -0,0 +1,38 @@
+// 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.
+
+#include "content/ppapi_plugin/broker_process_dispatcher.h"
+
+#include "content/common/child_process.h"
+
+namespace {
+
+class PluginReleaseTask : public Task {
+ public:
+ void Run() {
+ ChildProcess::current()->ReleaseProcess();
+ }
+};
+
+// How long we wait before releasing the plugin process.
+const int kPluginReleaseTimeMs = 30 * 1000; // 30 seconds.
+
+} // namespace
+
+BrokerProcessDispatcher::BrokerProcessDispatcher(
+ base::ProcessHandle remote_process_handle,
+ PP_ConnectInstance_Func connect_instance)
+ : pp::proxy::BrokerDispatcher(remote_process_handle, connect_instance) {
+ ChildProcess::current()->AddRefProcess();
+}
+
+BrokerProcessDispatcher::~BrokerProcessDispatcher() {
+ // Don't free the process right away. This timer allows the child process
+ // to be re-used if the user rapidly goes to a new page that requires this
+ // plugin. This is the case for common plugins where they may be used on a
+ // source and destination page of a navigation. We don't want to tear down
+ // and re-start processes each time in these cases.
+ MessageLoop::current()->PostDelayedTask(FROM_HERE, new PluginReleaseTask(),
+ kPluginReleaseTimeMs);
+}
diff --git a/content/ppapi_plugin/broker_process_dispatcher.h b/content/ppapi_plugin/broker_process_dispatcher.h
new file mode 100644
index 0000000..e5086fd
--- /dev/null
+++ b/content/ppapi_plugin/broker_process_dispatcher.h
@@ -0,0 +1,24 @@
+// 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.
+
+#ifndef CONTENT_PPAPI_PLUGIN_BROKER_PROCESS_DISPATCHER_H_
+#define CONTENT_PPAPI_PLUGIN_BROKER_PROCESS_DISPATCHER_H_
+
+#include "base/basictypes.h"
+#include "ppapi/proxy/broker_dispatcher.h"
+
+// Wrapper around a BrokerDispatcher that provides the necessary integration
+// for plugin process management. This class is to avoid direct dependencies
+// from the PPAPI proxy on the Chrome multiprocess infrastructure.
+class BrokerProcessDispatcher : public pp::proxy::BrokerDispatcher {
+ public:
+ BrokerProcessDispatcher(base::ProcessHandle remote_process_handle,
+ PP_ConnectInstance_Func connect_instance);
+ virtual ~BrokerProcessDispatcher();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(BrokerProcessDispatcher);
+};
+
+#endif // CONTENT_PPAPI_PLUGIN_BROKER_PROCESS_DISPATCHER_H_
diff --git a/content/ppapi_plugin/ppapi_thread.cc b/content/ppapi_plugin/ppapi_thread.cc
index cab4d93..54215a2 100644
--- a/content/ppapi_plugin/ppapi_thread.cc
+++ b/content/ppapi_plugin/ppapi_thread.cc
@@ -9,6 +9,7 @@
#include "base/process_util.h"
#include "base/rand_util.h"
#include "content/common/child_process.h"
+#include "content/ppapi_plugin/broker_process_dispatcher.h"
#include "content/ppapi_plugin/plugin_process_dispatcher.h"
#include "ipc/ipc_channel_handle.h"
#include "ipc/ipc_sync_channel.h"
@@ -32,11 +33,11 @@ PpapiThread::~PpapiThread() {
return;
// The ShutdownModule/ShutdownBroker function is optional.
- pp::proxy::Dispatcher::ShutdownModuleFunc shutdown_function =
+ pp::proxy::ProxyChannel::ShutdownModuleFunc shutdown_function =
is_broker_ ?
- reinterpret_cast<pp::proxy::Dispatcher::ShutdownModuleFunc>(
+ reinterpret_cast<pp::proxy::ProxyChannel::ShutdownModuleFunc>(
library_.GetFunctionPointer("PPP_ShutdownBroker")) :
- reinterpret_cast<pp::proxy::Dispatcher::ShutdownModuleFunc>(
+ reinterpret_cast<pp::proxy::ProxyChannel::ShutdownModuleFunc>(
library_.GetFunctionPointer("PPP_ShutdownModule"));
if (shutdown_function)
shutdown_function();
@@ -139,18 +140,31 @@ void PpapiThread::OnMsgCreateChannel(base::ProcessHandle host_process_handle,
bool PpapiThread::SetupRendererChannel(base::ProcessHandle host_process_handle,
int renderer_id,
IPC::ChannelHandle* handle) {
- // TODO(ddorwin): PluginProcessDispatcher is overkill for the broker. TBD
- // whether to create separate dispatcher classes for the broker.
- // TODO(ddorwin): Provide connect_instance_func_ when is_broker_.
DCHECK(is_broker_ == (connect_instance_func_ != NULL));
DCHECK(is_broker_ == (get_plugin_interface_ == NULL));
- PluginProcessDispatcher* dispatcher(new PluginProcessDispatcher(
- host_process_handle, get_plugin_interface_));
-
IPC::ChannelHandle plugin_handle;
plugin_handle.name = StringPrintf("%d.r%d", base::GetCurrentProcId(),
renderer_id);
- if (!dispatcher->InitWithChannel(this, plugin_handle, false)) {
+
+ pp::proxy::ProxyChannel* dispatcher = NULL;
+ bool init_result = false;
+ if (is_broker_) {
+ BrokerProcessDispatcher* broker_dispatcher =
+ new BrokerProcessDispatcher(host_process_handle, connect_instance_func_);
+ init_result = broker_dispatcher->InitBrokerWithChannel(this,
+ plugin_handle,
+ false);
+ dispatcher = broker_dispatcher;
+ } else {
+ PluginProcessDispatcher* plugin_dispatcher =
+ new PluginProcessDispatcher(host_process_handle, get_plugin_interface_);
+ init_result = plugin_dispatcher->InitPluginWithChannel(this,
+ plugin_handle,
+ false);
+ dispatcher = plugin_dispatcher;
+ }
+
+ if (!init_result) {
delete dispatcher;
return false;
}
diff --git a/content/ppapi_plugin/ppapi_thread.h b/content/ppapi_plugin/ppapi_thread.h
index 95cd7dc..ea8593c 100644
--- a/content/ppapi_plugin/ppapi_thread.h
+++ b/content/ppapi_plugin/ppapi_thread.h
@@ -22,12 +22,6 @@ namespace IPC {
struct ChannelHandle;
}
-namespace pp {
-namespace proxy {
-class PluginDispatcher;
-}
-}
-
class PpapiThread : public ChildThread,
public pp::proxy::Dispatcher::Delegate {
public:
diff --git a/content/renderer/pepper_plugin_delegate_impl.cc b/content/renderer/pepper_plugin_delegate_impl.cc
index e63dd01..95d24db 100644
--- a/content/renderer/pepper_plugin_delegate_impl.cc
+++ b/content/renderer/pepper_plugin_delegate_impl.cc
@@ -318,8 +318,8 @@ bool DispatcherWrapper::Init(
dispatcher_.reset(new pp::proxy::HostDispatcher(
plugin_process_handle, pp_module, local_get_interface));
- if (!dispatcher_->InitWithChannel(PepperPluginRegistry::GetInstance(),
- channel_handle, true)) {
+ if (!dispatcher_->InitHostWithChannel(PepperPluginRegistry::GetInstance(),
+ channel_handle, true)) {
dispatcher_.reset();
return false;
}