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

Side by Side Diff: mojo/public/cpp/bindings/binding.h

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: Fixed BUILD.gn file. Created 5 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 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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_
7 7
8 #include "mojo/public/c/environment/async_waiter.h" 8 #include "mojo/public/c/environment/async_waiter.h"
9 #include "mojo/public/cpp/bindings/error_handler.h" 9 #include "mojo/public/cpp/bindings/error_handler.h"
10 #include "mojo/public/cpp/bindings/interface_ptr.h" 10 #include "mojo/public/cpp/bindings/interface_ptr.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // Blocks the calling thread until either a call arrives on the previously 149 // Blocks the calling thread until either a call arrives on the previously
150 // bound message pipe, or an error occurs. 150 // bound message pipe, or an error occurs.
151 bool WaitForIncomingMethodCall() { 151 bool WaitForIncomingMethodCall() {
152 MOJO_DCHECK(internal_router_); 152 MOJO_DCHECK(internal_router_);
153 return internal_router_->WaitForIncomingMessage(); 153 return internal_router_->WaitForIncomingMessage();
154 } 154 }
155 155
156 // Closes the message pipe that was previously bound. Put this object into a 156 // Closes the message pipe that was previously bound. Put this object into a
157 // state where it can be rebound to a new pipe. 157 // state where it can be rebound to a new pipe.
158 void Close() { 158 void Close() {
159 stub_.Close();
159 MOJO_DCHECK(internal_router_); 160 MOJO_DCHECK(internal_router_);
160 internal_router_->CloseMessagePipe(); 161 internal_router_->CloseMessagePipe();
161 DestroyRouter(); 162 DestroyRouter();
162 } 163 }
163 164
164 // Unbinds the underlying pipe from this binding and returns it so it can be 165 // Unbinds the underlying pipe from this binding and returns it so it can be
165 // used in another context, such as on another thread or with a different 166 // used in another context, such as on another thread or with a different
166 // implementation. Put this object into a state where it can be rebound to a 167 // implementation. Put this object into a state where it can be rebound to a
167 // new pipe. 168 // new pipe.
168 InterfaceRequest<Interface> Unbind() { 169 InterfaceRequest<Interface> Unbind() {
169 InterfaceRequest<Interface> request = 170 InterfaceRequest<Interface> request =
170 MakeRequest<Interface>(internal_router_->PassMessagePipe()); 171 MakeRequest<Interface>(internal_router_->PassMessagePipe());
171 DestroyRouter(); 172 DestroyRouter();
172 // TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove 173 // TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove
173 // it once that's fixed. 174 // it once that's fixed.
174 return request.Pass(); 175 return request.Pass();
175 } 176 }
176 177
177 // Sets an error handler that will be called if a connection error occurs on 178 // Sets an error handler that will be called if a connection error occurs on
178 // the bound message pipe. 179 // the bound message pipe.
179 void set_error_handler(ErrorHandler* error_handler) { 180 void set_error_handler(ErrorHandler* error_handler) {
180 error_handler_ = error_handler; 181 error_handler_ = error_handler;
181 } 182 }
182 183
183 // Implements the |Binding|'s response to a connection error. 184 // Implements the |Binding|'s response to a connection error.
184 void OnConnectionError() override { 185 void OnConnectionError() override {
186 // Note that it is important that we tell |stub_| that there was a
187 // connection error before we tell |error_handler_|. This is because
188 // in response |error_handler_| may destroy a Callback that hasn't been
189 // run and this will cause |stub_| to DCHECK unless it also knows that
190 // this happened for a legitimate reason, namely that a connection error
191 // occurred.
192 stub_.OnConnectionError();
185 if (error_handler_) 193 if (error_handler_)
186 error_handler_->OnConnectionError(); 194 error_handler_->OnConnectionError();
187 } 195 }
188 196
189 // Returns the interface implementation that was previously specified. Caller 197 // Returns the interface implementation that was previously specified. Caller
190 // does not take ownership. 198 // does not take ownership.
191 Interface* impl() { return impl_; } 199 Interface* impl() { return impl_; }
192 200
193 // Indicates whether the binding has been completed (i.e., whether a message 201 // Indicates whether the binding has been completed (i.e., whether a message
194 // pipe has been bound to the implementation). 202 // pipe has been bound to the implementation).
(...skipping 13 matching lines...) Expand all
208 typename Interface::Stub_ stub_; 216 typename Interface::Stub_ stub_;
209 Interface* impl_; 217 Interface* impl_;
210 ErrorHandler* error_handler_ = nullptr; 218 ErrorHandler* error_handler_ = nullptr;
211 219
212 MOJO_DISALLOW_COPY_AND_ASSIGN(Binding); 220 MOJO_DISALLOW_COPY_AND_ASSIGN(Binding);
213 }; 221 };
214 222
215 } // namespace mojo 223 } // namespace mojo
216 224
217 #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ 225 #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/tests/BUILD.gn » ('j') | mojo/public/cpp/bindings/tests/BUILD.gn » ('J')

Powered by Google App Engine
This is Rietveld 408576698