Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: ppapi/proxy/resource_message_test_sink.cc

Issue 11039012: Implement plugin side of sync EnumerateVideoCaptureDevices (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/resource_message_test_sink.h ('k') | ppapi/shared_impl/resource.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/proxy/resource_message_test_sink.h" 5 #include "ppapi/proxy/resource_message_test_sink.h"
6 6
7 #include "ppapi/proxy/ppapi_messages.h" 7 #include "ppapi/proxy/ppapi_messages.h"
8 #include "ppapi/proxy/resource_message_params.h" 8 #include "ppapi/proxy/resource_message_params.h"
9 9
10 namespace ppapi { 10 namespace ppapi {
(...skipping 24 matching lines...) Expand all
35 } 35 }
36 36
37 } // namespace 37 } // namespace
38 38
39 ResourceMessageTestSink::ResourceMessageTestSink() { 39 ResourceMessageTestSink::ResourceMessageTestSink() {
40 } 40 }
41 41
42 ResourceMessageTestSink::~ResourceMessageTestSink() { 42 ResourceMessageTestSink::~ResourceMessageTestSink() {
43 } 43 }
44 44
45 bool ResourceMessageTestSink::Send(IPC::Message* msg) {
46 int message_id = 0;
47 scoped_ptr<IPC::MessageReplyDeserializer> reply_deserializer;
48 if (msg->is_sync()) {
49 reply_deserializer.reset(
50 static_cast<IPC::SyncMessage*>(msg)->GetReplyDeserializer());
51 message_id = IPC::SyncMessage::GetMessageId(*msg);
52 }
53 bool result = IPC::TestSink::Send(msg); // Deletes |msg|.
54 if (sync_reply_msg_.get()) {
55 // |sync_reply_msg_| should always be a reply to the pending sync message.
56 DCHECK(IPC::SyncMessage::IsMessageReplyTo(*sync_reply_msg_.get(),
57 message_id));
58 reply_deserializer->SerializeOutputParameters(*sync_reply_msg_.get());
59 sync_reply_msg_.reset(NULL);
60 }
61 return result;
62 }
63
64 void ResourceMessageTestSink::SetSyncReplyMessage(IPC::Message* reply_msg) {
65 DCHECK(!sync_reply_msg_.get());
66 sync_reply_msg_.reset(reply_msg);
67 }
68
45 bool ResourceMessageTestSink::GetFirstResourceCallMatching( 69 bool ResourceMessageTestSink::GetFirstResourceCallMatching(
46 uint32 id, 70 uint32 id,
47 ResourceMessageCallParams* params, 71 ResourceMessageCallParams* params,
48 IPC::Message* nested_msg) const { 72 IPC::Message* nested_msg) const {
49 return GetFirstResourceMessageMatching<PpapiHostMsg_ResourceCall, 73 return GetFirstResourceMessageMatching<PpapiHostMsg_ResourceCall,
50 ResourceMessageCallParams>( 74 ResourceMessageCallParams>(
51 *this, id, params, nested_msg); 75 *this, id, params, nested_msg);
52 } 76 }
53 77
54 bool ResourceMessageTestSink::GetFirstResourceReplyMatching( 78 bool ResourceMessageTestSink::GetFirstResourceReplyMatching(
55 uint32 id, 79 uint32 id,
56 ResourceMessageReplyParams* params, 80 ResourceMessageReplyParams* params,
57 IPC::Message* nested_msg) { 81 IPC::Message* nested_msg) {
58 return GetFirstResourceMessageMatching<PpapiPluginMsg_ResourceReply, 82 return GetFirstResourceMessageMatching<PpapiPluginMsg_ResourceReply,
59 ResourceMessageReplyParams>( 83 ResourceMessageReplyParams>(
60 *this, id, params, nested_msg); 84 *this, id, params, nested_msg);
61 } 85 }
62 86
87 ResourceSyncCallHandler::ResourceSyncCallHandler(
88 ResourceMessageTestSink* test_sink,
89 uint32 incoming_type,
90 int32_t result,
91 const IPC::Message& reply_msg)
92 : test_sink_(test_sink),
93 incoming_type_(incoming_type),
94 result_(result),
95 reply_msg_(reply_msg) {
96 }
97
98 ResourceSyncCallHandler::~ResourceSyncCallHandler() {
99 }
100
101 bool ResourceSyncCallHandler::OnMessageReceived(const IPC::Message& msg) {
102 if (msg.type() != PpapiHostMsg_ResourceSyncCall::ID)
103 return false;
104 PpapiHostMsg_ResourceSyncCall::Schema::SendParam send_params;
105 bool success = PpapiHostMsg_ResourceSyncCall::ReadSendParam(
106 &msg, &send_params);
107 DCHECK(success);
108 ResourceMessageCallParams call_params = send_params.a;
109 IPC::Message call_msg = send_params.b;
110 if (call_msg.type() != incoming_type_)
111 return false;
112 IPC::Message* wrapper_reply_msg = IPC::SyncMessage::GenerateReply(&msg);
113 ResourceMessageReplyParams reply_params(call_params.pp_resource(),
114 call_params.sequence());
115 reply_params.set_result(result_);
116 PpapiHostMsg_ResourceSyncCall::WriteReplyParams(
117 wrapper_reply_msg, reply_params, reply_msg_);
118 test_sink_->SetSyncReplyMessage(wrapper_reply_msg);
119
120 // Stash a copy of the message for inspection later.
121 last_handled_msg_ = call_msg;
122 return true;
123 }
124
63 } // namespace proxy 125 } // namespace proxy
64 } // namespace ppapi 126 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/resource_message_test_sink.h ('k') | ppapi/shared_impl/resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698