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 = Callback<void(const Callback<void()>&)>; | 41 using PingHandler = base::Callback<void(const base::Callback<void()>&)>; |
42 using PingBinder = LambdaBinder<const Callback<void()>&>; | 42 using PingBinder = LambdaBinder<const base::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 = Callback<void(int32_t, const Callback<void(int32_t)>&)>; | 48 using EchoHandler = |
49 using EchoBinder = LambdaBinder<int32_t, const Callback<void(int32_t)>&>; | 49 base::Callback<void(int32_t, const base::Callback<void(int32_t)>&)>; |
| 50 using EchoBinder = |
| 51 LambdaBinder<int32_t, const base::Callback<void(int32_t)>&>; |
50 template <typename Func> | 52 template <typename Func> |
51 void set_echo_handler(Func handler) { | 53 void set_echo_handler(Func handler) { |
52 echo_handler_ = EchoBinder::BindLambda(handler); | 54 echo_handler_ = EchoBinder::BindLambda(handler); |
53 } | 55 } |
54 | 56 |
55 using AsyncEchoHandler = | 57 using AsyncEchoHandler = |
56 Callback<void(int32_t, const Callback<void(int32_t)>&)>; | 58 base::Callback<void(int32_t, const base::Callback<void(int32_t)>&)>; |
57 using AsyncEchoBinder = LambdaBinder<int32_t, const Callback<void(int32_t)>&>; | 59 using AsyncEchoBinder = |
| 60 LambdaBinder<int32_t, const base::Callback<void(int32_t)>&>; |
58 template <typename Func> | 61 template <typename Func> |
59 void set_async_echo_handler(Func handler) { | 62 void set_async_echo_handler(Func handler) { |
60 async_echo_handler_ = AsyncEchoBinder::BindLambda(handler); | 63 async_echo_handler_ = AsyncEchoBinder::BindLambda(handler); |
61 } | 64 } |
62 | 65 |
63 using SendInterfaceHandler = Callback<void(TestSyncAssociatedPtrInfo)>; | 66 using SendInterfaceHandler = base::Callback<void(TestSyncAssociatedPtrInfo)>; |
64 using SendInterfaceBinder = LambdaBinder<TestSyncAssociatedPtrInfo>; | 67 using SendInterfaceBinder = LambdaBinder<TestSyncAssociatedPtrInfo>; |
65 template <typename Func> | 68 template <typename Func> |
66 void set_send_interface_handler(Func handler) { | 69 void set_send_interface_handler(Func handler) { |
67 send_interface_handler_ = SendInterfaceBinder::BindLambda(handler); | 70 send_interface_handler_ = SendInterfaceBinder::BindLambda(handler); |
68 } | 71 } |
69 | 72 |
70 using SendRequestHandler = Callback<void(TestSyncAssociatedRequest)>; | 73 using SendRequestHandler = base::Callback<void(TestSyncAssociatedRequest)>; |
71 using SendRequestBinder = LambdaBinder<TestSyncAssociatedRequest>; | 74 using SendRequestBinder = LambdaBinder<TestSyncAssociatedRequest>; |
72 template <typename Func> | 75 template <typename Func> |
73 void set_send_request_handler(Func handler) { | 76 void set_send_request_handler(Func handler) { |
74 send_request_handler_ = SendRequestBinder::BindLambda(handler); | 77 send_request_handler_ = SendRequestBinder::BindLambda(handler); |
75 } | 78 } |
76 | 79 |
77 void PingImpl(const Callback<void()>& callback) { | 80 void PingImpl(const base::Callback<void()>& callback) { |
78 if (ping_handler_.is_null()) { | 81 if (ping_handler_.is_null()) { |
79 callback.Run(); | 82 callback.Run(); |
80 return; | 83 return; |
81 } | 84 } |
82 ping_handler_.Run(callback); | 85 ping_handler_.Run(callback); |
83 } | 86 } |
84 void EchoImpl(int32_t value, const Callback<void(int32_t)>& callback) { | 87 void EchoImpl(int32_t value, const base::Callback<void(int32_t)>& callback) { |
85 if (echo_handler_.is_null()) { | 88 if (echo_handler_.is_null()) { |
86 callback.Run(value); | 89 callback.Run(value); |
87 return; | 90 return; |
88 } | 91 } |
89 echo_handler_.Run(value, callback); | 92 echo_handler_.Run(value, callback); |
90 } | 93 } |
91 void AsyncEchoImpl(int32_t value, const Callback<void(int32_t)>& callback) { | 94 void AsyncEchoImpl(int32_t value, |
| 95 const base::Callback<void(int32_t)>& callback) { |
92 if (async_echo_handler_.is_null()) { | 96 if (async_echo_handler_.is_null()) { |
93 callback.Run(value); | 97 callback.Run(value); |
94 return; | 98 return; |
95 } | 99 } |
96 async_echo_handler_.Run(value, callback); | 100 async_echo_handler_.Run(value, callback); |
97 } | 101 } |
98 void SendInterfaceImpl(TestSyncAssociatedPtrInfo ptr) { | 102 void SendInterfaceImpl(TestSyncAssociatedPtrInfo ptr) { |
99 send_interface_handler_.Run(std::move(ptr)); | 103 send_interface_handler_.Run(std::move(ptr)); |
100 } | 104 } |
101 void SendRequestImpl(TestSyncAssociatedRequest request) { | 105 void SendRequestImpl(TestSyncAssociatedRequest request) { |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 int32_t result_value = -1; | 733 int32_t result_value = -1; |
730 ASSERT_TRUE(master_ptr_->Echo(456, &result_value)); | 734 ASSERT_TRUE(master_ptr_->Echo(456, &result_value)); |
731 EXPECT_EQ(456, result_value); | 735 EXPECT_EQ(456, result_value); |
732 } | 736 } |
733 | 737 |
734 // TODO(yzshen): Add more tests related to associated interfaces. | 738 // TODO(yzshen): Add more tests related to associated interfaces. |
735 | 739 |
736 } // namespace | 740 } // namespace |
737 } // namespace test | 741 } // namespace test |
738 } // namespace mojo | 742 } // namespace mojo |
OLD | NEW |