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

Unified 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: Implement GetFirst* methods in terms of GetAll* ones. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/proxy/resource_message_test_sink.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 75a47396c67f405d6bdbc666fd0e069d4bfeca70..a17e1d5cf0f3d598d7b0d3f94c561769ff449fd5 100644
--- a/ppapi/proxy/resource_message_test_sink.cc
+++ b/ppapi/proxy/resource_message_test_sink.cc
@@ -13,37 +13,29 @@ namespace proxy {
namespace {
-// Backend for GetFirstResource[Call|Reply]Matching.
+// Backend for GetAllResource[Calls|Replies]Matching.
template<class WrapperMessage, class Params>
-int GetNextResourceMessageMatching(const ResourceMessageTestSink& sink,
- uint32 id,
- int start_index,
- Params* params,
- IPC::Message* nested_msg) {
- if (start_index < 0)
- return -1;
- int message_count = static_cast<int>(sink.message_count());
- for (int i = start_index; i < message_count; i++) {
+std::vector<std::pair<Params, IPC::Message> >
+GetAllResourceMessagesMatching(const ResourceMessageTestSink& sink,
+ uint32 id) {
+ std::vector<std::pair<Params, IPC::Message> > result;
+ for (size_t i = 0; i < sink.message_count(); i++) {
const IPC::Message* msg = sink.GetMessageAt(i);
if (msg->type() == WrapperMessage::ID) {
Params cur_params;
IPC::Message cur_msg;
WrapperMessage::Read(msg, &cur_params, &cur_msg);
if (cur_msg.type() == id) {
- *params = cur_params;
- *nested_msg = cur_msg;
- return i;
+ result.push_back(std::make_pair(cur_params, cur_msg));
}
}
}
- return -1;
+ return result;
}
} // namespace
-ResourceMessageTestSink::ResourceMessageTestSink()
- : next_resource_call_(0),
- next_resource_reply_(0) {
+ResourceMessageTestSink::ResourceMessageTestSink() {
}
ResourceMessageTestSink::~ResourceMessageTestSink() {
@@ -77,48 +69,42 @@ bool ResourceMessageTestSink::GetFirstResourceCallMatching(
uint32 id,
ResourceMessageCallParams* params,
IPC::Message* nested_msg) const {
- int index = GetNextResourceMessageMatching<PpapiHostMsg_ResourceCall,
- ResourceMessageCallParams>(
- *this, id, 0 /* start_index */, params, nested_msg);
- return index >= 0;
+ ResourceCallVector matching_messages =
+ GetAllResourceMessagesMatching<PpapiHostMsg_ResourceCall,
+ ResourceMessageCallParams>(*this, id);
+ if (matching_messages.empty())
+ return false;
+
+ *params = matching_messages[0].first;
+ *nested_msg = matching_messages[0].second;
+ return true;
}
bool ResourceMessageTestSink::GetFirstResourceReplyMatching(
uint32 id,
ResourceMessageReplyParams* params,
IPC::Message* nested_msg) {
- int index = GetNextResourceMessageMatching<PpapiPluginMsg_ResourceReply,
- ResourceMessageReplyParams>(
- *this, id, 0 /* start_index */, params, nested_msg);
- return index >= 0;
+ ResourceReplyVector matching_messages =
+ GetAllResourceMessagesMatching<PpapiPluginMsg_ResourceReply,
+ ResourceMessageReplyParams>(*this, id);
+ if (matching_messages.empty())
+ return false;
+
+ *params = matching_messages[0].first;
+ *nested_msg = matching_messages[0].second;
+ return true;
}
-bool ResourceMessageTestSink::GetNextResourceCallMatching(
- uint32 id,
- ResourceMessageCallParams* params,
- IPC::Message* nested_msg) {
- int index = GetNextResourceMessageMatching<PpapiHostMsg_ResourceCall,
- ResourceMessageCallParams>(
- *this, id, next_resource_call_, params, nested_msg);
- if (index >= 0) {
- next_resource_call_ = index + 1;
- return true;
- }
- return false;
+ResourceMessageTestSink::ResourceCallVector
+ResourceMessageTestSink::GetAllResourceCallsMatching(uint32 id) {
+ return GetAllResourceMessagesMatching<PpapiHostMsg_ResourceCall,
+ ResourceMessageCallParams>(*this, id);
}
-bool ResourceMessageTestSink::GetNextResourceReplyMatching(
- uint32 id,
- ResourceMessageReplyParams* params,
- IPC::Message* nested_msg) {
- int index = GetNextResourceMessageMatching<PpapiPluginMsg_ResourceReply,
- ResourceMessageReplyParams>(
- *this, id, next_resource_reply_, params, nested_msg);
- if (index >= 0) {
- next_resource_reply_ = index + 1;
- return true;
- }
- return false;
+ResourceMessageTestSink::ResourceReplyVector
+ResourceMessageTestSink::GetAllResourceRepliesMatching(uint32 id) {
+ return GetAllResourceMessagesMatching<PpapiPluginMsg_ResourceReply,
+ ResourceMessageReplyParams>(*this, id);
}
ResourceSyncCallHandler::ResourceSyncCallHandler(
« no previous file with comments | « 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