| 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 <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/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
| 21 #include "mojo/public/cpp/bindings/associated_group.h" | 21 #include "mojo/public/cpp/bindings/associated_group.h" |
| 22 #include "mojo/public/cpp/bindings/interface_endpoint_client.h" |
| 23 #include "mojo/public/cpp/bindings/interface_id.h" |
| 22 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | 24 #include "mojo/public/cpp/bindings/interface_ptr_info.h" |
| 23 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" | 25 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" |
| 24 #include "mojo/public/cpp/bindings/lib/filter_chain.h" | 26 #include "mojo/public/cpp/bindings/lib/filter_chain.h" |
| 25 #include "mojo/public/cpp/bindings/lib/interface_endpoint_client.h" | |
| 26 #include "mojo/public/cpp/bindings/lib/interface_id.h" | |
| 27 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" | 27 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" |
| 28 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" | 28 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" |
| 29 #include "mojo/public/cpp/bindings/lib/router.h" | 29 #include "mojo/public/cpp/bindings/lib/router.h" |
| 30 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" | 30 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
| 31 | 31 |
| 32 namespace mojo { | 32 namespace mojo { |
| 33 namespace internal { | 33 namespace internal { |
| 34 | 34 |
| 35 template <typename Interface, bool use_multiplex_router> | 35 template <typename Interface, bool use_multiplex_router> |
| 36 class InterfacePtrState; | 36 class InterfacePtrState; |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 if (!handle_.is_valid()) | 323 if (!handle_.is_valid()) |
| 324 return; | 324 return; |
| 325 | 325 |
| 326 router_ = new MultiplexRouter(true, std::move(handle_), runner_); | 326 router_ = new MultiplexRouter(true, std::move(handle_), runner_); |
| 327 router_->SetMasterInterfaceName(Interface::Name_); | 327 router_->SetMasterInterfaceName(Interface::Name_); |
| 328 endpoint_client_.reset(new InterfaceEndpointClient( | 328 endpoint_client_.reset(new InterfaceEndpointClient( |
| 329 router_->CreateLocalEndpointHandle(kMasterInterfaceId), nullptr, | 329 router_->CreateLocalEndpointHandle(kMasterInterfaceId), nullptr, |
| 330 base::WrapUnique(new typename Interface::ResponseValidator_()), false, | 330 base::WrapUnique(new typename Interface::ResponseValidator_()), false, |
| 331 std::move(runner_))); | 331 std::move(runner_))); |
| 332 proxy_.reset(new Proxy(endpoint_client_.get())); | 332 proxy_.reset(new Proxy(endpoint_client_.get())); |
| 333 proxy_->serialization_context()->router = endpoint_client_->router(); | 333 proxy_->serialization_context()->group_controller = |
| 334 endpoint_client_->group_controller(); |
| 334 } | 335 } |
| 335 | 336 |
| 336 void OnQueryVersion(const base::Callback<void(uint32_t)>& callback, | 337 void OnQueryVersion(const base::Callback<void(uint32_t)>& callback, |
| 337 uint32_t version) { | 338 uint32_t version) { |
| 338 version_ = version; | 339 version_ = version; |
| 339 callback.Run(version); | 340 callback.Run(version); |
| 340 } | 341 } |
| 341 | 342 |
| 342 scoped_refptr<MultiplexRouter> router_; | 343 scoped_refptr<MultiplexRouter> router_; |
| 343 | 344 |
| 344 std::unique_ptr<InterfaceEndpointClient> endpoint_client_; | 345 std::unique_ptr<InterfaceEndpointClient> endpoint_client_; |
| 345 std::unique_ptr<Proxy> proxy_; | 346 std::unique_ptr<Proxy> proxy_; |
| 346 | 347 |
| 347 // |router_| (as well as other members above) is not initialized until | 348 // |router_| (as well as other members above) is not initialized until |
| 348 // read/write with the message pipe handle is needed. |handle_| is valid | 349 // read/write with the message pipe handle is needed. |handle_| is valid |
| 349 // between the Bind() call and the initialization of |router_|. | 350 // between the Bind() call and the initialization of |router_|. |
| 350 ScopedMessagePipeHandle handle_; | 351 ScopedMessagePipeHandle handle_; |
| 351 scoped_refptr<base::SingleThreadTaskRunner> runner_; | 352 scoped_refptr<base::SingleThreadTaskRunner> runner_; |
| 352 | 353 |
| 353 uint32_t version_; | 354 uint32_t version_; |
| 354 | 355 |
| 355 DISALLOW_COPY_AND_ASSIGN(InterfacePtrState); | 356 DISALLOW_COPY_AND_ASSIGN(InterfacePtrState); |
| 356 }; | 357 }; |
| 357 | 358 |
| 358 } // namespace internal | 359 } // namespace internal |
| 359 } // namespace mojo | 360 } // namespace mojo |
| 360 | 361 |
| 361 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ | 362 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ |
| OLD | NEW |