Index: tools/ipc_fuzzer/replay/replay_process.cc |
diff --git a/tools/ipc_fuzzer/ipc_fuzzer_main.cc b/tools/ipc_fuzzer/replay/replay_process.cc |
similarity index 58% |
rename from tools/ipc_fuzzer/ipc_fuzzer_main.cc |
rename to tools/ipc_fuzzer/replay/replay_process.cc |
index 3fa1d48c034c5a07b1ab6f71fe82783434ae4a31..67b96edd259cd0678cf483ebfd6a1643d668feec 100644 |
--- a/tools/ipc_fuzzer/ipc_fuzzer_main.cc |
+++ b/tools/ipc_fuzzer/replay/replay_process.cc |
@@ -2,78 +2,34 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include <limits.h> |
-#include <list> |
+#include "tools/ipc_fuzzer/replay/replay_process.h" |
+#include <limits.h> |
+#include <string> |
#include "base/bind.h" |
#include "base/command_line.h" |
-#include "base/files/memory_mapped_file.h" |
+#include "base/files/file_path.h" |
#include "base/logging.h" |
-#include "base/memory/scoped_ptr.h" |
-#include "base/message_loop/message_loop.h" |
#include "base/posix/global_descriptors.h" |
Tom Sepez
2013/12/05 19:05:49
Ok. Would be nice if we didn't need posix-specifi
aedla
2013/12/05 23:16:21
Yes, I made ipc_fuzzer target linux-only. I would
|
#include "base/stl_util.h" |
-#include "base/synchronization/waitable_event.h" |
-#include "base/threading/thread.h" |
-#include "base/timer/timer.h" |
#include "chrome/common/chrome_switches.h" |
-#include "ipc/ipc_channel_proxy.h" |
#include "ipc/ipc_descriptors.h" |
-#include "ipc/ipc_listener.h" |
-#include "ipc/ipc_message.h" |
-#include "ipc/ipc_platform_file.h" |
#include "ipc/ipc_switches.h" |
-namespace { |
- |
-class IpcFuzzerProcess : public IPC::Listener { |
- public: |
- IpcFuzzerProcess(); |
- virtual ~IpcFuzzerProcess(); |
- |
- // Set up command line, logging, IO thread. |
- void Initialize(int argc, const char **argv); |
- |
- // Open a channel to the browser process. It will think we are a renderer. |
- void OpenChannel(); |
- |
- // Extract messages from a file specified by --ipc-fuzzer-testcase=. |
- bool OpenTestcase(); |
- |
- // Trigger the sending of messages to the browser. |
- void StartSendingMessages(); |
- |
- // IPC::Listener implementation. |
- virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
- virtual void OnChannelError() OVERRIDE; |
- |
- private: |
- bool ExtractMessages(const char *data, size_t len); |
- void SendNextMessage(); |
+namespace ipc_fuzzer { |
- scoped_ptr<IPC::ChannelProxy> channel_; |
- base::MessageLoop main_loop_; |
- base::Thread io_thread_; |
- base::WaitableEvent shutdown_event_; |
- scoped_ptr<base::Timer> timer_; |
- scoped_ptr<base::MemoryMappedFile> testcase_map_; |
- std::list<IPC::Message*> messages_; |
- |
- DISALLOW_COPY_AND_ASSIGN(IpcFuzzerProcess); |
-}; |
- |
-IpcFuzzerProcess::IpcFuzzerProcess() |
+ReplayProcess::ReplayProcess() |
: main_loop_(base::MessageLoop::TYPE_DEFAULT), |
io_thread_("Chrome_ChildIOThread"), |
shutdown_event_(true, false) { |
} |
-IpcFuzzerProcess::~IpcFuzzerProcess() { |
+ReplayProcess::~ReplayProcess() { |
channel_.reset(); |
STLDeleteElements(&messages_); |
} |
-void IpcFuzzerProcess::Initialize(int argc, const char **argv) { |
+void ReplayProcess::Initialize(int argc, const char **argv) { |
CommandLine::Init(argc, argv); |
// Log to default destination. |
@@ -90,7 +46,7 @@ void IpcFuzzerProcess::Initialize(int argc, const char **argv) { |
#endif |
} |
-void IpcFuzzerProcess::OpenChannel() { |
+void ReplayProcess::OpenChannel() { |
std::string channel_name = |
CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
switches::kProcessChannelID); |
@@ -102,7 +58,7 @@ void IpcFuzzerProcess::OpenChannel() { |
io_thread_.message_loop_proxy())); |
} |
-bool IpcFuzzerProcess::ExtractMessages(const char *data, size_t len) { |
+bool ReplayProcess::ExtractMessages(const char *data, size_t len) { |
const char* end = data + len; |
while (data < end) { |
@@ -130,7 +86,7 @@ bool IpcFuzzerProcess::ExtractMessages(const char *data, size_t len) { |
return true; |
} |
-bool IpcFuzzerProcess::OpenTestcase() { |
+bool ReplayProcess::OpenTestcase() { |
const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
if (!command_line.HasSwitch(switches::kIpcFuzzerTestcase)) { |
@@ -152,7 +108,7 @@ bool IpcFuzzerProcess::OpenTestcase() { |
return ExtractMessages(data, len); |
} |
-void IpcFuzzerProcess::SendNextMessage() { |
+void ReplayProcess::SendNextMessage() { |
if (messages_.empty()) { |
base::MessageLoop::current()->Quit(); |
return; |
@@ -164,35 +120,22 @@ void IpcFuzzerProcess::SendNextMessage() { |
channel_->Send(message); |
Tom Sepez
2013/12/05 19:05:49
check return value. this could fail.
aedla
2013/12/05 23:16:21
ChannelProxy::Send() doesn't actually return false
|
} |
-void IpcFuzzerProcess::StartSendingMessages() { |
+void ReplayProcess::Run() { |
timer_.reset(new base::Timer(false, true)); |
timer_->Start(FROM_HERE, |
base::TimeDelta::FromMilliseconds(1), |
- base::Bind(&IpcFuzzerProcess::SendNextMessage, |
+ base::Bind(&ReplayProcess::SendNextMessage, |
base::Unretained(this))); |
+ base::MessageLoop::current()->Run(); |
} |
-bool IpcFuzzerProcess::OnMessageReceived(const IPC::Message& msg) { |
+bool ReplayProcess::OnMessageReceived(const IPC::Message& msg) { |
return true; |
} |
-void IpcFuzzerProcess::OnChannelError() { |
+void ReplayProcess::OnChannelError() { |
LOG(ERROR) << "Channel error, quitting"; |
base::MessageLoop::current()->Quit(); |
} |
-} // namespace |
- |
-int main(int argc, const char **argv) { |
- IpcFuzzerProcess fuzzer; |
- fuzzer.Initialize(argc, argv); |
- fuzzer.OpenChannel(); |
- |
- if (!fuzzer.OpenTestcase()) |
- return 0; |
- |
- fuzzer.StartSendingMessages(); |
- |
- base::MessageLoop::current()->Run(); |
- return 0; |
-} |
+} // namespace ipc_fuzzer |