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 #include "mojo/edk/test/scoped_ipc_support.h" | 5 #include "mojo/edk/test/scoped_ipc_support.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "mojo/edk/embedder/embedder.h" | 9 #include "mojo/edk/embedder/embedder.h" |
10 | 10 |
| 11 using mojo::platform::PlatformHandleWatcher; |
11 using mojo::platform::ScopedPlatformHandle; | 12 using mojo::platform::ScopedPlatformHandle; |
12 using mojo::platform::TaskRunner; | 13 using mojo::platform::TaskRunner; |
13 using mojo::util::RefPtr; | 14 using mojo::util::RefPtr; |
14 | 15 |
15 namespace mojo { | 16 namespace mojo { |
16 namespace test { | 17 namespace test { |
17 | 18 |
18 namespace internal { | 19 namespace internal { |
19 | 20 |
20 ScopedIPCSupportHelper::ScopedIPCSupportHelper() {} | 21 ScopedIPCSupportHelper::ScopedIPCSupportHelper() {} |
21 | 22 |
22 ScopedIPCSupportHelper::~ScopedIPCSupportHelper() { | 23 ScopedIPCSupportHelper::~ScopedIPCSupportHelper() { |
23 if (io_thread_task_runner_->RunsTasksOnCurrentThread()) { | 24 if (io_task_runner_->RunsTasksOnCurrentThread()) { |
24 embedder::ShutdownIPCSupportOnIOThread(); | 25 embedder::ShutdownIPCSupportOnIOThread(); |
25 } else { | 26 } else { |
26 embedder::ShutdownIPCSupport(); | 27 embedder::ShutdownIPCSupport(); |
27 event_.Wait(); | 28 event_.Wait(); |
28 } | 29 } |
29 } | 30 } |
30 | 31 |
31 void ScopedIPCSupportHelper::Init(embedder::ProcessType process_type, | 32 void ScopedIPCSupportHelper::Init(embedder::ProcessType process_type, |
32 embedder::ProcessDelegate* process_delegate, | 33 embedder::ProcessDelegate* process_delegate, |
33 RefPtr<TaskRunner>&& io_thread_task_runner, | 34 RefPtr<TaskRunner>&& io_task_runner, |
| 35 PlatformHandleWatcher* io_watcher, |
34 ScopedPlatformHandle platform_handle) { | 36 ScopedPlatformHandle platform_handle) { |
35 io_thread_task_runner_ = std::move(io_thread_task_runner); | 37 io_task_runner_ = std::move(io_task_runner); |
| 38 io_watcher_ = io_watcher; |
36 // Note: Run delegate methods on the I/O thread. | 39 // Note: Run delegate methods on the I/O thread. |
37 embedder::InitIPCSupport(process_type, io_thread_task_runner_.Clone(), | 40 embedder::InitIPCSupport(process_type, io_task_runner_.Clone(), |
38 process_delegate, io_thread_task_runner_.Clone(), | 41 process_delegate, io_task_runner_.Clone(), |
39 platform_handle.Pass()); | 42 io_watcher_, platform_handle.Pass()); |
40 } | 43 } |
41 | 44 |
42 void ScopedIPCSupportHelper::OnShutdownCompleteImpl() { | 45 void ScopedIPCSupportHelper::OnShutdownCompleteImpl() { |
43 event_.Signal(); | 46 event_.Signal(); |
44 } | 47 } |
45 | 48 |
46 } // namespace internal | 49 } // namespace internal |
47 | 50 |
48 ScopedIPCSupport::ScopedIPCSupport(RefPtr<TaskRunner>&& io_thread_task_runner) { | 51 ScopedIPCSupport::ScopedIPCSupport(RefPtr<TaskRunner>&& io_task_runner, |
49 helper_.Init(embedder::ProcessType::NONE, this, | 52 PlatformHandleWatcher* io_watcher) { |
50 std::move(io_thread_task_runner), ScopedPlatformHandle()); | 53 helper_.Init(embedder::ProcessType::NONE, this, std::move(io_task_runner), |
| 54 io_watcher, ScopedPlatformHandle()); |
51 } | 55 } |
52 | 56 |
53 ScopedIPCSupport::~ScopedIPCSupport() { | 57 ScopedIPCSupport::~ScopedIPCSupport() { |
54 } | 58 } |
55 | 59 |
56 void ScopedIPCSupport::OnShutdownComplete() { | 60 void ScopedIPCSupport::OnShutdownComplete() { |
57 helper_.OnShutdownCompleteImpl(); | 61 helper_.OnShutdownCompleteImpl(); |
58 } | 62 } |
59 | 63 |
60 ScopedMasterIPCSupport::ScopedMasterIPCSupport( | 64 ScopedMasterIPCSupport::ScopedMasterIPCSupport( |
61 RefPtr<TaskRunner>&& io_thread_task_runner) { | 65 RefPtr<TaskRunner>&& io_task_runner, |
62 helper_.Init(embedder::ProcessType::MASTER, this, | 66 PlatformHandleWatcher* io_watcher) { |
63 std::move(io_thread_task_runner), ScopedPlatformHandle()); | 67 helper_.Init(embedder::ProcessType::MASTER, this, std::move(io_task_runner), |
| 68 io_watcher, ScopedPlatformHandle()); |
64 } | 69 } |
65 | 70 |
66 ScopedMasterIPCSupport::ScopedMasterIPCSupport( | 71 ScopedMasterIPCSupport::ScopedMasterIPCSupport( |
67 RefPtr<TaskRunner>&& io_thread_task_runner, | 72 RefPtr<TaskRunner>&& io_task_runner, |
| 73 PlatformHandleWatcher* io_watcher, |
68 std::function<void(embedder::SlaveInfo slave_info)>&& on_slave_disconnect) | 74 std::function<void(embedder::SlaveInfo slave_info)>&& on_slave_disconnect) |
69 : on_slave_disconnect_(std::move(on_slave_disconnect)) { | 75 : on_slave_disconnect_(std::move(on_slave_disconnect)) { |
70 helper_.Init(embedder::ProcessType::MASTER, this, | 76 helper_.Init(embedder::ProcessType::MASTER, this, std::move(io_task_runner), |
71 std::move(io_thread_task_runner), ScopedPlatformHandle()); | 77 io_watcher, ScopedPlatformHandle()); |
72 } | 78 } |
73 | 79 |
74 ScopedMasterIPCSupport::~ScopedMasterIPCSupport() { | 80 ScopedMasterIPCSupport::~ScopedMasterIPCSupport() { |
75 } | 81 } |
76 | 82 |
77 void ScopedMasterIPCSupport::OnShutdownComplete() { | 83 void ScopedMasterIPCSupport::OnShutdownComplete() { |
78 helper_.OnShutdownCompleteImpl(); | 84 helper_.OnShutdownCompleteImpl(); |
79 } | 85 } |
80 | 86 |
81 void ScopedMasterIPCSupport::OnSlaveDisconnect(embedder::SlaveInfo slave_info) { | 87 void ScopedMasterIPCSupport::OnSlaveDisconnect(embedder::SlaveInfo slave_info) { |
82 if (on_slave_disconnect_) | 88 if (on_slave_disconnect_) |
83 on_slave_disconnect_(slave_info); | 89 on_slave_disconnect_(slave_info); |
84 } | 90 } |
85 | 91 |
86 ScopedSlaveIPCSupport::ScopedSlaveIPCSupport( | 92 ScopedSlaveIPCSupport::ScopedSlaveIPCSupport( |
87 RefPtr<TaskRunner>&& io_thread_task_runner, | 93 RefPtr<TaskRunner>&& io_task_runner, |
| 94 PlatformHandleWatcher* io_watcher, |
88 ScopedPlatformHandle platform_handle) { | 95 ScopedPlatformHandle platform_handle) { |
89 helper_.Init(embedder::ProcessType::SLAVE, this, | 96 helper_.Init(embedder::ProcessType::SLAVE, this, std::move(io_task_runner), |
90 std::move(io_thread_task_runner), platform_handle.Pass()); | 97 io_watcher, platform_handle.Pass()); |
91 } | 98 } |
92 | 99 |
93 ScopedSlaveIPCSupport::ScopedSlaveIPCSupport( | 100 ScopedSlaveIPCSupport::ScopedSlaveIPCSupport( |
94 RefPtr<TaskRunner>&& io_thread_task_runner, | 101 RefPtr<TaskRunner>&& io_task_runner, |
| 102 PlatformHandleWatcher* io_watcher, |
95 ScopedPlatformHandle platform_handle, | 103 ScopedPlatformHandle platform_handle, |
96 std::function<void()>&& on_master_disconnect) | 104 std::function<void()>&& on_master_disconnect) |
97 : on_master_disconnect_(std::move(on_master_disconnect)) { | 105 : on_master_disconnect_(std::move(on_master_disconnect)) { |
98 helper_.Init(embedder::ProcessType::SLAVE, this, | 106 helper_.Init(embedder::ProcessType::SLAVE, this, std::move(io_task_runner), |
99 std::move(io_thread_task_runner), platform_handle.Pass()); | 107 io_watcher, platform_handle.Pass()); |
100 } | 108 } |
101 | 109 |
102 ScopedSlaveIPCSupport::~ScopedSlaveIPCSupport() { | 110 ScopedSlaveIPCSupport::~ScopedSlaveIPCSupport() { |
103 } | 111 } |
104 | 112 |
105 void ScopedSlaveIPCSupport::OnShutdownComplete() { | 113 void ScopedSlaveIPCSupport::OnShutdownComplete() { |
106 helper_.OnShutdownCompleteImpl(); | 114 helper_.OnShutdownCompleteImpl(); |
107 } | 115 } |
108 | 116 |
109 void ScopedSlaveIPCSupport::OnMasterDisconnect() { | 117 void ScopedSlaveIPCSupport::OnMasterDisconnect() { |
110 if (on_master_disconnect_) | 118 if (on_master_disconnect_) |
111 on_master_disconnect_(); | 119 on_master_disconnect_(); |
112 } | 120 } |
113 | 121 |
114 } // namespace test | 122 } // namespace test |
115 } // namespace mojo | 123 } // namespace mojo |
OLD | NEW |