summaryrefslogtreecommitdiffstats
path: root/ppapi/host
diff options
context:
space:
mode:
authorraymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-03 00:52:16 +0000
committerraymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-03 00:52:16 +0000
commitff44fc1d2a21260fc141fcea0f4196dd1af18848 (patch)
tree4c4c26b6c1391777babbca7a237483a445b67fe9 /ppapi/host
parentec2269074716dd93a815b11d73952807cbe75f27 (diff)
downloadchromium_src-ff44fc1d2a21260fc141fcea0f4196dd1af18848.zip
chromium_src-ff44fc1d2a21260fc141fcea0f4196dd1af18848.tar.gz
chromium_src-ff44fc1d2a21260fc141fcea0f4196dd1af18848.tar.bz2
Added sync calls to resources.
The resource (on the plugin side) provides an outgoing and a reply IPC message and the reply message will be set up synchronously. The nice thing about this change is that when writing new ResourceHosts, there is no difference between handling a sync message and a non-sync message. So, for example, you could have a single implementation of some function on the host side and the plugin could choose to call that implementation both synchronously and asynchronously. For example, for the function GetDefaultPrintSettings(), the plugin could call both: CallBrowser(PpapiHostMsg_Printing_GetDefaultPrintSettings()); AND CallBrowserSync(PpapiHostMsg_Printing_GetDefaultPrintSettings(), &reply); with only a single implementation of GetDefaultPrintSettings on the host side. This change also supports both synchronously and asynchronous handling sync messages on the host side (through IPC_MESSAGE_HANDLER_DELAY_REPLY). BUG=none Review URL: https://chromiumcodereview.appspot.com/10989042 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@159820 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/host')
-rw-r--r--ppapi/host/host_message_context.cc31
-rw-r--r--ppapi/host/host_message_context.h32
-rw-r--r--ppapi/host/ppapi_host.cc52
-rw-r--r--ppapi/host/ppapi_host.h13
4 files changed, 107 insertions, 21 deletions
diff --git a/ppapi/host/host_message_context.cc b/ppapi/host/host_message_context.cc
index ed785bc..c6e74cb 100644
--- a/ppapi/host/host_message_context.cc
+++ b/ppapi/host/host_message_context.cc
@@ -7,18 +7,39 @@
namespace ppapi {
namespace host {
+ReplyMessageContext::ReplyMessageContext() {
+}
+
+ReplyMessageContext::ReplyMessageContext(
+ const ppapi::proxy::ResourceMessageReplyParams& cp,
+ IPC::Message* sync_reply_msg)
+ : params(cp),
+ sync_reply_msg(sync_reply_msg) {
+}
+
+ReplyMessageContext::~ReplyMessageContext() {
+}
+
HostMessageContext::HostMessageContext(
const ppapi::proxy::ResourceMessageCallParams& cp)
- : params(cp) {
+ : params(cp),
+ sync_reply_msg(NULL) {
+}
+
+HostMessageContext::HostMessageContext(
+ const ppapi::proxy::ResourceMessageCallParams& cp,
+ IPC::Message* reply_msg)
+ : params(cp),
+ sync_reply_msg(reply_msg) {
}
HostMessageContext::~HostMessageContext() {
}
-ppapi::proxy::ResourceMessageReplyParams
-HostMessageContext::MakeReplyParams() const {
- return ppapi::proxy::ResourceMessageReplyParams(params.pp_resource(),
- params.sequence());
+ReplyMessageContext HostMessageContext::MakeReplyMessageContext() const {
+ ppapi::proxy::ResourceMessageReplyParams reply_params(params.pp_resource(),
+ params.sequence());
+ return ReplyMessageContext(reply_params, sync_reply_msg);
}
} // namespace host
diff --git a/ppapi/host/host_message_context.h b/ppapi/host/host_message_context.h
index d0958ab..c9b3b3c 100644
--- a/ppapi/host/host_message_context.h
+++ b/ppapi/host/host_message_context.h
@@ -12,16 +12,38 @@
namespace ppapi {
namespace host {
+// This context structure provides information about outgoing resource message
+// replies.
+struct PPAPI_HOST_EXPORT ReplyMessageContext {
+ ReplyMessageContext();
+ ReplyMessageContext(
+ const ppapi::proxy::ResourceMessageReplyParams& cp,
+ IPC::Message* sync_reply_msg);
+ ~ReplyMessageContext();
+
+ // The "reply params" struct with the same resource and sequence number
+ // as the original resource message call.
+ ppapi::proxy::ResourceMessageReplyParams params;
+
+ // If this context is generated from a sync message, this will be set to the
+ // incoming sync message. Otherwise, it will be NULL. The plugin controls
+ // whether or not the resource call is synchronous or asynchronous so a
+ // ResoureHost cannot make any assumptions about whether or not this is NULL.
+ IPC::Message* sync_reply_msg;
+};
+
// This context structure provides information about incoming resource message
// call requests when passed to resources.
struct PPAPI_HOST_EXPORT HostMessageContext {
explicit HostMessageContext(
const ppapi::proxy::ResourceMessageCallParams& cp);
+ HostMessageContext(
+ const ppapi::proxy::ResourceMessageCallParams& cp,
+ IPC::Message* sync_reply_msg);
~HostMessageContext();
- // Returns a "reply params" struct with the same resource and sequence number
- // as this request.
- ppapi::proxy::ResourceMessageReplyParams MakeReplyParams() const;
+ // Returns a reply message context struct which includes the reply params.
+ ReplyMessageContext MakeReplyMessageContext() const;
// The original call parameters passed to the resource message call.
const ppapi::proxy::ResourceMessageCallParams& params;
@@ -31,6 +53,10 @@ struct PPAPI_HOST_EXPORT HostMessageContext {
// handler wants to send something else, it should just assign the message
// it wants to this value.
IPC::Message reply_msg;
+
+ // If this context is generated from a sync message, this will be set to the
+ // incoming sync message. Otherwise, it will be NULL.
+ IPC::Message* sync_reply_msg;
};
} // namespace host
diff --git a/ppapi/host/ppapi_host.cc b/ppapi/host/ppapi_host.cc
index 0ec37b6..f13cea0 100644
--- a/ppapi/host/ppapi_host.cc
+++ b/ppapi/host/ppapi_host.cc
@@ -47,6 +47,8 @@ bool PpapiHost::OnMessageReceived(const IPC::Message& msg) {
IPC_BEGIN_MESSAGE_MAP(PpapiHost, msg)
IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCall,
OnHostMsgResourceCall)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiHostMsg_ResourceSyncCall,
+ OnHostMsgResourceSyncCall)
IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCreated,
OnHostMsgResourceCreated)
IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceDestroyed,
@@ -66,9 +68,15 @@ bool PpapiHost::OnMessageReceived(const IPC::Message& msg) {
return handled;
}
-void PpapiHost::SendReply(const proxy::ResourceMessageReplyParams& params,
+void PpapiHost::SendReply(const ReplyMessageContext& context,
const IPC::Message& msg) {
- Send(new PpapiPluginMsg_ResourceReply(params, msg));
+ if (context.sync_reply_msg) {
+ PpapiHostMsg_ResourceSyncCall::WriteReplyParams(context.sync_reply_msg,
+ context.params, msg);
+ Send(context.sync_reply_msg);
+ } else {
+ Send(new PpapiPluginMsg_ResourceReply(context.params, msg));
+ }
}
void PpapiHost::AddHostFactoryFilter(scoped_ptr<HostFactory> filter) {
@@ -84,35 +92,55 @@ void PpapiHost::OnHostMsgResourceCall(
const proxy::ResourceMessageCallParams& params,
const IPC::Message& nested_msg) {
HostMessageContext context(params);
- proxy::ResourceMessageReplyParams reply_params(params.pp_resource(),
- params.sequence());
+ HandleResourceCall(params, nested_msg, &context);
+}
+
+void PpapiHost::OnHostMsgResourceSyncCall(
+ const proxy::ResourceMessageCallParams& params,
+ const IPC::Message& nested_msg,
+ IPC::Message* reply_msg) {
+ // Sync messages should always have callback set because they always expect
+ // a reply from the host.
+ DCHECK(params.has_callback());
+ // Stash the |reply_msg| in the context so that it can be used to reply
+ // to the sync message.
+ HostMessageContext context(params, reply_msg);
+ HandleResourceCall(params, nested_msg, &context);
+}
+
+void PpapiHost::HandleResourceCall(
+ const proxy::ResourceMessageCallParams& params,
+ const IPC::Message& nested_msg,
+ HostMessageContext* context) {
+ ReplyMessageContext reply_context = context->MakeReplyMessageContext();
ResourceHost* resource_host = GetResourceHost(params.pp_resource());
if (resource_host) {
- reply_params.set_result(resource_host->OnResourceMessageReceived(
- nested_msg, &context));
+ reply_context.params.set_result(
+ resource_host->OnResourceMessageReceived(nested_msg, context));
// Sanity check the resource handler. Note if the result was
// "completion pending" the resource host may have already sent the reply.
- if (reply_params.result() == PP_OK_COMPLETIONPENDING) {
+ if (reply_context.params.result() == PP_OK_COMPLETIONPENDING) {
// Message handler should have only returned a pending result if a
// response will be sent to the plugin.
DCHECK(params.has_callback());
// Message handler should not have written a message to be returned if
// completion is pending.
- DCHECK(context.reply_msg.type() == 0);
+ DCHECK(context->reply_msg.type() == 0);
} else if (!params.has_callback()) {
// When no response is required, the message handler should not have
// written a message to be returned.
- DCHECK(context.reply_msg.type() == 0);
+ DCHECK(context->reply_msg.type() == 0);
}
} else {
- reply_params.set_result(PP_ERROR_BADRESOURCE);
+ reply_context.params.set_result(PP_ERROR_BADRESOURCE);
}
- if (params.has_callback() && reply_params.result() != PP_OK_COMPLETIONPENDING)
- SendReply(reply_params, context.reply_msg);
+ if (params.has_callback() &&
+ reply_context.params.result() != PP_OK_COMPLETIONPENDING)
+ SendReply(reply_context, context->reply_msg);
}
void PpapiHost::OnHostMsgResourceCreated(
diff --git a/ppapi/host/ppapi_host.h b/ppapi/host/ppapi_host.h
index 748d47a..79731e6 100644
--- a/ppapi/host/ppapi_host.h
+++ b/ppapi/host/ppapi_host.h
@@ -29,7 +29,9 @@ class ResourceMessageReplyParams;
namespace host {
class HostFactory;
+struct HostMessageContext;
class InstanceMessageFilter;
+struct ReplyMessageContext;
class ResourceHost;
// The host provides routing and tracking for resource message calls that
@@ -53,7 +55,7 @@ class PPAPI_HOST_EXPORT PpapiHost : public IPC::Sender, public IPC::Listener {
virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
// Sends the given reply message to the plugin.
- void SendReply(const proxy::ResourceMessageReplyParams& params,
+ void SendReply(const ReplyMessageContext& context,
const IPC::Message& msg);
// Adds the given host factory filter to the host. The PpapiHost will take
@@ -67,9 +69,18 @@ class PPAPI_HOST_EXPORT PpapiHost : public IPC::Sender, public IPC::Listener {
private:
friend class InstanceMessageFilter;
+ void HandleResourceCall(
+ const proxy::ResourceMessageCallParams& params,
+ const IPC::Message& nested_msg,
+ HostMessageContext* context);
+
// Message handlers.
void OnHostMsgResourceCall(const proxy::ResourceMessageCallParams& params,
const IPC::Message& nested_msg);
+ void OnHostMsgResourceSyncCall(
+ const proxy::ResourceMessageCallParams& params,
+ const IPC::Message& nested_msg,
+ IPC::Message* reply_msg);
void OnHostMsgResourceCreated(const proxy::ResourceMessageCallParams& param,
PP_Instance instance,
const IPC::Message& nested_msg);