Chromium Code Reviews| Index: ipc/ipc_test_sink.h |
| diff --git a/ipc/ipc_test_sink.h b/ipc/ipc_test_sink.h |
| index c6114f166821de69e8563125a5d76e083c62b49b..3acb3dc8c8f5a812e8a63f10c10245bdf84dc4de 100644 |
| --- a/ipc/ipc_test_sink.h |
| +++ b/ipc/ipc_test_sink.h |
| @@ -10,6 +10,7 @@ |
| #include <vector> |
| #include "base/basictypes.h" |
| +#include "base/observer_list.h" |
| #include "ipc/ipc_channel.h" |
| namespace IPC { |
| @@ -41,10 +42,39 @@ class Message; |
| // // Go on to the next phase of the test. |
| // test_sink.ClearMessages(); |
| // |
| +// You can also register to be notified when messages are posted to the sink. |
| +// This can be useful if you need to wait for a particular message that will |
| +// be posted asynchronously. Example usage: |
| +// |
| +// class MyObserver : public IPC::TestSink::Observer { |
| +// public: |
|
noelutz
2011/01/28 02:13:06
nit: indentation is wrong I think.
Brian Ryner
2011/01/28 20:43:07
Done.
|
| +// virtual void OnMessageReceived(const IPC::Message& msg) { |
| +// <do something with the message> |
| +// MessageLoop::current()->Quit(); |
| +// } |
| +// }; |
| +// |
| +// MyObserver observer; |
| +// test_sink.AddObserver(&observer); |
| +// StartSomeAsynchronousProcess(&test_sink); |
| +// MessageLoop::current()->Run(); |
| +// <inspect the results> |
| +// ... |
| +// |
| // To hook up the sink, all you need to do is call OnMessageReceived when a |
| // message is received. |
| class TestSink : public Channel { |
| public: |
| + // Callers can register as an observer to be notified for each message |
| + // that is sent to the TestSink. |
| + class Observer { |
| + public: |
| + virtual ~Observer() {} |
| + |
| + // OnMessageReceived is called after each message is added to the TestSink. |
| + virtual void OnMessageReceived(const Message& msg) = 0; |
| + }; |
| + |
| TestSink(); |
| ~TestSink(); |
| @@ -79,9 +109,16 @@ class TestSink : public Channel { |
| // or the list is cleared. |
| const Message* GetUniqueMessageMatching(uint32 id) const; |
| + // Adds the given observer to the TestSink. |
| + void AddObserver(Observer* obs); |
| + |
| + // Removes the given observer from the TestSink. |
| + void RemoveObserver(Observer* obs); |
| + |
| private: |
| // The actual list of received messages. |
| std::vector<Message> messages_; |
| + ObserverList<Observer> observer_list_; |
| DISALLOW_COPY_AND_ASSIGN(TestSink); |
| }; |