| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_EDK_TEST_SCOPED_IPC_SUPPORT_H_ | 5 #ifndef MOJO_EDK_TEST_SCOPED_IPC_SUPPORT_H_ |
| 6 #define MOJO_EDK_TEST_SCOPED_IPC_SUPPORT_H_ | 6 #define MOJO_EDK_TEST_SCOPED_IPC_SUPPORT_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "mojo/edk/embedder/master_process_delegate.h" | 9 #include "mojo/edk/embedder/master_process_delegate.h" |
| 10 #include "mojo/edk/embedder/platform_task_runner.h" | 10 #include "mojo/edk/embedder/platform_task_runner.h" |
| 11 #include "mojo/edk/embedder/process_delegate.h" | 11 #include "mojo/edk/embedder/process_delegate.h" |
| 12 #include "mojo/edk/embedder/process_type.h" | 12 #include "mojo/edk/embedder/process_type.h" |
| 13 #include "mojo/edk/embedder/scoped_platform_handle.h" | 13 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 14 #include "mojo/edk/embedder/slave_process_delegate.h" | 14 #include "mojo/edk/embedder/slave_process_delegate.h" |
| 15 #include "mojo/edk/util/waitable_event.h" | 15 #include "mojo/edk/util/waitable_event.h" |
| 16 #include "mojo/public/cpp/system/macros.h" | 16 #include "mojo/public/cpp/system/macros.h" |
| 17 | 17 |
| 18 namespace mojo { | 18 namespace mojo { |
| 19 namespace test { | 19 namespace test { |
| 20 | 20 |
| 21 namespace internal { | 21 namespace internal { |
| 22 | 22 |
| 23 class ScopedIPCSupportHelper { | 23 class ScopedIPCSupportHelper final { |
| 24 public: | 24 public: |
| 25 ScopedIPCSupportHelper(); | 25 ScopedIPCSupportHelper(); |
| 26 ~ScopedIPCSupportHelper(); | 26 ~ScopedIPCSupportHelper(); |
| 27 | 27 |
| 28 void Init(embedder::ProcessType process_type, | 28 void Init(embedder::ProcessType process_type, |
| 29 embedder::ProcessDelegate* process_delegate, | 29 embedder::ProcessDelegate* process_delegate, |
| 30 embedder::PlatformTaskRunnerRefPtr, | 30 embedder::PlatformTaskRunnerRefPtr, |
| 31 embedder::ScopedPlatformHandle platform_handle); | 31 embedder::ScopedPlatformHandle platform_handle); |
| 32 | 32 |
| 33 void OnShutdownCompleteImpl(); | 33 void OnShutdownCompleteImpl(); |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 embedder::PlatformTaskRunnerRefPtr io_thread_task_runner_; | 36 embedder::PlatformTaskRunnerRefPtr io_thread_task_runner_; |
| 37 | 37 |
| 38 // Set after shut down. | 38 // Set after shut down. |
| 39 util::ManualResetWaitableEvent event_; | 39 util::ManualResetWaitableEvent event_; |
| 40 | 40 |
| 41 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedIPCSupportHelper); | 41 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedIPCSupportHelper); |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 } // namespace internal | 44 } // namespace internal |
| 45 | 45 |
| 46 // A simple class that calls |mojo::embedder::InitIPCSupport()| (with | 46 // A simple class that calls |mojo::embedder::InitIPCSupport()| (with |
| 47 // |ProcessType::NONE|) on construction and |ShutdownIPCSupport()| on | 47 // |ProcessType::NONE|) on construction and |ShutdownIPCSupport()| on |
| 48 // destruction (or |ShutdownIPCSupportOnIOThread()| if destroyed on the I/O | 48 // destruction (or |ShutdownIPCSupportOnIOThread()| if destroyed on the I/O |
| 49 // thread). | 49 // thread). |
| 50 class ScopedIPCSupport : public embedder::ProcessDelegate { | 50 class ScopedIPCSupport final : public embedder::ProcessDelegate { |
| 51 public: | 51 public: |
| 52 explicit ScopedIPCSupport( | 52 explicit ScopedIPCSupport( |
| 53 embedder::PlatformTaskRunnerRefPtr io_thread_task_runner); | 53 embedder::PlatformTaskRunnerRefPtr io_thread_task_runner); |
| 54 ~ScopedIPCSupport() override; | 54 ~ScopedIPCSupport() override; |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 // |ProcessDelegate| implementation: | 57 // |ProcessDelegate| implementation: |
| 58 // Note: Executed on the I/O thread. | 58 // Note: Executed on the I/O thread. |
| 59 void OnShutdownComplete() override; | 59 void OnShutdownComplete() override; |
| 60 | 60 |
| 61 internal::ScopedIPCSupportHelper helper_; | 61 internal::ScopedIPCSupportHelper helper_; |
| 62 | 62 |
| 63 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedIPCSupport); | 63 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedIPCSupport); |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 // Like |ScopedIPCSupport|, but with |ProcessType::MASTER|. It will (optionally) | 66 // Like |ScopedIPCSupport|, but with |ProcessType::MASTER|. It will (optionally) |
| 67 // call a callback (on the I/O thread) on receiving |OnSlaveDisconnect()|. | 67 // call a callback (on the I/O thread) on receiving |OnSlaveDisconnect()|. |
| 68 class ScopedMasterIPCSupport : public embedder::MasterProcessDelegate { | 68 class ScopedMasterIPCSupport final : public embedder::MasterProcessDelegate { |
| 69 public: | 69 public: |
| 70 explicit ScopedMasterIPCSupport( | 70 explicit ScopedMasterIPCSupport( |
| 71 embedder::PlatformTaskRunnerRefPtr io_thread_task_runner); | 71 embedder::PlatformTaskRunnerRefPtr io_thread_task_runner); |
| 72 ScopedMasterIPCSupport( | 72 ScopedMasterIPCSupport( |
| 73 embedder::PlatformTaskRunnerRefPtr io_thread_task_runner, | 73 embedder::PlatformTaskRunnerRefPtr io_thread_task_runner, |
| 74 base::Callback<void(embedder::SlaveInfo slave_info)> on_slave_disconnect); | 74 base::Callback<void(embedder::SlaveInfo slave_info)> on_slave_disconnect); |
| 75 ~ScopedMasterIPCSupport() override; | 75 ~ScopedMasterIPCSupport() override; |
| 76 | 76 |
| 77 private: | 77 private: |
| 78 // |MasterProcessDelegate| implementation: | 78 // |MasterProcessDelegate| implementation: |
| 79 // Note: Executed on the I/O thread. | 79 // Note: Executed on the I/O thread. |
| 80 void OnShutdownComplete() override; | 80 void OnShutdownComplete() override; |
| 81 void OnSlaveDisconnect(embedder::SlaveInfo slave_info) override; | 81 void OnSlaveDisconnect(embedder::SlaveInfo slave_info) override; |
| 82 | 82 |
| 83 internal::ScopedIPCSupportHelper helper_; | 83 internal::ScopedIPCSupportHelper helper_; |
| 84 base::Callback<void(embedder::SlaveInfo slave_info)> on_slave_disconnect_; | 84 base::Callback<void(embedder::SlaveInfo slave_info)> on_slave_disconnect_; |
| 85 | 85 |
| 86 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedMasterIPCSupport); | 86 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedMasterIPCSupport); |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 // Like |ScopedIPCSupport|, but with |ProcessType::SLAVE|. It will (optionally) | 89 // Like |ScopedIPCSupport|, but with |ProcessType::SLAVE|. It will (optionally) |
| 90 // call a callback (on the I/O thread) on receiving |OnMasterDisconnect()|. | 90 // call a callback (on the I/O thread) on receiving |OnMasterDisconnect()|. |
| 91 class ScopedSlaveIPCSupport : public embedder::SlaveProcessDelegate { | 91 class ScopedSlaveIPCSupport final : public embedder::SlaveProcessDelegate { |
| 92 public: | 92 public: |
| 93 ScopedSlaveIPCSupport( | 93 ScopedSlaveIPCSupport( |
| 94 embedder::PlatformTaskRunnerRefPtr io_thread_task_runner, | 94 embedder::PlatformTaskRunnerRefPtr io_thread_task_runner, |
| 95 embedder::ScopedPlatformHandle platform_handle); | 95 embedder::ScopedPlatformHandle platform_handle); |
| 96 ScopedSlaveIPCSupport( | 96 ScopedSlaveIPCSupport( |
| 97 embedder::PlatformTaskRunnerRefPtr io_thread_task_runner, | 97 embedder::PlatformTaskRunnerRefPtr io_thread_task_runner, |
| 98 embedder::ScopedPlatformHandle platform_handle, | 98 embedder::ScopedPlatformHandle platform_handle, |
| 99 base::Closure on_master_disconnect); | 99 base::Closure on_master_disconnect); |
| 100 ~ScopedSlaveIPCSupport() override; | 100 ~ScopedSlaveIPCSupport() override; |
| 101 | 101 |
| 102 private: | 102 private: |
| 103 // |SlaveProcessDelegate| implementation: | 103 // |SlaveProcessDelegate| implementation: |
| 104 // Note: Executed on the I/O thread. | 104 // Note: Executed on the I/O thread. |
| 105 void OnShutdownComplete() override; | 105 void OnShutdownComplete() override; |
| 106 void OnMasterDisconnect() override; | 106 void OnMasterDisconnect() override; |
| 107 | 107 |
| 108 internal::ScopedIPCSupportHelper helper_; | 108 internal::ScopedIPCSupportHelper helper_; |
| 109 base::Closure on_master_disconnect_; | 109 base::Closure on_master_disconnect_; |
| 110 | 110 |
| 111 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedSlaveIPCSupport); | 111 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedSlaveIPCSupport); |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 } // namespace test | 114 } // namespace test |
| 115 } // namespace mojo | 115 } // namespace mojo |
| 116 | 116 |
| 117 #endif // MOJO_EDK_TEST_SCOPED_IPC_SUPPORT_H_ | 117 #endif // MOJO_EDK_TEST_SCOPED_IPC_SUPPORT_H_ |
| OLD | NEW |