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 <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" | 11 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" |
| 12 #include "mojo/public/cpp/bindings/associated_interface_request.h" | 12 #include "mojo/public/cpp/bindings/associated_interface_request.h" |
| 13 #include "mojo/public/cpp/bindings/bindings_export.h" | 13 #include "mojo/public/cpp/bindings/bindings_export.h" |
| 14 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" | |
| 14 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" | 15 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
| 15 | 16 |
| 16 namespace mojo { | 17 namespace mojo { |
| 17 | 18 |
| 18 class AssociatedGroupController; | 19 class AssociatedGroupController; |
| 19 | 20 |
| 20 // AssociatedGroup refers to all the interface endpoints running at one end of a | 21 // AssociatedGroup refers to all the interface endpoints running at one end of a |
| 21 // message pipe. It is used to create associated interfaces for that message | 22 // message pipe. It is used to create associated interfaces for that message |
| 22 // pipe. | 23 // pipe. |
| 23 // It is thread safe and cheap to make copies. | 24 // It is thread safe and cheap to make copies. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 private: | 80 private: |
| 80 friend class AssociatedGroupController; | 81 friend class AssociatedGroupController; |
| 81 | 82 |
| 82 void CreateEndpointHandlePair( | 83 void CreateEndpointHandlePair( |
| 83 ScopedInterfaceEndpointHandle* local_endpoint, | 84 ScopedInterfaceEndpointHandle* local_endpoint, |
| 84 ScopedInterfaceEndpointHandle* remote_endpoint); | 85 ScopedInterfaceEndpointHandle* remote_endpoint); |
| 85 | 86 |
| 86 scoped_refptr<AssociatedGroupController> controller_; | 87 scoped_refptr<AssociatedGroupController> controller_; |
| 87 }; | 88 }; |
| 88 | 89 |
| 90 // Creates an associated interface proxy in its own AssociatedGroup. | |
| 91 template <typename Interface> | |
| 92 AssociatedInterfaceRequest<Interface> GetProxyForTesting( | |
|
yzshen1
2016/11/15 17:39:50
Does it make sense to:
- move this function to ass
Reilly Grant (use Gerrit)
2016/11/15 17:43:11
I tried putting it in associated_interface_ptr_inf
yzshen1
2016/11/15 17:59:35
I meant associated_interface_ptr.h (instead of ass
| |
| 93 AssociatedInterfacePtrInfo<Interface>* ptr_info, | |
| 94 scoped_refptr<base::SingleThreadTaskRunner> runner = | |
| 95 base::ThreadTaskRunnerHandle::Get()) { | |
| 96 MessagePipe pipe; | |
| 97 using internal::MultiplexRouter; | |
| 98 scoped_refptr<MultiplexRouter> router0 = new MultiplexRouter( | |
| 99 std::move(pipe.handle0), MultiplexRouter::MULTI_INTERFACE, true, runner); | |
| 100 scoped_refptr<MultiplexRouter> router1 = new MultiplexRouter( | |
| 101 std::move(pipe.handle1), MultiplexRouter::MULTI_INTERFACE, false, runner); | |
| 102 | |
| 103 AssociatedInterfaceRequest<Interface> request; | |
| 104 router1->CreateAssociatedGroup()->CreateAssociatedInterface( | |
| 105 AssociatedGroup::WILL_PASS_PTR, ptr_info, &request); | |
| 106 | |
| 107 // Emulate passing |ptr_info| across a pipe. | |
| 108 ScopedInterfaceEndpointHandle handle = ptr_info->PassHandle(); | |
| 109 CHECK(!handle.is_local()); | |
| 110 *ptr_info = AssociatedInterfacePtrInfo<Interface>( | |
| 111 router0->CreateLocalEndpointHandle(handle.release()), | |
| 112 ptr_info->version()); | |
| 113 | |
| 114 return request; | |
| 115 } | |
| 116 | |
| 89 } // namespace mojo | 117 } // namespace mojo |
| 90 | 118 |
| 91 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_GROUP_H_ | 119 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_GROUP_H_ |
| OLD | NEW |