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

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

Issue 2086223002: Convert instant search messages to Mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge Created 4 years, 2 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_ASSOCIATED_INTERFACE_PTR_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 bool operator!=(const AssociatedInterfacePtr<T>& other) const = delete; 197 bool operator!=(const AssociatedInterfacePtr<T>& other) const = delete;
198 198
199 typedef internal::AssociatedInterfacePtrState<Interface> State; 199 typedef internal::AssociatedInterfacePtrState<Interface> State;
200 mutable State internal_state_; 200 mutable State internal_state_;
201 201
202 DISALLOW_COPY_AND_ASSIGN(AssociatedInterfacePtr); 202 DISALLOW_COPY_AND_ASSIGN(AssociatedInterfacePtr);
203 }; 203 };
204 204
205 // Creates an associated interface. The output |ptr| should be used locally 205 // Creates an associated interface. The output |ptr| should be used locally
206 // while the returned request should be passed through the message pipe endpoint 206 // while the returned request should be passed through the message pipe endpoint
207 // referred to by |associated_group| to setup the corresponding asssociated 207 // referred to by |associated_group| to setup the corresponding associated
208 // interface implementation at the remote side. 208 // interface implementation at the remote side.
209 // 209 //
210 // NOTE: |ptr| should NOT be used to make calls before the request is sent. 210 // NOTE: |ptr| should NOT be used to make calls before the request is sent.
211 // Violating that will cause the message pipe to be closed. On the other hand, 211 // Violating that will cause the message pipe to be closed. On the other hand,
212 // as soon as the request is sent, |ptr| is usable. There is no need to wait 212 // as soon as the request is sent, |ptr| is usable. There is no need to wait
213 // until the request is bound to an implementation at the remote side. 213 // until the request is bound to an implementation at the remote side.
214 template <typename Interface> 214 template <typename Interface>
215 AssociatedInterfaceRequest<Interface> GetProxy( 215 AssociatedInterfaceRequest<Interface> GetProxy(
216 AssociatedInterfacePtr<Interface>* ptr, 216 AssociatedInterfacePtr<Interface>* ptr,
217 AssociatedGroup* group, 217 AssociatedGroup* group,
218 scoped_refptr<base::SingleThreadTaskRunner> runner = 218 scoped_refptr<base::SingleThreadTaskRunner> runner =
219 base::ThreadTaskRunnerHandle::Get()) { 219 base::ThreadTaskRunnerHandle::Get()) {
220 AssociatedInterfaceRequest<Interface> request; 220 AssociatedInterfaceRequest<Interface> request;
221 AssociatedInterfacePtrInfo<Interface> ptr_info; 221 AssociatedInterfacePtrInfo<Interface> ptr_info;
222 group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_REQUEST, 222 group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_REQUEST,
223 &ptr_info, &request); 223 &ptr_info, &request);
224 224
225 ptr->Bind(std::move(ptr_info), std::move(runner)); 225 ptr->Bind(std::move(ptr_info), std::move(runner));
226 return request; 226 return request;
227 } 227 }
228 228
229 // Creates an associated interface proxy which casts its messages into the void. 229 // Like |GetProxy|, but the interface is never associated with any other
230 // interface. The returned request can be bound directly to the corresponding
231 // associated interface implementation, without first passing it through a
232 // message pipe endpoint.
233 //
234 // This function has two main uses:
235 //
236 // * In testing, where the returned request is bound to e.g. a mock and there
237 // are no other interfaces involved.
238 //
239 // * When discarding messages sent on an interface, which can be done by
240 // discarding the returned request.
230 template <typename Interface> 241 template <typename Interface>
231 void GetDummyProxyForTesting(AssociatedInterfacePtr<Interface>* proxy) { 242 AssociatedInterfaceRequest<Interface> GetIsolatedProxy(
243 AssociatedInterfacePtr<Interface>* ptr) {
232 MessagePipe pipe; 244 MessagePipe pipe;
233 scoped_refptr<internal::MultiplexRouter> router = 245 scoped_refptr<internal::MultiplexRouter> router0 =
234 new internal::MultiplexRouter(std::move(pipe.handle0), 246 new internal::MultiplexRouter(std::move(pipe.handle0),
235 internal::MultiplexRouter::MULTI_INTERFACE, 247 internal::MultiplexRouter::MULTI_INTERFACE,
236 false, base::ThreadTaskRunnerHandle::Get()); 248 false, base::ThreadTaskRunnerHandle::Get());
237 std::unique_ptr<AssociatedGroup> group = router->CreateAssociatedGroup(); 249 scoped_refptr<internal::MultiplexRouter> router1 =
238 GetProxy(proxy, group.get()); 250 new internal::MultiplexRouter(std::move(pipe.handle1),
251 internal::MultiplexRouter::MULTI_INTERFACE,
252 true, base::ThreadTaskRunnerHandle::Get());
253
254 ScopedInterfaceEndpointHandle endpoint0, endpoint1;
255 router0->CreateEndpointHandlePair(&endpoint0, &endpoint1);
256 endpoint1 = router1->CreateLocalEndpointHandle(endpoint1.release());
257
258 ptr->Bind(AssociatedInterfacePtrInfo<Interface>(std::move(endpoint0),
259 Interface::Version_));
260
261 AssociatedInterfaceRequest<Interface> request;
262 request.Bind(std::move(endpoint1));
263 return request;
239 } 264 }
240 265
241 } // namespace mojo 266 } // namespace mojo
242 267
243 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ 268 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698