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

Side by Side Diff: mojo/public/cpp/bindings/lib/router.cc

Issue 1003773002: CPP bindings: DCHECK when a Callback is destructed without being invoked (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased again Created 5 years, 8 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
« no previous file with comments | « mojo/public/cpp/bindings/lib/router.h ('k') | mojo/public/cpp/bindings/message.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/lib/router.h" 5 #include "mojo/public/cpp/bindings/lib/router.h"
6 6
7 #include "mojo/public/cpp/environment/logging.h" 7 #include "mojo/public/cpp/environment/logging.h"
8 8
9 namespace mojo { 9 namespace mojo {
10 namespace internal { 10 namespace internal {
11 11
12 // ---------------------------------------------------------------------------- 12 // ----------------------------------------------------------------------------
13 13
14 class ResponderThunk : public MessageReceiver { 14 class ResponderThunk : public MessageReceiverWithStatus {
15 public: 15 public:
16 explicit ResponderThunk(const SharedData<Router*>& router) 16 explicit ResponderThunk(const SharedData<Router*>& router)
17 : router_(router), accept_was_invoked_(false) {} 17 : router_(router), accept_was_invoked_(false) {}
18 ~ResponderThunk() override { 18 ~ResponderThunk() override {
19 if (!accept_was_invoked_) { 19 if (!accept_was_invoked_) {
20 // The Mojo application handled a message that was expecting a response 20 // The Mojo application handled a message that was expecting a response
21 // but did not send a response. 21 // but did not send a response.
22 Router* router = router_.value(); 22 Router* router = router_.value();
23 if (router) { 23 if (router) {
24 // We close the pipe here as a way of signaling to the calling 24 // We close the pipe here as a way of signaling to the calling
(...skipping 12 matching lines...) Expand all
37 37
38 bool result = false; 38 bool result = false;
39 39
40 Router* router = router_.value(); 40 Router* router = router_.value();
41 if (router) 41 if (router)
42 result = router->Accept(message); 42 result = router->Accept(message);
43 43
44 return result; 44 return result;
45 } 45 }
46 46
47 // MessageReceiverWithStatus implementation:
48 bool IsValid() override {
49 Router* router = router_.value();
50 return router && !router->encountered_error() && router->is_valid();
51 }
52
47 private: 53 private:
48 SharedData<Router*> router_; 54 SharedData<Router*> router_;
49 bool accept_was_invoked_; 55 bool accept_was_invoked_;
50 }; 56 };
51 57
52 // ---------------------------------------------------------------------------- 58 // ----------------------------------------------------------------------------
53 59
54 Router::HandleIncomingMessageThunk::HandleIncomingMessageThunk(Router* router) 60 Router::HandleIncomingMessageThunk::HandleIncomingMessageThunk(Router* router)
55 : router_(router) { 61 : router_(router) {
56 } 62 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 117 }
112 118
113 void Router::EnableTestingMode() { 119 void Router::EnableTestingMode() {
114 testing_mode_ = true; 120 testing_mode_ = true;
115 connector_.set_enforce_errors_from_incoming_receiver(false); 121 connector_.set_enforce_errors_from_incoming_receiver(false);
116 } 122 }
117 123
118 bool Router::HandleIncomingMessage(Message* message) { 124 bool Router::HandleIncomingMessage(Message* message) {
119 if (message->has_flag(kMessageExpectsResponse)) { 125 if (message->has_flag(kMessageExpectsResponse)) {
120 if (incoming_receiver_) { 126 if (incoming_receiver_) {
121 MessageReceiver* responder = new ResponderThunk(weak_self_); 127 MessageReceiverWithStatus* responder = new ResponderThunk(weak_self_);
122 bool ok = incoming_receiver_->AcceptWithResponder(message, responder); 128 bool ok = incoming_receiver_->AcceptWithResponder(message, responder);
123 if (!ok) 129 if (!ok)
124 delete responder; 130 delete responder;
125 return ok; 131 return ok;
126 } 132 }
127 133
128 // If we receive a request expecting a response when the client is not 134 // If we receive a request expecting a response when the client is not
129 // listening, then we have no choice but to tear down the pipe. 135 // listening, then we have no choice but to tear down the pipe.
130 connector_.CloseMessagePipe(); 136 connector_.CloseMessagePipe();
131 } else if (message->has_flag(kMessageIsResponse)) { 137 } else if (message->has_flag(kMessageIsResponse)) {
(...skipping 14 matching lines...) Expand all
146 // OK to drop message on the floor. 152 // OK to drop message on the floor.
147 } 153 }
148 154
149 return false; 155 return false;
150 } 156 }
151 157
152 // ---------------------------------------------------------------------------- 158 // ----------------------------------------------------------------------------
153 159
154 } // namespace internal 160 } // namespace internal
155 } // namespace mojo 161 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/router.h ('k') | mojo/public/cpp/bindings/message.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698