Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_GROUP_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_GROUP_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_GROUP_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_GROUP_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" | 9 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" |
| 10 #include "mojo/public/cpp/bindings/associated_interface_request.h" | 10 #include "mojo/public/cpp/bindings/associated_interface_request.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 // remote side of the message pipe. | 37 // remote side of the message pipe. |
| 38 // | 38 // |
| 39 // NOTE: If |config| is |WILL_PASS_REQUEST|, you will want to bind |ptr_info| | 39 // NOTE: If |config| is |WILL_PASS_REQUEST|, you will want to bind |ptr_info| |
| 40 // to a local AssociatedInterfacePtr to make calls. However, there is one | 40 // to a local AssociatedInterfacePtr to make calls. However, there is one |
| 41 // restriction: the pointer should NOT be used to make calls before |request| | 41 // restriction: the pointer should NOT be used to make calls before |request| |
| 42 // is sent. Violating that will cause the message pipe to be closed. On the | 42 // is sent. Violating that will cause the message pipe to be closed. On the |
| 43 // other hand, as soon as |request| is sent, the pointer is usable. There is | 43 // other hand, as soon as |request| is sent, the pointer is usable. There is |
| 44 // no need to wait until |request| is bound to an implementation at the remote | 44 // no need to wait until |request| is bound to an implementation at the remote |
| 45 // side. | 45 // side. |
| 46 template <typename T> | 46 template <typename T> |
| 47 void CreateAssociatedInterface(AssociatedInterfaceConfig config, | 47 void CreateAssociatedInterface( |
| 48 AssociatedInterfacePtrInfo<T>* ptr_info, | 48 AssociatedInterfaceConfig config, |
| 49 AssociatedInterfaceRequest<T>* request) { | 49 AssociatedInterfacePtrInfo<T>* ptr_info, |
|
yzshen1
2015/12/14 23:58:26
ptr_info should use the same type as the request,
| |
| 50 AssociatedInterfaceRequest<typename T::GenericInterface>* request) { | |
| 50 internal::ScopedInterfaceEndpointHandle local; | 51 internal::ScopedInterfaceEndpointHandle local; |
| 51 internal::ScopedInterfaceEndpointHandle remote; | 52 internal::ScopedInterfaceEndpointHandle remote; |
| 52 CreateEndpointHandlePair(&local, &remote); | 53 CreateEndpointHandlePair(&local, &remote); |
| 53 | 54 |
| 54 if (!local.is_valid() || !remote.is_valid()) { | 55 if (!local.is_valid() || !remote.is_valid()) { |
| 55 *ptr_info = AssociatedInterfacePtrInfo<T>(); | 56 *ptr_info = AssociatedInterfacePtrInfo<T>(); |
| 56 *request = AssociatedInterfaceRequest<T>(); | 57 *request = AssociatedInterfaceRequest<typename T::GenericInterface>(); |
| 57 return; | 58 return; |
| 58 } | 59 } |
| 59 | 60 |
| 60 if (config == WILL_PASS_PTR) { | 61 if (config == WILL_PASS_PTR) { |
| 61 internal::AssociatedInterfacePtrInfoHelper::SetHandle(ptr_info, | 62 internal::AssociatedInterfacePtrInfoHelper::SetHandle(ptr_info, |
| 62 remote.Pass()); | 63 remote.Pass()); |
| 63 // The implementation is local, therefore set the version according to | 64 // The implementation is local, therefore set the version according to |
| 64 // the interface definition that this code is built against. | 65 // the interface definition that this code is built against. |
| 65 ptr_info->set_version(T::Version_); | 66 ptr_info->set_version(T::Version_); |
| 66 internal::AssociatedInterfaceRequestHelper::SetHandle(request, | 67 internal::AssociatedInterfaceRequestHelper::SetHandle(request, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 82 void CreateEndpointHandlePair( | 83 void CreateEndpointHandlePair( |
| 83 internal::ScopedInterfaceEndpointHandle* local_endpoint, | 84 internal::ScopedInterfaceEndpointHandle* local_endpoint, |
| 84 internal::ScopedInterfaceEndpointHandle* remote_endpoint); | 85 internal::ScopedInterfaceEndpointHandle* remote_endpoint); |
| 85 | 86 |
| 86 scoped_refptr<internal::MultiplexRouter> router_; | 87 scoped_refptr<internal::MultiplexRouter> router_; |
| 87 }; | 88 }; |
| 88 | 89 |
| 89 } // namespace mojo | 90 } // namespace mojo |
| 90 | 91 |
| 91 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_GROUP_H_ | 92 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_GROUP_H_ |
| OLD | NEW |