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

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

Issue 2702603002: Mojo C++ bindings: remove unnecessary getters/params of AssociatedGroup. (Closed)
Patch Set: . Created 3 years, 10 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 | « no previous file | 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 <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
20 #include "mojo/public/cpp/bindings/associated_group.h" 20 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h"
21 #include "mojo/public/cpp/bindings/associated_interface_request.h" 21 #include "mojo/public/cpp/bindings/associated_interface_request.h"
22 #include "mojo/public/cpp/bindings/bindings_export.h" 22 #include "mojo/public/cpp/bindings/bindings_export.h"
23 #include "mojo/public/cpp/bindings/connection_error_callback.h" 23 #include "mojo/public/cpp/bindings/connection_error_callback.h"
24 #include "mojo/public/cpp/bindings/interface_endpoint_client.h" 24 #include "mojo/public/cpp/bindings/interface_endpoint_client.h"
25 #include "mojo/public/cpp/bindings/raw_ptr_impl_ref_traits.h" 25 #include "mojo/public/cpp/bindings/raw_ptr_impl_ref_traits.h"
26 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" 26 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
27 27
28 namespace mojo { 28 namespace mojo {
29 29
30 class MessageReceiver; 30 class MessageReceiver;
(...skipping 23 matching lines...) Expand all
54 // to a message pipe. The error handler will be reset when this 54 // to a message pipe. The error handler will be reset when this
55 // AssociatedBinding is unbound or closed. 55 // AssociatedBinding is unbound or closed.
56 void set_connection_error_handler(const base::Closure& error_handler); 56 void set_connection_error_handler(const base::Closure& error_handler);
57 57
58 void set_connection_error_with_reason_handler( 58 void set_connection_error_with_reason_handler(
59 const ConnectionErrorWithReasonCallback& error_handler); 59 const ConnectionErrorWithReasonCallback& error_handler);
60 60
61 // Indicates whether the associated binding has been completed. 61 // Indicates whether the associated binding has been completed.
62 bool is_bound() const { return !!endpoint_client_; } 62 bool is_bound() const { return !!endpoint_client_; }
63 63
64 // Returns the associated group that this object belongs to. Returns null if
65 // the object is not bound.
66 AssociatedGroup* associated_group() {
67 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr;
68 }
69
70 // Sends a message on the underlying message pipe and runs the current 64 // Sends a message on the underlying message pipe and runs the current
71 // message loop until its response is received. This can be used in tests to 65 // message loop until its response is received. This can be used in tests to
72 // verify that no message was sent on a message pipe in response to some 66 // verify that no message was sent on a message pipe in response to some
73 // stimulus. 67 // stimulus.
74 void FlushForTesting(); 68 void FlushForTesting();
75 69
76 protected: 70 protected:
77 void BindImpl(ScopedInterfaceEndpointHandle handle, 71 void BindImpl(ScopedInterfaceEndpointHandle handle,
78 MessageReceiverWithResponderStatus* receiver, 72 MessageReceiverWithResponderStatus* receiver,
79 std::unique_ptr<MessageReceiver> payload_validator, 73 std::unique_ptr<MessageReceiver> payload_validator,
(...skipping 23 matching lines...) Expand all
103 // Constructs an incomplete associated binding that will use the 97 // Constructs an incomplete associated binding that will use the
104 // implementation |impl|. It may be completed with a subsequent call to the 98 // implementation |impl|. It may be completed with a subsequent call to the
105 // |Bind| method. Does not take ownership of |impl|, which must outlive this 99 // |Bind| method. Does not take ownership of |impl|, which must outlive this
106 // object. 100 // object.
107 explicit AssociatedBinding(ImplPointerType impl) { stub_.set_sink(impl); } 101 explicit AssociatedBinding(ImplPointerType impl) { stub_.set_sink(impl); }
108 102
109 // Constructs a completed associated binding of |impl|. The output |ptr_info| 103 // Constructs a completed associated binding of |impl|. The output |ptr_info|
110 // should be sent by another interface. |impl| must outlive this object. 104 // should be sent by another interface. |impl| must outlive this object.
111 AssociatedBinding(ImplPointerType impl, 105 AssociatedBinding(ImplPointerType impl,
112 AssociatedInterfacePtrInfo<Interface>* ptr_info, 106 AssociatedInterfacePtrInfo<Interface>* ptr_info,
113 AssociatedGroup* associated_group = nullptr,
114 scoped_refptr<base::SingleThreadTaskRunner> runner = 107 scoped_refptr<base::SingleThreadTaskRunner> runner =
115 base::ThreadTaskRunnerHandle::Get()) 108 base::ThreadTaskRunnerHandle::Get())
116 : AssociatedBinding(std::move(impl)) { 109 : AssociatedBinding(std::move(impl)) {
117 Bind(ptr_info, associated_group, std::move(runner)); 110 Bind(ptr_info, std::move(runner));
118 } 111 }
119 112
120 // Constructs a completed associated binding of |impl|. |impl| must outlive 113 // Constructs a completed associated binding of |impl|. |impl| must outlive
121 // the binding. 114 // the binding.
122 AssociatedBinding(ImplPointerType impl, 115 AssociatedBinding(ImplPointerType impl,
123 AssociatedInterfaceRequest<Interface> request, 116 AssociatedInterfaceRequest<Interface> request,
124 scoped_refptr<base::SingleThreadTaskRunner> runner = 117 scoped_refptr<base::SingleThreadTaskRunner> runner =
125 base::ThreadTaskRunnerHandle::Get()) 118 base::ThreadTaskRunnerHandle::Get())
126 : AssociatedBinding(std::move(impl)) { 119 : AssociatedBinding(std::move(impl)) {
127 Bind(std::move(request), std::move(runner)); 120 Bind(std::move(request), std::move(runner));
128 } 121 }
129 122
130 ~AssociatedBinding() {} 123 ~AssociatedBinding() {}
131 124
132 // Creates an associated inteface and sets up this object as the 125 // Creates an associated inteface and sets up this object as the
133 // implementation side. The output |ptr_info| should be sent by another 126 // implementation side. The output |ptr_info| should be sent by another
134 // interface. 127 // interface.
135 void Bind(AssociatedInterfacePtrInfo<Interface>* ptr_info, 128 void Bind(AssociatedInterfacePtrInfo<Interface>* ptr_info,
136 AssociatedGroup* associated_group = nullptr,
137 scoped_refptr<base::SingleThreadTaskRunner> runner = 129 scoped_refptr<base::SingleThreadTaskRunner> runner =
138 base::ThreadTaskRunnerHandle::Get()) { 130 base::ThreadTaskRunnerHandle::Get()) {
139 auto request = MakeRequest(ptr_info); 131 auto request = MakeRequest(ptr_info);
140 ptr_info->set_version(Interface::Version_); 132 ptr_info->set_version(Interface::Version_);
141 Bind(std::move(request), std::move(runner)); 133 Bind(std::move(request), std::move(runner));
142 } 134 }
143 135
144 // Sets up this object as the implementation side of an associated interface. 136 // Sets up this object as the implementation side of an associated interface.
145 void Bind(AssociatedInterfaceRequest<Interface> request, 137 void Bind(AssociatedInterfaceRequest<Interface> request,
146 scoped_refptr<base::SingleThreadTaskRunner> runner = 138 scoped_refptr<base::SingleThreadTaskRunner> runner =
(...skipping 23 matching lines...) Expand all
170 162
171 private: 163 private:
172 typename Interface::template Stub_<ImplRefTraits> stub_; 164 typename Interface::template Stub_<ImplRefTraits> stub_;
173 165
174 DISALLOW_COPY_AND_ASSIGN(AssociatedBinding); 166 DISALLOW_COPY_AND_ASSIGN(AssociatedBinding);
175 }; 167 };
176 168
177 } // namespace mojo 169 } // namespace mojo
178 170
179 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ 171 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/associated_group.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698