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

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

Issue 1531543003: Modify bindings to enforce that an error handler callback is only set after binding to a msg pipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-binding-error-handler
Patch Set: Add error handler comment. Created 5 years 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 | « no previous file | mojo/public/cpp/bindings/binding.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 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_ASSOCIATED_BINDING_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "mojo/public/cpp/bindings/associated_group.h" 10 #include "mojo/public/cpp/bindings/associated_group.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 [this]() { connection_error_handler_.Run(); }); 83 [this]() { connection_error_handler_.Run(); });
84 84
85 stub_.serialization_context()->router = endpoint_client_->router(); 85 stub_.serialization_context()->router = endpoint_client_->router();
86 } 86 }
87 87
88 // Closes the associated interface. Puts this object into a state where it can 88 // Closes the associated interface. Puts this object into a state where it can
89 // be rebound. 89 // be rebound.
90 void Close() { 90 void Close() {
91 DCHECK(endpoint_client_); 91 DCHECK(endpoint_client_);
92 endpoint_client_.reset(); 92 endpoint_client_.reset();
93 connection_error_handler_.reset();
93 } 94 }
94 95
95 // Unbinds and returns the associated interface request so it can be 96 // Unbinds and returns the associated interface request so it can be
96 // used in another context, such as on another thread or with a different 97 // used in another context, such as on another thread or with a different
97 // implementation. Puts this object into a state where it can be rebound. 98 // implementation. Puts this object into a state where it can be rebound.
98 AssociatedInterfaceRequest<Interface> Unbind() { 99 AssociatedInterfaceRequest<Interface> Unbind() {
99 DCHECK(endpoint_client_); 100 DCHECK(endpoint_client_);
100 101
101 AssociatedInterfaceRequest<Interface> request; 102 AssociatedInterfaceRequest<Interface> request;
102 internal::AssociatedInterfaceRequestHelper::SetHandle( 103 internal::AssociatedInterfaceRequestHelper::SetHandle(
103 &request, endpoint_client_->PassHandle()); 104 &request, endpoint_client_->PassHandle());
104 105
105 endpoint_client_.reset(); 106 endpoint_client_.reset();
107 connection_error_handler_.reset();
106 108
107 return request.Pass(); 109 return request.Pass();
108 } 110 }
109 111
110 // Sets an error handler that will be called if a connection error occurs. 112 // Sets an error handler that will be called if a connection error occurs.
113 //
114 // This method may only be called after this AssociatedBinding has been bound
115 // to a message pipe. The error handler will be reset when this
116 // AssociatedBinding is unbound or closed.
111 void set_connection_error_handler(const Closure& error_handler) { 117 void set_connection_error_handler(const Closure& error_handler) {
118 DCHECK(is_bound());
112 connection_error_handler_ = error_handler; 119 connection_error_handler_ = error_handler;
113 } 120 }
114 121
115 // Returns the interface implementation that was previously specified. 122 // Returns the interface implementation that was previously specified.
116 Interface* impl() { return impl_; } 123 Interface* impl() { return impl_; }
117 124
118 // Indicates whether the associated binding has been completed. 125 // Indicates whether the associated binding has been completed.
119 bool is_bound() const { return !!endpoint_client_; } 126 bool is_bound() const { return !!endpoint_client_; }
120 127
121 // Returns the associated group that this object belongs to. Returns null if 128 // Returns the associated group that this object belongs to. Returns null if
122 // the object is not bound. 129 // the object is not bound.
123 AssociatedGroup* associated_group() { 130 AssociatedGroup* associated_group() {
124 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr; 131 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr;
125 } 132 }
126 133
127 private: 134 private:
128 scoped_ptr<internal::InterfaceEndpointClient> endpoint_client_; 135 scoped_ptr<internal::InterfaceEndpointClient> endpoint_client_;
129 136
130 typename Interface::Stub_ stub_; 137 typename Interface::Stub_ stub_;
131 Interface* impl_; 138 Interface* impl_;
132 Closure connection_error_handler_; 139 Closure connection_error_handler_;
133 140
134 DISALLOW_COPY_AND_ASSIGN(AssociatedBinding); 141 DISALLOW_COPY_AND_ASSIGN(AssociatedBinding);
135 }; 142 };
136 143
137 } // namespace mojo 144 } // namespace mojo
138 145
139 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ 146 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/binding.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698