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

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

Issue 2766523002: mojo: MessageReceiver*::AcceptWithResponder() now take a unique_ptr to the responder (Closed)
Patch Set: comments Created 3 years, 9 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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_ROUTER_TEST_UTIL_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_ROUTER_TEST_UTIL_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_ROUTER_TEST_UTIL_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_ROUTER_TEST_UTIL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 24 matching lines...) Expand all
35 MessageQueue* queue_; 35 MessageQueue* queue_;
36 base::Closure closure_; 36 base::Closure closure_;
37 }; 37 };
38 38
39 class ResponseGenerator : public MessageReceiverWithResponderStatus { 39 class ResponseGenerator : public MessageReceiverWithResponderStatus {
40 public: 40 public:
41 ResponseGenerator(); 41 ResponseGenerator();
42 42
43 bool Accept(Message* message) override; 43 bool Accept(Message* message) override;
44 44
45 bool AcceptWithResponder(Message* message, 45 bool AcceptWithResponder(
46 MessageReceiverWithStatus* responder) override; 46 Message* message,
47 47 std::unique_ptr<MessageReceiverWithStatus> responder) override;
48 bool SendResponse(uint32_t name, 48 bool SendResponse(uint32_t name,
49 uint64_t request_id, 49 uint64_t request_id,
50 const char* request_string, 50 const char* request_string,
51 MessageReceiver* responder); 51 MessageReceiver* responder);
52 }; 52 };
53 53
54 class LazyResponseGenerator : public ResponseGenerator { 54 class LazyResponseGenerator : public ResponseGenerator {
55 public: 55 public:
56 explicit LazyResponseGenerator( 56 explicit LazyResponseGenerator(
57 const base::Closure& closure = base::Closure()); 57 const base::Closure& closure = base::Closure());
58 58
59 ~LazyResponseGenerator() override; 59 ~LazyResponseGenerator() override;
60 60
61 bool AcceptWithResponder(Message* message, 61 bool AcceptWithResponder(
62 MessageReceiverWithStatus* responder) override; 62 Message* message,
63 std::unique_ptr<MessageReceiverWithStatus> responder) override;
63 64
64 bool has_responder() const { return !!responder_; } 65 bool has_responder() const { return !!responder_; }
65 66
66 bool responder_is_valid() const { return responder_->IsValid(); } 67 bool responder_is_valid() const { return responder_->IsValid(); }
67 68
68 void set_closure(const base::Closure& closure) { closure_ = closure; } 69 void set_closure(const base::Closure& closure) { closure_ = closure; }
69 70
70 // Sends the response and delete the responder. 71 // Sends the response and delete the responder.
71 void CompleteWithResponse() { Complete(true); } 72 void CompleteWithResponse() { Complete(true); }
72 73
73 // Deletes the responder without sending a response. 74 // Deletes the responder without sending a response.
74 void CompleteWithoutResponse() { Complete(false); } 75 void CompleteWithoutResponse() { Complete(false); }
75 76
76 private: 77 private:
77 // Completes the request handling by deleting responder_. Optionally 78 // Completes the request handling by deleting responder_. Optionally
78 // also sends a response. 79 // also sends a response.
79 void Complete(bool send_response); 80 void Complete(bool send_response);
80 81
81 MessageReceiverWithStatus* responder_; 82 std::unique_ptr<MessageReceiverWithStatus> responder_;
82 uint32_t name_; 83 uint32_t name_;
83 uint64_t request_id_; 84 uint64_t request_id_;
84 std::string request_string_; 85 std::string request_string_;
85 base::Closure closure_; 86 base::Closure closure_;
86 }; 87 };
87 88
88 } // namespace test 89 } // namespace test
89 } // namespace mojo 90 } // namespace mojo
90 91
91 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_ROUTER_TEST_UTIL_H_ 92 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_ROUTER_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/multiplex_router_unittest.cc ('k') | mojo/public/cpp/bindings/tests/router_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698