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_LIB_INTERFACE_PTR_STATE_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ |
7 | 7 |
8 #include <algorithm> // For |std::swap()|. | 8 #include <algorithm> // For |std::swap()|. |
| 9 #include <utility> |
9 | 10 |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "mojo/public/cpp/bindings/associated_group.h" | 15 #include "mojo/public/cpp/bindings/associated_group.h" |
15 #include "mojo/public/cpp/bindings/callback.h" | 16 #include "mojo/public/cpp/bindings/callback.h" |
16 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | 17 #include "mojo/public/cpp/bindings/interface_ptr_info.h" |
17 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" | 18 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" |
18 #include "mojo/public/cpp/bindings/lib/filter_chain.h" | 19 #include "mojo/public/cpp/bindings/lib/filter_chain.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 ConfigureProxyIfNecessary(); | 117 ConfigureProxyIfNecessary(); |
117 | 118 |
118 DCHECK(router_); | 119 DCHECK(router_); |
119 return router_->WaitForIncomingMessage(MOJO_DEADLINE_INDEFINITE); | 120 return router_->WaitForIncomingMessage(MOJO_DEADLINE_INDEFINITE); |
120 } | 121 } |
121 | 122 |
122 // After this method is called, the object is in an invalid state and | 123 // After this method is called, the object is in an invalid state and |
123 // shouldn't be reused. | 124 // shouldn't be reused. |
124 InterfacePtrInfo<GenericInterface> PassInterface() { | 125 InterfacePtrInfo<GenericInterface> PassInterface() { |
125 return InterfacePtrInfo<GenericInterface>( | 126 return InterfacePtrInfo<GenericInterface>( |
126 router_ ? router_->PassMessagePipe() : handle_.Pass(), version_); | 127 router_ ? router_->PassMessagePipe() : std::move(handle_), version_); |
127 } | 128 } |
128 | 129 |
129 bool is_bound() const { return handle_.is_valid() || router_; } | 130 bool is_bound() const { return handle_.is_valid() || router_; } |
130 | 131 |
131 bool encountered_error() const { | 132 bool encountered_error() const { |
132 return router_ ? router_->encountered_error() : false; | 133 return router_ ? router_->encountered_error() : false; |
133 } | 134 } |
134 | 135 |
135 void set_connection_error_handler(const Closure& error_handler) { | 136 void set_connection_error_handler(const Closure& error_handler) { |
136 ConfigureProxyIfNecessary(); | 137 ConfigureProxyIfNecessary(); |
(...skipping 26 matching lines...) Expand all Loading... |
163 // The object hasn't been bound. | 164 // The object hasn't been bound. |
164 if (!waiter_) { | 165 if (!waiter_) { |
165 DCHECK(!handle_.is_valid()); | 166 DCHECK(!handle_.is_valid()); |
166 return; | 167 return; |
167 } | 168 } |
168 | 169 |
169 FilterChain filters; | 170 FilterChain filters; |
170 filters.Append<MessageHeaderValidator>(); | 171 filters.Append<MessageHeaderValidator>(); |
171 filters.Append<typename Interface::ResponseValidator_>(); | 172 filters.Append<typename Interface::ResponseValidator_>(); |
172 | 173 |
173 router_ = new Router(handle_.Pass(), filters.Pass(), waiter_); | 174 router_ = new Router(std::move(handle_), std::move(filters), waiter_); |
174 waiter_ = nullptr; | 175 waiter_ = nullptr; |
175 | 176 |
176 proxy_ = new Proxy(router_); | 177 proxy_ = new Proxy(router_); |
177 } | 178 } |
178 | 179 |
179 Proxy* proxy_; | 180 Proxy* proxy_; |
180 Router* router_; | 181 Router* router_; |
181 | 182 |
182 // |proxy_| and |router_| are not initialized until read/write with the | 183 // |proxy_| and |router_| are not initialized until read/write with the |
183 // message pipe handle is needed. |handle_| and |waiter_| are valid between | 184 // message pipe handle is needed. |handle_| and |waiter_| are valid between |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 DCHECK(router_); | 326 DCHECK(router_); |
326 DCHECK(endpoint_client_); | 327 DCHECK(endpoint_client_); |
327 return; | 328 return; |
328 } | 329 } |
329 // The object hasn't been bound. | 330 // The object hasn't been bound. |
330 if (!waiter_) { | 331 if (!waiter_) { |
331 DCHECK(!handle_.is_valid()); | 332 DCHECK(!handle_.is_valid()); |
332 return; | 333 return; |
333 } | 334 } |
334 | 335 |
335 router_ = new MultiplexRouter(true, handle_.Pass(), waiter_); | 336 router_ = new MultiplexRouter(true, std::move(handle_), waiter_); |
336 endpoint_client_.reset(new InterfaceEndpointClient( | 337 endpoint_client_.reset(new InterfaceEndpointClient( |
337 router_->CreateLocalEndpointHandle(kMasterInterfaceId), nullptr, | 338 router_->CreateLocalEndpointHandle(kMasterInterfaceId), nullptr, |
338 make_scoped_ptr(new typename Interface::ResponseValidator_()))); | 339 make_scoped_ptr(new typename Interface::ResponseValidator_()))); |
339 proxy_.reset(new Proxy(endpoint_client_.get())); | 340 proxy_.reset(new Proxy(endpoint_client_.get())); |
340 proxy_->serialization_context()->router = endpoint_client_->router(); | 341 proxy_->serialization_context()->router = endpoint_client_->router(); |
341 | 342 |
342 waiter_ = nullptr; | 343 waiter_ = nullptr; |
343 } | 344 } |
344 | 345 |
345 scoped_refptr<MultiplexRouter> router_; | 346 scoped_refptr<MultiplexRouter> router_; |
346 | 347 |
347 scoped_ptr<InterfaceEndpointClient> endpoint_client_; | 348 scoped_ptr<InterfaceEndpointClient> endpoint_client_; |
348 scoped_ptr<Proxy> proxy_; | 349 scoped_ptr<Proxy> proxy_; |
349 | 350 |
350 // |router_| (as well as other members above) is not initialized until | 351 // |router_| (as well as other members above) is not initialized until |
351 // read/write with the message pipe handle is needed. |handle_| and |waiter_| | 352 // read/write with the message pipe handle is needed. |handle_| and |waiter_| |
352 // are valid between the Bind() call and the initialization of |router_|. | 353 // are valid between the Bind() call and the initialization of |router_|. |
353 ScopedMessagePipeHandle handle_; | 354 ScopedMessagePipeHandle handle_; |
354 const MojoAsyncWaiter* waiter_; | 355 const MojoAsyncWaiter* waiter_; |
355 | 356 |
356 uint32_t version_; | 357 uint32_t version_; |
357 | 358 |
358 DISALLOW_COPY_AND_ASSIGN(InterfacePtrState); | 359 DISALLOW_COPY_AND_ASSIGN(InterfacePtrState); |
359 }; | 360 }; |
360 | 361 |
361 } // namespace internal | 362 } // namespace internal |
362 } // namespace mojo | 363 } // namespace mojo |
363 | 364 |
364 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ | 365 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ |
OLD | NEW |