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

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

Issue 127243002: Pepper: Change ResourceMessageTestSink API for getting multiple messages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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
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 #include "ppapi/proxy/serialized_handle.h" 9 #include "ppapi/proxy/serialized_handle.h"
10 10
11 namespace ppapi { 11 namespace ppapi {
12 namespace proxy { 12 namespace proxy {
13 13
14 namespace { 14 namespace {
15 15
16 // Backend for GetFirstResource[Call|Reply]Matching. 16 // Backend for GetFirstResource[Call|Reply]Matching.
17 template<class WrapperMessage, class Params> 17 template<class WrapperMessage, class Params>
18 int GetNextResourceMessageMatching(const ResourceMessageTestSink& sink, 18 bool GetFirstResourceMessageMatching(const ResourceMessageTestSink& sink,
19 uint32 id, 19 uint32 id,
20 int start_index, 20 Params* params,
21 Params* params, 21 IPC::Message* nested_msg) {
22 IPC::Message* nested_msg) { 22 for (size_t i = 0; i < sink.message_count(); i++) {
23 if (start_index < 0)
24 return -1;
25 int message_count = static_cast<int>(sink.message_count());
26 for (int i = start_index; i < message_count; i++) {
27 const IPC::Message* msg = sink.GetMessageAt(i); 23 const IPC::Message* msg = sink.GetMessageAt(i);
28 if (msg->type() == WrapperMessage::ID) { 24 if (msg->type() == WrapperMessage::ID) {
29 Params cur_params; 25 Params cur_params;
30 IPC::Message cur_msg; 26 IPC::Message cur_msg;
31 WrapperMessage::Read(msg, &cur_params, &cur_msg); 27 WrapperMessage::Read(msg, &cur_params, &cur_msg);
32 if (cur_msg.type() == id) { 28 if (cur_msg.type() == id) {
33 *params = cur_params; 29 *params = cur_params;
34 *nested_msg = cur_msg; 30 *nested_msg = cur_msg;
35 return i; 31 return true;
36 } 32 }
37 } 33 }
38 } 34 }
39 return -1; 35 return false;
36 }
37
38 // Backend for GetAllResource[Calls|Replies]Matching.
39 template<class WrapperMessage, class Params>
40 std::vector<std::pair<Params, IPC::Message> >
41 GetAllResourceMessagesMatching(const ResourceMessageTestSink& sink,
42 uint32 id) {
43 std::vector<std::pair<Params, IPC::Message> > result;
44 for (size_t i = 0; i < sink.message_count(); i++) {
45 const IPC::Message* msg = sink.GetMessageAt(i);
46 if (msg->type() == WrapperMessage::ID) {
47 Params cur_params;
48 IPC::Message cur_msg;
49 WrapperMessage::Read(msg, &cur_params, &cur_msg);
50 if (cur_msg.type() == id) {
51 result.push_back(std::make_pair(cur_params, cur_msg));
52 }
53 }
54 }
55 return result;
40 } 56 }
41 57
42 } // namespace 58 } // namespace
43 59
44 ResourceMessageTestSink::ResourceMessageTestSink() 60 ResourceMessageTestSink::ResourceMessageTestSink() {
45 : next_resource_call_(0),
46 next_resource_reply_(0) {
47 } 61 }
48 62
49 ResourceMessageTestSink::~ResourceMessageTestSink() { 63 ResourceMessageTestSink::~ResourceMessageTestSink() {
50 } 64 }
51 65
52 bool ResourceMessageTestSink::Send(IPC::Message* msg) { 66 bool ResourceMessageTestSink::Send(IPC::Message* msg) {
53 int message_id = 0; 67 int message_id = 0;
54 scoped_ptr<IPC::MessageReplyDeserializer> reply_deserializer; 68 scoped_ptr<IPC::MessageReplyDeserializer> reply_deserializer;
55 if (msg->is_sync()) { 69 if (msg->is_sync()) {
56 reply_deserializer.reset( 70 reply_deserializer.reset(
(...skipping 13 matching lines...) Expand all
70 84
71 void ResourceMessageTestSink::SetSyncReplyMessage(IPC::Message* reply_msg) { 85 void ResourceMessageTestSink::SetSyncReplyMessage(IPC::Message* reply_msg) {
72 DCHECK(!sync_reply_msg_.get()); 86 DCHECK(!sync_reply_msg_.get());
73 sync_reply_msg_.reset(reply_msg); 87 sync_reply_msg_.reset(reply_msg);
74 } 88 }
75 89
76 bool ResourceMessageTestSink::GetFirstResourceCallMatching( 90 bool ResourceMessageTestSink::GetFirstResourceCallMatching(
77 uint32 id, 91 uint32 id,
78 ResourceMessageCallParams* params, 92 ResourceMessageCallParams* params,
79 IPC::Message* nested_msg) const { 93 IPC::Message* nested_msg) const {
80 int index = GetNextResourceMessageMatching<PpapiHostMsg_ResourceCall, 94 return GetFirstResourceMessageMatching<PpapiHostMsg_ResourceCall,
81 ResourceMessageCallParams>( 95 ResourceMessageCallParams>(
82 *this, id, 0 /* start_index */, params, nested_msg); 96 *this, id, params, nested_msg);
83 return index >= 0;
84 } 97 }
85 98
86 bool ResourceMessageTestSink::GetFirstResourceReplyMatching( 99 bool ResourceMessageTestSink::GetFirstResourceReplyMatching(
87 uint32 id, 100 uint32 id,
88 ResourceMessageReplyParams* params, 101 ResourceMessageReplyParams* params,
89 IPC::Message* nested_msg) { 102 IPC::Message* nested_msg) {
90 int index = GetNextResourceMessageMatching<PpapiPluginMsg_ResourceReply, 103 return GetFirstResourceMessageMatching<PpapiPluginMsg_ResourceReply,
91 ResourceMessageReplyParams>( 104 ResourceMessageReplyParams>(
92 *this, id, 0 /* start_index */, params, nested_msg); 105 *this, id, params, nested_msg);
93 return index >= 0;
94 } 106 }
95 107
96 bool ResourceMessageTestSink::GetNextResourceCallMatching( 108 ResourceMessageTestSink::ResourceCallVector
97 uint32 id, 109 ResourceMessageTestSink::GetAllResourceCallsMatching(uint32 id) {
98 ResourceMessageCallParams* params, 110 return GetAllResourceMessagesMatching<PpapiHostMsg_ResourceCall,
99 IPC::Message* nested_msg) { 111 ResourceMessageCallParams>(*this, id);
100 int index = GetNextResourceMessageMatching<PpapiHostMsg_ResourceCall,
101 ResourceMessageCallParams>(
102 *this, id, next_resource_call_, params, nested_msg);
103 if (index >= 0) {
104 next_resource_call_ = index + 1;
105 return true;
106 }
107 return false;
108 } 112 }
109 113
110 bool ResourceMessageTestSink::GetNextResourceReplyMatching( 114 ResourceMessageTestSink::ResourceReplyVector
111 uint32 id, 115 ResourceMessageTestSink::GetAllResourceRepliesMatching(uint32 id) {
112 ResourceMessageReplyParams* params, 116 return GetAllResourceMessagesMatching<PpapiPluginMsg_ResourceReply,
113 IPC::Message* nested_msg) { 117 ResourceMessageReplyParams>(*this, id);
114 int index = GetNextResourceMessageMatching<PpapiPluginMsg_ResourceReply,
115 ResourceMessageReplyParams>(
116 *this, id, next_resource_reply_, params, nested_msg);
117 if (index >= 0) {
118 next_resource_reply_ = index + 1;
119 return true;
120 }
121 return false;
122 } 118 }
123 119
124 ResourceSyncCallHandler::ResourceSyncCallHandler( 120 ResourceSyncCallHandler::ResourceSyncCallHandler(
125 ResourceMessageTestSink* test_sink, 121 ResourceMessageTestSink* test_sink,
126 uint32 incoming_type, 122 uint32 incoming_type,
127 int32_t result, 123 int32_t result,
128 const IPC::Message& reply_msg) 124 const IPC::Message& reply_msg)
129 : test_sink_(test_sink), 125 : test_sink_(test_sink),
130 incoming_type_(incoming_type), 126 incoming_type_(incoming_type),
131 result_(result), 127 result_(result),
(...skipping 25 matching lines...) Expand all
157 wrapper_reply_msg, reply_params, reply_msg_); 153 wrapper_reply_msg, reply_params, reply_msg_);
158 test_sink_->SetSyncReplyMessage(wrapper_reply_msg); 154 test_sink_->SetSyncReplyMessage(wrapper_reply_msg);
159 155
160 // Stash a copy of the message for inspection later. 156 // Stash a copy of the message for inspection later.
161 last_handled_msg_ = call_msg; 157 last_handled_msg_ = call_msg;
162 return true; 158 return true;
163 } 159 }
164 160
165 } // namespace proxy 161 } // namespace proxy
166 } // namespace ppapi 162 } // namespace ppapi
OLDNEW
« ppapi/proxy/resource_message_test_sink.h ('K') | « ppapi/proxy/resource_message_test_sink.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698