Skip to content

Commit

Permalink
Modify Pepper CreateResourceHostFromHost to create multiple hosts.
Browse files Browse the repository at this point in the history
This alters CreateResourceHostFromHost so that multiple resource hosts can be
created with a single IPC. The general case is for many resources to be
created at the same time. For example, you may pass an array of file refs
across IPC.

BUG=177017
TBR=teravest@chromium.org, tsepez@chromium.org

Review URL: https://codereview.chromium.org/23011018

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@218884 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
raymes@google.com committed Aug 22, 2013
1 parent a524a40 commit 6790107
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 79 deletions.
55 changes: 29 additions & 26 deletions content/browser/renderer_host/pepper/pepper_renderer_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ bool PepperRendererConnection::OnMessageReceived(const IPC::Message& msg,

bool handled = true;
IPC_BEGIN_MESSAGE_MAP_EX(PepperRendererConnection, msg, *message_was_ok)
IPC_MESSAGE_HANDLER(PpapiHostMsg_CreateResourceHostFromHost,
OnMsgCreateResourceHostFromHost)
IPC_MESSAGE_HANDLER(PpapiHostMsg_CreateResourceHostsFromHost,
OnMsgCreateResourceHostsFromHost)
IPC_MESSAGE_HANDLER(PpapiHostMsg_FileRef_GetInfoForRenderer,
OnMsgFileRefGetInfoForRenderer)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidCreateInProcessInstance,
Expand All @@ -86,45 +86,48 @@ bool PepperRendererConnection::OnMessageReceived(const IPC::Message& msg,
return handled;
}

void PepperRendererConnection::OnMsgCreateResourceHostFromHost(
void PepperRendererConnection::OnMsgCreateResourceHostsFromHost(
int routing_id,
int child_process_id,
const ppapi::proxy::ResourceMessageCallParams& params,
PP_Instance instance,
const IPC::Message& nested_msg) {
const std::vector<IPC::Message>& nested_msgs) {
BrowserPpapiHostImpl* host = GetHostForChildProcess(child_process_id);

int pending_resource_host_id;
std::vector<int> pending_resource_host_ids(nested_msgs.size(), 0);
if (!host) {
DLOG(ERROR) << "Invalid plugin process ID.";
pending_resource_host_id = 0;
} else {
// FileRef_CreateExternal is only permitted from the renderer. Because of
// this, we handle this message here and not in
// content_browser_pepper_host_factory.cc.
scoped_ptr<ppapi::host::ResourceHost> resource_host;
if (host->IsValidInstance(instance)) {
if (nested_msg.type() == PpapiHostMsg_FileRef_CreateExternal::ID) {
base::FilePath external_path;
if (ppapi::UnpackMessage<PpapiHostMsg_FileRef_CreateExternal>(
nested_msg, &external_path)) {
resource_host.reset(new PepperFileRefHost(
host, instance, params.pp_resource(), external_path));
for (size_t i = 0; i < nested_msgs.size(); ++i) {
// FileRef_CreateExternal is only permitted from the renderer. Because of
// this, we handle this message here and not in
// content_browser_pepper_host_factory.cc.
scoped_ptr<ppapi::host::ResourceHost> resource_host;
if (host->IsValidInstance(instance)) {
if (nested_msgs[i].type() == PpapiHostMsg_FileRef_CreateExternal::ID) {
base::FilePath external_path;
if (ppapi::UnpackMessage<PpapiHostMsg_FileRef_CreateExternal>(
nested_msgs[i], &external_path)) {
resource_host.reset(new PepperFileRefHost(
host, instance, params.pp_resource(), external_path));
}
}
}
}

if (!resource_host.get()) {
resource_host = host->GetPpapiHost()->CreateResourceHost(params,
instance,
nested_msg);
if (!resource_host.get()) {
resource_host = host->GetPpapiHost()->CreateResourceHost(
params, instance, nested_msgs[i]);
}

if (resource_host.get()) {
pending_resource_host_ids[i] =
host->GetPpapiHost()->AddPendingResourceHost(resource_host.Pass());
}
}
pending_resource_host_id =
host->GetPpapiHost()->AddPendingResourceHost(resource_host.Pass());
}

Send(new PpapiHostMsg_CreateResourceHostFromHostReply(
routing_id, params.sequence(), pending_resource_host_id));
Send(new PpapiHostMsg_CreateResourceHostsFromHostReply(
routing_id, params.sequence(), pending_resource_host_ids));
}

void PepperRendererConnection::OnMsgFileRefGetInfoForRenderer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_RENDERER_CONNECTION_H_
#define CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_RENDERER_CONNECTION_H_

#include <vector>

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
Expand Down Expand Up @@ -45,12 +47,12 @@ class PepperRendererConnection : public BrowserMessageFilter {
// PepperRendererConnection, which serves as the host for in-process plugins.
BrowserPpapiHostImpl* GetHostForChildProcess(int child_process_id) const;

void OnMsgCreateResourceHostFromHost(
void OnMsgCreateResourceHostsFromHost(
int routing_id,
int child_process_id,
const ppapi::proxy::ResourceMessageCallParams& params,
PP_Instance instance,
const IPC::Message& nested_msg);
const std::vector<IPC::Message>& nested_msgs);

void OnMsgFileRefGetInfoForRenderer(
int routing_id,
Expand Down
18 changes: 10 additions & 8 deletions content/public/renderer/renderer_ppapi_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef CONTENT_PUBLIC_RENDERER_RENDERER_PPAPI_HOST_H_
#define CONTENT_PUBLIC_RENDERER_RENDERER_PPAPI_HOST_H_

#include <vector>

#include "base/callback_forward.h"
#include "base/memory/ref_counted.h"
#include "base/platform_file.h"
Expand Down Expand Up @@ -110,16 +112,16 @@ class RendererPpapiHost {
virtual bool IsRunningInProcess() const = 0;

// There are times when the renderer needs to create a ResourceHost in the
// browser. This function does so asynchronously. |nested_msg| is the
// resource host creation message and |instance| is the PP_Instance which
// browser. This function does so asynchronously. |nested_msgs| is a list of
// resource host creation messages and |instance| is the PP_Instance which
// the resource will belong to. |callback| will be called with the pending
// host ID when the ResourceHost has been created. This can be passed back
// to the plugin to attach to the ResourceHost. A pending ID of 0 will be
// passed to the callback upon error.
virtual void CreateBrowserResourceHost(
// host IDs when the ResourceHosts have been created. This can be passed back
// to the plugin to attach to the ResourceHosts. Pending IDs of 0 will be
// passed to the callback if a ResourceHost fails to be created.
virtual void CreateBrowserResourceHosts(
PP_Instance instance,
const IPC::Message& nested_msg,
const base::Callback<void(int)>& callback) const = 0;
const std::vector<IPC::Message>& nested_msgs,
const base::Callback<void(const std::vector<int>&)>& callback) const = 0;

protected:
virtual ~RendererPpapiHost() {}
Expand Down
8 changes: 4 additions & 4 deletions content/renderer/pepper/mock_renderer_ppapi_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ bool MockRendererPpapiHost::IsRunningInProcess() const {
return false;
}

void MockRendererPpapiHost::CreateBrowserResourceHost(
void MockRendererPpapiHost::CreateBrowserResourceHosts(
PP_Instance instance,
const IPC::Message& nested_msg,
const base::Callback<void(int)>& callback) const {
const std::vector<IPC::Message>& nested_msg,
const base::Callback<void(const std::vector<int>&)>& callback) const {
NOTIMPLEMENTED();
callback.Run(0);
callback.Run(std::vector<int>());
return;
}

Expand Down
7 changes: 4 additions & 3 deletions content/renderer/pepper/mock_renderer_ppapi_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ class MockRendererPpapiHost : public RendererPpapiHost {
base::PlatformFile handle,
bool should_close_source) OVERRIDE;
virtual bool IsRunningInProcess() const OVERRIDE;
virtual void CreateBrowserResourceHost(
virtual void CreateBrowserResourceHosts(
PP_Instance instance,
const IPC::Message& nested_msg,
const base::Callback<void(int)>& callback) const OVERRIDE;
const std::vector<IPC::Message>& nested_msgs,
const base::Callback<void(
const std::vector<int>&)>& callback) const OVERRIDE;

private:
ppapi::proxy::ResourceMessageTestSink sink_;
Expand Down
22 changes: 11 additions & 11 deletions content/renderer/pepper/pepper_browser_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ bool PepperBrowserConnection::OnMessageReceived(const IPC::Message& msg) {

bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PepperBrowserConnection, msg)
IPC_MESSAGE_HANDLER(PpapiHostMsg_CreateResourceHostFromHostReply,
OnMsgCreateResourceHostFromHostReply)
IPC_MESSAGE_HANDLER(PpapiHostMsg_CreateResourceHostsFromHostReply,
OnMsgCreateResourceHostsFromHostReply)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()

Expand All @@ -49,9 +49,9 @@ void PepperBrowserConnection::DidCreateInProcessInstance(
instance,
// Browser provides the render process id.
PepperRendererInstanceData(0,
render_view_id,
document_url,
plugin_url)));
render_view_id,
document_url,
plugin_url)));
}

void PepperBrowserConnection::DidDeleteInProcessInstance(PP_Instance instance) {
Expand All @@ -61,17 +61,17 @@ void PepperBrowserConnection::DidDeleteInProcessInstance(PP_Instance instance) {
void PepperBrowserConnection::SendBrowserCreate(
int child_process_id,
PP_Instance instance,
const IPC::Message& nested_msg,
const std::vector<IPC::Message>& nested_msgs,
const PendingResourceIDCallback& callback) {
int32_t sequence_number = GetNextSequence();
pending_create_map_[sequence_number] = callback;
ppapi::proxy::ResourceMessageCallParams params(0, sequence_number);
Send(new PpapiHostMsg_CreateResourceHostFromHost(
Send(new PpapiHostMsg_CreateResourceHostsFromHost(
routing_id(),
child_process_id,
params,
instance,
nested_msg));
nested_msgs));
}

void PepperBrowserConnection::SendBrowserFileRefGetInfo(
Expand All @@ -84,15 +84,15 @@ void PepperBrowserConnection::SendBrowserFileRefGetInfo(
routing_id(), child_process_id, sequence_number, resources));
}

void PepperBrowserConnection::OnMsgCreateResourceHostFromHostReply(
void PepperBrowserConnection::OnMsgCreateResourceHostsFromHostReply(
int32_t sequence_number,
int pending_resource_host_id) {
const std::vector<int>& pending_resource_host_ids) {
// Check that the message is destined for the plugin this object is associated
// with.
std::map<int32_t, PendingResourceIDCallback>::iterator it =
pending_create_map_.find(sequence_number);
if (it != pending_create_map_.end()) {
it->second.Run(pending_resource_host_id);
it->second.Run(pending_resource_host_ids);
pending_create_map_.erase(it);
} else {
NOTREACHED();
Expand Down
15 changes: 9 additions & 6 deletions content/renderer/pepper/pepper_browser_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <map>
#include <string>
#include <vector>

#include "base/callback.h"
#include "base/files/file_path.h"
Expand All @@ -26,7 +27,8 @@ class PepperBrowserConnection
: public RenderViewObserver,
public RenderViewObserverTracker<PepperBrowserConnection> {
public:
typedef base::Callback<void(int)> PendingResourceIDCallback;
typedef base::Callback<void(const std::vector<int>&)>
PendingResourceIDCallback;
typedef base::Callback<void(
const std::vector<PP_Resource>&,
const std::vector<PP_FileSystemType>&,
Expand All @@ -41,12 +43,12 @@ class PepperBrowserConnection
// TODO(teravest): Instead of having separate methods per message, we should
// add generic functionality similar to PluginResource::Call().

// Sends a request to the browser to create a ResourceHost for the given
// Sends a request to the browser to create ResourceHosts for the given
// |instance| of a plugin identified by |child_process_id|. |callback| will be
// run when a reply is received with the pending resource ID.
// run when a reply is received with the pending resource IDs.
void SendBrowserCreate(PP_Instance instance,
int child_process_id,
const IPC::Message& create_message,
const std::vector<IPC::Message>& create_messages,
const PendingResourceIDCallback& callback);

// Sends a request to the browser to get information about the given FileRef
Expand All @@ -67,8 +69,9 @@ class PepperBrowserConnection

private:
// Message handlers.
void OnMsgCreateResourceHostFromHostReply(int32_t sequence_number,
int pending_resource_host_id);
void OnMsgCreateResourceHostsFromHostReply(
int32_t sequence_number,
const std::vector<int>& pending_resource_host_ids);
void OnMsgFileRefGetInfoReply(
int32_t sequence_number,
const std::vector<PP_Resource>& resources,
Expand Down
10 changes: 5 additions & 5 deletions content/renderer/pepper/renderer_ppapi_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,19 @@ bool RendererPpapiHostImpl::IsRunningInProcess() const {
return is_running_in_process_;
}

void RendererPpapiHostImpl::CreateBrowserResourceHost(
void RendererPpapiHostImpl::CreateBrowserResourceHosts(
PP_Instance instance,
const IPC::Message& nested_msg,
const base::Callback<void(int)>& callback) const {
const std::vector<IPC::Message>& nested_msgs,
const base::Callback<void(const std::vector<int>&)>& callback) const {
RenderView* render_view = GetRenderViewForInstance(instance);
PepperBrowserConnection* browser_connection =
PepperBrowserConnection::Get(render_view);
if (!browser_connection) {
callback.Run(0);
callback.Run(std::vector<int>(nested_msgs.size(), 0));
} else {
browser_connection->SendBrowserCreate(module_->GetPluginChildId(),
instance,
nested_msg,
nested_msgs,
callback);
}
}
Expand Down
7 changes: 4 additions & 3 deletions content/renderer/pepper/renderer_ppapi_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ class RendererPpapiHostImpl : public RendererPpapiHost {
base::PlatformFile handle,
bool should_close_source) OVERRIDE;
virtual bool IsRunningInProcess() const OVERRIDE;
virtual void CreateBrowserResourceHost(
virtual void CreateBrowserResourceHosts(
PP_Instance instance,
const IPC::Message& nested_msg,
const base::Callback<void(int)>& callback) const OVERRIDE;
const std::vector<IPC::Message>& nested_msgs,
const base::Callback<void(
const std::vector<int>&)>& callback) const OVERRIDE;

private:
RendererPpapiHostImpl(PluginModule* module,
Expand Down
22 changes: 11 additions & 11 deletions ppapi/proxy/ppapi_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -1275,27 +1275,27 @@ IPC_SYNC_MESSAGE_CONTROL2_2(PpapiHostMsg_ResourceSyncCall,
IPC::Message /* reply_msg */)

// This message is sent from the renderer to the browser when it wants to create
// a ResourceHost in the browser. It contains the process ID of the plugin and
// ResourceHosts in the browser. It contains the process ID of the plugin and
// the instance of the plugin for which to create the resource for. params
// contains the sequence number for the message to track the response.
// The nested message is a ResourceHost creation message.
// The nested messages are ResourceHost creation messages.
IPC_MESSAGE_CONTROL5(
PpapiHostMsg_CreateResourceHostFromHost,
PpapiHostMsg_CreateResourceHostsFromHost,
int /* routing_id */,
int /* child_process_id */,
ppapi::proxy::ResourceMessageCallParams /* params */,
PP_Instance /* instance */,
IPC::Message /* nested_msg */)
std::vector<IPC::Message> /* nested_msgs */)

// This message is sent from the browser to the renderer when it has created a
// ResourceHost for the renderer. It contains the sequence number that was sent
// in the request and the ID of the pending ResourceHost which was created in
// the browser. This ID is only useful for the plugin which can attach to the
// ResourceHost in the browser.
// This message is sent from the browser to the renderer when it has created
// ResourceHosts for the renderer. It contains the sequence number that was sent
// in the request and the IDs of the pending ResourceHosts which were created in
// the browser. These IDs are only useful for the plugin which can attach to the
// ResourceHosts in the browser.
IPC_MESSAGE_ROUTED2(
PpapiHostMsg_CreateResourceHostFromHostReply,
PpapiHostMsg_CreateResourceHostsFromHostReply,
int32_t /* sequence */,
int /* pending_host_id */)
std::vector<int> /* pending_host_ids */)

//-----------------------------------------------------------------------------
// Messages for resources using call/reply above.
Expand Down

0 comments on commit 6790107

Please sign in to comment.