diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-01 23:48:34 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-01 23:48:34 +0000 |
commit | dc90da2c3f8c87baa8dcea7fbf0272001d771ecf (patch) | |
tree | 99baf8465918e25521eab024315a5aa9ce78734d /chrome/common | |
parent | bf1b47dfbe8294738c0db628af036e2fd363ddac (diff) | |
download | chromium_src-dc90da2c3f8c87baa8dcea7fbf0272001d771ecf.zip chromium_src-dc90da2c3f8c87baa8dcea7fbf0272001d771ecf.tar.gz chromium_src-dc90da2c3f8c87baa8dcea7fbf0272001d771ecf.tar.bz2 |
* Add ipc_tests unittest target to xcode project.
* Stub out ipc_channel_posix.cc to allow other code that depends on it to be compiled.
* Cleanup some ipc code a bit to compile on gcc.
* Remove unused IPC::Channel::ProcessPendingMessages()
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6181 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/ipc_channel.cc | 36 | ||||
-rw-r--r-- | chrome/common/ipc_channel.h | 28 | ||||
-rw-r--r-- | chrome/common/ipc_channel_posix.cc | 32 | ||||
-rw-r--r-- | chrome/common/ipc_channel_proxy.h | 2 | ||||
-rw-r--r-- | chrome/common/ipc_fuzzing_tests.cc | 19 | ||||
-rw-r--r-- | chrome/common/ipc_message_utils.h | 16 | ||||
-rw-r--r-- | chrome/common/ipc_sync_message.h | 9 | ||||
-rw-r--r-- | chrome/common/ipc_tests.cc | 25 | ||||
-rw-r--r-- | chrome/common/ipc_tests.h | 4 |
9 files changed, 100 insertions, 71 deletions
diff --git a/chrome/common/ipc_channel.cc b/chrome/common/ipc_channel.cc index 934ea9b..4ffadc3 100644 --- a/chrome/common/ipc_channel.cc +++ b/chrome/common/ipc_channel.cc @@ -362,42 +362,6 @@ bool Channel::ProcessOutgoingMessages(MessageLoopForIO::IOContext* context, return true; } -bool Channel::ProcessPendingMessages(DWORD max_wait_msec) { - return false; - // TODO(darin): this code is broken and leads to busy waiting -#if 0 - DCHECK(max_wait_msec <= 0x7FFFFFFF || max_wait_msec == INFINITE); - - HANDLE events[] = { - input_state_.overlapped.hEvent, - output_state_.overlapped.hEvent - }; - // Only deal with output messages if we have a connection on which to send - const int wait_count = waiting_connect_ ? 1 : 2; - DCHECK(wait_count <= _countof(events)); - - if (max_wait_msec) { - DWORD result = WaitForMultipleObjects(wait_count, events, FALSE, - max_wait_msec); - if (result == WAIT_TIMEOUT) - return true; - } - - bool rv = true; - for (int i = 0; i < wait_count; ++i) { - if (WaitForSingleObject(events[i], 0) == WAIT_OBJECT_0) { - if (i == 0 && processing_incoming_) { - rv = false; - DLOG(WARNING) << "Would recurse into ProcessIncomingMessages"; - } else { - OnObjectSignaled(events[i]); - } - } - } - return rv; -#endif -} - void Channel::OnIOCompleted(MessageLoopForIO::IOContext* context, DWORD bytes_transfered, DWORD error) { bool ok; diff --git a/chrome/common/ipc_channel.h b/chrome/common/ipc_channel.h index b69f962..4709166 100644 --- a/chrome/common/ipc_channel.h +++ b/chrome/common/ipc_channel.h @@ -14,8 +14,11 @@ namespace IPC { //------------------------------------------------------------------------------ -class Channel : public MessageLoopForIO::IOHandler, - public Message::Sender { +class Channel : public Message::Sender +#if defined(OS_WIN) + , public MessageLoopForIO::IOHandler +#endif + { // Security tests need access to the pipe handle. friend class ChannelTest; @@ -86,16 +89,8 @@ class Channel : public MessageLoopForIO::IOHandler, // virtual bool Send(Message* message); - // Process any pending incoming and outgoing messages. Wait for at most - // max_wait_msec for pending messages if there are none. Returns true if - // there were no pending messages or if pending messages were successfully - // processed. Returns false if there are pending messages that cannot be - // processed for some reason (e.g., because ProcessIncomingMessages would be - // re-entered). - // TODO(darin): Need a better way of dealing with the recursion problem. - bool ProcessPendingMessages(DWORD max_wait_msec); - private: +#if defined(OS_WIN) const std::wstring PipeName(const std::wstring& channel_id) const; bool CreatePipe(const std::wstring& channel_id, Mode mode); bool ProcessConnection(); @@ -107,12 +102,14 @@ class Channel : public MessageLoopForIO::IOHandler, // MessageLoop::IOHandler implementation. virtual void OnIOCompleted(MessageLoopForIO::IOContext* context, DWORD bytes_transfered, DWORD error); +#endif private: enum { BUF_SIZE = 4096 }; +#if defined(OS_WIN) struct State { explicit State(Channel* channel); ~State(); @@ -124,6 +121,7 @@ class Channel : public MessageLoopForIO::IOHandler, State output_state_; HANDLE pipe_; +#endif Listener* listener_; // Messages to be sent are queued here. @@ -153,10 +151,10 @@ class Channel : public MessageLoopForIO::IOHandler, // just the process id (pid). The message has a special routing_id // (MSG_ROUTING_NONE) and type (HELLO_MESSAGE_TYPE). enum { - HELLO_MESSAGE_TYPE = MAXWORD // Maximum value of message type (WORD), - // to avoid conflicting with normal - // message types, which are enumeration - // constants starting from 0. + HELLO_MESSAGE_TYPE = kuint16max // Maximum value of message type (uint16), + // to avoid conflicting with normal + // message types, which are enumeration + // constants starting from 0. }; }; diff --git a/chrome/common/ipc_channel_posix.cc b/chrome/common/ipc_channel_posix.cc new file mode 100644 index 0000000..4cfcfe6 --- /dev/null +++ b/chrome/common/ipc_channel_posix.cc @@ -0,0 +1,32 @@ +// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/common/ipc_channel.h" + + +namespace IPC { + +// TODO(playmobil): implement. + +//------------------------------------------------------------------------------ + +Channel::Channel(const std::wstring& channel_id, Mode mode, Listener* listener) + : factory_(this) { + NOTREACHED(); +} + +void Channel::Close() { + NOTREACHED(); +} + +bool Channel::Send(Message* message) { + NOTREACHED(); + return false; +} + +bool Channel::Connect() { + NOTREACHED(); + return false; +} +} // namespace IPC diff --git a/chrome/common/ipc_channel_proxy.h b/chrome/common/ipc_channel_proxy.h index 59c8e47..6b9d777 100644 --- a/chrome/common/ipc_channel_proxy.h +++ b/chrome/common/ipc_channel_proxy.h @@ -171,7 +171,7 @@ class ChannelProxy : public Message::Sender { Channel::Listener* listener_; // List of filters. This is only accessed on the IPC thread. - std::vector<scoped_refptr<MessageFilter>> filters_; + std::vector<scoped_refptr<MessageFilter> > filters_; MessageLoop* ipc_message_loop_; Channel* channel_; std::wstring channel_id_; diff --git a/chrome/common/ipc_fuzzing_tests.cc b/chrome/common/ipc_fuzzing_tests.cc index 4b7563b..9216df9 100644 --- a/chrome/common/ipc_fuzzing_tests.cc +++ b/chrome/common/ipc_fuzzing_tests.cc @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <windows.h> #include <stdio.h> #include <iostream> #include <string> @@ -10,6 +9,8 @@ #include "chrome/common/ipc_tests.h" +#include "base/platform_thread.h" +#include "base/process_util.h" #include "chrome/common/ipc_channel.h" #include "chrome/common/ipc_channel_proxy.h" #include "chrome/common/ipc_message_utils.h" @@ -209,7 +210,7 @@ class FuzzerServerListener : public SimpleListener { std::wostringstream wos; wos << L"IPC fuzzer:" << caller << " [" << value << L" " << text << L"]\n"; std::wstring output = wos.str(); - ::OutputDebugStringW(output.c_str()); + LOG(WARNING) << output.c_str(); }; int message_count_; @@ -275,9 +276,9 @@ bool RunFuzzServer() { // This test makes sure that the FuzzerClientListener and FuzzerServerListener // are working properly by generating two well formed IPC calls. TEST(IPCFuzzingTest, SanityTest) { - HANDLE server_process = SpawnChild(FUZZER_SERVER); + base::ProcessHandle server_process = SpawnChild(FUZZER_SERVER); ASSERT_TRUE(server_process); - ::Sleep(1000); + PlatformThread::Sleep(1000); FuzzerClientListener listener; IPC::Channel chan(kFuzzerChannel, IPC::Channel::MODE_CLIENT, &listener); @@ -294,7 +295,7 @@ TEST(IPCFuzzingTest, SanityTest) { chan.Send(msg); EXPECT_TRUE(listener.ExpectMessage(value, MsgClassSI::ID)); - ASSERT_EQ(WAIT_OBJECT_0, ::WaitForSingleObject(server_process, 5000)); + EXPECT_TRUE(base::WaitForSingleProcess(server_process, 5000)); } // This test uses a payload that is smaller than expected. @@ -304,7 +305,7 @@ TEST(IPCFuzzingTest, SanityTest) { // properly. #ifdef NDEBUG TEST(IPCFuzzingTest, MsgBadPayloadShort) { - HANDLE server_process = SpawnChild(FUZZER_SERVER); + base::ProcessHandle server_process = SpawnChild(FUZZER_SERVER); ASSERT_TRUE(server_process); ::Sleep(1000); FuzzerClientListener listener; @@ -333,9 +334,9 @@ TEST(IPCFuzzingTest, MsgBadPayloadShort) { // This test does not pinpoint a flaw (per se) as by design we don't carry // type information on the IPC message. TEST(IPCFuzzingTest, MsgBadPayloadArgs) { - HANDLE server_process = SpawnChild(FUZZER_SERVER); + base::ProcessHandle server_process = SpawnChild(FUZZER_SERVER); ASSERT_TRUE(server_process); - ::Sleep(1000); + PlatformThread::Sleep(1000); FuzzerClientListener listener; IPC::Channel chan(kFuzzerChannel, IPC::Channel::MODE_CLIENT, &listener); @@ -355,7 +356,7 @@ TEST(IPCFuzzingTest, MsgBadPayloadArgs) { chan.Send(msg); EXPECT_TRUE(listener.ExpectMessage(3, MsgClassIS::ID)); - ASSERT_EQ(WAIT_OBJECT_0, ::WaitForSingleObject(server_process, 5000)); + EXPECT_TRUE(base::WaitForSingleProcess(server_process, 5000)); } // This class is for testing the IPC_BEGIN_MESSAGE_MAP_EX macros. diff --git a/chrome/common/ipc_message_utils.h b/chrome/common/ipc_message_utils.h index 4fd66e1..af61c85 100644 --- a/chrome/common/ipc_message_utils.h +++ b/chrome/common/ipc_message_utils.h @@ -255,6 +255,7 @@ struct ParamTraits<base::Time> { } }; +#if defined(OS_WIN) template <> struct ParamTraits<LOGFONT> { typedef LOGFONT param_type; @@ -299,6 +300,7 @@ struct ParamTraits<MSG> { return result; } }; +#endif // defined(OS_WIN) template <> struct ParamTraits<SkBitmap> { @@ -423,7 +425,7 @@ struct ParamTraits<std::map<K, V> > { typedef std::map<K, V> param_type; static void Write(Message* m, const param_type& p) { WriteParam(m, static_cast<int>(p.size())); - param_type::const_iterator iter; + typename param_type::const_iterator iter; for (iter = p.begin(); iter != p.end(); ++iter) { WriteParam(m, iter->first); WriteParam(m, iter->second); @@ -471,6 +473,7 @@ struct ParamTraits<GURL> { }; // and, a few more useful types... +#if defined(OS_WIN) template <> struct ParamTraits<HANDLE> { typedef HANDLE param_type; @@ -580,6 +583,7 @@ struct ParamTraits<POINT> { l->append(StringPrintf(L"(%d, %d)", p.x, p.y)); } }; +#endif // defined(OS_WIN) template <> struct ParamTraits<gfx::Point> { @@ -723,6 +727,7 @@ struct ParamTraits<CacheManager::ResourceTypeStats> { } }; +#if defined(OS_WIN) template <> struct ParamTraits<XFORM> { typedef XFORM param_type; @@ -746,6 +751,7 @@ struct ParamTraits<XFORM> { l->append(L"<XFORM>"); } }; +#endif // defined(OS_WIN) template <> struct ParamTraits<WebCursor> { @@ -975,7 +981,7 @@ struct ParamTraits<webkit_glue::WebApplicationInfo> { template <class Param> class MessageWithTuple : public Message { public: - MessageWithTuple(int32 routing_id, WORD type, const Param& p) + MessageWithTuple(int32 routing_id, uint16 type, const Param& p) : Message(routing_id, type, PRIORITY_NORMAL) { WriteParam(this, p); } @@ -1086,7 +1092,7 @@ void GenerateLogData(const std::wstring& channel, const Message& message, template <class SendParam, class ReplyParam> class MessageWithReply : public SyncMessage { public: - MessageWithReply(int32 routing_id, WORD type, + MessageWithReply(int32 routing_id, uint16 type, const SendParam& send, const ReplyParam& reply) : SyncMessage(routing_id, type, PRIORITY_NORMAL, new ParamDeserializer<ReplyParam>(reply)) { @@ -1108,7 +1114,7 @@ class MessageWithReply : public SyncMessage { } else { // This is an outgoing reply. Now that we have the output parameters, we // can finally log the message. - ReplyParam::ValueTuple p; + typename ReplyParam::ValueTuple p; void* iter = SyncMessage::GetDataIterator(msg); ReadParam(msg, &iter, &p); LogParam(p, l); @@ -1122,7 +1128,7 @@ class MessageWithReply : public SyncMessage { Message* reply = GenerateReply(msg); bool error; if (ReadParam(msg, &iter, &send_params)) { - ReplyParam::ValueTuple reply_params; + typename ReplyParam::ValueTuple reply_params; DispatchToMethod(obj, func, send_params, &reply_params); WriteParam(reply, reply_params); error = false; diff --git a/chrome/common/ipc_sync_message.h b/chrome/common/ipc_sync_message.h index 86cb62f..116e6c7 100644 --- a/chrome/common/ipc_sync_message.h +++ b/chrome/common/ipc_sync_message.h @@ -5,7 +5,9 @@ #ifndef CHROME_COMMON_IPC_SYNC_MESSAGE_H__ #define CHROME_COMMON_IPC_SYNC_MESSAGE_H__ +#if defined(OS_WIN) #include <windows.h> +#endif #include <string> #include "base/basictypes.h" #include "chrome/common/ipc_message.h" @@ -16,7 +18,7 @@ class MessageReplyDeserializer; class SyncMessage : public Message { public: - SyncMessage(int32 routing_id, WORD type, PriorityValue priority, + SyncMessage(int32 routing_id, uint16 type, PriorityValue priority, MessageReplyDeserializer* deserializer); // Call this to get a deserializer for the output parameters. @@ -24,6 +26,8 @@ class SyncMessage : public Message { // for deleting the deserializer when they're done. MessageReplyDeserializer* GetReplyDeserializer(); +// TODO(playmobil): reimplement on POSIX. +#if defined(OS_WIN) // If this message can cause the receiver to block while waiting for user // input (i.e. by calling MessageBox), then the caller needs to pump window // messages and dispatch asynchronous messages while waiting for the reply. @@ -44,6 +48,7 @@ class SyncMessage : public Message { void EnableMessagePumping(); HANDLE pump_messages_event() const { return pump_messages_event_; } +#endif // defined(OS_WIN) // Returns true if the message is a reply to the given request id. static bool IsMessageReplyTo(const Message& msg, int request_id); @@ -68,7 +73,9 @@ class SyncMessage : public Message { static bool WriteSyncHeader(Message* msg, const SyncHeader& header); MessageReplyDeserializer* deserializer_; +#if defined(OS_WIN) HANDLE pump_messages_event_; +#endif static uint32 next_id_; // for generation of unique ids }; diff --git a/chrome/common/ipc_tests.cc b/chrome/common/ipc_tests.cc index 251e970..e0c14c8 100644 --- a/chrome/common/ipc_tests.cc +++ b/chrome/common/ipc_tests.cc @@ -2,7 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if defined(OS_WIN) #include <windows.h> +#endif #include <stdio.h> #include <iostream> #include <string> @@ -15,6 +17,7 @@ #include "base/debug_on_start.h" #include "base/perftimer.h" #include "base/process_util.h" +#include "base/scoped_nsautorelease_pool.h" #include "base/thread.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/ipc_channel.h" @@ -89,7 +92,7 @@ class MyChannelListener : public IPC::Channel::Listener { virtual void OnMessageReceived(const IPC::Message& message) { IPC::MessageIterator iter(message); - int index = iter.NextInt(); + iter.NextInt(); const std::string data = iter.NextString(); if (--messages_left_ == 0) { @@ -116,6 +119,8 @@ class MyChannelListener : public IPC::Channel::Listener { }; static MyChannelListener channel_listener; +// TODO(playmobil): Implement +#if defined(OS_WIN) TEST(IPCChannelTest, ChannelTest) { // setup IPC channel IPC::Channel chan(kTestClientChannel, IPC::Channel::MODE_SERVER, @@ -164,6 +169,7 @@ TEST(IPCChannelTest, ChannelProxyTest) { } thread.Stop(); } +#endif // defined(OS_WIN) static bool RunTestClient() { // setup IPC channel @@ -176,7 +182,6 @@ static bool RunTestClient() { MessageLoop::current()->Run(); return true; } - #endif // !PERFORMANCE_TEST #ifdef PERFORMANCE_TEST @@ -340,6 +345,8 @@ static bool RunReflector() { #endif // PERFORMANCE_TEST +// TODO(playmobil): Implement +#if defined(OS_WIN) // All fatal log messages (e.g. DCHECK failures) imply unit test failures static void IPCTestAssertHandler(const std::string& str) { FAIL() << str; @@ -382,9 +389,21 @@ HANDLE SpawnChild(ChildType child_type) { return process; } +#endif // defined(OS_WIN) + +// TODO(playmobil): Implement +#if defined(OS_POSIX) +base::ProcessHandle SpawnChild(ChildType child_type) { + NOTIMPLEMENTED(); + return NULL; +} +#endif + int main(int argc, char** argv) { + base::ScopedNSAutoreleasePool scoped_pool; base::EnableTerminationOnHeapCorruption(); +#if defined(OS_WIN) // Some tests may use base::Singleton<>, thus we need to instanciate // the AtExitManager or else we will leak objects. base::AtExitManager at_exit_manager; @@ -396,6 +415,7 @@ int main(int argc, char** argv) { SuppressErrorDialogs(); logging::SetLogAssertHandler(IPCTestAssertHandler); } +#endif // defined(OS_WIN) #ifndef PERFORMANCE_TEST if (CommandLine().HasSwitch(kChild)) @@ -413,4 +433,3 @@ int main(int argc, char** argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } - diff --git a/chrome/common/ipc_tests.h b/chrome/common/ipc_tests.h index e4ef4ce..ceac51a 100644 --- a/chrome/common/ipc_tests.h +++ b/chrome/common/ipc_tests.h @@ -5,6 +5,8 @@ #ifndef CHROME_COMMON_IPC_TESTS_H__ #define CHROME_COMMON_IPC_TESTS_H__ +#include "base/process.h" + // This unit test uses 3 types of child processes, a regular pipe client, // a client reflector and a IPC server used for fuzzing tests. enum ChildType { @@ -20,7 +22,7 @@ extern const wchar_t kFuzzerChannel[]; // Spawns a child process and then runs the code for one of the 3 possible // child modes. -HANDLE SpawnChild(ChildType child_type); +base::ProcessHandle SpawnChild(ChildType child_type); // Runs the fuzzing server child mode. Returns true when the preset number // of messages have been received. |