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

Side by Side Diff: mojo/public/cpp/bindings/lib/multiplex_router.h

Issue 2064903002: Mojo: Report bindings validation errors via MojoNotifyBadMessage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 6 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_LIB_MULTIPLEX_ROUTER_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_MULTIPLEX_ROUTER_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MULTIPLEX_ROUTER_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MULTIPLEX_ROUTER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <deque> 10 #include <deque>
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 const ScopedInterfaceEndpointHandle& handle, 88 const ScopedInterfaceEndpointHandle& handle,
89 InterfaceEndpointClient* endpoint_client, 89 InterfaceEndpointClient* endpoint_client,
90 scoped_refptr<base::SingleThreadTaskRunner> runner); 90 scoped_refptr<base::SingleThreadTaskRunner> runner);
91 91
92 // Detaches the client attached to the specified endpoint. It must be called 92 // Detaches the client attached to the specified endpoint. It must be called
93 // on the same thread as the corresponding AttachEndpointClient() call. 93 // on the same thread as the corresponding AttachEndpointClient() call.
94 void DetachEndpointClient(const ScopedInterfaceEndpointHandle& handle); 94 void DetachEndpointClient(const ScopedInterfaceEndpointHandle& handle);
95 95
96 // Raises an error on the underlying message pipe. It disconnects the pipe 96 // Raises an error on the underlying message pipe. It disconnects the pipe
97 // and notifies all interfaces running on this pipe. 97 // and notifies all interfaces running on this pipe.
98 void RaiseError(); 98 void RaiseError(Result error);
99 99
100 std::unique_ptr<AssociatedGroup> CreateAssociatedGroup(); 100 std::unique_ptr<AssociatedGroup> CreateAssociatedGroup();
101 101
102 static MultiplexRouter* GetRouter(AssociatedGroup* associated_group); 102 static MultiplexRouter* GetRouter(AssociatedGroup* associated_group);
103 103
104 // --------------------------------------------------------------------------- 104 // ---------------------------------------------------------------------------
105 // The following public methods are called on the creating thread. 105 // The following public methods are called on the creating thread.
106 106
107 // Please note that this method shouldn't be called unless it results from an 107 // Please note that this method shouldn't be called unless it results from an
108 // explicit request of the user of bindings (e.g., the user sets an 108 // explicit request of the user of bindings (e.g., the user sets an
(...skipping 19 matching lines...) Expand all
128 connector_.PauseIncomingMethodCallProcessing(); 128 connector_.PauseIncomingMethodCallProcessing();
129 } 129 }
130 void ResumeIncomingMethodCallProcessing() { 130 void ResumeIncomingMethodCallProcessing() {
131 DCHECK(thread_checker_.CalledOnValidThread()); 131 DCHECK(thread_checker_.CalledOnValidThread());
132 connector_.ResumeIncomingMethodCallProcessing(); 132 connector_.ResumeIncomingMethodCallProcessing();
133 } 133 }
134 134
135 // Whether there are any associated interfaces running currently. 135 // Whether there are any associated interfaces running currently.
136 bool HasAssociatedEndpoints() const; 136 bool HasAssociatedEndpoints() const;
137 137
138 // Sets the master interface name. Used only for debugging information.
139 void SetMasterInterfaceName(const std::string& name);
140
138 // Sets this object to testing mode. 141 // Sets this object to testing mode.
139 // In testing mode, the object doesn't disconnect the underlying message pipe 142 // In testing mode, the object doesn't disconnect the underlying message pipe
140 // when it receives unexpected or invalid messages. 143 // when it receives unexpected or invalid messages.
141 void EnableTestingMode(); 144 void EnableTestingMode();
142 145
143 // Is the router bound to a message pipe handle? 146 // Is the router bound to a message pipe handle?
144 bool is_valid() const { 147 bool is_valid() const {
145 DCHECK(thread_checker_.CalledOnValidThread()); 148 DCHECK(thread_checker_.CalledOnValidThread());
146 return connector_.is_valid(); 149 return connector_.is_valid();
147 } 150 }
148 151
149 // TODO(yzshen): consider removing this getter. 152 // TODO(yzshen): consider removing this getter.
150 MessagePipeHandle handle() const { 153 MessagePipeHandle handle() const {
151 DCHECK(thread_checker_.CalledOnValidThread()); 154 DCHECK(thread_checker_.CalledOnValidThread());
152 return connector_.handle(); 155 return connector_.handle();
153 } 156 }
154 157
155 private: 158 private:
156 friend class base::RefCountedDeleteOnMessageLoop<MultiplexRouter>; 159 friend class base::RefCountedDeleteOnMessageLoop<MultiplexRouter>;
157 friend class base::DeleteHelper<MultiplexRouter>; 160 friend class base::DeleteHelper<MultiplexRouter>;
158 161
159 class InterfaceEndpoint; 162 class InterfaceEndpoint;
160 struct Task; 163 struct Task;
161 164
162 ~MultiplexRouter() override; 165 ~MultiplexRouter() override;
163 166
164 // MessageReceiver implementation: 167 // MessageReceiver implementation:
165 bool Accept(Message* message) override; 168 Result Accept(Message* message) override;
166 169
167 // PipeControlMessageHandlerDelegate implementation: 170 // PipeControlMessageHandlerDelegate implementation:
168 bool OnPeerAssociatedEndpointClosed(InterfaceId id) override; 171 bool OnPeerAssociatedEndpointClosed(InterfaceId id) override;
169 bool OnAssociatedEndpointClosedBeforeSent(InterfaceId id) override; 172 bool OnAssociatedEndpointClosedBeforeSent(InterfaceId id) override;
170 173
171 void OnPipeConnectionError(); 174 void OnPipeConnectionError();
172 175
173 // Specifies whether we are allowed to directly call into 176 // Specifies whether we are allowed to directly call into
174 // InterfaceEndpointClient (given that we are already on the same thread as 177 // InterfaceEndpointClient (given that we are already on the same thread as
175 // the client). 178 // the client).
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 void MaybePostToProcessTasks(base::SingleThreadTaskRunner* task_runner); 219 void MaybePostToProcessTasks(base::SingleThreadTaskRunner* task_runner);
217 void LockAndCallProcessTasks(); 220 void LockAndCallProcessTasks();
218 221
219 // Updates the state of |endpoint|. If both the endpoint and its peer have 222 // Updates the state of |endpoint|. If both the endpoint and its peer have
220 // been closed, removes it from |endpoints_|. 223 // been closed, removes it from |endpoints_|.
221 // NOTE: The method may invalidate |endpoint|. 224 // NOTE: The method may invalidate |endpoint|.
222 enum EndpointStateUpdateType { ENDPOINT_CLOSED, PEER_ENDPOINT_CLOSED }; 225 enum EndpointStateUpdateType { ENDPOINT_CLOSED, PEER_ENDPOINT_CLOSED };
223 void UpdateEndpointStateMayRemove(InterfaceEndpoint* endpoint, 226 void UpdateEndpointStateMayRemove(InterfaceEndpoint* endpoint,
224 EndpointStateUpdateType type); 227 EndpointStateUpdateType type);
225 228
226 void RaiseErrorInNonTestingMode(); 229 void RaiseErrorInNonTestingMode(Result error);
227 230
228 InterfaceEndpoint* FindOrInsertEndpoint(InterfaceId id, bool* inserted); 231 InterfaceEndpoint* FindOrInsertEndpoint(InterfaceId id, bool* inserted);
229 232
230 // Whether to set the namespace bit when generating interface IDs. Please see 233 // Whether to set the namespace bit when generating interface IDs. Please see
231 // comments of kInterfaceIdNamespaceMask. 234 // comments of kInterfaceIdNamespaceMask.
232 const bool set_interface_id_namespace_bit_; 235 const bool set_interface_id_namespace_bit_;
233 236
234 MessageHeaderValidator header_validator_; 237 MessageHeaderValidator header_validator_;
235 Connector connector_; 238 Connector connector_;
236 239
(...skipping 18 matching lines...) Expand all
255 258
256 bool testing_mode_; 259 bool testing_mode_;
257 260
258 DISALLOW_COPY_AND_ASSIGN(MultiplexRouter); 261 DISALLOW_COPY_AND_ASSIGN(MultiplexRouter);
259 }; 262 };
260 263
261 } // namespace internal 264 } // namespace internal
262 } // namespace mojo 265 } // namespace mojo
263 266
264 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MULTIPLEX_ROUTER_H_ 267 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MULTIPLEX_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698