| OLD | NEW | 
|---|
| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 51 } | 51 } | 
| 52 | 52 | 
| 53 ResponseGenerator::ResponseGenerator() {} | 53 ResponseGenerator::ResponseGenerator() {} | 
| 54 | 54 | 
| 55 bool ResponseGenerator::Accept(Message* message) { | 55 bool ResponseGenerator::Accept(Message* message) { | 
| 56   return false; | 56   return false; | 
| 57 } | 57 } | 
| 58 | 58 | 
| 59 bool ResponseGenerator::AcceptWithResponder( | 59 bool ResponseGenerator::AcceptWithResponder( | 
| 60     Message* message, | 60     Message* message, | 
| 61     MessageReceiverWithStatus* responder) { | 61     std::unique_ptr<MessageReceiverWithStatus> responder) { | 
| 62   EXPECT_TRUE(message->has_flag(Message::kFlagExpectsResponse)); | 62   EXPECT_TRUE(message->has_flag(Message::kFlagExpectsResponse)); | 
| 63 | 63 | 
| 64   bool result = SendResponse(message->name(), message->request_id(), | 64   bool result = SendResponse(message->name(), message->request_id(), | 
| 65                              reinterpret_cast<const char*>(message->payload()), | 65                              reinterpret_cast<const char*>(message->payload()), | 
| 66                              responder); | 66                              responder.get()); | 
| 67   EXPECT_TRUE(responder->IsValid()); | 67   EXPECT_TRUE(responder->IsValid()); | 
| 68   delete responder; |  | 
| 69   return result; | 68   return result; | 
| 70 } | 69 } | 
| 71 | 70 | 
| 72 bool ResponseGenerator::SendResponse(uint32_t name, | 71 bool ResponseGenerator::SendResponse(uint32_t name, | 
| 73                                      uint64_t request_id, | 72                                      uint64_t request_id, | 
| 74                                      const char* request_string, | 73                                      const char* request_string, | 
| 75                                      MessageReceiver* responder) { | 74                                      MessageReceiver* responder) { | 
| 76   Message response; | 75   Message response; | 
| 77   std::string response_string(request_string); | 76   std::string response_string(request_string); | 
| 78   response_string += " world!"; | 77   response_string += " world!"; | 
| 79   AllocResponseMessage(name, response_string.c_str(), request_id, &response); | 78   AllocResponseMessage(name, response_string.c_str(), request_id, &response); | 
| 80 | 79 | 
| 81   return responder->Accept(&response); | 80   return responder->Accept(&response); | 
| 82 } | 81 } | 
| 83 | 82 | 
| 84 LazyResponseGenerator::LazyResponseGenerator(const base::Closure& closure) | 83 LazyResponseGenerator::LazyResponseGenerator(const base::Closure& closure) | 
| 85     : responder_(nullptr), name_(0), request_id_(0), closure_(closure) {} | 84     : responder_(nullptr), name_(0), request_id_(0), closure_(closure) {} | 
| 86 | 85 | 
| 87 LazyResponseGenerator::~LazyResponseGenerator() { | 86 LazyResponseGenerator::~LazyResponseGenerator() = default; | 
| 88   delete responder_; |  | 
| 89 } |  | 
| 90 | 87 | 
| 91 bool LazyResponseGenerator::AcceptWithResponder( | 88 bool LazyResponseGenerator::AcceptWithResponder( | 
| 92     Message* message, | 89     Message* message, | 
| 93     MessageReceiverWithStatus* responder) { | 90     std::unique_ptr<MessageReceiverWithStatus> responder) { | 
| 94   name_ = message->name(); | 91   name_ = message->name(); | 
| 95   request_id_ = message->request_id(); | 92   request_id_ = message->request_id(); | 
| 96   request_string_ = | 93   request_string_ = | 
| 97       std::string(reinterpret_cast<const char*>(message->payload())); | 94       std::string(reinterpret_cast<const char*>(message->payload())); | 
| 98   responder_ = responder; | 95   responder_ = std::move(responder); | 
| 99   if (!closure_.is_null()) { | 96   if (!closure_.is_null()) { | 
| 100     closure_.Run(); | 97     closure_.Run(); | 
| 101     closure_.Reset(); | 98     closure_.Reset(); | 
| 102   } | 99   } | 
| 103   return true; | 100   return true; | 
| 104 } | 101 } | 
| 105 | 102 | 
| 106 void LazyResponseGenerator::Complete(bool send_response) { | 103 void LazyResponseGenerator::Complete(bool send_response) { | 
| 107   if (send_response) { | 104   if (send_response) { | 
| 108     SendResponse(name_, request_id_, request_string_.c_str(), responder_); | 105     SendResponse(name_, request_id_, request_string_.c_str(), responder_.get()); | 
| 109   } | 106   } | 
| 110   delete responder_; |  | 
| 111   responder_ = nullptr; | 107   responder_ = nullptr; | 
| 112 } | 108 } | 
| 113 | 109 | 
| 114 }  // namespace test | 110 }  // namespace test | 
| 115 }  // namespace mojo | 111 }  // namespace mojo | 
| OLD | NEW | 
|---|