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

Unified Diff: ipc/ipc_test_sink.h

Issue 6387007: Add support for attaching filters to an IPC TestSink. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix brace style issue Created 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ipc/ipc_test_sink.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/ipc_test_sink.h
diff --git a/ipc/ipc_test_sink.h b/ipc/ipc_test_sink.h
index c6114f166821de69e8563125a5d76e083c62b49b..d0895aa5d9c39980b0ffa4c702e39b3994b85006 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,6 +42,26 @@ 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 MyListener : public IPC::Channel::Listener {
+// public:
+// virtual bool OnMessageReceived(const IPC::Message& msg) {
+// <do something with the message>
+// MessageLoop::current()->Quit();
+// return false; // to store the message in the sink, or true to drop it
+// }
+// };
+//
+// MyListener listener;
+// test_sink.AddFilter(&listener);
+// 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 {
@@ -79,9 +100,20 @@ class TestSink : public Channel {
// or the list is cleared.
const Message* GetUniqueMessageMatching(uint32 id) const;
+ // Adds the given listener as a filter to the TestSink.
+ // When a message is received by the TestSink, it will be dispatched to
+ // the filters, in the order they were added. If a filter returns true
+ // from OnMessageReceived, subsequent filters will not receive the message
+ // and the TestSink will not store it.
+ void AddFilter(Channel::Listener* filter);
+
+ // Removes the given filter from the TestSink.
+ void RemoveFilter(Channel::Listener* filter);
+
private:
// The actual list of received messages.
std::vector<Message> messages_;
+ ObserverList<Channel::Listener> filter_list_;
DISALLOW_COPY_AND_ASSIGN(TestSink);
};
« no previous file with comments | « no previous file | ipc/ipc_test_sink.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698