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

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

Issue 1552983003: Fix a bunch of mojo_public_*_unittests with the new EDK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 11 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 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 "mojo/public/cpp/bindings/tests/router_test_util.h" 5 #include "mojo/public/cpp/bindings/tests/router_test_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string.h> 9 #include <string.h>
10 10
(...skipping 16 matching lines...) Expand all
27 const char* text, 27 const char* text,
28 uint64_t request_id, 28 uint64_t request_id,
29 Message* message) { 29 Message* message) {
30 size_t payload_size = strlen(text) + 1; // Plus null terminator. 30 size_t payload_size = strlen(text) + 1; // Plus null terminator.
31 internal::ResponseMessageBuilder builder(name, payload_size, request_id); 31 internal::ResponseMessageBuilder builder(name, payload_size, request_id);
32 memcpy(builder.buffer()->Allocate(payload_size), text, payload_size); 32 memcpy(builder.buffer()->Allocate(payload_size), text, payload_size);
33 33
34 builder.message()->MoveTo(message); 34 builder.message()->MoveTo(message);
35 } 35 }
36 36
37 MessageAccumulator::MessageAccumulator(MessageQueue* queue) : queue_(queue) {} 37 MessageAccumulator::MessageAccumulator(MessageQueue* queue,
38 const base::Closure& closure)
39 : queue_(queue), closure_(closure) {}
40
41 MessageAccumulator::~MessageAccumulator() {}
38 42
39 bool MessageAccumulator::Accept(Message* message) { 43 bool MessageAccumulator::Accept(Message* message) {
40 queue_->Push(message); 44 queue_->Push(message);
45 if (!closure_.is_null()) {
46 closure_.Run();
47 closure_.Reset();
48 }
41 return true; 49 return true;
42 } 50 }
43 51
44 ResponseGenerator::ResponseGenerator() {} 52 ResponseGenerator::ResponseGenerator() {}
45 53
46 bool ResponseGenerator::Accept(Message* message) { 54 bool ResponseGenerator::Accept(Message* message) {
47 return false; 55 return false;
48 } 56 }
49 57
50 bool ResponseGenerator::AcceptWithResponder( 58 bool ResponseGenerator::AcceptWithResponder(
(...skipping 14 matching lines...) Expand all
65 const char* request_string, 73 const char* request_string,
66 MessageReceiver* responder) { 74 MessageReceiver* responder) {
67 Message response; 75 Message response;
68 std::string response_string(request_string); 76 std::string response_string(request_string);
69 response_string += " world!"; 77 response_string += " world!";
70 AllocResponseMessage(name, response_string.c_str(), request_id, &response); 78 AllocResponseMessage(name, response_string.c_str(), request_id, &response);
71 79
72 return responder->Accept(&response); 80 return responder->Accept(&response);
73 } 81 }
74 82
75 LazyResponseGenerator::LazyResponseGenerator() 83 LazyResponseGenerator::LazyResponseGenerator(const base::Closure& closure)
76 : responder_(nullptr), name_(0), request_id_(0) {} 84 : responder_(nullptr), name_(0), request_id_(0), closure_(closure) {}
77 85
78 LazyResponseGenerator::~LazyResponseGenerator() { 86 LazyResponseGenerator::~LazyResponseGenerator() {
79 delete responder_; 87 delete responder_;
80 } 88 }
81 89
82 bool LazyResponseGenerator::AcceptWithResponder( 90 bool LazyResponseGenerator::AcceptWithResponder(
83 Message* message, 91 Message* message,
84 MessageReceiverWithStatus* responder) { 92 MessageReceiverWithStatus* responder) {
85 name_ = message->name(); 93 name_ = message->name();
86 request_id_ = message->request_id(); 94 request_id_ = message->request_id();
87 request_string_ = 95 request_string_ =
88 std::string(reinterpret_cast<const char*>(message->payload())); 96 std::string(reinterpret_cast<const char*>(message->payload()));
89 responder_ = responder; 97 responder_ = responder;
98 if (!closure_.is_null()) {
99 closure_.Run();
100 closure_.Reset();
101 }
90 return true; 102 return true;
91 } 103 }
92 104
93 void LazyResponseGenerator::Complete(bool send_response) { 105 void LazyResponseGenerator::Complete(bool send_response) {
94 if (send_response) { 106 if (send_response) {
95 SendResponse(name_, request_id_, request_string_.c_str(), responder_); 107 SendResponse(name_, request_id_, request_string_.c_str(), responder_);
96 } 108 }
97 delete responder_; 109 delete responder_;
98 responder_ = nullptr; 110 responder_ = nullptr;
99 } 111 }
100 112
101 } // namespace test 113 } // namespace test
102 } // namespace mojo 114 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/router_test_util.h ('k') | mojo/public/cpp/bindings/tests/router_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698