| 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "base/message_loop/message_loop_proxy.h" | 6 #include "base/message_loop/message_loop_proxy.h" |
| 7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
| 8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
| 9 #include "ipc/ipc_message.h" | 9 #include "ipc/ipc_message.h" |
| 10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 void AddMessageFilter(scoped_refptr<ResourceMessageFilter> filter) { | 58 void AddMessageFilter(scoped_refptr<ResourceMessageFilter> filter) { |
| 59 AddFilter(filter); | 59 AddFilter(filter); |
| 60 } | 60 } |
| 61 | 61 |
| 62 virtual int32_t OnResourceMessageReceived( | 62 virtual int32_t OnResourceMessageReceived( |
| 63 const IPC::Message& msg, | 63 const IPC::Message& msg, |
| 64 HostMessageContext* context) OVERRIDE { | 64 HostMessageContext* context) OVERRIDE { |
| 65 last_handled_msg_ = msg; | 65 last_handled_msg_ = msg; |
| 66 if (msg.type() == msg_type_) { | 66 if (msg.type() == msg_type_) { |
| 67 context->reply_msg = IPC::Message(0, reply_msg_type_, | 67 context->reply_msg = IPC::Message(0, reply_msg_type_); |
| 68 IPC::Message::PRIORITY_NORMAL); | |
| 69 return PP_OK; | 68 return PP_OK; |
| 70 } | 69 } |
| 71 return PP_ERROR_FAILED; | 70 return PP_ERROR_FAILED; |
| 72 } | 71 } |
| 73 | 72 |
| 74 virtual void SendReply(const ReplyMessageContext& context, | 73 virtual void SendReply(const ReplyMessageContext& context, |
| 75 const IPC::Message& msg) OVERRIDE { | 74 const IPC::Message& msg) OVERRIDE { |
| 76 last_reply_msg_ = msg; | 75 last_reply_msg_ = msg; |
| 77 last_reply_message_loop_ = base::MessageLoop::current(); | 76 last_reply_message_loop_ = base::MessageLoop::current(); |
| 78 g_handler_completion.Signal(); | 77 g_handler_completion.Signal(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 return message_loop_proxy_; | 115 return message_loop_proxy_; |
| 117 return NULL; | 116 return NULL; |
| 118 } | 117 } |
| 119 | 118 |
| 120 virtual int32_t OnResourceMessageReceived( | 119 virtual int32_t OnResourceMessageReceived( |
| 121 const IPC::Message& msg, | 120 const IPC::Message& msg, |
| 122 HostMessageContext* context) OVERRIDE { | 121 HostMessageContext* context) OVERRIDE { |
| 123 last_handled_msg_ = msg; | 122 last_handled_msg_ = msg; |
| 124 last_message_loop_ = base::MessageLoop::current(); | 123 last_message_loop_ = base::MessageLoop::current(); |
| 125 if (msg.type() == msg_type_) { | 124 if (msg.type() == msg_type_) { |
| 126 context->reply_msg = IPC::Message(0, reply_msg_type_, | 125 context->reply_msg = IPC::Message(0, reply_msg_type_); |
| 127 IPC::Message::PRIORITY_NORMAL); | |
| 128 return PP_OK; | 126 return PP_OK; |
| 129 } | 127 } |
| 130 return PP_ERROR_FAILED; | 128 return PP_ERROR_FAILED; |
| 131 } | 129 } |
| 132 | 130 |
| 133 private: | 131 private: |
| 134 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 132 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 135 uint32 msg_type_; | 133 uint32 msg_type_; |
| 136 uint32 reply_msg_type_; | 134 uint32 reply_msg_type_; |
| 137 | 135 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 159 | 157 |
| 160 PP_Instance instance = 12345; | 158 PP_Instance instance = 12345; |
| 161 PP_Resource resource = 67890; | 159 PP_Resource resource = 67890; |
| 162 MyResourceHost host(NULL, instance, resource, MSG3_TYPE, REPLY_MSG3_TYPE); | 160 MyResourceHost host(NULL, instance, resource, MSG3_TYPE, REPLY_MSG3_TYPE); |
| 163 host.AddMessageFilter(filter1); | 161 host.AddMessageFilter(filter1); |
| 164 host.AddMessageFilter(filter2); | 162 host.AddMessageFilter(filter2); |
| 165 | 163 |
| 166 proxy::ResourceMessageCallParams params(resource, 1); | 164 proxy::ResourceMessageCallParams params(resource, 1); |
| 167 params.set_has_callback(); | 165 params.set_has_callback(); |
| 168 HostMessageContext context(params); | 166 HostMessageContext context(params); |
| 169 IPC::Message message1(0, MSG1_TYPE, IPC::Message::PRIORITY_NORMAL); | 167 IPC::Message message1(0, MSG1_TYPE); |
| 170 IPC::Message message2(0, MSG2_TYPE, IPC::Message::PRIORITY_NORMAL); | 168 IPC::Message message2(0, MSG2_TYPE); |
| 171 IPC::Message message3(0, MSG3_TYPE, IPC::Message::PRIORITY_NORMAL); | 169 IPC::Message message3(0, MSG3_TYPE); |
| 172 | 170 |
| 173 // Message 1 handled by the first filter. | 171 // Message 1 handled by the first filter. |
| 174 host.HandleMessage(message1, &context); | 172 host.HandleMessage(message1, &context); |
| 175 g_handler_completion.Wait(); | 173 g_handler_completion.Wait(); |
| 176 EXPECT_EQ(filter1->last_handled_msg().type(), message1.type()); | 174 EXPECT_EQ(filter1->last_handled_msg().type(), message1.type()); |
| 177 EXPECT_EQ(filter1->last_message_loop(), bg_thread1.message_loop()); | 175 EXPECT_EQ(filter1->last_message_loop(), bg_thread1.message_loop()); |
| 178 EXPECT_EQ(host.last_reply_msg().type(), static_cast<uint32>(REPLY_MSG1_TYPE)); | 176 EXPECT_EQ(host.last_reply_msg().type(), static_cast<uint32>(REPLY_MSG1_TYPE)); |
| 179 EXPECT_EQ(host.last_reply_message_loop(), io_thread.message_loop()); | 177 EXPECT_EQ(host.last_reply_message_loop(), io_thread.message_loop()); |
| 180 g_handler_completion.Reset(); | 178 g_handler_completion.Reset(); |
| 181 | 179 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 193 EXPECT_EQ(host.last_handled_msg().type(), message3.type()); | 191 EXPECT_EQ(host.last_handled_msg().type(), message3.type()); |
| 194 EXPECT_EQ(host.last_reply_msg().type(), static_cast<uint32>(REPLY_MSG3_TYPE)); | 192 EXPECT_EQ(host.last_reply_msg().type(), static_cast<uint32>(REPLY_MSG3_TYPE)); |
| 195 | 193 |
| 196 io_thread.Stop(); | 194 io_thread.Stop(); |
| 197 bg_thread1.Stop(); | 195 bg_thread1.Stop(); |
| 198 bg_thread2.Stop(); | 196 bg_thread2.Stop(); |
| 199 } | 197 } |
| 200 | 198 |
| 201 } // namespace proxy | 199 } // namespace proxy |
| 202 } // namespace ppapi | 200 } // namespace ppapi |
| OLD | NEW |