| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef IPC_IPC_TEST_SINK_H_ | 5 #ifndef IPC_IPC_TEST_SINK_H_ |
| 6 #define IPC_IPC_TEST_SINK_H_ | 6 #define IPC_IPC_TEST_SINK_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 // ASSERT_TRUE(msg); | 52 // ASSERT_TRUE(msg); |
| 53 // base::TupleTypes<ViewHostMsg_Foo::ReplyParam>::ValueTuple reply_data; | 53 // base::TupleTypes<ViewHostMsg_Foo::ReplyParam>::ValueTuple reply_data; |
| 54 // EXPECT_TRUE(ViewHostMsg_Foo::ReadReplyParam(msg, &reply_data)); | 54 // EXPECT_TRUE(ViewHostMsg_Foo::ReadReplyParam(msg, &reply_data)); |
| 55 // | 55 // |
| 56 // You can also register to be notified when messages are posted to the sink. | 56 // You can also register to be notified when messages are posted to the sink. |
| 57 // This can be useful if you need to wait for a particular message that will | 57 // This can be useful if you need to wait for a particular message that will |
| 58 // be posted asynchronously. Example usage: | 58 // be posted asynchronously. Example usage: |
| 59 // | 59 // |
| 60 // class MyListener : public IPC::Listener { | 60 // class MyListener : public IPC::Listener { |
| 61 // public: | 61 // public: |
| 62 // MyListener(const base::Closure& closure) |
| 63 // : message_received_closure_(closure) {} |
| 62 // virtual bool OnMessageReceived(const IPC::Message& msg) { | 64 // virtual bool OnMessageReceived(const IPC::Message& msg) { |
| 63 // <do something with the message> | 65 // <do something with the message> |
| 64 // MessageLoop::current()->QuitWhenIdle(); | 66 // message_received_closure_.Run(); |
| 65 // return false; // to store the message in the sink, or true to drop it | 67 // return false; // to store the message in the sink, or true to drop it |
| 66 // } | 68 // } |
| 69 // private: |
| 70 // base::Closure message_received_closure_; |
| 67 // }; | 71 // }; |
| 68 // | 72 // |
| 69 // MyListener listener; | 73 // base::RunLoop run_loop; |
| 74 // MyListener listener(run_loop.QuitClosure()); |
| 70 // test_sink.AddFilter(&listener); | 75 // test_sink.AddFilter(&listener); |
| 71 // StartSomeAsynchronousProcess(&test_sink); | 76 // StartSomeAsynchronousProcess(&test_sink); |
| 72 // MessageLoop::current()->Run(); | 77 // run_loop.Run(); |
| 73 // <inspect the results> | 78 // <inspect the results> |
| 74 // ... | 79 // ... |
| 75 // | 80 // |
| 76 // To hook up the sink, all you need to do is call OnMessageReceived when a | 81 // To hook up the sink, all you need to do is call OnMessageReceived when a |
| 77 // message is received. | 82 // message is received. |
| 78 class TestSink : public Channel { | 83 class TestSink : public Channel { |
| 79 public: | 84 public: |
| 80 TestSink(); | 85 TestSink(); |
| 81 ~TestSink() override; | 86 ~TestSink() override; |
| 82 | 87 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 // The actual list of received messages. | 139 // The actual list of received messages. |
| 135 std::vector<Message> messages_; | 140 std::vector<Message> messages_; |
| 136 base::ObserverList<Listener> filter_list_; | 141 base::ObserverList<Listener> filter_list_; |
| 137 | 142 |
| 138 DISALLOW_COPY_AND_ASSIGN(TestSink); | 143 DISALLOW_COPY_AND_ASSIGN(TestSink); |
| 139 }; | 144 }; |
| 140 | 145 |
| 141 } // namespace IPC | 146 } // namespace IPC |
| 142 | 147 |
| 143 #endif // IPC_IPC_TEST_SINK_H_ | 148 #endif // IPC_IPC_TEST_SINK_H_ |
| OLD | NEW |