Chromium Code Reviews| Index: test/win/win_multiprocess.h |
| diff --git a/test/win/win_multiprocess.h b/test/win/win_multiprocess.h |
| index 3d5e1e5178d75bdc4f24f5ce3570698fa9b51191..815348ac42636102d87a34efcb5a9972820c0857 100644 |
| --- a/test/win/win_multiprocess.h |
| +++ b/test/win/win_multiprocess.h |
| @@ -18,6 +18,8 @@ |
| #include <windows.h> |
| #include "base/basictypes.h" |
| +#include "gtest/gtest.h" |
| +#include "test/win/win_child_process.h" |
| #include "util/file/file_io.h" |
| #include "util/win/scoped_handle.h" |
| @@ -36,7 +38,17 @@ class WinMultiprocess { |
| //! |
| //! In the parent process, WinMultiprocessParent() is run, and in the child |
| //! WinMultiprocessChild(). |
| - void Run(); |
| + template <class T> |
| + static void Run() { |
| + ASSERT_NO_FATAL_FAILURE( |
| + WinChildProcess::EntryPoint<ChildProcessHelper<T>>()); |
| + // If WinChildProcess::EntryPoint returns, we are in the parent process. |
| + scoped_ptr<WinChildProcess::Handles> child_handles = WinChildProcess::Launch(); |
|
scottmg
2015/06/01 21:53:22
80 col
erikwright (departed)
2015/06/24 20:01:35
Done.
|
| + ASSERT_TRUE(child_handles.get()); |
| + T parent_process; |
| + parent_process.child_handles_ = child_handles.get(); |
| + static_cast<WinMultiprocess*>(&parent_process)->WinMultiprocessParent(); |
| + } |
| protected: |
| virtual ~WinMultiprocess(); |
| @@ -82,6 +94,40 @@ class WinMultiprocess { |
| HANDLE ChildProcess() const; |
| private: |
| + // Implements an adapter to provide WinMultiprocess with access to the |
| + // anonymous pipe handles from WinChildProcess. |
| + class ChildProcessHelperBase : public WinChildProcess { |
| + public: |
| + ChildProcessHelperBase() {} |
| + ~ChildProcessHelperBase() override {} |
| + |
| + void CloseWritePipeForwarder() { CloseWritePipe(); } |
| + void CloseReadPipeForwarder() { CloseReadPipe(); } |
| + FileHandle ReadPipeHandleForwarder() const { return ReadPipeHandle(); } |
| + FileHandle WritePipeHandleForwarder() const { return WritePipeHandle(); } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(ChildProcessHelperBase); |
| + }; |
| + |
| + // Forwards WinChildProcess::Run to T::WinMultiprocessChild. |
| + template <class T> |
| + class ChildProcessHelper : public ChildProcessHelperBase { |
| + public: |
| + ChildProcessHelper() {} |
| + ~ChildProcessHelper() override {} |
| + |
| + private: |
| + void Run() override { |
| + T child_process; |
| + child_process.child_process_helper_ = this; |
| + static_cast<WinMultiprocess*>(&child_process)->WinMultiprocessChild(); |
| + exit(0); |
| + } |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ChildProcessHelper); |
| + }; |
| + |
| //! \brief The subclass-provided parent routine. |
| //! |
| //! Test failures should be reported via gtest: `EXPECT_*()`, `ASSERT_*()`, |
| @@ -91,7 +137,8 @@ class WinMultiprocess { |
| //! the child process to exit, as this is handled by this class. |
| //! |
| //! Subclasses must implement this method to define how the parent operates. |
| - virtual void WinMultiprocessParent() = 0; |
| + virtual void |
|
scottmg
2015/06/01 21:53:22
extra \n
erikwright (departed)
2015/06/24 20:01:35
Done.
|
| + WinMultiprocessParent() = 0; |
| //! \brief The subclass-provided child routine. |
| //! |
| @@ -104,11 +151,8 @@ class WinMultiprocess { |
| //! method. |
| virtual void WinMultiprocessChild() = 0; |
| - ScopedFileHANDLE pipe_c2p_read_; |
| - ScopedFileHANDLE pipe_c2p_write_; |
| - ScopedFileHANDLE pipe_p2c_read_; |
| - ScopedFileHANDLE pipe_p2c_write_; |
| - ScopedKernelHANDLE child_handle_; |
| + WinChildProcess::Handles* child_handles_; |
| + ChildProcessHelperBase* child_process_helper_; |
| DISALLOW_COPY_AND_ASSIGN(WinMultiprocess); |
| }; |