Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Side by Side Diff: mojo/edk/test/scoped_ipc_support.h

Issue 1523883002: EDK: Add a PlatformHandleWatcher argument to embedder::InitIPCSupport(). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/embedder/embedder_unittest.cc ('k') | mojo/edk/test/scoped_ipc_support.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <functional> 8 #include <functional>
9 9
10 #include "mojo/edk/embedder/master_process_delegate.h" 10 #include "mojo/edk/embedder/master_process_delegate.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/slave_process_delegate.h" 13 #include "mojo/edk/embedder/slave_process_delegate.h"
14 #include "mojo/edk/platform/scoped_platform_handle.h" 14 #include "mojo/edk/platform/scoped_platform_handle.h"
15 #include "mojo/edk/platform/task_runner.h" 15 #include "mojo/edk/platform/task_runner.h"
16 #include "mojo/edk/util/ref_ptr.h" 16 #include "mojo/edk/util/ref_ptr.h"
17 #include "mojo/edk/util/waitable_event.h" 17 #include "mojo/edk/util/waitable_event.h"
18 #include "mojo/public/cpp/system/macros.h" 18 #include "mojo/public/cpp/system/macros.h"
19 19
20 namespace mojo { 20 namespace mojo {
21
22 namespace platform {
23 class PlatformHandleWatcher;
24 }
25
21 namespace test { 26 namespace test {
22 27
23 namespace internal { 28 namespace internal {
24 29
25 class ScopedIPCSupportHelper final { 30 class ScopedIPCSupportHelper final {
26 public: 31 public:
27 ScopedIPCSupportHelper(); 32 ScopedIPCSupportHelper();
28 ~ScopedIPCSupportHelper(); 33 ~ScopedIPCSupportHelper();
29 34
30 void Init(embedder::ProcessType process_type, 35 void Init(embedder::ProcessType process_type,
31 embedder::ProcessDelegate* process_delegate, 36 embedder::ProcessDelegate* process_delegate,
32 util::RefPtr<platform::TaskRunner>&& io_thread_task_runner, 37 util::RefPtr<platform::TaskRunner>&& io_task_runner,
38 platform::PlatformHandleWatcher* io_watcher,
33 platform::ScopedPlatformHandle platform_handle); 39 platform::ScopedPlatformHandle platform_handle);
34 40
35 void OnShutdownCompleteImpl(); 41 void OnShutdownCompleteImpl();
36 42
37 private: 43 private:
38 util::RefPtr<platform::TaskRunner> io_thread_task_runner_; 44 util::RefPtr<platform::TaskRunner> io_task_runner_;
45 platform::PlatformHandleWatcher* io_watcher_ = nullptr;
39 46
40 // Set after shut down. 47 // Set after shut down.
41 util::ManualResetWaitableEvent event_; 48 util::ManualResetWaitableEvent event_;
42 49
43 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedIPCSupportHelper); 50 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedIPCSupportHelper);
44 }; 51 };
45 52
46 } // namespace internal 53 } // namespace internal
47 54
48 // A simple class that calls |mojo::embedder::InitIPCSupport()| (with 55 // A simple class that calls |mojo::embedder::InitIPCSupport()| (with
49 // |ProcessType::NONE|) on construction and |ShutdownIPCSupport()| on 56 // |ProcessType::NONE|) on construction and |ShutdownIPCSupport()| on
50 // destruction (or |ShutdownIPCSupportOnIOThread()| if destroyed on the I/O 57 // destruction (or |ShutdownIPCSupportOnIOThread()| if destroyed on the I/O
51 // thread). 58 // thread).
52 class ScopedIPCSupport final : public embedder::ProcessDelegate { 59 class ScopedIPCSupport final : public embedder::ProcessDelegate {
53 public: 60 public:
54 explicit ScopedIPCSupport( 61 ScopedIPCSupport(util::RefPtr<platform::TaskRunner>&& io_task_runner,
55 util::RefPtr<platform::TaskRunner>&& io_thread_task_runner); 62 platform::PlatformHandleWatcher* io_watcher);
56 ~ScopedIPCSupport() override; 63 ~ScopedIPCSupport() override;
57 64
58 private: 65 private:
59 // |ProcessDelegate| implementation: 66 // |ProcessDelegate| implementation:
60 // Note: Executed on the I/O thread. 67 // Note: Executed on the I/O thread.
61 void OnShutdownComplete() override; 68 void OnShutdownComplete() override;
62 69
63 internal::ScopedIPCSupportHelper helper_; 70 internal::ScopedIPCSupportHelper helper_;
64 71
65 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedIPCSupport); 72 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedIPCSupport);
66 }; 73 };
67 74
68 // Like |ScopedIPCSupport|, but with |ProcessType::MASTER|. It will (optionally) 75 // Like |ScopedIPCSupport|, but with |ProcessType::MASTER|. It will (optionally)
69 // call a callback (on the I/O thread) on receiving |OnSlaveDisconnect()|. 76 // call a callback (on the I/O thread) on receiving |OnSlaveDisconnect()|.
70 class ScopedMasterIPCSupport final : public embedder::MasterProcessDelegate { 77 class ScopedMasterIPCSupport final : public embedder::MasterProcessDelegate {
71 public: 78 public:
72 explicit ScopedMasterIPCSupport( 79 ScopedMasterIPCSupport(util::RefPtr<platform::TaskRunner>&& io_task_runner,
73 util::RefPtr<platform::TaskRunner>&& io_thread_task_runner); 80 platform::PlatformHandleWatcher* io_watcher);
74 ScopedMasterIPCSupport( 81 ScopedMasterIPCSupport(util::RefPtr<platform::TaskRunner>&& io_task_runner,
75 util::RefPtr<platform::TaskRunner>&& io_thread_task_runner, 82 platform::PlatformHandleWatcher* io_watcher,
76 std::function<void(embedder::SlaveInfo slave_info)>&& 83 std::function<void(embedder::SlaveInfo slave_info)>&&
77 on_slave_disconnect); 84 on_slave_disconnect);
78 ~ScopedMasterIPCSupport() override; 85 ~ScopedMasterIPCSupport() override;
79 86
80 private: 87 private:
81 // |MasterProcessDelegate| implementation: 88 // |MasterProcessDelegate| implementation:
82 // Note: Executed on the I/O thread. 89 // Note: Executed on the I/O thread.
83 void OnShutdownComplete() override; 90 void OnShutdownComplete() override;
84 void OnSlaveDisconnect(embedder::SlaveInfo slave_info) override; 91 void OnSlaveDisconnect(embedder::SlaveInfo slave_info) override;
85 92
86 internal::ScopedIPCSupportHelper helper_; 93 internal::ScopedIPCSupportHelper helper_;
87 std::function<void(embedder::SlaveInfo slave_info)> on_slave_disconnect_; 94 std::function<void(embedder::SlaveInfo slave_info)> on_slave_disconnect_;
88 95
89 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedMasterIPCSupport); 96 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedMasterIPCSupport);
90 }; 97 };
91 98
92 // Like |ScopedIPCSupport|, but with |ProcessType::SLAVE|. It will (optionally) 99 // Like |ScopedIPCSupport|, but with |ProcessType::SLAVE|. It will (optionally)
93 // call a callback (on the I/O thread) on receiving |OnMasterDisconnect()|. 100 // call a callback (on the I/O thread) on receiving |OnMasterDisconnect()|.
94 class ScopedSlaveIPCSupport final : public embedder::SlaveProcessDelegate { 101 class ScopedSlaveIPCSupport final : public embedder::SlaveProcessDelegate {
95 public: 102 public:
96 ScopedSlaveIPCSupport( 103 ScopedSlaveIPCSupport(util::RefPtr<platform::TaskRunner>&& io_task_runner,
97 util::RefPtr<platform::TaskRunner>&& io_thread_task_runner, 104 platform::PlatformHandleWatcher* io_watcher,
98 platform::ScopedPlatformHandle platform_handle); 105 platform::ScopedPlatformHandle platform_handle);
99 ScopedSlaveIPCSupport( 106 ScopedSlaveIPCSupport(util::RefPtr<platform::TaskRunner>&& io_task_runner,
100 util::RefPtr<platform::TaskRunner>&& io_thread_task_runner, 107 platform::PlatformHandleWatcher* io_watcher,
101 platform::ScopedPlatformHandle platform_handle, 108 platform::ScopedPlatformHandle platform_handle,
102 std::function<void()>&& on_master_disconnect); 109 std::function<void()>&& on_master_disconnect);
103 ~ScopedSlaveIPCSupport() override; 110 ~ScopedSlaveIPCSupport() override;
104 111
105 private: 112 private:
106 // |SlaveProcessDelegate| implementation: 113 // |SlaveProcessDelegate| implementation:
107 // Note: Executed on the I/O thread. 114 // Note: Executed on the I/O thread.
108 void OnShutdownComplete() override; 115 void OnShutdownComplete() override;
109 void OnMasterDisconnect() override; 116 void OnMasterDisconnect() override;
110 117
111 internal::ScopedIPCSupportHelper helper_; 118 internal::ScopedIPCSupportHelper helper_;
112 std::function<void()> on_master_disconnect_; 119 std::function<void()> on_master_disconnect_;
113 120
114 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedSlaveIPCSupport); 121 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedSlaveIPCSupport);
115 }; 122 };
116 123
117 } // namespace test 124 } // namespace test
118 } // namespace mojo 125 } // namespace mojo
119 126
120 #endif // MOJO_EDK_TEST_SCOPED_IPC_SUPPORT_H_ 127 #endif // MOJO_EDK_TEST_SCOPED_IPC_SUPPORT_H_
OLDNEW
« no previous file with comments | « mojo/edk/embedder/embedder_unittest.cc ('k') | mojo/edk/test/scoped_ipc_support.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698