summaryrefslogtreecommitdiffstats
path: root/content/ppapi_plugin
diff options
context:
space:
mode:
authorddorwin@chromium.org <ddorwin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-14 02:41:09 +0000
committerddorwin@chromium.org <ddorwin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-14 02:41:09 +0000
commit6407f289f81ac09476e66c59fc4887eb46112981 (patch)
tree290db44c6c93d900582fdd5cee40d210defc6f8e /content/ppapi_plugin
parent0c534273b9592e78a0e5392449814c13a1e3285c (diff)
downloadchromium_src-6407f289f81ac09476e66c59fc4887eb46112981.zip
chromium_src-6407f289f81ac09476e66c59fc4887eb46112981.tar.gz
chromium_src-6407f289f81ac09476e66c59fc4887eb46112981.tar.bz2
Added ppp_broker.h and parameterized PpapiThread to support the broker process.
BUG=none TEST=none Review URL: http://codereview.chromium.org/6813071 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81524 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/ppapi_plugin')
-rw-r--r--content/ppapi_plugin/ppapi_broker_main.cc5
-rw-r--r--content/ppapi_plugin/ppapi_plugin_main.cc2
-rw-r--r--content/ppapi_plugin/ppapi_thread.cc102
-rw-r--r--content/ppapi_plugin/ppapi_thread.h12
4 files changed, 81 insertions, 40 deletions
diff --git a/content/ppapi_plugin/ppapi_broker_main.cc b/content/ppapi_plugin/ppapi_broker_main.cc
index edaaa10..7b63f56 100644
--- a/content/ppapi_plugin/ppapi_broker_main.cc
+++ b/content/ppapi_plugin/ppapi_broker_main.cc
@@ -14,15 +14,14 @@
int PpapiBrokerMain(const MainFunctionParams& parameters) {
const CommandLine& command_line = parameters.command_line_;
if (command_line.HasSwitch(switches::kPpapiStartupDialog)) {
- ChildProcess::WaitForDebugger("Ppapi");
+ ChildProcess::WaitForDebugger("PpapiBroker");
}
MessageLoop main_message_loop(MessageLoop::TYPE_DEFAULT);
base::PlatformThread::SetName("CrPPAPIBrokerMain");
ChildProcess ppapi_broker_process;
- //TODO:(ddorwin): Parameterize PpapiThread so the broker can reuse it.
- ppapi_broker_process.set_main_thread(new PpapiThread());
+ ppapi_broker_process.set_main_thread(new PpapiThread(true)); // Broker.
main_message_loop.Run();
return 0;
diff --git a/content/ppapi_plugin/ppapi_plugin_main.cc b/content/ppapi_plugin/ppapi_plugin_main.cc
index e18051a..655e18a 100644
--- a/content/ppapi_plugin/ppapi_plugin_main.cc
+++ b/content/ppapi_plugin/ppapi_plugin_main.cc
@@ -21,7 +21,7 @@ int PpapiPluginMain(const MainFunctionParams& parameters) {
base::PlatformThread::SetName("CrPPAPIMain");
ChildProcess ppapi_process;
- ppapi_process.set_main_thread(new PpapiThread());
+ ppapi_process.set_main_thread(new PpapiThread(false)); // Not a broker.
main_message_loop.Run();
return 0;
diff --git a/content/ppapi_plugin/ppapi_thread.cc b/content/ppapi_plugin/ppapi_thread.cc
index ecec2dd..cab4d93 100644
--- a/content/ppapi_plugin/ppapi_thread.cc
+++ b/content/ppapi_plugin/ppapi_thread.cc
@@ -16,21 +16,30 @@
#include "ppapi/c/ppp.h"
#include "ppapi/proxy/ppapi_messages.h"
-PpapiThread::PpapiThread()
- : get_plugin_interface_(NULL),
+typedef int32_t (*InitializeBrokerFunc)
+ (PP_ConnectInstance_Func* connect_instance_func);
+
+PpapiThread::PpapiThread(bool is_broker)
+ : is_broker_(is_broker),
+ get_plugin_interface_(NULL),
+ connect_instance_func_(NULL),
local_pp_module_(
base::RandInt(0, std::numeric_limits<PP_Module>::max())) {
}
PpapiThread::~PpapiThread() {
- if (library_.is_valid()) {
- // The ShutdownModule function is optional.
- pp::proxy::Dispatcher::ShutdownModuleFunc shutdown_module =
- reinterpret_cast<pp::proxy::Dispatcher::ShutdownModuleFunc>(
- library_.GetFunctionPointer("PPP_ShutdownModule"));
- if (shutdown_module)
- shutdown_module();
- }
+ if (!library_.is_valid())
+ return;
+
+ // The ShutdownModule/ShutdownBroker function is optional.
+ pp::proxy::Dispatcher::ShutdownModuleFunc shutdown_function =
+ is_broker_ ?
+ reinterpret_cast<pp::proxy::Dispatcher::ShutdownModuleFunc>(
+ library_.GetFunctionPointer("PPP_ShutdownBroker")) :
+ reinterpret_cast<pp::proxy::Dispatcher::ShutdownModuleFunc>(
+ library_.GetFunctionPointer("PPP_ShutdownModule"));
+ if (shutdown_function)
+ shutdown_function();
}
// The "regular" ChildThread implements this function and does some standard
@@ -65,29 +74,50 @@ void PpapiThread::OnMsgLoadPlugin(const FilePath& path) {
if (!library.is_valid())
return;
- // Get the GetInterface function (required).
- get_plugin_interface_ =
- reinterpret_cast<pp::proxy::Dispatcher::GetInterfaceFunc>(
- library.GetFunctionPointer("PPP_GetInterface"));
- if (!get_plugin_interface_) {
- LOG(WARNING) << "No PPP_GetInterface in plugin library";
- return;
- }
-
- // Get the InitializeModule function (required).
- pp::proxy::Dispatcher::InitModuleFunc init_module =
- reinterpret_cast<pp::proxy::Dispatcher::InitModuleFunc>(
- library.GetFunctionPointer("PPP_InitializeModule"));
- if (!init_module) {
- LOG(WARNING) << "No PPP_InitializeModule in plugin library";
- return;
- }
- int32_t init_error = init_module(
- local_pp_module_,
- &pp::proxy::PluginDispatcher::GetInterfaceFromDispatcher);
- if (init_error != PP_OK) {
- LOG(WARNING) << "InitModule failed with error " << init_error;
- return;
+ if (is_broker_) {
+ // Get the InitializeBroker function (required).
+ InitializeBrokerFunc init_broker =
+ reinterpret_cast<InitializeBrokerFunc>(
+ library.GetFunctionPointer("PPP_InitializeBroker"));
+ if (!init_broker) {
+ LOG(WARNING) << "No PPP_InitializeBroker in plugin library";
+ return;
+ }
+
+ int32_t init_error = init_broker(&connect_instance_func_);
+ if (init_error != PP_OK) {
+ LOG(WARNING) << "InitBroker failed with error " << init_error;
+ return;
+ }
+ if (!connect_instance_func_) {
+ LOG(WARNING) << "InitBroker did not provide PP_ConnectInstance_Func";
+ return;
+ }
+ } else {
+ // Get the GetInterface function (required).
+ get_plugin_interface_ =
+ reinterpret_cast<pp::proxy::Dispatcher::GetInterfaceFunc>(
+ library.GetFunctionPointer("PPP_GetInterface"));
+ if (!get_plugin_interface_) {
+ LOG(WARNING) << "No PPP_GetInterface in plugin library";
+ return;
+ }
+
+ // Get the InitializeModule function (required).
+ pp::proxy::Dispatcher::InitModuleFunc init_module =
+ reinterpret_cast<pp::proxy::Dispatcher::InitModuleFunc>(
+ library.GetFunctionPointer("PPP_InitializeModule"));
+ if (!init_module) {
+ LOG(WARNING) << "No PPP_InitializeModule in plugin library";
+ return;
+ }
+ int32_t init_error = init_module(
+ local_pp_module_,
+ &pp::proxy::PluginDispatcher::GetInterfaceFromDispatcher);
+ if (init_error != PP_OK) {
+ LOG(WARNING) << "InitModule failed with error " << init_error;
+ return;
+ }
}
library_.Reset(library.Release());
@@ -109,6 +139,11 @@ 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_));
@@ -131,4 +166,3 @@ bool PpapiThread::SetupRendererChannel(base::ProcessHandle host_process_handle,
// lifetime of the attached channel.
return true;
}
-
diff --git a/content/ppapi_plugin/ppapi_thread.h b/content/ppapi_plugin/ppapi_thread.h
index b1cd3bf..95cd7dc 100644
--- a/content/ppapi_plugin/ppapi_thread.h
+++ b/content/ppapi_plugin/ppapi_thread.h
@@ -14,6 +14,7 @@
#include "content/common/child_thread.h"
#include "ppapi/c/pp_module.h"
#include "ppapi/proxy/dispatcher.h"
+#include "ppapi/c/trusted/ppp_broker.h"
class FilePath;
@@ -30,7 +31,7 @@ class PluginDispatcher;
class PpapiThread : public ChildThread,
public pp::proxy::Dispatcher::Delegate {
public:
- PpapiThread();
+ explicit PpapiThread(bool is_broker);
~PpapiThread();
private:
@@ -53,10 +54,17 @@ class PpapiThread : public ChildThread,
int renderer_id,
IPC::ChannelHandle* handle);
+ // True if running in a broker process rather than a normal plugin process.
+ bool is_broker_;
+
base::ScopedNativeLibrary library_;
pp::proxy::Dispatcher::GetInterfaceFunc get_plugin_interface_;
+ // Callback to call when a new instance connects to the broker.
+ // Used only when is_broker_.
+ PP_ConnectInstance_Func connect_instance_func_;
+
// Local concept of the module ID. Some functions take this. It's necessary
// for the in-process PPAPI to handle this properly, but for proxied it's
// unnecessary. The proxy talking to multiple renderers means that each
@@ -68,7 +76,7 @@ class PpapiThread : public ChildThread,
// See Dispatcher::Delegate::GetGloballySeenInstanceIDSet.
std::set<PP_Instance> globally_seen_instance_ids_;
- DISALLOW_COPY_AND_ASSIGN(PpapiThread);
+ DISALLOW_IMPLICIT_CONSTRUCTORS(PpapiThread);
};
#endif // CONTENT_PPAPI_PLUGIN_PPAPI_THREAD_H_