OLD | NEW |
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 <stddef.h> |
| 8 |
7 #include "ppapi/proxy/ppapi_messages.h" | 9 #include "ppapi/proxy/ppapi_messages.h" |
8 #include "ppapi/proxy/resource_message_params.h" | 10 #include "ppapi/proxy/resource_message_params.h" |
9 #include "ppapi/proxy/serialized_handle.h" | 11 #include "ppapi/proxy/serialized_handle.h" |
10 | 12 |
11 namespace ppapi { | 13 namespace ppapi { |
12 namespace proxy { | 14 namespace proxy { |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 // Backend for GetAllResource[Calls|Replies]Matching. | 18 // Backend for GetAllResource[Calls|Replies]Matching. |
17 template<class WrapperMessage, class Params> | 19 template <class WrapperMessage, class Params> |
18 std::vector<std::pair<Params, IPC::Message> > | 20 std::vector<std::pair<Params, IPC::Message>> GetAllResourceMessagesMatching( |
19 GetAllResourceMessagesMatching(const ResourceMessageTestSink& sink, | 21 const ResourceMessageTestSink& sink, |
20 uint32 id) { | 22 uint32_t id) { |
21 std::vector<std::pair<Params, IPC::Message> > result; | 23 std::vector<std::pair<Params, IPC::Message> > result; |
22 for (size_t i = 0; i < sink.message_count(); i++) { | 24 for (size_t i = 0; i < sink.message_count(); i++) { |
23 const IPC::Message* msg = sink.GetMessageAt(i); | 25 const IPC::Message* msg = sink.GetMessageAt(i); |
24 if (msg->type() == WrapperMessage::ID) { | 26 if (msg->type() == WrapperMessage::ID) { |
25 typename WrapperMessage::Param params; | 27 typename WrapperMessage::Param params; |
26 WrapperMessage::Read(msg, ¶ms); | 28 WrapperMessage::Read(msg, ¶ms); |
27 Params cur_params = base::get<0>(params); | 29 Params cur_params = base::get<0>(params); |
28 IPC::Message cur_msg = base::get<1>(params); | 30 IPC::Message cur_msg = base::get<1>(params); |
29 if (cur_msg.type() == id) { | 31 if (cur_msg.type() == id) { |
30 result.push_back(std::make_pair(cur_params, cur_msg)); | 32 result.push_back(std::make_pair(cur_params, cur_msg)); |
(...skipping 29 matching lines...) Expand all Loading... |
60 } | 62 } |
61 return result; | 63 return result; |
62 } | 64 } |
63 | 65 |
64 void ResourceMessageTestSink::SetSyncReplyMessage(IPC::Message* reply_msg) { | 66 void ResourceMessageTestSink::SetSyncReplyMessage(IPC::Message* reply_msg) { |
65 DCHECK(!sync_reply_msg_.get()); | 67 DCHECK(!sync_reply_msg_.get()); |
66 sync_reply_msg_.reset(reply_msg); | 68 sync_reply_msg_.reset(reply_msg); |
67 } | 69 } |
68 | 70 |
69 bool ResourceMessageTestSink::GetFirstResourceCallMatching( | 71 bool ResourceMessageTestSink::GetFirstResourceCallMatching( |
70 uint32 id, | 72 uint32_t id, |
71 ResourceMessageCallParams* params, | 73 ResourceMessageCallParams* params, |
72 IPC::Message* nested_msg) const { | 74 IPC::Message* nested_msg) const { |
73 ResourceCallVector matching_messages = | 75 ResourceCallVector matching_messages = |
74 GetAllResourceMessagesMatching<PpapiHostMsg_ResourceCall, | 76 GetAllResourceMessagesMatching<PpapiHostMsg_ResourceCall, |
75 ResourceMessageCallParams>(*this, id); | 77 ResourceMessageCallParams>(*this, id); |
76 if (matching_messages.empty()) | 78 if (matching_messages.empty()) |
77 return false; | 79 return false; |
78 | 80 |
79 *params = matching_messages[0].first; | 81 *params = matching_messages[0].first; |
80 *nested_msg = matching_messages[0].second; | 82 *nested_msg = matching_messages[0].second; |
81 return true; | 83 return true; |
82 } | 84 } |
83 | 85 |
84 bool ResourceMessageTestSink::GetFirstResourceReplyMatching( | 86 bool ResourceMessageTestSink::GetFirstResourceReplyMatching( |
85 uint32 id, | 87 uint32_t id, |
86 ResourceMessageReplyParams* params, | 88 ResourceMessageReplyParams* params, |
87 IPC::Message* nested_msg) { | 89 IPC::Message* nested_msg) { |
88 ResourceReplyVector matching_messages = | 90 ResourceReplyVector matching_messages = |
89 GetAllResourceMessagesMatching<PpapiPluginMsg_ResourceReply, | 91 GetAllResourceMessagesMatching<PpapiPluginMsg_ResourceReply, |
90 ResourceMessageReplyParams>(*this, id); | 92 ResourceMessageReplyParams>(*this, id); |
91 if (matching_messages.empty()) | 93 if (matching_messages.empty()) |
92 return false; | 94 return false; |
93 | 95 |
94 *params = matching_messages[0].first; | 96 *params = matching_messages[0].first; |
95 *nested_msg = matching_messages[0].second; | 97 *nested_msg = matching_messages[0].second; |
96 return true; | 98 return true; |
97 } | 99 } |
98 | 100 |
99 ResourceMessageTestSink::ResourceCallVector | 101 ResourceMessageTestSink::ResourceCallVector |
100 ResourceMessageTestSink::GetAllResourceCallsMatching(uint32 id) { | 102 ResourceMessageTestSink::GetAllResourceCallsMatching(uint32_t id) { |
101 return GetAllResourceMessagesMatching<PpapiHostMsg_ResourceCall, | 103 return GetAllResourceMessagesMatching<PpapiHostMsg_ResourceCall, |
102 ResourceMessageCallParams>(*this, id); | 104 ResourceMessageCallParams>(*this, id); |
103 } | 105 } |
104 | 106 |
105 ResourceMessageTestSink::ResourceReplyVector | 107 ResourceMessageTestSink::ResourceReplyVector |
106 ResourceMessageTestSink::GetAllResourceRepliesMatching(uint32 id) { | 108 ResourceMessageTestSink::GetAllResourceRepliesMatching(uint32_t id) { |
107 return GetAllResourceMessagesMatching<PpapiPluginMsg_ResourceReply, | 109 return GetAllResourceMessagesMatching<PpapiPluginMsg_ResourceReply, |
108 ResourceMessageReplyParams>(*this, id); | 110 ResourceMessageReplyParams>(*this, id); |
109 } | 111 } |
110 | 112 |
111 ResourceSyncCallHandler::ResourceSyncCallHandler( | 113 ResourceSyncCallHandler::ResourceSyncCallHandler( |
112 ResourceMessageTestSink* test_sink, | 114 ResourceMessageTestSink* test_sink, |
113 uint32 incoming_type, | 115 uint32_t incoming_type, |
114 int32_t result, | 116 int32_t result, |
115 const IPC::Message& reply_msg) | 117 const IPC::Message& reply_msg) |
116 : test_sink_(test_sink), | 118 : test_sink_(test_sink), |
117 incoming_type_(incoming_type), | 119 incoming_type_(incoming_type), |
118 result_(result), | 120 result_(result), |
119 serialized_handle_(NULL), | 121 serialized_handle_(NULL), |
120 reply_msg_(reply_msg) { | 122 reply_msg_(reply_msg) {} |
121 } | |
122 | 123 |
123 ResourceSyncCallHandler::~ResourceSyncCallHandler() { | 124 ResourceSyncCallHandler::~ResourceSyncCallHandler() { |
124 } | 125 } |
125 | 126 |
126 bool ResourceSyncCallHandler::OnMessageReceived(const IPC::Message& msg) { | 127 bool ResourceSyncCallHandler::OnMessageReceived(const IPC::Message& msg) { |
127 if (msg.type() != PpapiHostMsg_ResourceSyncCall::ID) | 128 if (msg.type() != PpapiHostMsg_ResourceSyncCall::ID) |
128 return false; | 129 return false; |
129 PpapiHostMsg_ResourceSyncCall::Schema::SendParam send_params; | 130 PpapiHostMsg_ResourceSyncCall::Schema::SendParam send_params; |
130 bool success = PpapiHostMsg_ResourceSyncCall::ReadSendParam( | 131 bool success = PpapiHostMsg_ResourceSyncCall::ReadSendParam( |
131 &msg, &send_params); | 132 &msg, &send_params); |
(...skipping 12 matching lines...) Expand all Loading... |
144 wrapper_reply_msg, reply_params, reply_msg_); | 145 wrapper_reply_msg, reply_params, reply_msg_); |
145 test_sink_->SetSyncReplyMessage(wrapper_reply_msg); | 146 test_sink_->SetSyncReplyMessage(wrapper_reply_msg); |
146 | 147 |
147 // Stash a copy of the message for inspection later. | 148 // Stash a copy of the message for inspection later. |
148 last_handled_msg_ = call_msg; | 149 last_handled_msg_ = call_msg; |
149 return true; | 150 return true; |
150 } | 151 } |
151 | 152 |
152 } // namespace proxy | 153 } // namespace proxy |
153 } // namespace ppapi | 154 } // namespace ppapi |
OLD | NEW |