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

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

Issue 1991463002: Mojo: Expose untyped associated endpoints through public API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/BUILD.gn ('k') | mojo/public/cpp/bindings/associated_group.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 <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "mojo/public/cpp/bindings/associated_group.h" 16 #include "mojo/public/cpp/bindings/associated_group.h"
17 #include "mojo/public/cpp/bindings/associated_interface_request.h" 17 #include "mojo/public/cpp/bindings/associated_interface_request.h"
18 #include "mojo/public/cpp/bindings/callback.h" 18 #include "mojo/public/cpp/bindings/callback.h"
19 #include "mojo/public/cpp/bindings/lib/interface_endpoint_client.h" 19 #include "mojo/public/cpp/bindings/lib/interface_endpoint_client.h"
20 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" 20 #include "mojo/public/cpp/bindings/lib/multiplex_router.h"
21 #include "mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h" 21 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
22 22
23 namespace mojo { 23 namespace mojo {
24 24
25 // Represents the implementation side of an associated interface. It is similar 25 // Represents the implementation side of an associated interface. It is similar
26 // to Binding, except that it doesn't own a message pipe handle. 26 // to Binding, except that it doesn't own a message pipe handle.
27 // 27 //
28 // When you bind this class to a request, optionally you can specify a 28 // When you bind this class to a request, optionally you can specify a
29 // base::SingleThreadTaskRunner. This task runner must belong to the same 29 // base::SingleThreadTaskRunner. This task runner must belong to the same
30 // thread. It will be used to dispatch incoming method calls and connection 30 // thread. It will be used to dispatch incoming method calls and connection
31 // error notification. It is useful when you attach multiple task runners to a 31 // error notification. It is useful when you attach multiple task runners to a
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 AssociatedInterfaceRequest<Interface> request; 79 AssociatedInterfaceRequest<Interface> request;
80 associated_group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_PTR, 80 associated_group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_PTR,
81 ptr_info, &request); 81 ptr_info, &request);
82 Bind(std::move(request), std::move(runner)); 82 Bind(std::move(request), std::move(runner));
83 } 83 }
84 84
85 // Sets up this object as the implementation side of an associated interface. 85 // Sets up this object as the implementation side of an associated interface.
86 void Bind(AssociatedInterfaceRequest<Interface> request, 86 void Bind(AssociatedInterfaceRequest<Interface> request,
87 scoped_refptr<base::SingleThreadTaskRunner> runner = 87 scoped_refptr<base::SingleThreadTaskRunner> runner =
88 base::ThreadTaskRunnerHandle::Get()) { 88 base::ThreadTaskRunnerHandle::Get()) {
89 internal::ScopedInterfaceEndpointHandle handle = 89 ScopedInterfaceEndpointHandle handle = request.PassHandle();
90 internal::AssociatedInterfaceRequestHelper::PassHandle(&request);
91 90
92 DCHECK(handle.is_local()) 91 DCHECK(handle.is_local())
93 << "The AssociatedInterfaceRequest is supposed to be used at the " 92 << "The AssociatedInterfaceRequest is supposed to be used at the "
94 << "other side of the message pipe."; 93 << "other side of the message pipe.";
95 94
96 if (!handle.is_valid() || !handle.is_local()) { 95 if (!handle.is_valid() || !handle.is_local()) {
97 endpoint_client_.reset(); 96 endpoint_client_.reset();
98 return; 97 return;
99 } 98 }
100 99
(...skipping 15 matching lines...) Expand all
116 connection_error_handler_.reset(); 115 connection_error_handler_.reset();
117 } 116 }
118 117
119 // Unbinds and returns the associated interface request so it can be 118 // Unbinds and returns the associated interface request so it can be
120 // used in another context, such as on another thread or with a different 119 // used in another context, such as on another thread or with a different
121 // implementation. Puts this object into a state where it can be rebound. 120 // implementation. Puts this object into a state where it can be rebound.
122 AssociatedInterfaceRequest<Interface> Unbind() { 121 AssociatedInterfaceRequest<Interface> Unbind() {
123 DCHECK(endpoint_client_); 122 DCHECK(endpoint_client_);
124 123
125 AssociatedInterfaceRequest<Interface> request; 124 AssociatedInterfaceRequest<Interface> request;
126 internal::AssociatedInterfaceRequestHelper::SetHandle( 125 request.Bind(endpoint_client_->PassHandle());
127 &request, endpoint_client_->PassHandle());
128 126
129 endpoint_client_.reset(); 127 endpoint_client_.reset();
130 connection_error_handler_.reset(); 128 connection_error_handler_.reset();
131 129
132 return request; 130 return request;
133 } 131 }
134 132
135 // Sets an error handler that will be called if a connection error occurs. 133 // Sets an error handler that will be called if a connection error occurs.
136 // 134 //
137 // This method may only be called after this AssociatedBinding has been bound 135 // This method may only be called after this AssociatedBinding has been bound
(...skipping 22 matching lines...) Expand all
160 typename Interface::Stub_ stub_; 158 typename Interface::Stub_ stub_;
161 Interface* impl_; 159 Interface* impl_;
162 Closure connection_error_handler_; 160 Closure connection_error_handler_;
163 161
164 DISALLOW_COPY_AND_ASSIGN(AssociatedBinding); 162 DISALLOW_COPY_AND_ASSIGN(AssociatedBinding);
165 }; 163 };
166 164
167 } // namespace mojo 165 } // namespace mojo
168 166
169 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ 167 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/BUILD.gn ('k') | mojo/public/cpp/bindings/associated_group.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698