| 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 #include "content/browser/mojo/mojo_application_host.h" | 5 #include "content/browser/mojo/mojo_application_host.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "mojo/edk/embedder/embedder.h" | 11 #include "mojo/edk/embedder/embedder.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // TODO(beng): remove this in favor of just using shell APIs directly. | 16 // TODO(beng): remove this in favor of just using shell APIs directly. |
| 17 // http://crbug.com/2072603002 | 17 // http://crbug.com/2072603002 |
| 18 class ApplicationSetupImpl : public mojom::ApplicationSetup { | 18 class ApplicationSetupImpl : public mojom::ApplicationSetup { |
| 19 public: | 19 public: |
| 20 ApplicationSetupImpl(ServiceRegistryImpl* service_registry, | 20 ApplicationSetupImpl(shell::InterfaceRegistry* interface_registry, |
| 21 shell::InterfaceProvider* remote_interfaces, |
| 21 mojo::InterfaceRequest<mojom::ApplicationSetup> request) | 22 mojo::InterfaceRequest<mojom::ApplicationSetup> request) |
| 22 : binding_(this, std::move(request)), | 23 : binding_(this, std::move(request)), |
| 23 service_registry_(service_registry) {} | 24 interface_registry_(interface_registry), |
| 25 remote_interfaces_(remote_interfaces) { |
| 26 shell::mojom::InterfaceProviderPtr remote; |
| 27 pending_interfaces_request_ = GetProxy(&remote); |
| 28 remote_interfaces_->Bind(std::move(remote)); |
| 29 } |
| 24 | 30 |
| 25 ~ApplicationSetupImpl() override { | 31 ~ApplicationSetupImpl() override { |
| 26 } | 32 } |
| 27 | 33 |
| 28 private: | 34 private: |
| 29 // mojom::ApplicationSetup implementation. | 35 // mojom::ApplicationSetup implementation. |
| 30 void ExchangeInterfaceProviders( | 36 void ExchangeInterfaceProviders( |
| 31 shell::mojom::InterfaceProviderRequest services, | 37 shell::mojom::InterfaceProviderRequest request, |
| 32 shell::mojom::InterfaceProviderPtr exposed_services) override { | 38 shell::mojom::InterfaceProviderPtr remote_interfaces) override { |
| 33 service_registry_->Bind(std::move(services)); | 39 mojo::FuseInterface(std::move(pending_interfaces_request_), |
| 34 mojo::FuseInterface(service_registry_->TakeRemoteRequest(), | 40 remote_interfaces.PassInterface()); |
| 35 exposed_services.PassInterface()); | 41 interface_registry_->Bind(std::move(request)); |
| 36 } | 42 } |
| 37 | 43 |
| 38 mojo::Binding<mojom::ApplicationSetup> binding_; | 44 mojo::Binding<mojom::ApplicationSetup> binding_; |
| 39 ServiceRegistryImpl* service_registry_; | 45 shell::InterfaceRegistry* interface_registry_; |
| 46 shell::InterfaceProvider* remote_interfaces_; |
| 47 shell::mojom::InterfaceProviderRequest pending_interfaces_request_; |
| 40 }; | 48 }; |
| 41 | 49 |
| 42 } // namespace | 50 } // namespace |
| 43 | 51 |
| 44 MojoApplicationHost::MojoApplicationHost(const std::string& child_token) | 52 MojoApplicationHost::MojoApplicationHost(const std::string& child_token) |
| 45 : token_(mojo::edk::GenerateRandomToken()) { | 53 : token_(mojo::edk::GenerateRandomToken()), |
| 54 interface_registry_(new shell::InterfaceRegistry(nullptr)), |
| 55 remote_interfaces_(new shell::InterfaceProvider) { |
| 46 #if defined(OS_ANDROID) | 56 #if defined(OS_ANDROID) |
| 47 service_registry_android_ = | 57 service_registry_android_ = ServiceRegistryAndroid::Create( |
| 48 ServiceRegistryAndroid::Create(&service_registry_); | 58 interface_registry_.get(), remote_interfaces_.get()); |
| 49 #endif | 59 #endif |
| 50 | 60 |
| 51 mojo::ScopedMessagePipeHandle pipe = | 61 mojo::ScopedMessagePipeHandle pipe = |
| 52 mojo::edk::CreateParentMessagePipe(token_, child_token); | 62 mojo::edk::CreateParentMessagePipe(token_, child_token); |
| 53 DCHECK(pipe.is_valid()); | 63 DCHECK(pipe.is_valid()); |
| 54 application_setup_.reset(new ApplicationSetupImpl( | 64 application_setup_.reset(new ApplicationSetupImpl( |
| 55 &service_registry_, | 65 interface_registry_.get(), |
| 66 remote_interfaces_.get(), |
| 56 mojo::MakeRequest<mojom::ApplicationSetup>(std::move(pipe)))); | 67 mojo::MakeRequest<mojom::ApplicationSetup>(std::move(pipe)))); |
| 57 } | 68 } |
| 58 | 69 |
| 59 MojoApplicationHost::~MojoApplicationHost() { | 70 MojoApplicationHost::~MojoApplicationHost() { |
| 60 } | 71 } |
| 61 | 72 |
| 62 } // namespace content | 73 } // namespace content |
| OLD | NEW |