diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-24 06:19:28 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-24 06:19:28 +0000 |
commit | a95986a837fc86e079b5c6dac357636478b50092 (patch) | |
tree | 66a32009250791e64741216cdd6c21ecf1ff7f86 /ipc | |
parent | 125a7ba65ad10ace9edcf36d6943ce9ae2bdc1d6 (diff) | |
download | chromium_src-a95986a837fc86e079b5c6dac357636478b50092.zip chromium_src-a95986a837fc86e079b5c6dac357636478b50092.tar.gz chromium_src-a95986a837fc86e079b5c6dac357636478b50092.tar.bz2 |
Make IPC::Channel::Listener:OnMessageReceived have a return value indicating whether a message was processed or not.
TBR=brettw
Review URL: http://codereview.chromium.org/5978003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70139 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/ipc_channel.h | 5 | ||||
-rw-r--r-- | ipc/ipc_channel_posix_unittest.cc | 3 | ||||
-rw-r--r-- | ipc/ipc_channel_proxy.cc | 6 | ||||
-rw-r--r-- | ipc/ipc_channel_proxy.h | 4 | ||||
-rw-r--r-- | ipc/ipc_fuzzing_tests.cc | 6 | ||||
-rw-r--r-- | ipc/ipc_message_macros.h | 9 | ||||
-rw-r--r-- | ipc/ipc_send_fds_test.cc | 8 | ||||
-rw-r--r-- | ipc/ipc_sync_channel.cc | 10 | ||||
-rw-r--r-- | ipc/ipc_sync_channel.h | 2 | ||||
-rw-r--r-- | ipc/ipc_sync_channel_unittest.cc | 3 | ||||
-rw-r--r-- | ipc/ipc_sync_message_unittest.cc | 3 | ||||
-rw-r--r-- | ipc/ipc_tests.cc | 14 | ||||
-rw-r--r-- | ipc/sync_socket_unittest.cc | 6 |
13 files changed, 46 insertions, 33 deletions
diff --git a/ipc/ipc_channel.h b/ipc/ipc_channel.h index c257a8e..3b8afd8 100644 --- a/ipc/ipc_channel.h +++ b/ipc/ipc_channel.h @@ -39,8 +39,9 @@ class Channel : public Message::Sender { public: virtual ~Listener() {} - // Called when a message is received. - virtual void OnMessageReceived(const Message& message) = 0; + // Called when a message is received. Returns true iff the message was + // handled. + virtual bool OnMessageReceived(const Message& message) = 0; // Called when the channel is connected and we have received the internal // Hello message from the peer. diff --git a/ipc/ipc_channel_posix_unittest.cc b/ipc/ipc_channel_posix_unittest.cc index 09c635f..459aafb 100644 --- a/ipc/ipc_channel_posix_unittest.cc +++ b/ipc/ipc_channel_posix_unittest.cc @@ -43,10 +43,11 @@ class IPCChannelPosixTestListener : public IPC::Channel::Listener { virtual ~IPCChannelPosixTestListener() {} - virtual void OnMessageReceived(const IPC::Message& message) { + virtual bool OnMessageReceived(const IPC::Message& message) { EXPECT_EQ(message.type(), QUIT_MESSAGE); status_ = MESSAGE_RECEIVED; QuitRunLoop(); + return true; } virtual void OnChannelConnected(int32 peer_pid) { diff --git a/ipc/ipc_channel_proxy.cc b/ipc/ipc_channel_proxy.cc index aba6bf5e..b9533e6 100644 --- a/ipc/ipc_channel_proxy.cc +++ b/ipc/ipc_channel_proxy.cc @@ -96,20 +96,22 @@ bool ChannelProxy::Context::TryFilters(const Message& message) { } // Called on the IPC::Channel thread -void ChannelProxy::Context::OnMessageReceived(const Message& message) { +bool ChannelProxy::Context::OnMessageReceived(const Message& message) { // First give a chance to the filters to process this message. if (!TryFilters(message)) OnMessageReceivedNoFilter(message); + return true; } // Called on the IPC::Channel thread -void ChannelProxy::Context::OnMessageReceivedNoFilter(const Message& message) { +bool ChannelProxy::Context::OnMessageReceivedNoFilter(const Message& message) { // NOTE: This code relies on the listener's message loop not going away while // this thread is active. That should be a reasonable assumption, but it // feels risky. We may want to invent some more indirect way of referring to // a MessageLoop if this becomes a problem. listener_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( this, &Context::OnDispatchMessage, message)); + return true; } // Called on the IPC::Channel thread diff --git a/ipc/ipc_channel_proxy.h b/ipc/ipc_channel_proxy.h index a256ab6..82a243b 100644 --- a/ipc/ipc_channel_proxy.h +++ b/ipc/ipc_channel_proxy.h @@ -176,12 +176,12 @@ class ChannelProxy : public Message::Sender { virtual ~Context() { } // IPC::Channel::Listener methods: - virtual void OnMessageReceived(const Message& message); + virtual bool OnMessageReceived(const Message& message); virtual void OnChannelConnected(int32 peer_pid); virtual void OnChannelError(); // Like OnMessageReceived but doesn't try the filters. - void OnMessageReceivedNoFilter(const Message& message); + bool OnMessageReceivedNoFilter(const Message& message); // Gives the filters a chance at processing |message|. // Returns true if the message was processed, false otherwise. diff --git a/ipc/ipc_fuzzing_tests.cc b/ipc/ipc_fuzzing_tests.cc index 4b5e938..5dd916f 100644 --- a/ipc/ipc_fuzzing_tests.cc +++ b/ipc/ipc_fuzzing_tests.cc @@ -158,7 +158,7 @@ class FuzzerServerListener : public SimpleListener { public: FuzzerServerListener() : message_count_(2), pending_messages_(0) { } - virtual void OnMessageReceived(const IPC::Message& msg) { + virtual bool OnMessageReceived(const IPC::Message& msg) { if (msg.routing_id() == MSG_ROUTING_CONTROL) { ++pending_messages_; IPC_BEGIN_MESSAGE_MAP(FuzzerServerListener, msg) @@ -170,6 +170,7 @@ class FuzzerServerListener : public SimpleListener { ReplyMsgNotHandled(msg.type()); } } + return true; } private: @@ -221,9 +222,10 @@ class FuzzerClientListener : public SimpleListener { FuzzerClientListener() : last_msg_(NULL) { } - virtual void OnMessageReceived(const IPC::Message& msg) { + virtual bool OnMessageReceived(const IPC::Message& msg) { last_msg_ = new IPC::Message(msg); MessageLoop::current()->Quit(); + return true; } bool ExpectMessage(int value, uint32 type_id) { diff --git a/ipc/ipc_message_macros.h b/ipc/ipc_message_macros.h index 504be00..af2901a 100644 --- a/ipc/ipc_message_macros.h +++ b/ipc/ipc_message_macros.h @@ -1163,23 +1163,22 @@ LogFunctionMap g_log_function_mapping; // Prefer to use the IPC_BEGIN_MESSAGE_MAP_EX to the older macros since they // allow you to detect when a message could not be de-serialized. Usage: // -// void MyClass::OnMessageReceived(const IPC::Message& msg) { +// bool MyClass::OnMessageReceived(const IPC::Message& msg) { +// bool handled = true; // bool msg_is_good = false; // IPC_BEGIN_MESSAGE_MAP_EX(MyClass, msg, msg_is_good) // IPC_MESSAGE_HANDLER(MsgClassOne, OnMsgClassOne) // ...more handlers here ... // IPC_MESSAGE_HANDLER(MsgClassTen, OnMsgClassTen) +// IPC_MESSAGE_UNHANDLED(handled = false) // IPC_END_MESSAGE_MAP_EX() // if (!msg_is_good) { // // Signal error here or terminate offending process. // } +// return handled; // } -#define IPC_DEFINE_MESSAGE_MAP(class_name) \ -void class_name::OnMessageReceived(const IPC::Message& msg) \ - IPC_BEGIN_MESSAGE_MAP(class_name, msg) - #define IPC_BEGIN_MESSAGE_MAP_EX(class_name, msg, msg_is_ok) \ { \ typedef class_name _IpcMessageHandlerClass; \ diff --git a/ipc/ipc_send_fds_test.cc b/ipc/ipc_send_fds_test.cc index 809f4f5..3b845f8 100644 --- a/ipc/ipc_send_fds_test.cc +++ b/ipc/ipc_send_fds_test.cc @@ -51,20 +51,20 @@ class MyChannelDescriptorListener : public IPC::Channel::Listener { : expected_inode_num_(expected_inode_num), num_fds_received_(0) {} - virtual void OnMessageReceived(const IPC::Message& message) { + virtual bool OnMessageReceived(const IPC::Message& message) { void* iter = NULL; ++num_fds_received_; base::FileDescriptor descriptor; - ASSERT_TRUE( - IPC::ParamTraits<base::FileDescriptor>::Read( - &message, &iter, &descriptor)); + IPC::ParamTraits<base::FileDescriptor>::Read( + &message, &iter, &descriptor); VerifyAndCloseDescriptor(descriptor.fd, expected_inode_num_); if (num_fds_received_ == kNumFDsToSend) { MessageLoop::current()->Quit(); } + return true; } virtual void OnChannelError() { diff --git a/ipc/ipc_sync_channel.cc b/ipc/ipc_sync_channel.cc index 7425a9b..79b1e60 100644 --- a/ipc/ipc_sync_channel.cc +++ b/ipc/ipc_sync_channel.cc @@ -285,22 +285,22 @@ void SyncChannel::SyncContext::Clear() { Context::Clear(); } -void SyncChannel::SyncContext::OnMessageReceived(const Message& msg) { +bool SyncChannel::SyncContext::OnMessageReceived(const Message& msg) { // Give the filters a chance at processing this message. if (TryFilters(msg)) - return; + return true; if (TryToUnblockListener(&msg)) - return; + return true; if (msg.should_unblock()) { received_sync_msgs_->QueueMessage(msg, this); - return; + return true; } if (msg.is_reply()) { received_sync_msgs_->QueueReply(msg, this); - return; + return true; } return Context::OnMessageReceivedNoFilter(msg); diff --git a/ipc/ipc_sync_channel.h b/ipc/ipc_sync_channel.h index fce2e38..d1cef93 100644 --- a/ipc/ipc_sync_channel.h +++ b/ipc/ipc_sync_channel.h @@ -106,7 +106,7 @@ class SyncChannel : public ChannelProxy, virtual void Clear(); // Called on the IPC thread. - virtual void OnMessageReceived(const Message& msg); + virtual bool OnMessageReceived(const Message& msg); virtual void OnChannelError(); virtual void OnChannelOpened(); virtual void OnChannelClosed(); diff --git a/ipc/ipc_sync_channel_unittest.cc b/ipc/ipc_sync_channel_unittest.cc index 772df0b..e580ba4 100644 --- a/ipc/ipc_sync_channel_unittest.cc +++ b/ipc/ipc_sync_channel_unittest.cc @@ -195,7 +195,7 @@ class Worker : public Channel::Listener, public Message::Sender { listener_event->Signal(); } - void OnMessageReceived(const Message& message) { + bool OnMessageReceived(const Message& message) { IPC_BEGIN_MESSAGE_MAP(Worker, message) IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelTestMsg_Double, OnDoubleDelay) IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelTestMsg_AnswerToLife, @@ -203,6 +203,7 @@ class Worker : public Channel::Listener, public Message::Sender { IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelNestedTestMsg_String, OnNestedTestMsg) IPC_END_MESSAGE_MAP() + return true; } void StartThread(base::Thread* thread, MessageLoop::Type type) { diff --git a/ipc/ipc_sync_message_unittest.cc b/ipc/ipc_sync_message_unittest.cc index e64e0c3..9a72aa3 100644 --- a/ipc/ipc_sync_message_unittest.cc +++ b/ipc/ipc_sync_message_unittest.cc @@ -108,7 +108,7 @@ class TestMessageReceiver { return true; } - void OnMessageReceived(const IPC::Message& msg) { + bool OnMessageReceived(const IPC::Message& msg) { IPC_BEGIN_MESSAGE_MAP(TestMessageReceiver, msg) IPC_MESSAGE_HANDLER(Msg_C_0_1, On_0_1) IPC_MESSAGE_HANDLER(Msg_C_0_2, On_0_2) @@ -137,6 +137,7 @@ class TestMessageReceiver { IPC_MESSAGE_HANDLER(Msg_R_3_3, On_3_3) IPC_MESSAGE_HANDLER(Msg_R_3_4, On_3_4) IPC_END_MESSAGE_MAP() + return true; } }; diff --git a/ipc/ipc_tests.cc b/ipc/ipc_tests.cc index aee01f5..925aeab 100644 --- a/ipc/ipc_tests.cc +++ b/ipc/ipc_tests.cc @@ -182,7 +182,7 @@ static void Send(IPC::Message::Sender* sender, const char* text) { class MyChannelListener : public IPC::Channel::Listener { public: - virtual void OnMessageReceived(const IPC::Message& message) { + virtual bool OnMessageReceived(const IPC::Message& message) { IPC::MessageIterator iter(message); iter.NextInt(); @@ -196,6 +196,7 @@ class MyChannelListener : public IPC::Channel::Listener { } else { Send(sender_, "Foo"); } + return true; } virtual void OnChannelError() { @@ -291,7 +292,7 @@ class ChannelListenerWithOnConnectedSend : public IPC::Channel::Listener { SendNextMessage(); } - virtual void OnMessageReceived(const IPC::Message& message) { + virtual bool OnMessageReceived(const IPC::Message& message) { IPC::MessageIterator iter(message); iter.NextInt(); @@ -299,6 +300,7 @@ class ChannelListenerWithOnConnectedSend : public IPC::Channel::Listener { const std::string big_string = iter.NextString(); EXPECT_EQ(kLongMessageStringNumBytes - 1, big_string.length()); SendNextMessage(); + return true; } virtual void OnChannelError() { @@ -402,7 +404,7 @@ class ChannelReflectorListener : public IPC::Channel::Listener { std::cout << "Client Latency: " << latency_messages_ << std::endl; } - virtual void OnMessageReceived(const IPC::Message& message) { + virtual bool OnMessageReceived(const IPC::Message& message) { count_messages_++; IPC::MessageIterator iter(message); int time = iter.NextInt(); @@ -421,6 +423,7 @@ class ChannelReflectorListener : public IPC::Channel::Listener { msg->WriteInt(msgid); msg->WriteString(payload); channel_->Send(msg); + return true; } private: IPC::Channel *channel_; @@ -446,7 +449,7 @@ class ChannelPerfListener : public IPC::Channel::Listener { std::cout << "Server Latency: " << latency_messages_ << std::endl; } - virtual void OnMessageReceived(const IPC::Message& message) { + virtual bool OnMessageReceived(const IPC::Message& message) { count_messages_++; // decode the string so this gets counted in the total time IPC::MessageIterator iter(message); @@ -467,7 +470,7 @@ class ChannelPerfListener : public IPC::Channel::Listener { msg->WriteString("quit"); channel_->Send(msg); SetTimer(NULL, 1, 250, (TIMERPROC) PostQuitMessage); - return; + return true; } IPC::Message* msg = new IPC::Message(0, @@ -477,6 +480,7 @@ class ChannelPerfListener : public IPC::Channel::Listener { msg->WriteInt(count_down_); msg->WriteString(payload_); channel_->Send(msg); + return true; } private: diff --git a/ipc/sync_socket_unittest.cc b/ipc/sync_socket_unittest.cc index 451f307..3598cf3 100644 --- a/ipc/sync_socket_unittest.cc +++ b/ipc/sync_socket_unittest.cc @@ -107,13 +107,14 @@ class SyncSocketServerListener : public IPC::Channel::Listener { chan_ = chan; } - virtual void OnMessageReceived(const IPC::Message& msg) { + virtual bool OnMessageReceived(const IPC::Message& msg) { if (msg.routing_id() == MSG_ROUTING_CONTROL) { IPC_BEGIN_MESSAGE_MAP(SyncSocketServerListener, msg) IPC_MESSAGE_HANDLER(MsgClassSetHandle, OnMsgClassSetHandle) IPC_MESSAGE_HANDLER(MsgClassShutdown, OnMsgClassShutdown) IPC_END_MESSAGE_MAP() } + return true; } private: @@ -175,12 +176,13 @@ class SyncSocketClientListener : public IPC::Channel::Listener { chan_ = chan; } - virtual void OnMessageReceived(const IPC::Message& msg) { + virtual bool OnMessageReceived(const IPC::Message& msg) { if (msg.routing_id() == MSG_ROUTING_CONTROL) { IPC_BEGIN_MESSAGE_MAP(SyncSocketClientListener, msg) IPC_MESSAGE_HANDLER(MsgClassResponse, OnMsgClassResponse) IPC_END_MESSAGE_MAP() } + return true; } private: |