| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 template <typename Func> | 31 template <typename Func> |
| 32 static CallbackType BindLambda(Func func) { | 32 static CallbackType BindLambda(Func func) { |
| 33 return base::Bind(&LambdaBinder::RunLambda<Func>, func); | 33 return base::Bind(&LambdaBinder::RunLambda<Func>, func); |
| 34 } | 34 } |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 class TestSyncCommonImpl { | 37 class TestSyncCommonImpl { |
| 38 public: | 38 public: |
| 39 TestSyncCommonImpl() {} | 39 TestSyncCommonImpl() {} |
| 40 | 40 |
| 41 using PingHandler = base::Callback<void(const base::Callback<void()>&)>; | 41 using PingHandler = Callback<void(const Callback<void()>&)>; |
| 42 using PingBinder = LambdaBinder<const base::Callback<void()>&>; | 42 using PingBinder = LambdaBinder<const Callback<void()>&>; |
| 43 template <typename Func> | 43 template <typename Func> |
| 44 void set_ping_handler(Func handler) { | 44 void set_ping_handler(Func handler) { |
| 45 ping_handler_ = PingBinder::BindLambda(handler); | 45 ping_handler_ = PingBinder::BindLambda(handler); |
| 46 } | 46 } |
| 47 | 47 |
| 48 using EchoHandler = | 48 using EchoHandler = Callback<void(int32_t, const Callback<void(int32_t)>&)>; |
| 49 base::Callback<void(int32_t, const base::Callback<void(int32_t)>&)>; | 49 using EchoBinder = LambdaBinder<int32_t, const Callback<void(int32_t)>&>; |
| 50 using EchoBinder = | |
| 51 LambdaBinder<int32_t, const base::Callback<void(int32_t)>&>; | |
| 52 template <typename Func> | 50 template <typename Func> |
| 53 void set_echo_handler(Func handler) { | 51 void set_echo_handler(Func handler) { |
| 54 echo_handler_ = EchoBinder::BindLambda(handler); | 52 echo_handler_ = EchoBinder::BindLambda(handler); |
| 55 } | 53 } |
| 56 | 54 |
| 57 using AsyncEchoHandler = | 55 using AsyncEchoHandler = |
| 58 base::Callback<void(int32_t, const base::Callback<void(int32_t)>&)>; | 56 Callback<void(int32_t, const Callback<void(int32_t)>&)>; |
| 59 using AsyncEchoBinder = | 57 using AsyncEchoBinder = LambdaBinder<int32_t, const Callback<void(int32_t)>&>; |
| 60 LambdaBinder<int32_t, const base::Callback<void(int32_t)>&>; | |
| 61 template <typename Func> | 58 template <typename Func> |
| 62 void set_async_echo_handler(Func handler) { | 59 void set_async_echo_handler(Func handler) { |
| 63 async_echo_handler_ = AsyncEchoBinder::BindLambda(handler); | 60 async_echo_handler_ = AsyncEchoBinder::BindLambda(handler); |
| 64 } | 61 } |
| 65 | 62 |
| 66 using SendInterfaceHandler = base::Callback<void(TestSyncAssociatedPtrInfo)>; | 63 using SendInterfaceHandler = Callback<void(TestSyncAssociatedPtrInfo)>; |
| 67 using SendInterfaceBinder = LambdaBinder<TestSyncAssociatedPtrInfo>; | 64 using SendInterfaceBinder = LambdaBinder<TestSyncAssociatedPtrInfo>; |
| 68 template <typename Func> | 65 template <typename Func> |
| 69 void set_send_interface_handler(Func handler) { | 66 void set_send_interface_handler(Func handler) { |
| 70 send_interface_handler_ = SendInterfaceBinder::BindLambda(handler); | 67 send_interface_handler_ = SendInterfaceBinder::BindLambda(handler); |
| 71 } | 68 } |
| 72 | 69 |
| 73 using SendRequestHandler = base::Callback<void(TestSyncAssociatedRequest)>; | 70 using SendRequestHandler = Callback<void(TestSyncAssociatedRequest)>; |
| 74 using SendRequestBinder = LambdaBinder<TestSyncAssociatedRequest>; | 71 using SendRequestBinder = LambdaBinder<TestSyncAssociatedRequest>; |
| 75 template <typename Func> | 72 template <typename Func> |
| 76 void set_send_request_handler(Func handler) { | 73 void set_send_request_handler(Func handler) { |
| 77 send_request_handler_ = SendRequestBinder::BindLambda(handler); | 74 send_request_handler_ = SendRequestBinder::BindLambda(handler); |
| 78 } | 75 } |
| 79 | 76 |
| 80 void PingImpl(const base::Callback<void()>& callback) { | 77 void PingImpl(const Callback<void()>& callback) { |
| 81 if (ping_handler_.is_null()) { | 78 if (ping_handler_.is_null()) { |
| 82 callback.Run(); | 79 callback.Run(); |
| 83 return; | 80 return; |
| 84 } | 81 } |
| 85 ping_handler_.Run(callback); | 82 ping_handler_.Run(callback); |
| 86 } | 83 } |
| 87 void EchoImpl(int32_t value, const base::Callback<void(int32_t)>& callback) { | 84 void EchoImpl(int32_t value, const Callback<void(int32_t)>& callback) { |
| 88 if (echo_handler_.is_null()) { | 85 if (echo_handler_.is_null()) { |
| 89 callback.Run(value); | 86 callback.Run(value); |
| 90 return; | 87 return; |
| 91 } | 88 } |
| 92 echo_handler_.Run(value, callback); | 89 echo_handler_.Run(value, callback); |
| 93 } | 90 } |
| 94 void AsyncEchoImpl(int32_t value, | 91 void AsyncEchoImpl(int32_t value, const Callback<void(int32_t)>& callback) { |
| 95 const base::Callback<void(int32_t)>& callback) { | |
| 96 if (async_echo_handler_.is_null()) { | 92 if (async_echo_handler_.is_null()) { |
| 97 callback.Run(value); | 93 callback.Run(value); |
| 98 return; | 94 return; |
| 99 } | 95 } |
| 100 async_echo_handler_.Run(value, callback); | 96 async_echo_handler_.Run(value, callback); |
| 101 } | 97 } |
| 102 void SendInterfaceImpl(TestSyncAssociatedPtrInfo ptr) { | 98 void SendInterfaceImpl(TestSyncAssociatedPtrInfo ptr) { |
| 103 send_interface_handler_.Run(std::move(ptr)); | 99 send_interface_handler_.Run(std::move(ptr)); |
| 104 } | 100 } |
| 105 void SendRequestImpl(TestSyncAssociatedRequest request) { | 101 void SendRequestImpl(TestSyncAssociatedRequest request) { |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 int32_t result_value = -1; | 729 int32_t result_value = -1; |
| 734 ASSERT_TRUE(master_ptr_->Echo(456, &result_value)); | 730 ASSERT_TRUE(master_ptr_->Echo(456, &result_value)); |
| 735 EXPECT_EQ(456, result_value); | 731 EXPECT_EQ(456, result_value); |
| 736 } | 732 } |
| 737 | 733 |
| 738 // TODO(yzshen): Add more tests related to associated interfaces. | 734 // TODO(yzshen): Add more tests related to associated interfaces. |
| 739 | 735 |
| 740 } // namespace | 736 } // namespace |
| 741 } // namespace test | 737 } // namespace test |
| 742 } // namespace mojo | 738 } // namespace mojo |
| OLD | NEW |