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

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

Issue 2696233002: Mojo C++ bindings: remove some usage of AssociatedGroup from user code. (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
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>
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 public: 100 public:
101 using ImplPointerType = typename ImplRefTraits::PointerType; 101 using ImplPointerType = typename ImplRefTraits::PointerType;
102 102
103 // Constructs an incomplete associated binding that will use the 103 // Constructs an incomplete associated binding that will use the
104 // implementation |impl|. It may be completed with a subsequent call to the 104 // 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 105 // |Bind| method. Does not take ownership of |impl|, which must outlive this
106 // object. 106 // object.
107 explicit AssociatedBinding(ImplPointerType impl) { stub_.set_sink(impl); } 107 explicit AssociatedBinding(ImplPointerType impl) { stub_.set_sink(impl); }
108 108
109 // Constructs a completed associated binding of |impl|. The output |ptr_info| 109 // Constructs a completed associated binding of |impl|. The output |ptr_info|
110 // should be passed through the message pipe endpoint referred to by 110 // should be sent by another interface. |impl| must outlive this object.
111 // |associated_group| to setup the corresponding asssociated interface
112 // pointer. |impl| must outlive this object.
113 AssociatedBinding(ImplPointerType impl, 111 AssociatedBinding(ImplPointerType impl,
114 AssociatedInterfacePtrInfo<Interface>* ptr_info, 112 AssociatedInterfacePtrInfo<Interface>* ptr_info,
115 AssociatedGroup* associated_group, 113 AssociatedGroup* associated_group = nullptr,
116 scoped_refptr<base::SingleThreadTaskRunner> runner = 114 scoped_refptr<base::SingleThreadTaskRunner> runner =
117 base::ThreadTaskRunnerHandle::Get()) 115 base::ThreadTaskRunnerHandle::Get())
118 : AssociatedBinding(std::move(impl)) { 116 : AssociatedBinding(std::move(impl)) {
119 Bind(ptr_info, associated_group, std::move(runner)); 117 Bind(ptr_info, associated_group, std::move(runner));
120 } 118 }
121 119
122 // Constructs a completed associated binding of |impl|. |impl| must outlive 120 // Constructs a completed associated binding of |impl|. |impl| must outlive
123 // the binding. 121 // the binding.
124 AssociatedBinding(ImplPointerType impl, 122 AssociatedBinding(ImplPointerType impl,
125 AssociatedInterfaceRequest<Interface> request, 123 AssociatedInterfaceRequest<Interface> request,
126 scoped_refptr<base::SingleThreadTaskRunner> runner = 124 scoped_refptr<base::SingleThreadTaskRunner> runner =
127 base::ThreadTaskRunnerHandle::Get()) 125 base::ThreadTaskRunnerHandle::Get())
128 : AssociatedBinding(std::move(impl)) { 126 : AssociatedBinding(std::move(impl)) {
129 Bind(std::move(request), std::move(runner)); 127 Bind(std::move(request), std::move(runner));
130 } 128 }
131 129
132 ~AssociatedBinding() {} 130 ~AssociatedBinding() {}
133 131
134 // Creates an associated inteface and sets up this object as the 132 // Creates an associated inteface and sets up this object as the
135 // implementation side. The output |ptr_info| should be passed through the 133 // implementation side. The output |ptr_info| should be sent by another
136 // message pipe endpoint referred to by |associated_group| to setup the 134 // interface.
137 // corresponding asssociated interface pointer.
138 void Bind(AssociatedInterfacePtrInfo<Interface>* ptr_info, 135 void Bind(AssociatedInterfacePtrInfo<Interface>* ptr_info,
139 AssociatedGroup* associated_group, 136 AssociatedGroup* associated_group = nullptr,
140 scoped_refptr<base::SingleThreadTaskRunner> runner = 137 scoped_refptr<base::SingleThreadTaskRunner> runner =
141 base::ThreadTaskRunnerHandle::Get()) { 138 base::ThreadTaskRunnerHandle::Get()) {
142 AssociatedInterfaceRequest<Interface> request; 139 auto request = MakeRequest(ptr_info);
143 associated_group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_PTR, 140 ptr_info->set_version(Interface::Version_);
144 ptr_info, &request);
145 Bind(std::move(request), std::move(runner)); 141 Bind(std::move(request), std::move(runner));
146 } 142 }
147 143
148 // Sets up this object as the implementation side of an associated interface. 144 // Sets up this object as the implementation side of an associated interface.
149 void Bind(AssociatedInterfaceRequest<Interface> request, 145 void Bind(AssociatedInterfaceRequest<Interface> request,
150 scoped_refptr<base::SingleThreadTaskRunner> runner = 146 scoped_refptr<base::SingleThreadTaskRunner> runner =
151 base::ThreadTaskRunnerHandle::Get()) { 147 base::ThreadTaskRunnerHandle::Get()) {
152 BindImpl(request.PassHandle(), &stub_, 148 BindImpl(request.PassHandle(), &stub_,
153 base::WrapUnique(new typename Interface::RequestValidator_()), 149 base::WrapUnique(new typename Interface::RequestValidator_()),
154 Interface::HasSyncMethods_, std::move(runner), 150 Interface::HasSyncMethods_, std::move(runner),
(...skipping 19 matching lines...) Expand all
174 170
175 private: 171 private:
176 typename Interface::template Stub_<ImplRefTraits> stub_; 172 typename Interface::template Stub_<ImplRefTraits> stub_;
177 173
178 DISALLOW_COPY_AND_ASSIGN(AssociatedBinding); 174 DISALLOW_COPY_AND_ASSIGN(AssociatedBinding);
179 }; 175 };
180 176
181 } // namespace mojo 177 } // namespace mojo
182 178
183 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ 179 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/media_client.cc ('k') | mojo/public/cpp/bindings/associated_interface_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698