replay_process.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef TOOLS_IPC_FUZZER_REPLAY_REPLAY_PROCESS_H_
  5. #define TOOLS_IPC_FUZZER_REPLAY_REPLAY_PROCESS_H_
  6. #include <stddef.h>
  7. #include <memory>
  8. #include "base/macros.h"
  9. #include "base/synchronization/waitable_event.h"
  10. #include "base/task/single_thread_task_executor.h"
  11. #include "base/threading/thread.h"
  12. #include "base/timer/timer.h"
  13. #include "ipc/ipc_channel_proxy.h"
  14. #include "ipc/ipc_listener.h"
  15. #include "ipc/ipc_message.h"
  16. #include "tools/ipc_fuzzer/message_lib/message_file.h"
  17. namespace mojo {
  18. class IncomingInvitation;
  19. namespace core {
  20. class ScopedIPCSupport;
  21. } // namespace core
  22. } // namespace mojo
  23. namespace ipc_fuzzer {
  24. class ReplayProcess : public IPC::Listener {
  25. public:
  26. ReplayProcess();
  27. ~ReplayProcess() override;
  28. // Set up command line, logging, IO thread. Returns true on success, false
  29. // otherwise.
  30. bool Initialize(int argc, const char** argv);
  31. // Open a channel to the browser process. It will think we are a renderer.
  32. void OpenChannel();
  33. // Extract messages from a file specified by --ipc-fuzzer-testcase=
  34. // Returns true on success, false otherwise.
  35. bool OpenTestcase();
  36. // Send messages to the browser.
  37. void Run();
  38. // IPC::Listener implementation.
  39. bool OnMessageReceived(const IPC::Message& message) override;
  40. void OnChannelError() override;
  41. private:
  42. void SendNextMessage();
  43. std::unique_ptr<mojo::core::ScopedIPCSupport> mojo_ipc_support_;
  44. std::unique_ptr<mojo::IncomingInvitation> mojo_invitation_;
  45. std::unique_ptr<IPC::ChannelProxy> channel_;
  46. base::SingleThreadTaskExecutor main_task_executor_;
  47. base::Thread io_thread_;
  48. base::WaitableEvent shutdown_event_;
  49. MessageVector messages_;
  50. size_t message_index_;
  51. DISALLOW_COPY_AND_ASSIGN(ReplayProcess);
  52. };
  53. } // namespace ipc_fuzzer
  54. #endif // TOOLS_IPC_FUZZER_REPLAY_REPLAY_PROCESS_H_