Index: ppapi/proxy/resource_message_test_sink.cc |
diff --git a/ppapi/proxy/resource_message_test_sink.cc b/ppapi/proxy/resource_message_test_sink.cc |
index 7daf43570794a76cf9adab620d2b31082d49929a..a2920e3f122fc4c254e4abb593b58d2cbb520ea2 100644 |
--- a/ppapi/proxy/resource_message_test_sink.cc |
+++ b/ppapi/proxy/resource_message_test_sink.cc |
@@ -42,6 +42,30 @@ ResourceMessageTestSink::ResourceMessageTestSink() { |
ResourceMessageTestSink::~ResourceMessageTestSink() { |
} |
+bool ResourceMessageTestSink::Send(IPC::Message* msg) { |
+ int message_id = 0; |
+ scoped_ptr<IPC::MessageReplyDeserializer> reply_deserializer; |
+ if (msg->is_sync()) { |
+ reply_deserializer.reset( |
+ static_cast<IPC::SyncMessage*>(msg)->GetReplyDeserializer()); |
+ message_id = IPC::SyncMessage::GetMessageId(*msg); |
+ } |
+ bool result = IPC::TestSink::Send(msg); // Deletes |msg|. |
+ if (sync_reply_msg_.get()) { |
+ // |sync_reply_msg_| should always be a reply to the pending sync message. |
+ DCHECK(IPC::SyncMessage::IsMessageReplyTo(*sync_reply_msg_.get(), |
+ message_id)); |
+ reply_deserializer->SerializeOutputParameters(*sync_reply_msg_.get()); |
+ sync_reply_msg_.reset(NULL); |
+ } |
+ return result; |
+} |
+ |
+void ResourceMessageTestSink::SetSyncReplyMessage(IPC::Message* reply_msg) { |
+ DCHECK(!sync_reply_msg_.get()); |
+ sync_reply_msg_.reset(reply_msg); |
+} |
+ |
bool ResourceMessageTestSink::GetFirstResourceCallMatching( |
uint32 id, |
ResourceMessageCallParams* params, |
@@ -60,5 +84,43 @@ bool ResourceMessageTestSink::GetFirstResourceReplyMatching( |
*this, id, params, nested_msg); |
} |
+ResourceSyncCallHandler::ResourceSyncCallHandler( |
+ ResourceMessageTestSink* test_sink, |
+ uint32 incoming_type, |
+ int32_t result, |
+ const IPC::Message& reply_msg) |
+ : test_sink_(test_sink), |
+ incoming_type_(incoming_type), |
+ result_(result), |
+ reply_msg_(reply_msg) { |
+} |
+ |
+ResourceSyncCallHandler::~ResourceSyncCallHandler() { |
+} |
+ |
+bool ResourceSyncCallHandler::OnMessageReceived(const IPC::Message& msg) { |
+ if (msg.type() != PpapiHostMsg_ResourceSyncCall::ID) |
+ return false; |
+ PpapiHostMsg_ResourceSyncCall::Schema::SendParam send_params; |
+ bool success = PpapiHostMsg_ResourceSyncCall::ReadSendParam( |
+ &msg, &send_params); |
+ DCHECK(success); |
+ ResourceMessageCallParams call_params = send_params.a; |
+ IPC::Message call_msg = send_params.b; |
+ if (call_msg.type() != incoming_type_) |
+ return false; |
+ IPC::Message* wrapper_reply_msg = IPC::SyncMessage::GenerateReply(&msg); |
+ ResourceMessageReplyParams reply_params(call_params.pp_resource(), |
+ call_params.sequence()); |
+ reply_params.set_result(result_); |
+ PpapiHostMsg_ResourceSyncCall::WriteReplyParams( |
+ wrapper_reply_msg, reply_params, reply_msg_); |
+ test_sink_->SetSyncReplyMessage(wrapper_reply_msg); |
+ |
+ // Stash a copy of the message for inspection later. |
+ last_handled_msg_ = call_msg; |
+ return true; |
+} |
+ |
} // namespace proxy |
} // namespace ppapi |