| 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 <string> | 5 #include <string> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/test/perf_time_logger.h" | 13 #include "base/test/perf_time_logger.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "mojo/edk/test/mojo_test_base.h" | 15 #include "mojo/edk/test/mojo_test_base.h" |
| 16 #include "mojo/edk/test/scoped_ipc_support.h" | 16 #include "mojo/edk/test/scoped_ipc_support.h" |
| 17 #include "mojo/public/cpp/bindings/strong_binding.h" | 17 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 18 #include "mojo/public/interfaces/bindings/tests/ping_service.mojom.h" | 18 #include "mojo/public/interfaces/bindings/tests/ping_service.mojom.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 namespace mojo { | 21 namespace mojo { |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 class EchoServiceImpl : public test::EchoService { | 24 class EchoServiceImpl : public test::EchoService { |
| 25 public: | 25 public: |
| 26 EchoServiceImpl(InterfaceRequest<EchoService> request, | 26 explicit EchoServiceImpl(const base::Closure& quit_closure); |
| 27 const base::Closure& quit_closure); | |
| 28 ~EchoServiceImpl() override; | 27 ~EchoServiceImpl() override; |
| 29 | 28 |
| 30 // |EchoService| methods: | 29 // |EchoService| methods: |
| 31 void Echo(const std::string& test_data, | 30 void Echo(const std::string& test_data, |
| 32 const EchoCallback& callback) override; | 31 const EchoCallback& callback) override; |
| 33 | 32 |
| 34 private: | 33 private: |
| 35 const StrongBinding<EchoService> binding_; | |
| 36 const base::Closure quit_closure_; | 34 const base::Closure quit_closure_; |
| 37 }; | 35 }; |
| 38 | 36 |
| 39 EchoServiceImpl::EchoServiceImpl(InterfaceRequest<EchoService> request, | 37 EchoServiceImpl::EchoServiceImpl(const base::Closure& quit_closure) |
| 40 const base::Closure& quit_closure) | 38 : quit_closure_(quit_closure) {} |
| 41 : binding_(this, std::move(request)), quit_closure_(quit_closure) {} | |
| 42 | 39 |
| 43 EchoServiceImpl::~EchoServiceImpl() { | 40 EchoServiceImpl::~EchoServiceImpl() { |
| 44 quit_closure_.Run(); | 41 quit_closure_.Run(); |
| 45 } | 42 } |
| 46 | 43 |
| 47 void EchoServiceImpl::Echo(const std::string& test_data, | 44 void EchoServiceImpl::Echo(const std::string& test_data, |
| 48 const EchoCallback& callback) { | 45 const EchoCallback& callback) { |
| 49 callback.Run(test_data); | 46 callback.Run(test_data); |
| 50 } | 47 } |
| 51 | 48 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 batch_size, message_size); | 153 batch_size, message_size); |
| 157 base::PerfTimeLogger timer(sub_test_name.c_str()); | 154 base::PerfTimeLogger timer(sub_test_name.c_str()); |
| 158 test.RunTest(num_messages / batch_size, batch_size, message_size); | 155 test.RunTest(num_messages / batch_size, batch_size, message_size); |
| 159 } | 156 } |
| 160 } | 157 } |
| 161 } | 158 } |
| 162 }; | 159 }; |
| 163 | 160 |
| 164 void CreateAndRunService(InterfaceRequest<test::EchoService> request, | 161 void CreateAndRunService(InterfaceRequest<test::EchoService> request, |
| 165 const base::Closure& cb) { | 162 const base::Closure& cb) { |
| 166 new EchoServiceImpl(std::move(request), cb); | 163 MakeStrongBinding(base::MakeUnique<EchoServiceImpl>(cb), std::move(request)); |
| 167 } | 164 } |
| 168 | 165 |
| 169 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(PingService, MojoE2EPerftest, mp) { | 166 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(PingService, MojoE2EPerftest, mp) { |
| 170 MojoHandle service_mp; | 167 MojoHandle service_mp; |
| 171 EXPECT_EQ("hello", ReadMessageWithHandles(mp, &service_mp, 1)); | 168 EXPECT_EQ("hello", ReadMessageWithHandles(mp, &service_mp, 1)); |
| 172 | 169 |
| 173 InterfaceRequest<test::EchoService> request; | 170 InterfaceRequest<test::EchoService> request; |
| 174 request.Bind(ScopedMessagePipeHandle(MessagePipeHandle(service_mp))); | 171 request.Bind(ScopedMessagePipeHandle(MessagePipeHandle(service_mp))); |
| 175 base::RunLoop run_loop; | 172 base::RunLoop run_loop; |
| 176 edk::test::GetIoTaskRunner()->PostTask( | 173 edk::test::GetIoTaskRunner()->PostTask( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 197 MojoHandle client_mp, service_mp; | 194 MojoHandle client_mp, service_mp; |
| 198 CreateMessagePipe(&client_mp, &service_mp); | 195 CreateMessagePipe(&client_mp, &service_mp); |
| 199 WriteMessageWithHandles(mp, "hello", &service_mp, 1); | 196 WriteMessageWithHandles(mp, "hello", &service_mp, 1); |
| 200 RunTestOnTaskRunner(edk::test::GetIoTaskRunner(), client_mp, | 197 RunTestOnTaskRunner(edk::test::GetIoTaskRunner(), client_mp, |
| 201 "MultiProcessEchoIoThread"); | 198 "MultiProcessEchoIoThread"); |
| 202 END_CHILD() | 199 END_CHILD() |
| 203 } | 200 } |
| 204 | 201 |
| 205 } // namespace | 202 } // namespace |
| 206 } // namespace mojo | 203 } // namespace mojo |
| OLD | NEW |