OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stdint.h> | 5 #include <stdint.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/message_loop/message_loop.h" | |
16 #include "mojo/edk/embedder/platform_channel_pair.h" | 15 #include "mojo/edk/embedder/platform_channel_pair.h" |
17 #include "mojo/edk/embedder/platform_shared_buffer.h" | 16 #include "mojo/edk/embedder/platform_shared_buffer.h" |
18 #include "mojo/edk/embedder/scoped_platform_handle.h" | 17 #include "mojo/edk/embedder/scoped_platform_handle.h" |
19 #include "mojo/edk/embedder/simple_platform_support.h" | 18 #include "mojo/edk/embedder/simple_platform_support.h" |
20 #include "mojo/edk/system/channel.h" | 19 #include "mojo/edk/system/channel.h" |
21 #include "mojo/edk/system/channel_endpoint.h" | 20 #include "mojo/edk/system/channel_endpoint.h" |
22 #include "mojo/edk/system/channel_endpoint_id.h" | 21 #include "mojo/edk/system/channel_endpoint_id.h" |
23 #include "mojo/edk/system/incoming_endpoint.h" | 22 #include "mojo/edk/system/incoming_endpoint.h" |
24 #include "mojo/edk/system/message_pipe.h" | 23 #include "mojo/edk/system/message_pipe.h" |
25 #include "mojo/edk/system/message_pipe_dispatcher.h" | 24 #include "mojo/edk/system/message_pipe_dispatcher.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 91 } |
93 | 92 |
94 embedder::PlatformSupport* platform_support() { return &platform_support_; } | 93 embedder::PlatformSupport* platform_support() { return &platform_support_; } |
95 test::TestIOThread* io_thread() { return &io_thread_; } | 94 test::TestIOThread* io_thread() { return &io_thread_; } |
96 // Warning: It's up to the caller to ensure that the returned channel | 95 // Warning: It's up to the caller to ensure that the returned channel |
97 // is/remains valid. | 96 // is/remains valid. |
98 Channel* channels(size_t i) { return channels_[i].get(); } | 97 Channel* channels(size_t i) { return channels_[i].get(); } |
99 | 98 |
100 private: | 99 private: |
101 void SetUpOnIOThread() { | 100 void SetUpOnIOThread() { |
102 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 101 CHECK(io_thread()->IsCurrentAndRunning()); |
103 | 102 |
104 embedder::PlatformChannelPair channel_pair; | 103 embedder::PlatformChannelPair channel_pair; |
105 platform_handles_[0] = channel_pair.PassServerHandle(); | 104 platform_handles_[0] = channel_pair.PassServerHandle(); |
106 platform_handles_[1] = channel_pair.PassClientHandle(); | 105 platform_handles_[1] = channel_pair.PassClientHandle(); |
107 } | 106 } |
108 | 107 |
109 void TearDownOnIOThread() { | 108 void TearDownOnIOThread() { |
110 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 109 CHECK(io_thread()->IsCurrentAndRunning()); |
111 | 110 |
112 if (channels_[0]) { | 111 if (channels_[0]) { |
113 channels_[0]->Shutdown(); | 112 channels_[0]->Shutdown(); |
114 channels_[0] = nullptr; | 113 channels_[0] = nullptr; |
115 } | 114 } |
116 if (channels_[1]) { | 115 if (channels_[1]) { |
117 channels_[1]->Shutdown(); | 116 channels_[1]->Shutdown(); |
118 channels_[1] = nullptr; | 117 channels_[1] = nullptr; |
119 } | 118 } |
120 } | 119 } |
121 | 120 |
122 void CreateAndInitChannel(unsigned channel_index) { | 121 void CreateAndInitChannel(unsigned channel_index) { |
123 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 122 CHECK(io_thread()->IsCurrentAndRunning()); |
124 CHECK(channel_index == 0 || channel_index == 1); | 123 CHECK(channel_index == 0 || channel_index == 1); |
125 CHECK(!channels_[channel_index]); | 124 CHECK(!channels_[channel_index]); |
126 | 125 |
127 channels_[channel_index] = MakeRefCounted<Channel>(&platform_support_); | 126 channels_[channel_index] = MakeRefCounted<Channel>(&platform_support_); |
128 channels_[channel_index]->Init( | 127 channels_[channel_index]->Init( |
129 RawChannel::Create(platform_handles_[channel_index].Pass())); | 128 RawChannel::Create(platform_handles_[channel_index].Pass())); |
130 } | 129 } |
131 | 130 |
132 // TODO(vtl): The arguments should be rvalue references, but that doesn't | 131 // TODO(vtl): The arguments should be rvalue references, but that doesn't |
133 // currently work correctly with base::Bind. | 132 // currently work correctly with base::Bind. |
134 void BootstrapChannelEndpointsOnIOThread(RefPtr<ChannelEndpoint> ep0, | 133 void BootstrapChannelEndpointsOnIOThread(RefPtr<ChannelEndpoint> ep0, |
135 RefPtr<ChannelEndpoint> ep1) { | 134 RefPtr<ChannelEndpoint> ep1) { |
136 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 135 CHECK(io_thread()->IsCurrentAndRunning()); |
137 | 136 |
138 if (!channels_[0]) | 137 if (!channels_[0]) |
139 CreateAndInitChannel(0); | 138 CreateAndInitChannel(0); |
140 if (!channels_[1]) | 139 if (!channels_[1]) |
141 CreateAndInitChannel(1); | 140 CreateAndInitChannel(1); |
142 | 141 |
143 channels_[0]->SetBootstrapEndpoint(std::move(ep0)); | 142 channels_[0]->SetBootstrapEndpoint(std::move(ep0)); |
144 channels_[1]->SetBootstrapEndpoint(std::move(ep1)); | 143 channels_[1]->SetBootstrapEndpoint(std::move(ep1)); |
145 } | 144 } |
146 | 145 |
147 // TODO(vtl): |ep| should be an rvalue reference, but that doesn't currently | 146 // TODO(vtl): |ep| should be an rvalue reference, but that doesn't currently |
148 // work correctly with base::Bind. | 147 // work correctly with base::Bind. |
149 void BootstrapChannelEndpointOnIOThread(unsigned channel_index, | 148 void BootstrapChannelEndpointOnIOThread(unsigned channel_index, |
150 RefPtr<ChannelEndpoint> ep) { | 149 RefPtr<ChannelEndpoint> ep) { |
151 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 150 CHECK(io_thread()->IsCurrentAndRunning()); |
152 CHECK(channel_index == 0 || channel_index == 1); | 151 CHECK(channel_index == 0 || channel_index == 1); |
153 | 152 |
154 CreateAndInitChannel(channel_index); | 153 CreateAndInitChannel(channel_index); |
155 channels_[channel_index]->SetBootstrapEndpoint(std::move(ep)); | 154 channels_[channel_index]->SetBootstrapEndpoint(std::move(ep)); |
156 } | 155 } |
157 | 156 |
158 void RestoreInitialStateOnIOThread() { | 157 void RestoreInitialStateOnIOThread() { |
159 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 158 CHECK(io_thread()->IsCurrentAndRunning()); |
160 | 159 |
161 TearDownOnIOThread(); | 160 TearDownOnIOThread(); |
162 SetUpOnIOThread(); | 161 SetUpOnIOThread(); |
163 } | 162 } |
164 | 163 |
165 embedder::SimplePlatformSupport platform_support_; | 164 embedder::SimplePlatformSupport platform_support_; |
166 test::TestIOThread io_thread_; | 165 test::TestIOThread io_thread_; |
167 embedder::ScopedPlatformHandle platform_handles_[2]; | 166 embedder::ScopedPlatformHandle platform_handles_[2]; |
168 RefPtr<Channel> channels_[2]; | 167 RefPtr<Channel> channels_[2]; |
169 | 168 |
(...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 mp0->Close(0); | 1355 mp0->Close(0); |
1357 mp1->Close(1); | 1356 mp1->Close(1); |
1358 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 1357 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
1359 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. | 1358 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. |
1360 local_mp->Close(1); | 1359 local_mp->Close(1); |
1361 } | 1360 } |
1362 | 1361 |
1363 } // namespace | 1362 } // namespace |
1364 } // namespace system | 1363 } // namespace system |
1365 } // namespace mojo | 1364 } // namespace mojo |
OLD | NEW |