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

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: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/resource_message_test_sink.h ('k') | no next file » | 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 #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 GetAllResource[Calls|Replies]Matching.
17 template<class WrapperMessage, class Params> 17 template<class WrapperMessage, class Params>
18 int GetNextResourceMessageMatching(const ResourceMessageTestSink& sink, 18 std::vector<std::pair<Params, IPC::Message> >
19 uint32 id, 19 GetAllResourceMessagesMatching(const ResourceMessageTestSink& sink,
20 int start_index, 20 uint32 id) {
21 Params* params, 21 std::vector<std::pair<Params, IPC::Message> > result;
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 result.push_back(std::make_pair(cur_params, cur_msg));
34 *nested_msg = cur_msg;
35 return i;
36 } 30 }
37 } 31 }
38 } 32 }
39 return -1; 33 return result;
40 } 34 }
41 35
42 } // namespace 36 } // namespace
43 37
44 ResourceMessageTestSink::ResourceMessageTestSink() 38 ResourceMessageTestSink::ResourceMessageTestSink() {
45 : next_resource_call_(0),
46 next_resource_reply_(0) {
47 } 39 }
48 40
49 ResourceMessageTestSink::~ResourceMessageTestSink() { 41 ResourceMessageTestSink::~ResourceMessageTestSink() {
50 } 42 }
51 43
52 bool ResourceMessageTestSink::Send(IPC::Message* msg) { 44 bool ResourceMessageTestSink::Send(IPC::Message* msg) {
53 int message_id = 0; 45 int message_id = 0;
54 scoped_ptr<IPC::MessageReplyDeserializer> reply_deserializer; 46 scoped_ptr<IPC::MessageReplyDeserializer> reply_deserializer;
55 if (msg->is_sync()) { 47 if (msg->is_sync()) {
56 reply_deserializer.reset( 48 reply_deserializer.reset(
(...skipping 13 matching lines...) Expand all
70 62
71 void ResourceMessageTestSink::SetSyncReplyMessage(IPC::Message* reply_msg) { 63 void ResourceMessageTestSink::SetSyncReplyMessage(IPC::Message* reply_msg) {
72 DCHECK(!sync_reply_msg_.get()); 64 DCHECK(!sync_reply_msg_.get());
73 sync_reply_msg_.reset(reply_msg); 65 sync_reply_msg_.reset(reply_msg);
74 } 66 }
75 67
76 bool ResourceMessageTestSink::GetFirstResourceCallMatching( 68 bool ResourceMessageTestSink::GetFirstResourceCallMatching(
77 uint32 id, 69 uint32 id,
78 ResourceMessageCallParams* params, 70 ResourceMessageCallParams* params,
79 IPC::Message* nested_msg) const { 71 IPC::Message* nested_msg) const {
80 int index = GetNextResourceMessageMatching<PpapiHostMsg_ResourceCall, 72 ResourceCallVector matching_messages =
81 ResourceMessageCallParams>( 73 GetAllResourceMessagesMatching<PpapiHostMsg_ResourceCall,
82 *this, id, 0 /* start_index */, params, nested_msg); 74 ResourceMessageCallParams>(*this, id);
83 return index >= 0; 75 if (matching_messages.empty())
76 return false;
77
78 *params = matching_messages[0].first;
79 *nested_msg = matching_messages[0].second;
80 return true;
84 } 81 }
85 82
86 bool ResourceMessageTestSink::GetFirstResourceReplyMatching( 83 bool ResourceMessageTestSink::GetFirstResourceReplyMatching(
87 uint32 id, 84 uint32 id,
88 ResourceMessageReplyParams* params, 85 ResourceMessageReplyParams* params,
89 IPC::Message* nested_msg) { 86 IPC::Message* nested_msg) {
90 int index = GetNextResourceMessageMatching<PpapiPluginMsg_ResourceReply, 87 ResourceReplyVector matching_messages =
91 ResourceMessageReplyParams>( 88 GetAllResourceMessagesMatching<PpapiPluginMsg_ResourceReply,
92 *this, id, 0 /* start_index */, params, nested_msg); 89 ResourceMessageReplyParams>(*this, id);
93 return index >= 0; 90 if (matching_messages.empty())
91 return false;
92
93 *params = matching_messages[0].first;
94 *nested_msg = matching_messages[0].second;
95 return true;
94 } 96 }
95 97
96 bool ResourceMessageTestSink::GetNextResourceCallMatching( 98 ResourceMessageTestSink::ResourceCallVector
97 uint32 id, 99 ResourceMessageTestSink::GetAllResourceCallsMatching(uint32 id) {
98 ResourceMessageCallParams* params, 100 return GetAllResourceMessagesMatching<PpapiHostMsg_ResourceCall,
99 IPC::Message* nested_msg) { 101 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 } 102 }
109 103
110 bool ResourceMessageTestSink::GetNextResourceReplyMatching( 104 ResourceMessageTestSink::ResourceReplyVector
111 uint32 id, 105 ResourceMessageTestSink::GetAllResourceRepliesMatching(uint32 id) {
112 ResourceMessageReplyParams* params, 106 return GetAllResourceMessagesMatching<PpapiPluginMsg_ResourceReply,
113 IPC::Message* nested_msg) { 107 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 } 108 }
123 109
124 ResourceSyncCallHandler::ResourceSyncCallHandler( 110 ResourceSyncCallHandler::ResourceSyncCallHandler(
125 ResourceMessageTestSink* test_sink, 111 ResourceMessageTestSink* test_sink,
126 uint32 incoming_type, 112 uint32 incoming_type,
127 int32_t result, 113 int32_t result,
128 const IPC::Message& reply_msg) 114 const IPC::Message& reply_msg)
129 : test_sink_(test_sink), 115 : test_sink_(test_sink),
130 incoming_type_(incoming_type), 116 incoming_type_(incoming_type),
131 result_(result), 117 result_(result),
(...skipping 25 matching lines...) Expand all
157 wrapper_reply_msg, reply_params, reply_msg_); 143 wrapper_reply_msg, reply_params, reply_msg_);
158 test_sink_->SetSyncReplyMessage(wrapper_reply_msg); 144 test_sink_->SetSyncReplyMessage(wrapper_reply_msg);
159 145
160 // Stash a copy of the message for inspection later. 146 // Stash a copy of the message for inspection later.
161 last_handled_msg_ = call_msg; 147 last_handled_msg_ = call_msg;
162 return true; 148 return true;
163 } 149 }
164 150
165 } // namespace proxy 151 } // namespace proxy
166 } // namespace ppapi 152 } // namespace ppapi
OLDNEW
« 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