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

Side by Side Diff: mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h

Issue 1991463002: Mojo: Expose untyped associated endpoints through public API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> // For |std::swap()|. 10 #include <algorithm> // For |std::swap()|.
11 #include <memory> 11 #include <memory>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "mojo/public/cpp/bindings/associated_group.h" 18 #include "mojo/public/cpp/bindings/associated_group.h"
19 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" 19 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h"
20 #include "mojo/public/cpp/bindings/callback.h" 20 #include "mojo/public/cpp/bindings/callback.h"
21 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" 21 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h"
22 #include "mojo/public/cpp/bindings/lib/interface_endpoint_client.h" 22 #include "mojo/public/cpp/bindings/lib/interface_endpoint_client.h"
23 #include "mojo/public/cpp/bindings/lib/interface_id.h" 23 #include "mojo/public/cpp/bindings/lib/interface_id.h"
24 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" 24 #include "mojo/public/cpp/bindings/lib/multiplex_router.h"
25 #include "mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h" 25 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
26 #include "mojo/public/cpp/system/message_pipe.h" 26 #include "mojo/public/cpp/system/message_pipe.h"
27 27
28 namespace mojo { 28 namespace mojo {
29 namespace internal { 29 namespace internal {
30 30
31 template <typename Interface> 31 template <typename Interface>
32 class AssociatedInterfacePtrState { 32 class AssociatedInterfacePtrState {
33 public: 33 public:
34 AssociatedInterfacePtrState() : version_(0u) {} 34 AssociatedInterfacePtrState() : version_(0u) {}
35 35
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 void Bind(AssociatedInterfacePtrInfo<Interface> info, 84 void Bind(AssociatedInterfacePtrInfo<Interface> info,
85 scoped_refptr<base::SingleThreadTaskRunner> runner) { 85 scoped_refptr<base::SingleThreadTaskRunner> runner) {
86 DCHECK(!endpoint_client_); 86 DCHECK(!endpoint_client_);
87 DCHECK(!proxy_); 87 DCHECK(!proxy_);
88 DCHECK_EQ(0u, version_); 88 DCHECK_EQ(0u, version_);
89 DCHECK(info.is_valid()); 89 DCHECK(info.is_valid());
90 90
91 version_ = info.version(); 91 version_ = info.version();
92 endpoint_client_.reset(new InterfaceEndpointClient( 92 endpoint_client_.reset(new InterfaceEndpointClient(
93 AssociatedInterfacePtrInfoHelper::PassHandle(&info), nullptr, 93 info.PassHandle(), nullptr,
94 base::WrapUnique(new typename Interface::ResponseValidator_()), false, 94 base::WrapUnique(new typename Interface::ResponseValidator_()), false,
95 std::move(runner))); 95 std::move(runner)));
96 proxy_.reset(new Proxy(endpoint_client_.get())); 96 proxy_.reset(new Proxy(endpoint_client_.get()));
97 proxy_->serialization_context()->router = endpoint_client_->router(); 97 proxy_->serialization_context()->router = endpoint_client_->router();
98 } 98 }
99 99
100 // After this method is called, the object is in an invalid state and 100 // After this method is called, the object is in an invalid state and
101 // shouldn't be reused. 101 // shouldn't be reused.
102 AssociatedInterfacePtrInfo<Interface> PassInterface() { 102 AssociatedInterfacePtrInfo<Interface> PassInterface() {
103 ScopedInterfaceEndpointHandle handle = endpoint_client_->PassHandle(); 103 ScopedInterfaceEndpointHandle handle = endpoint_client_->PassHandle();
104 endpoint_client_.reset(); 104 endpoint_client_.reset();
105 proxy_.reset(); 105 proxy_.reset();
106 106 return AssociatedInterfacePtrInfo<Interface>(std::move(handle), version_);
107 AssociatedInterfacePtrInfo<Interface> result;
108 result.set_version(version_);
109 AssociatedInterfacePtrInfoHelper::SetHandle(&result, std::move(handle));
110 return result;
111 } 107 }
112 108
113 bool is_bound() const { return !!endpoint_client_; } 109 bool is_bound() const { return !!endpoint_client_; }
114 110
115 bool encountered_error() const { 111 bool encountered_error() const {
116 return endpoint_client_ ? endpoint_client_->encountered_error() : false; 112 return endpoint_client_ ? endpoint_client_->encountered_error() : false;
117 } 113 }
118 114
119 void set_connection_error_handler(const Closure& error_handler) { 115 void set_connection_error_handler(const Closure& error_handler) {
120 DCHECK(endpoint_client_); 116 DCHECK(endpoint_client_);
(...skipping 17 matching lines...) Expand all
138 134
139 uint32_t version_; 135 uint32_t version_;
140 136
141 DISALLOW_COPY_AND_ASSIGN(AssociatedInterfacePtrState); 137 DISALLOW_COPY_AND_ASSIGN(AssociatedInterfacePtrState);
142 }; 138 };
143 139
144 } // namespace internal 140 } // namespace internal
145 } // namespace mojo 141 } // namespace mojo
146 142
147 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_ 143 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/associated_group.cc ('k') | mojo/public/cpp/bindings/lib/binding_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698