| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "mojo/public/cpp/bindings/associated_binding.h" | 15 #include "mojo/public/cpp/bindings/associated_binding.h" |
| 16 #include "mojo/public/cpp/bindings/associated_group.h" | 16 #include "mojo/public/cpp/bindings/associated_group.h" |
| 17 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" | 17 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" |
| 18 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" | 18 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" |
| 19 #include "mojo/public/cpp/bindings/associated_interface_request.h" | 19 #include "mojo/public/cpp/bindings/associated_interface_request.h" |
| 20 #include "mojo/public/cpp/bindings/binding.h" | 20 #include "mojo/public/cpp/bindings/binding.h" |
| 21 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" | 21 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" |
| 22 #include "mojo/public/interfaces/bindings/tests/test_associated_interfaces.mojom
.h" | 22 #include "mojo/public/interfaces/bindings/tests/test_associated_interfaces.mojom
.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 namespace mojo { | 25 namespace mojo { |
| 26 namespace test { | 26 namespace test { |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 using mojo::internal::AssociatedInterfacePtrInfoHelper; | |
| 30 using mojo::internal::AssociatedInterfaceRequestHelper; | |
| 31 using mojo::internal::MultiplexRouter; | 29 using mojo::internal::MultiplexRouter; |
| 32 using mojo::internal::ScopedInterfaceEndpointHandle; | |
| 33 | 30 |
| 34 class IntegerSenderImpl : public IntegerSender { | 31 class IntegerSenderImpl : public IntegerSender { |
| 35 public: | 32 public: |
| 36 explicit IntegerSenderImpl(AssociatedInterfaceRequest<IntegerSender> request) | 33 explicit IntegerSenderImpl(AssociatedInterfaceRequest<IntegerSender> request) |
| 37 : binding_(this, std::move(request)) {} | 34 : binding_(this, std::move(request)) {} |
| 38 | 35 |
| 39 ~IntegerSenderImpl() override {} | 36 ~IntegerSenderImpl() override {} |
| 40 | 37 |
| 41 void set_notify_send_method_called( | 38 void set_notify_send_method_called( |
| 42 const base::Callback<void(int32_t)>& callback) { | 39 const base::Callback<void(int32_t)>& callback) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 public: | 89 public: |
| 93 AssociatedInterfaceTest() {} | 90 AssociatedInterfaceTest() {} |
| 94 ~AssociatedInterfaceTest() override { loop_.RunUntilIdle(); } | 91 ~AssociatedInterfaceTest() override { loop_.RunUntilIdle(); } |
| 95 | 92 |
| 96 void PumpMessages() { loop_.RunUntilIdle(); } | 93 void PumpMessages() { loop_.RunUntilIdle(); } |
| 97 | 94 |
| 98 template <typename T> | 95 template <typename T> |
| 99 AssociatedInterfacePtrInfo<T> EmulatePassingAssociatedPtrInfo( | 96 AssociatedInterfacePtrInfo<T> EmulatePassingAssociatedPtrInfo( |
| 100 AssociatedInterfacePtrInfo<T> ptr_info, | 97 AssociatedInterfacePtrInfo<T> ptr_info, |
| 101 scoped_refptr<MultiplexRouter> target) { | 98 scoped_refptr<MultiplexRouter> target) { |
| 102 ScopedInterfaceEndpointHandle handle = | 99 ScopedInterfaceEndpointHandle handle = ptr_info.PassHandle(); |
| 103 AssociatedInterfacePtrInfoHelper::PassHandle(&ptr_info); | |
| 104 CHECK(!handle.is_local()); | 100 CHECK(!handle.is_local()); |
| 105 | 101 return AssociatedInterfacePtrInfo<T>( |
| 106 ScopedInterfaceEndpointHandle new_handle = | 102 target->CreateLocalEndpointHandle(handle.release()), |
| 107 target->CreateLocalEndpointHandle(handle.release()); | 103 ptr_info.version()); |
| 108 | |
| 109 AssociatedInterfacePtrInfo<T> result; | |
| 110 AssociatedInterfacePtrInfoHelper::SetHandle(&result, std::move(new_handle)); | |
| 111 result.set_version(ptr_info.version()); | |
| 112 return std::move(result); | |
| 113 } | 104 } |
| 114 | 105 |
| 115 template <typename T> | 106 template <typename T> |
| 116 AssociatedInterfaceRequest<T> EmulatePassingAssociatedRequest( | 107 AssociatedInterfaceRequest<T> EmulatePassingAssociatedRequest( |
| 117 AssociatedInterfaceRequest<T> request, | 108 AssociatedInterfaceRequest<T> request, |
| 118 scoped_refptr<MultiplexRouter> target) { | 109 scoped_refptr<MultiplexRouter> target) { |
| 119 ScopedInterfaceEndpointHandle handle = | 110 ScopedInterfaceEndpointHandle handle = request.PassHandle(); |
| 120 AssociatedInterfaceRequestHelper::PassHandle(&request); | |
| 121 CHECK(!handle.is_local()); | 111 CHECK(!handle.is_local()); |
| 122 | 112 return MakeAssociatedRequest<T>( |
| 123 ScopedInterfaceEndpointHandle new_handle = | 113 target->CreateLocalEndpointHandle(handle.release())); |
| 124 target->CreateLocalEndpointHandle(handle.release()); | |
| 125 | |
| 126 AssociatedInterfaceRequest<T> result; | |
| 127 AssociatedInterfaceRequestHelper::SetHandle(&result, std::move(new_handle)); | |
| 128 return std::move(result); | |
| 129 } | 114 } |
| 130 | 115 |
| 131 // Okay to call from any thread. | 116 // Okay to call from any thread. |
| 132 void QuitRunLoop(base::RunLoop* run_loop) { | 117 void QuitRunLoop(base::RunLoop* run_loop) { |
| 133 if (loop_.task_runner()->BelongsToCurrentThread()) { | 118 if (loop_.task_runner()->BelongsToCurrentThread()) { |
| 134 run_loop->Quit(); | 119 run_loop->Quit(); |
| 135 } else { | 120 } else { |
| 136 loop_.PostTask( | 121 loop_.PostTask( |
| 137 FROM_HERE, | 122 FROM_HERE, |
| 138 base::Bind(&AssociatedInterfaceTest::QuitRunLoop, | 123 base::Bind(&AssociatedInterfaceTest::QuitRunLoop, |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 | 557 |
| 573 // The previous wait has dispatched the GetSender request message, therefore | 558 // The previous wait has dispatched the GetSender request message, therefore |
| 574 // an associated interface has been set up on the pipe. It is not allowed to | 559 // an associated interface has been set up on the pipe. It is not allowed to |
| 575 // wait or pause. | 560 // wait or pause. |
| 576 EXPECT_TRUE(connection.binding()->HasAssociatedInterfaces()); | 561 EXPECT_TRUE(connection.binding()->HasAssociatedInterfaces()); |
| 577 } | 562 } |
| 578 | 563 |
| 579 } // namespace | 564 } // namespace |
| 580 } // namespace test | 565 } // namespace test |
| 581 } // namespace mojo | 566 } // namespace mojo |
| OLD | NEW |