OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_INTERFACE_PTR_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 bool Equals(const InterfacePtr& other) const { | 194 bool Equals(const InterfacePtr& other) const { |
195 if (this == &other) | 195 if (this == &other) |
196 return true; | 196 return true; |
197 | 197 |
198 // Now that the two refer to different objects, they are equivalent if | 198 // Now that the two refer to different objects, they are equivalent if |
199 // and only if they are both null. | 199 // and only if they are both null. |
200 return !(*this) && !other; | 200 return !(*this) && !other; |
201 } | 201 } |
202 | 202 |
203 // DO NOT USE. Exposed only for internal use and for testing. | 203 // DO NOT USE. Exposed only for internal use and for testing. |
204 internal::InterfacePtrState<Interface, true>* internal_state() { | 204 internal::InterfacePtrState<Interface, Interface::PassesAssociatedKinds_>* |
| 205 internal_state() { |
205 return &internal_state_; | 206 return &internal_state_; |
206 } | 207 } |
207 | 208 |
208 // Allow InterfacePtr<> to be used in boolean expressions, but not | 209 // Allow InterfacePtr<> to be used in boolean expressions, but not |
209 // implicitly convertible to a real bool (which is dangerous). | 210 // implicitly convertible to a real bool (which is dangerous). |
210 private: | 211 private: |
211 // TODO(dcheng): Use an explicit conversion operator. | 212 // TODO(dcheng): Use an explicit conversion operator. |
212 typedef internal::InterfacePtrState<Interface, true> InterfacePtr::*Testable; | 213 typedef internal::InterfacePtrState<Interface, |
| 214 Interface::PassesAssociatedKinds_> |
| 215 InterfacePtr::*Testable; |
213 | 216 |
214 public: | 217 public: |
215 operator Testable() const { | 218 operator Testable() const { |
216 return internal_state_.is_bound() ? &InterfacePtr::internal_state_ | 219 return internal_state_.is_bound() ? &InterfacePtr::internal_state_ |
217 : nullptr; | 220 : nullptr; |
218 } | 221 } |
219 | 222 |
220 private: | 223 private: |
221 // Forbid the == and != operators explicitly, otherwise InterfacePtr will be | 224 // Forbid the == and != operators explicitly, otherwise InterfacePtr will be |
222 // converted to Testable to do == or != comparison. | 225 // converted to Testable to do == or != comparison. |
223 template <typename T> | 226 template <typename T> |
224 bool operator==(const InterfacePtr<T>& other) const = delete; | 227 bool operator==(const InterfacePtr<T>& other) const = delete; |
225 template <typename T> | 228 template <typename T> |
226 bool operator!=(const InterfacePtr<T>& other) const = delete; | 229 bool operator!=(const InterfacePtr<T>& other) const = delete; |
227 | 230 |
228 typedef internal::InterfacePtrState<Interface, true> State; | 231 typedef internal::InterfacePtrState<Interface, |
| 232 Interface::PassesAssociatedKinds_> State; |
229 mutable State internal_state_; | 233 mutable State internal_state_; |
230 | 234 |
231 DISALLOW_COPY_AND_ASSIGN(InterfacePtr); | 235 DISALLOW_COPY_AND_ASSIGN(InterfacePtr); |
232 }; | 236 }; |
233 | 237 |
234 // If |info| is valid (containing a valid message pipe handle), returns an | 238 // If |info| is valid (containing a valid message pipe handle), returns an |
235 // InterfacePtr bound to it. Otherwise, returns an unbound InterfacePtr. | 239 // InterfacePtr bound to it. Otherwise, returns an unbound InterfacePtr. |
236 template <typename Interface> | 240 template <typename Interface> |
237 InterfacePtr<Interface> MakeProxy( | 241 InterfacePtr<Interface> MakeProxy( |
238 InterfacePtrInfo<Interface> info, | 242 InterfacePtrInfo<Interface> info, |
239 scoped_refptr<base::SingleThreadTaskRunner> runner = | 243 scoped_refptr<base::SingleThreadTaskRunner> runner = |
240 base::ThreadTaskRunnerHandle::Get()) { | 244 base::ThreadTaskRunnerHandle::Get()) { |
241 InterfacePtr<Interface> ptr; | 245 InterfacePtr<Interface> ptr; |
242 if (info.is_valid()) | 246 if (info.is_valid()) |
243 ptr.Bind(std::move(info), std::move(runner)); | 247 ptr.Bind(std::move(info), std::move(runner)); |
244 return std::move(ptr); | 248 return std::move(ptr); |
245 } | 249 } |
246 | 250 |
247 } // namespace mojo | 251 } // namespace mojo |
248 | 252 |
249 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ | 253 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
OLD | NEW |