diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-17 20:23:47 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-17 20:23:47 +0000 |
commit | 7edae3d068a840c998ad5db477e8ed793f5a3c07 (patch) | |
tree | 476eb556f0ffeabae80174d07cfbc16202440f90 /ipc | |
parent | 1fb0aca76730dfa439a426cc7a078ebf0f5652f5 (diff) | |
download | chromium_src-7edae3d068a840c998ad5db477e8ed793f5a3c07.zip chromium_src-7edae3d068a840c998ad5db477e8ed793f5a3c07.tar.gz chromium_src-7edae3d068a840c998ad5db477e8ed793f5a3c07.tar.bz2 |
Remove IPC::MessageIterator.
It's a rarely-used and completely unnecessary (and thin) wrapper around
PickleIterator.
Review URL: https://chromiumcodereview.appspot.com/11570038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173525 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/ipc_channel_win.cc | 18 | ||||
-rw-r--r-- | ipc/ipc_message_utils.cc | 17 | ||||
-rw-r--r-- | ipc/ipc_message_utils.h | 15 | ||||
-rw-r--r-- | ipc/ipc_tests.cc | 47 |
4 files changed, 42 insertions, 55 deletions
diff --git a/ipc/ipc_channel_win.cc b/ipc/ipc_channel_win.cc index 10af1fe..afed565 100644 --- a/ipc/ipc_channel_win.cc +++ b/ipc/ipc_channel_win.cc @@ -10,6 +10,7 @@ #include "base/bind.h" #include "base/compiler_specific.h" #include "base/logging.h" +#include "base/pickle.h" #include "base/process_util.h" #include "base/rand_util.h" #include "base/string_number_conversions.h" @@ -153,17 +154,24 @@ bool Channel::ChannelImpl::WillDispatchInputMessage(Message* msg) { void Channel::ChannelImpl::HandleHelloMessage(const Message& msg) { // The hello message contains one parameter containing the PID. - MessageIterator it = MessageIterator(msg); - int32 claimed_pid = it.NextInt(); - if (validate_client_ && (it.NextInt() != client_secret_)) { + PickleIterator it(msg); + int32 claimed_pid; + bool failed = !it.ReadInt(&claimed_pid); + + if (!failed && validate_client_) { + int32 secret; + failed = it.ReadInt(&secret) ? (secret != client_secret_) : true; + } + + if (failed) { NOTREACHED(); - // Something went wrong. Abort connection. Close(); listener()->OnChannelError(); return; } + peer_pid_ = claimed_pid; - // validation completed. + // Validation completed. validate_client_ = false; listener()->OnChannelConnected(claimed_pid); } diff --git a/ipc/ipc_message_utils.cc b/ipc/ipc_message_utils.cc index 4cc8494..5e7067e 100644 --- a/ipc/ipc_message_utils.cc +++ b/ipc/ipc_message_utils.cc @@ -256,23 +256,6 @@ LogData::LogData() LogData::~LogData() { } -MessageIterator::MessageIterator(const Message& m) : iter_(m) { -} - -int MessageIterator::NextInt() const { - int val = -1; - if (!iter_.ReadInt(&val)) - NOTREACHED(); - return val; -} - -const std::string MessageIterator::NextString() const { - std::string val; - if (!iter_.ReadString(&val)) - NOTREACHED(); - return val; -} - void ParamTraits<bool>::Log(const param_type& p, std::string* l) { l->append(p ? "true" : "false"); } diff --git a/ipc/ipc_message_utils.h b/ipc/ipc_message_utils.h index 19622b2..7300659 100644 --- a/ipc/ipc_message_utils.h +++ b/ipc/ipc_message_utils.h @@ -61,19 +61,6 @@ namespace IPC { struct ChannelHandle; -//----------------------------------------------------------------------------- -// An iterator class for reading the fields contained within a Message. -class IPC_EXPORT MessageIterator { - public: - explicit MessageIterator(const Message& m); - - int NextInt() const; - const std::string NextString() const; - - private: - mutable PickleIterator iter_; -}; - // ----------------------------------------------------------------------------- // How we send IPC message logs across channels. struct IPC_EXPORT LogData { @@ -93,8 +80,8 @@ struct IPC_EXPORT LogData { std::string params; }; - //----------------------------------------------------------------------------- + // A dummy struct to place first just to allow leading commas for all // members in the macro-generated constructor initializer lists. struct NoParams { diff --git a/ipc/ipc_tests.cc b/ipc/ipc_tests.cc index cecbf45..00a0f6e 100644 --- a/ipc/ipc_tests.cc +++ b/ipc/ipc_tests.cc @@ -21,6 +21,7 @@ #include "base/command_line.h" #include "base/debug/debug_on_start_win.h" #include "base/perftimer.h" +#include "base/pickle.h" #include "base/test/perf_test_suite.h" #include "base/test/test_suite.h" #include "base/threading/thread.h" @@ -185,11 +186,14 @@ static void Send(IPC::Sender* sender, const char* text) { class MyChannelListener : public IPC::Listener { public: virtual bool OnMessageReceived(const IPC::Message& message) { - IPC::MessageIterator iter(message); - - iter.NextInt(); - const std::string data = iter.NextString(); - const std::string big_string = iter.NextString(); + PickleIterator iter(message); + + int ignored; + EXPECT_TRUE(iter.ReadInt(&ignored)); + std::string data; + EXPECT_TRUE(iter.ReadString(&data)); + std::string big_string; + EXPECT_TRUE(iter.ReadString(&big_string)); EXPECT_EQ(kLongMessageStringNumBytes - 1, big_string.length()); @@ -339,11 +343,14 @@ class ChannelListenerWithOnConnectedSend : public IPC::Listener { } virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { - IPC::MessageIterator iter(message); - - iter.NextInt(); - const std::string data = iter.NextString(); - const std::string big_string = iter.NextString(); + PickleIterator iter(message); + + int ignored; + EXPECT_TRUE(iter.ReadInt(&ignored)); + std::string data; + EXPECT_TRUE(iter.ReadString(&data)); + std::string big_string; + EXPECT_TRUE(iter.ReadString(&big_string)); EXPECT_EQ(kLongMessageStringNumBytes - 1, big_string.length()); SendNextMessage(); return true; @@ -459,9 +466,11 @@ class ChannelReflectorListener : public IPC::Listener { virtual bool OnMessageReceived(const IPC::Message& message) { count_messages_++; - IPC::MessageIterator iter(message); - int time = iter.NextInt(); - int msgid = iter.NextInt(); + PickleIterator iter(message); + int time; + EXPECT_TRUE(iter.ReadInt(&time)); + int msgid; + EXPECT_TRUE(iter.ReadInt(&msgid)); std::string payload = iter.NextString(); latency_messages_ += GetTickCount() - time; @@ -505,15 +514,15 @@ class ChannelPerfListener : public IPC::Listener { virtual bool OnMessageReceived(const IPC::Message& message) { count_messages_++; - // decode the string so this gets counted in the total time - IPC::MessageIterator iter(message); - int time = iter.NextInt(); - int msgid = iter.NextInt(); + // Decode the string so this gets counted in the total time. + PickleIterator iter(message); + int time; + EXPECT_TRUE(iter.ReadInt(&time)); + int msgid; + EXPECT_TRUE(iter.ReadInt(&msgid)); std::string cur = iter.NextString(); latency_messages_ += GetTickCount() - time; - // cout << "perflistener got message" << endl; - count_down_--; if (count_down_ == 0) { IPC::Message* msg = new IPC::Message(0, |