| 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> |
| 8 |
| 7 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 8 #include "content/common/mojo/mojo_messages.h" | 10 #include "content/common/mojo/mojo_messages.h" |
| 9 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 10 #include "ipc/ipc_sender.h" | 12 #include "ipc/ipc_sender.h" |
| 11 #include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h" | 13 #include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h" |
| 12 | 14 |
| 13 namespace content { | 15 namespace content { |
| 14 namespace { | 16 namespace { |
| 15 | 17 |
| 16 base::PlatformFile PlatformFileFromScopedPlatformHandle( | 18 base::PlatformFile PlatformFileFromScopedPlatformHandle( |
| 17 mojo::embedder::ScopedPlatformHandle handle) { | 19 mojo::embedder::ScopedPlatformHandle handle) { |
| 18 #if defined(OS_POSIX) | 20 #if defined(OS_POSIX) |
| 19 return handle.release().fd; | 21 return handle.release().fd; |
| 20 #elif defined(OS_WIN) | 22 #elif defined(OS_WIN) |
| 21 return handle.release().handle; | 23 return handle.release().handle; |
| 22 #endif | 24 #endif |
| 23 } | 25 } |
| 24 | 26 |
| 25 class ApplicationSetupImpl : public ApplicationSetup { | 27 class ApplicationSetupImpl : public ApplicationSetup { |
| 26 public: | 28 public: |
| 27 ApplicationSetupImpl(ServiceRegistryImpl* service_registry, | 29 ApplicationSetupImpl(ServiceRegistryImpl* service_registry, |
| 28 mojo::InterfaceRequest<ApplicationSetup> request) | 30 mojo::InterfaceRequest<ApplicationSetup> request) |
| 29 : binding_(this, request.Pass()), | 31 : binding_(this, std::move(request)), |
| 30 service_registry_(service_registry) { | 32 service_registry_(service_registry) {} |
| 31 } | |
| 32 | 33 |
| 33 ~ApplicationSetupImpl() override { | 34 ~ApplicationSetupImpl() override { |
| 34 } | 35 } |
| 35 | 36 |
| 36 private: | 37 private: |
| 37 // ApplicationSetup implementation. | 38 // ApplicationSetup implementation. |
| 38 void ExchangeServiceProviders( | 39 void ExchangeServiceProviders( |
| 39 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 40 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
| 40 mojo::ServiceProviderPtr exposed_services) override { | 41 mojo::ServiceProviderPtr exposed_services) override { |
| 41 service_registry_->Bind(services.Pass()); | 42 service_registry_->Bind(std::move(services)); |
| 42 service_registry_->BindRemoteServiceProvider(exposed_services.Pass()); | 43 service_registry_->BindRemoteServiceProvider(std::move(exposed_services)); |
| 43 } | 44 } |
| 44 | 45 |
| 45 mojo::Binding<ApplicationSetup> binding_; | 46 mojo::Binding<ApplicationSetup> binding_; |
| 46 ServiceRegistryImpl* service_registry_; | 47 ServiceRegistryImpl* service_registry_; |
| 47 }; | 48 }; |
| 48 | 49 |
| 49 } // namespace | 50 } // namespace |
| 50 | 51 |
| 51 MojoApplicationHost::MojoApplicationHost() | 52 MojoApplicationHost::MojoApplicationHost() |
| 52 : did_activate_(false) { | 53 : did_activate_(false) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 77 PlatformFileFromScopedPlatformHandle(channel_pair.PassServerHandle()), | 78 PlatformFileFromScopedPlatformHandle(channel_pair.PassServerHandle()), |
| 78 io_task_runner); | 79 io_task_runner); |
| 79 if (!message_pipe.is_valid()) | 80 if (!message_pipe.is_valid()) |
| 80 return false; | 81 return false; |
| 81 | 82 |
| 82 // Forward this to the client once we know its process handle. | 83 // Forward this to the client once we know its process handle. |
| 83 client_handle_ = channel_pair.PassClientHandle(); | 84 client_handle_ = channel_pair.PassClientHandle(); |
| 84 | 85 |
| 85 application_setup_.reset(new ApplicationSetupImpl( | 86 application_setup_.reset(new ApplicationSetupImpl( |
| 86 &service_registry_, | 87 &service_registry_, |
| 87 mojo::MakeRequest<ApplicationSetup>(message_pipe.Pass()))); | 88 mojo::MakeRequest<ApplicationSetup>(std::move(message_pipe)))); |
| 88 return true; | 89 return true; |
| 89 } | 90 } |
| 90 | 91 |
| 91 void MojoApplicationHost::Activate(IPC::Sender* sender, | 92 void MojoApplicationHost::Activate(IPC::Sender* sender, |
| 92 base::ProcessHandle process_handle) { | 93 base::ProcessHandle process_handle) { |
| 93 DCHECK(!did_activate_); | 94 DCHECK(!did_activate_); |
| 94 DCHECK(client_handle_.is_valid()); | 95 DCHECK(client_handle_.is_valid()); |
| 95 | 96 |
| 96 base::PlatformFile client_file = | 97 base::PlatformFile client_file = |
| 97 PlatformFileFromScopedPlatformHandle(client_handle_.Pass()); | 98 PlatformFileFromScopedPlatformHandle(std::move(client_handle_)); |
| 98 did_activate_ = sender->Send(new MojoMsg_Activate( | 99 did_activate_ = sender->Send(new MojoMsg_Activate( |
| 99 IPC::GetFileHandleForProcess(client_file, process_handle, true))); | 100 IPC::GetFileHandleForProcess(client_file, process_handle, true))); |
| 100 } | 101 } |
| 101 | 102 |
| 102 void MojoApplicationHost::WillDestroySoon() { | 103 void MojoApplicationHost::WillDestroySoon() { |
| 103 channel_init_.WillDestroySoon(); | 104 channel_init_.WillDestroySoon(); |
| 104 } | 105 } |
| 105 | 106 |
| 106 void MojoApplicationHost::OverrideIOTaskRunnerForTest( | 107 void MojoApplicationHost::OverrideIOTaskRunnerForTest( |
| 107 scoped_refptr<base::TaskRunner> io_task_runner) { | 108 scoped_refptr<base::TaskRunner> io_task_runner) { |
| 108 io_task_runner_override_ = io_task_runner; | 109 io_task_runner_override_ = io_task_runner; |
| 109 } | 110 } |
| 110 | 111 |
| 111 } // namespace content | 112 } // namespace content |
| OLD | NEW |