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