Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(546)

Side by Side Diff: mojo/public/cpp/bindings/tests/e2e_perftest.cc

Issue 2136733002: Mojo C++ bindings: add a new mode to generator to use native STL/WTF types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@67_new
Patch Set: . Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 10 matching lines...) Expand all
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 EchoServiceImpl(InterfaceRequest<EchoService> request,
27 const base::Closure& quit_closure); 27 const base::Closure& quit_closure);
28 ~EchoServiceImpl() override; 28 ~EchoServiceImpl() override;
29 29
30 // |EchoService| methods: 30 // |EchoService| methods:
31 void Echo(const mojo::String& test_data, 31 void Echo(const std::string& test_data,
32 const EchoCallback& callback) override; 32 const EchoCallback& callback) override;
33 33
34 private: 34 private:
35 const StrongBinding<EchoService> binding_; 35 const StrongBinding<EchoService> binding_;
36 const base::Closure quit_closure_; 36 const base::Closure quit_closure_;
37 }; 37 };
38 38
39 EchoServiceImpl::EchoServiceImpl(InterfaceRequest<EchoService> request, 39 EchoServiceImpl::EchoServiceImpl(InterfaceRequest<EchoService> request,
40 const base::Closure& quit_closure) 40 const base::Closure& quit_closure)
41 : binding_(this, std::move(request)), quit_closure_(quit_closure) {} 41 : binding_(this, std::move(request)), quit_closure_(quit_closure) {}
42 42
43 EchoServiceImpl::~EchoServiceImpl() { 43 EchoServiceImpl::~EchoServiceImpl() {
44 quit_closure_.Run(); 44 quit_closure_.Run();
45 } 45 }
46 46
47 void EchoServiceImpl::Echo(const mojo::String& test_data, 47 void EchoServiceImpl::Echo(const std::string& test_data,
48 const EchoCallback& callback) { 48 const EchoCallback& callback) {
49 callback.Run(test_data); 49 callback.Run(test_data);
50 } 50 }
51 51
52 class PingPongTest { 52 class PingPongTest {
53 public: 53 public:
54 explicit PingPongTest(test::EchoServicePtr service); 54 explicit PingPongTest(test::EchoServicePtr service);
55 55
56 void RunTest(int iterations, int batch_size, int message_size); 56 void RunTest(int iterations, int batch_size, int message_size);
57 57
58 private: 58 private:
59 void DoPing(); 59 void DoPing();
60 void OnPingDone(mojo::String reply); 60 void OnPingDone(const std::string& reply);
61 61
62 test::EchoServicePtr service_; 62 test::EchoServicePtr service_;
63 const base::Callback<void(mojo::String)> ping_done_callback_; 63 const base::Callback<void(const std::string&)> ping_done_callback_;
64 64
65 int iterations_; 65 int iterations_;
66 int batch_size_; 66 int batch_size_;
67 std::string message_; 67 std::string message_;
68 68
69 int current_iterations_; 69 int current_iterations_;
70 int calls_outstanding_; 70 int calls_outstanding_;
71 71
72 base::Closure quit_closure_; 72 base::Closure quit_closure_;
73 }; 73 };
(...skipping 25 matching lines...) Expand all
99 quit_closure_.Run(); 99 quit_closure_.Run();
100 return; 100 return;
101 } 101 }
102 102
103 calls_outstanding_ = batch_size_; 103 calls_outstanding_ = batch_size_;
104 for (int i = 0; i < batch_size_; i++) { 104 for (int i = 0; i < batch_size_; i++) {
105 service_->Echo(message_, ping_done_callback_); 105 service_->Echo(message_, ping_done_callback_);
106 } 106 }
107 } 107 }
108 108
109 void PingPongTest::OnPingDone(mojo::String reply) { 109 void PingPongTest::OnPingDone(const std::string& reply) {
110 DCHECK_GT(calls_outstanding_, 0); 110 DCHECK_GT(calls_outstanding_, 0);
111 calls_outstanding_--; 111 calls_outstanding_--;
112 112
113 if (!calls_outstanding_) 113 if (!calls_outstanding_)
114 DoPing(); 114 DoPing();
115 } 115 }
116 116
117 class MojoE2EPerftest : public edk::test::MojoTestBase { 117 class MojoE2EPerftest : public edk::test::MojoTestBase {
118 public: 118 public:
119 void RunTestOnTaskRunner(base::TaskRunner* runner, 119 void RunTestOnTaskRunner(base::TaskRunner* runner,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 MojoHandle client_mp, service_mp; 197 MojoHandle client_mp, service_mp;
198 CreateMessagePipe(&client_mp, &service_mp); 198 CreateMessagePipe(&client_mp, &service_mp);
199 WriteMessageWithHandles(mp, "hello", &service_mp, 1); 199 WriteMessageWithHandles(mp, "hello", &service_mp, 1);
200 RunTestOnTaskRunner(edk::test::GetIoTaskRunner(), client_mp, 200 RunTestOnTaskRunner(edk::test::GetIoTaskRunner(), client_mp,
201 "MultiProcessEchoIoThread"); 201 "MultiProcessEchoIoThread");
202 END_CHILD() 202 END_CHILD()
203 } 203 }
204 204
205 } // namespace 205 } // namespace
206 } // namespace mojo 206 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/binding_callback_unittest.cc ('k') | mojo/public/cpp/bindings/tests/equals_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698