Home | History | Annotate | Download | only in replay
      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 
      5 #ifndef TOOLS_IPC_FUZZER_REPLAY_REPLAY_PROCESS_H_
      6 #define TOOLS_IPC_FUZZER_REPLAY_REPLAY_PROCESS_H_
      7 
      8 #include "base/memory/scoped_ptr.h"
      9 #include "base/message_loop/message_loop.h"
     10 #include "base/synchronization/waitable_event.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 
     18 namespace ipc_fuzzer {
     19 
     20 class ReplayProcess : public IPC::Listener {
     21  public:
     22   ReplayProcess();
     23   virtual ~ReplayProcess();
     24 
     25   // Set up command line, logging, IO thread. Returns true on success, false
     26   // otherwise.
     27   bool Initialize(int argc, const char** argv);
     28 
     29   // Open a channel to the browser process. It will think we are a renderer.
     30   void OpenChannel();
     31 
     32   // Extract messages from a file specified by --ipc-fuzzer-testcase=
     33   // Returns true on success, false otherwise.
     34   bool OpenTestcase();
     35 
     36   // Send messages to the browser.
     37   void Run();
     38 
     39   // IPC::Listener implementation.
     40   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
     41   virtual void OnChannelError() OVERRIDE;
     42 
     43  private:
     44   void SendNextMessage();
     45 
     46   scoped_ptr<IPC::ChannelProxy> channel_;
     47   base::MessageLoop main_loop_;
     48   base::Thread io_thread_;
     49   base::WaitableEvent shutdown_event_;
     50   scoped_ptr<base::Timer> timer_;
     51   MessageVector messages_;
     52   size_t message_index_;
     53 
     54   DISALLOW_COPY_AND_ASSIGN(ReplayProcess);
     55 };
     56 
     57 }  // namespace ipc_fuzzer
     58 
     59 #endif  // TOOLS_IPC_FUZZER_REPLAY_REPLAY_PROCESS_H_
     60