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 "ipc/ipc_channel_mojo.h" | 5 #include "ipc/ipc_channel_mojo.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 base::WaitableEvent::InitialState::NOT_SIGNALED) { | 732 base::WaitableEvent::InitialState::NOT_SIGNALED) { |
733 } | 733 } |
734 | 734 |
735 void CreateProxy(IPC::Listener* listener) { | 735 void CreateProxy(IPC::Listener* listener) { |
736 io_thread_.StartWithOptions( | 736 io_thread_.StartWithOptions( |
737 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 737 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
738 proxy_ = IPC::SyncChannel::Create( | 738 proxy_ = IPC::SyncChannel::Create( |
739 listener, io_thread_.task_runner(), &never_signaled_); | 739 listener, io_thread_.task_runner(), &never_signaled_); |
740 } | 740 } |
741 | 741 |
742 void RunProxy(bool create_paused) { | 742 void RunProxy() { |
743 std::unique_ptr<IPC::ChannelFactory> factory; | 743 std::unique_ptr<IPC::ChannelFactory> factory; |
744 if (for_server_) { | 744 if (for_server_) { |
745 factory = IPC::ChannelMojo::CreateServerFactory( | 745 factory = IPC::ChannelMojo::CreateServerFactory( |
746 std::move(handle_), io_thread_.task_runner()); | 746 std::move(handle_), io_thread_.task_runner()); |
747 } else { | 747 } else { |
748 factory = IPC::ChannelMojo::CreateClientFactory( | 748 factory = IPC::ChannelMojo::CreateClientFactory( |
749 std::move(handle_), io_thread_.task_runner()); | 749 std::move(handle_), io_thread_.task_runner()); |
750 } | 750 } |
751 proxy_->Init(std::move(factory), true, create_paused); | 751 proxy_->Init(std::move(factory), true); |
752 } | 752 } |
753 | 753 |
754 IPC::ChannelProxy* proxy() { return proxy_.get(); } | 754 IPC::ChannelProxy* proxy() { return proxy_.get(); } |
755 | 755 |
756 private: | 756 private: |
757 const bool for_server_; | 757 const bool for_server_; |
758 | 758 |
759 mojo::ScopedMessagePipeHandle handle_; | 759 mojo::ScopedMessagePipeHandle handle_; |
760 base::Thread io_thread_; | 760 base::Thread io_thread_; |
761 std::unique_ptr<IPC::ChannelProxy> proxy_; | 761 std::unique_ptr<IPC::ChannelProxy> proxy_; |
762 base::WaitableEvent never_signaled_; | 762 base::WaitableEvent never_signaled_; |
763 | 763 |
764 DISALLOW_COPY_AND_ASSIGN(ChannelProxyRunner); | 764 DISALLOW_COPY_AND_ASSIGN(ChannelProxyRunner); |
765 }; | 765 }; |
766 | 766 |
767 class IPCChannelProxyMojoTest : public IPCChannelMojoTestBase { | 767 class IPCChannelProxyMojoTest : public IPCChannelMojoTestBase { |
768 public: | 768 public: |
769 void InitWithMojo(const std::string& client_name) { | 769 void InitWithMojo(const std::string& client_name) { |
770 IPCChannelMojoTestBase::InitWithMojo(client_name); | 770 IPCChannelMojoTestBase::InitWithMojo(client_name); |
771 runner_.reset(new ChannelProxyRunner(TakeHandle(), true)); | 771 runner_.reset(new ChannelProxyRunner(TakeHandle(), true)); |
772 } | 772 } |
773 void CreateProxy(IPC::Listener* listener) { runner_->CreateProxy(listener); } | 773 void CreateProxy(IPC::Listener* listener) { runner_->CreateProxy(listener); } |
774 void RunProxy(bool create_paused = false) { | 774 void RunProxy() { |
775 runner_->RunProxy(create_paused); | 775 runner_->RunProxy(); |
776 } | 776 } |
777 void DestroyProxy() { | 777 void DestroyProxy() { |
778 runner_.reset(); | 778 runner_.reset(); |
779 base::RunLoop().RunUntilIdle(); | 779 base::RunLoop().RunUntilIdle(); |
780 } | 780 } |
781 | 781 |
782 IPC::ChannelProxy* proxy() { return runner_->proxy(); } | 782 IPC::ChannelProxy* proxy() { return runner_->proxy(); } |
783 | 783 |
784 private: | 784 private: |
785 base::MessageLoop message_loop_; | 785 base::MessageLoop message_loop_; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 } | 871 } |
872 | 872 |
873 class ChannelProxyClient { | 873 class ChannelProxyClient { |
874 public: | 874 public: |
875 void Init(mojo::ScopedMessagePipeHandle handle) { | 875 void Init(mojo::ScopedMessagePipeHandle handle) { |
876 runner_.reset(new ChannelProxyRunner(std::move(handle), false)); | 876 runner_.reset(new ChannelProxyRunner(std::move(handle), false)); |
877 } | 877 } |
878 | 878 |
879 void CreateProxy(IPC::Listener* listener) { runner_->CreateProxy(listener); } | 879 void CreateProxy(IPC::Listener* listener) { runner_->CreateProxy(listener); } |
880 | 880 |
881 void RunProxy() { runner_->RunProxy(false); } | 881 void RunProxy() { runner_->RunProxy(); } |
882 | 882 |
883 void DestroyProxy() { | 883 void DestroyProxy() { |
884 runner_.reset(); | 884 runner_.reset(); |
885 base::RunLoop().RunUntilIdle(); | 885 base::RunLoop().RunUntilIdle(); |
886 } | 886 } |
887 | 887 |
888 void RequestQuitAndWaitForAck(IPC::mojom::SimpleTestDriver* driver) { | 888 void RequestQuitAndWaitForAck(IPC::mojom::SimpleTestDriver* driver) { |
889 base::RunLoop loop; | 889 base::RunLoop loop; |
890 driver->RequestQuit(loop.QuitClosure()); | 890 driver->RequestQuit(loop.QuitClosure()); |
891 loop.Run(); | 891 loop.Run(); |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 client_impl.WaitForValueRequest(); | 1245 client_impl.WaitForValueRequest(); |
1246 | 1246 |
1247 // Wait for the test driver to perform a classical sync IPC request, with our | 1247 // Wait for the test driver to perform a classical sync IPC request, with our |
1248 // own sync associated interface message nested inside. | 1248 // own sync associated interface message nested inside. |
1249 client_impl.UseSyncSenderForRequest(false); | 1249 client_impl.UseSyncSenderForRequest(false); |
1250 client_impl.WaitForValueRequest(); | 1250 client_impl.WaitForValueRequest(); |
1251 | 1251 |
1252 DestroyProxy(); | 1252 DestroyProxy(); |
1253 } | 1253 } |
1254 | 1254 |
1255 TEST_F(IPCChannelProxyMojoTest, CreatePaused) { | 1255 TEST_F(IPCChannelProxyMojoTest, Pause) { |
1256 // Ensures that creating a paused channel elicits the expected behavior when | 1256 // Ensures that pausing a channel elicits the expected behavior when sending |
1257 // sending messages, unpausing, sending more messages, and then manually | 1257 // messages, unpausing, sending more messages, and then manually flushing. |
1258 // flushing. Specifically a sequence like: | 1258 // Specifically a sequence like: |
1259 // | 1259 // |
1260 // Connect() | 1260 // Connect() |
1261 // Send(A) | 1261 // Send(A) |
| 1262 // Pause() |
1262 // Send(B) | 1263 // Send(B) |
| 1264 // Send(C) |
1263 // Unpause(false) | 1265 // Unpause(false) |
1264 // Send(C) | 1266 // Send(D) |
| 1267 // Send(E) |
1265 // Flush() | 1268 // Flush() |
1266 // | 1269 // |
1267 // must result in the other end receiving messages C, A, and then B, in that | 1270 // must result in the other end receiving messages A, D, E, B, D; in that |
1268 // order. | 1271 // order. |
1269 // | 1272 // |
1270 // This behavior is required by some consumers of IPC::Channel, and it is not | 1273 // This behavior is required by some consumers of IPC::Channel, and it is not |
1271 // sufficient to leave this up to the consumer to implement since associated | 1274 // sufficient to leave this up to the consumer to implement since associated |
1272 // interface requests and messages also need to be queued according to the | 1275 // interface requests and messages also need to be queued according to the |
1273 // same policy. | 1276 // same policy. |
1274 InitWithMojo("CreatePausedClient"); | 1277 InitWithMojo("CreatePausedClient"); |
1275 | 1278 |
1276 DummyListener listener; | 1279 DummyListener listener; |
1277 CreateProxy(&listener); | 1280 CreateProxy(&listener); |
1278 RunProxy(true /* create_paused */); | 1281 RunProxy(); |
| 1282 |
| 1283 // This message must be sent immediately since the channel is unpaused. |
| 1284 SendValue(proxy(), 1); |
| 1285 |
| 1286 proxy()->Pause(); |
1279 | 1287 |
1280 // These messages must be queued internally since the channel is paused. | 1288 // These messages must be queued internally since the channel is paused. |
1281 SendValue(proxy(), 1); | |
1282 SendValue(proxy(), 2); | 1289 SendValue(proxy(), 2); |
| 1290 SendValue(proxy(), 3); |
1283 | 1291 |
1284 proxy()->Unpause(false /* flush */); | 1292 proxy()->Unpause(false /* flush */); |
1285 | 1293 |
1286 // These messages must be sent immediately since the channel is unpaused. | 1294 // These messages must be sent immediately since the channel is unpaused. |
1287 SendValue(proxy(), 3); | |
1288 SendValue(proxy(), 4); | 1295 SendValue(proxy(), 4); |
| 1296 SendValue(proxy(), 5); |
1289 | 1297 |
1290 // Now we flush the previously queued messages. | 1298 // Now we flush the previously queued messages. |
1291 proxy()->Flush(); | 1299 proxy()->Flush(); |
1292 | 1300 |
1293 EXPECT_TRUE(WaitForClientShutdown()); | 1301 EXPECT_TRUE(WaitForClientShutdown()); |
1294 DestroyProxy(); | 1302 DestroyProxy(); |
1295 } | 1303 } |
1296 | 1304 |
1297 class ExpectValueSequenceListener : public IPC::Listener { | 1305 class ExpectValueSequenceListener : public IPC::Listener { |
1298 public: | 1306 public: |
(...skipping 17 matching lines...) Expand all Loading... |
1316 private: | 1324 private: |
1317 std::queue<int32_t>* expected_values_; | 1325 std::queue<int32_t>* expected_values_; |
1318 | 1326 |
1319 DISALLOW_COPY_AND_ASSIGN(ExpectValueSequenceListener); | 1327 DISALLOW_COPY_AND_ASSIGN(ExpectValueSequenceListener); |
1320 }; | 1328 }; |
1321 | 1329 |
1322 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(CreatePausedClient, ChannelProxyClient) { | 1330 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(CreatePausedClient, ChannelProxyClient) { |
1323 std::queue<int32_t> expected_values; | 1331 std::queue<int32_t> expected_values; |
1324 ExpectValueSequenceListener listener(&expected_values); | 1332 ExpectValueSequenceListener listener(&expected_values); |
1325 CreateProxy(&listener); | 1333 CreateProxy(&listener); |
| 1334 expected_values.push(1); |
| 1335 expected_values.push(4); |
| 1336 expected_values.push(5); |
| 1337 expected_values.push(2); |
1326 expected_values.push(3); | 1338 expected_values.push(3); |
1327 expected_values.push(4); | |
1328 expected_values.push(1); | |
1329 expected_values.push(2); | |
1330 RunProxy(); | 1339 RunProxy(); |
1331 base::RunLoop().Run(); | 1340 base::RunLoop().Run(); |
1332 EXPECT_TRUE(expected_values.empty()); | 1341 EXPECT_TRUE(expected_values.empty()); |
1333 DestroyProxy(); | 1342 DestroyProxy(); |
1334 } | 1343 } |
1335 | 1344 |
1336 #if defined(OS_POSIX) | 1345 #if defined(OS_POSIX) |
1337 | 1346 |
1338 class ListenerThatExpectsFile : public IPC::Listener { | 1347 class ListenerThatExpectsFile : public IPC::Listener { |
1339 public: | 1348 public: |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1488 Connect(&listener); | 1497 Connect(&listener); |
1489 | 1498 |
1490 base::RunLoop().Run(); | 1499 base::RunLoop().Run(); |
1491 | 1500 |
1492 Close(); | 1501 Close(); |
1493 } | 1502 } |
1494 | 1503 |
1495 #endif // OS_LINUX | 1504 #endif // OS_LINUX |
1496 | 1505 |
1497 } // namespace | 1506 } // namespace |
OLD | NEW |