Avi Drissman | 8ba1bad | 2022-09-13 19:22:36 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "components/nacl/common/nacl_service.h" |
| 6 | |
Gyuyoung Kim | cb7965e | 2018-01-25 00:39:01 | [diff] [blame] | 7 | #include <memory> |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 8 | #include <string> |
| 9 | |
| 10 | #include "base/command_line.h" |
Sean Maher | e672a66 | 2023-01-09 21:42:28 | [diff] [blame] | 11 | #include "base/task/single_thread_task_runner.h" |
Robert Sesek | 5caa6b9 | 2019-03-26 14:05:51 | [diff] [blame] | 12 | #include "build/build_config.h" |
Ken Rockot | 9b26bc5 | 2018-07-04 19:57:49 | [diff] [blame] | 13 | #include "mojo/core/embedder/scoped_ipc_support.h" |
Ken Rockot | fe962ba | 2018-05-30 16:32:42 | [diff] [blame] | 14 | #include "mojo/public/cpp/platform/platform_channel.h" |
| 15 | #include "mojo/public/cpp/platform/platform_channel_endpoint.h" |
| 16 | #include "mojo/public/cpp/platform/platform_handle.h" |
| 17 | #include "mojo/public/cpp/system/invitation.h" |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 18 | |
Xiaohan Wang | b45377c8 | 2022-01-14 15:40:26 | [diff] [blame] | 19 | #if BUILDFLAG(IS_POSIX) |
Ken Rockot | fe962ba | 2018-05-30 16:32:42 | [diff] [blame] | 20 | #include "base/files/scoped_file.h" |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 21 | #include "base/posix/global_descriptors.h" |
Ken Rockot | 69fbb96 | 2020-09-21 22:22:03 | [diff] [blame] | 22 | #include "content/public/common/content_descriptors.h" |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 23 | #endif |
| 24 | |
| 25 | namespace { |
| 26 | |
Ken Rockot | 692493f | 2019-11-18 22:36:57 | [diff] [blame] | 27 | mojo::IncomingInvitation GetMojoInvitation() { |
Ken Rockot | fe962ba | 2018-05-30 16:32:42 | [diff] [blame] | 28 | mojo::PlatformChannelEndpoint endpoint; |
Ken Rockot | 69fbb96 | 2020-09-21 22:22:03 | [diff] [blame] | 29 | endpoint = mojo::PlatformChannelEndpoint(mojo::PlatformHandle(base::ScopedFD( |
| 30 | base::GlobalDescriptors::GetInstance()->Get(kMojoIPCChannel)))); |
Ken Rockot | fe962ba | 2018-05-30 16:32:42 | [diff] [blame] | 31 | DCHECK(endpoint.is_valid()); |
| 32 | return mojo::IncomingInvitation::Accept(std::move(endpoint)); |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 33 | } |
| 34 | |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 35 | } // namespace |
| 36 | |
Ken Rockot | 692493f | 2019-11-18 22:36:57 | [diff] [blame] | 37 | NaClService::NaClService( |
Gabriel Charette | e926fc1 | 2019-12-16 19:00:02 | [diff] [blame] | 38 | scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner) |
Ken Rockot | 692493f | 2019-11-18 22:36:57 | [diff] [blame] | 39 | : ipc_support_(std::move(ipc_task_runner), |
| 40 | mojo::core::ScopedIPCSupport::ShutdownPolicy::FAST) {} |
| 41 | |
| 42 | NaClService::~NaClService() = default; |
| 43 | |
| 44 | mojo::ScopedMessagePipeHandle NaClService::TakeChannelPipe() { |
| 45 | return GetMojoInvitation().ExtractMessagePipe(0); |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 46 | } |