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 <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/files/scoped_file.h" | 14 #include "base/files/scoped_file.h" |
15 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
16 #include "base/location.h" | 16 #include "base/location.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
20 #include "base/test/test_io_thread.h" | 20 #include "base/test/test_io_thread.h" |
21 #include "base/threading/platform_thread.h" // For |Sleep()|. | 21 #include "base/threading/platform_thread.h" // For |Sleep()|. |
22 #include "build/build_config.h" // TODO(vtl): Remove this. | 22 #include "build/build_config.h" // TODO(vtl): Remove this. |
23 #include "mojo/common/test/test_utils.h" | 23 #include "mojo/common/test/test_utils.h" |
24 #include "mojo/embedder/platform_channel_pair.h" | 24 #include "mojo/embedder/platform_channel_pair.h" |
25 #include "mojo/embedder/platform_shared_buffer.h" | 25 #include "mojo/embedder/platform_shared_buffer.h" |
26 #include "mojo/embedder/scoped_platform_handle.h" | 26 #include "mojo/embedder/scoped_platform_handle.h" |
27 #include "mojo/embedder/simple_platform_support.h" | 27 #include "mojo/embedder/simple_platform_support.h" |
28 #include "mojo/system/channel.h" | 28 #include "mojo/system/channel.h" |
| 29 #include "mojo/system/channel_endpoint.h" |
29 #include "mojo/system/message_pipe.h" | 30 #include "mojo/system/message_pipe.h" |
30 #include "mojo/system/message_pipe_dispatcher.h" | 31 #include "mojo/system/message_pipe_dispatcher.h" |
31 #include "mojo/system/platform_handle_dispatcher.h" | 32 #include "mojo/system/platform_handle_dispatcher.h" |
32 #include "mojo/system/raw_channel.h" | 33 #include "mojo/system/raw_channel.h" |
33 #include "mojo/system/shared_buffer_dispatcher.h" | 34 #include "mojo/system/shared_buffer_dispatcher.h" |
34 #include "mojo/system/test_utils.h" | 35 #include "mojo/system/test_utils.h" |
35 #include "mojo/system/waiter.h" | 36 #include "mojo/system/waiter.h" |
36 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
37 | 38 |
38 namespace mojo { | 39 namespace mojo { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 131 |
131 void ConnectMessagePipesOnIOThread(scoped_refptr<MessagePipe> mp0, | 132 void ConnectMessagePipesOnIOThread(scoped_refptr<MessagePipe> mp0, |
132 scoped_refptr<MessagePipe> mp1) { | 133 scoped_refptr<MessagePipe> mp1) { |
133 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 134 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); |
134 | 135 |
135 if (!channels_[0].get()) | 136 if (!channels_[0].get()) |
136 CreateAndInitChannel(0); | 137 CreateAndInitChannel(0); |
137 if (!channels_[1].get()) | 138 if (!channels_[1].get()) |
138 CreateAndInitChannel(1); | 139 CreateAndInitChannel(1); |
139 | 140 |
140 MessageInTransit::EndpointId local_id0 = | 141 MessageInTransit::EndpointId local_id0 = channels_[0]->AttachEndpoint( |
141 channels_[0]->AttachMessagePipeEndpoint(mp0, 1); | 142 make_scoped_refptr(new ChannelEndpoint(mp0.get(), 1))); |
142 MessageInTransit::EndpointId local_id1 = | 143 MessageInTransit::EndpointId local_id1 = channels_[1]->AttachEndpoint( |
143 channels_[1]->AttachMessagePipeEndpoint(mp1, 0); | 144 make_scoped_refptr(new ChannelEndpoint(mp1.get(), 0))); |
144 | 145 |
145 CHECK(channels_[0]->RunMessagePipeEndpoint(local_id0, local_id1)); | 146 CHECK(channels_[0]->RunMessagePipeEndpoint(local_id0, local_id1)); |
146 CHECK(channels_[1]->RunMessagePipeEndpoint(local_id1, local_id0)); | 147 CHECK(channels_[1]->RunMessagePipeEndpoint(local_id1, local_id0)); |
147 } | 148 } |
148 | 149 |
149 void BootstrapMessagePipeOnIOThread(unsigned channel_index, | 150 void BootstrapMessagePipeOnIOThread(unsigned channel_index, |
150 scoped_refptr<MessagePipe> mp) { | 151 scoped_refptr<MessagePipe> mp) { |
151 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 152 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); |
152 CHECK(channel_index == 0 || channel_index == 1); | 153 CHECK(channel_index == 0 || channel_index == 1); |
153 | 154 |
154 unsigned port = channel_index ^ 1u; | 155 unsigned port = channel_index ^ 1u; |
155 | 156 |
156 CreateAndInitChannel(channel_index); | 157 CreateAndInitChannel(channel_index); |
157 MessageInTransit::EndpointId endpoint_id = | 158 MessageInTransit::EndpointId endpoint_id = |
158 channels_[channel_index]->AttachMessagePipeEndpoint(mp, port); | 159 channels_[channel_index]->AttachEndpoint( |
| 160 make_scoped_refptr(new ChannelEndpoint(mp.get(), port))); |
159 if (endpoint_id == MessageInTransit::kInvalidEndpointId) | 161 if (endpoint_id == MessageInTransit::kInvalidEndpointId) |
160 return; | 162 return; |
161 | 163 |
162 CHECK_EQ(endpoint_id, Channel::kBootstrapEndpointId); | 164 CHECK_EQ(endpoint_id, Channel::kBootstrapEndpointId); |
163 CHECK(channels_[channel_index]->RunMessagePipeEndpoint( | 165 CHECK(channels_[channel_index]->RunMessagePipeEndpoint( |
164 Channel::kBootstrapEndpointId, Channel::kBootstrapEndpointId)); | 166 Channel::kBootstrapEndpointId, Channel::kBootstrapEndpointId)); |
165 } | 167 } |
166 | 168 |
167 void RestoreInitialStateOnIOThread() { | 169 void RestoreInitialStateOnIOThread() { |
168 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 170 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); |
(...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 mp0->Close(0); | 1162 mp0->Close(0); |
1161 mp1->Close(1); | 1163 mp1->Close(1); |
1162 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 1164 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
1163 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. | 1165 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. |
1164 local_mp->Close(1); | 1166 local_mp->Close(1); |
1165 } | 1167 } |
1166 | 1168 |
1167 } // namespace | 1169 } // namespace |
1168 } // namespace system | 1170 } // namespace system |
1169 } // namespace mojo | 1171 } // namespace mojo |
OLD | NEW |