[go: nahoru, domu]

blob: 5fb500df2db89ddf52ef6efe29a6372f8081ada2 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2016 The Chromium Authors
sammc2b0375b2016-12-22 01:26:172// 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 Kimcb7965e2018-01-25 00:39:017#include <memory>
sammc2b0375b2016-12-22 01:26:178#include <string>
9
10#include "base/command_line.h"
Sean Mahere672a662023-01-09 21:42:2811#include "base/task/single_thread_task_runner.h"
Robert Sesek5caa6b92019-03-26 14:05:5112#include "build/build_config.h"
Ken Rockot9b26bc52018-07-04 19:57:4913#include "mojo/core/embedder/scoped_ipc_support.h"
Ken Rockotfe962ba2018-05-30 16:32:4214#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"
sammc2b0375b2016-12-22 01:26:1718
Xiaohan Wangb45377c82022-01-14 15:40:2619#if BUILDFLAG(IS_POSIX)
Ken Rockotfe962ba2018-05-30 16:32:4220#include "base/files/scoped_file.h"
sammc2b0375b2016-12-22 01:26:1721#include "base/posix/global_descriptors.h"
Ken Rockot69fbb962020-09-21 22:22:0322#include "content/public/common/content_descriptors.h"
sammc2b0375b2016-12-22 01:26:1723#endif
24
25namespace {
26
Ken Rockot692493f2019-11-18 22:36:5727mojo::IncomingInvitation GetMojoInvitation() {
Ken Rockotfe962ba2018-05-30 16:32:4228 mojo::PlatformChannelEndpoint endpoint;
Ken Rockot69fbb962020-09-21 22:22:0329 endpoint = mojo::PlatformChannelEndpoint(mojo::PlatformHandle(base::ScopedFD(
30 base::GlobalDescriptors::GetInstance()->Get(kMojoIPCChannel))));
Ken Rockotfe962ba2018-05-30 16:32:4231 DCHECK(endpoint.is_valid());
32 return mojo::IncomingInvitation::Accept(std::move(endpoint));
sammc2b0375b2016-12-22 01:26:1733}
34
sammc2b0375b2016-12-22 01:26:1735} // namespace
36
Ken Rockot692493f2019-11-18 22:36:5737NaClService::NaClService(
Gabriel Charettee926fc12019-12-16 19:00:0238 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner)
Ken Rockot692493f2019-11-18 22:36:5739 : ipc_support_(std::move(ipc_task_runner),
40 mojo::core::ScopedIPCSupport::ShutdownPolicy::FAST) {}
41
42NaClService::~NaClService() = default;
43
44mojo::ScopedMessagePipeHandle NaClService::TakeChannelPipe() {
45 return GetMojoInvitation().ExtractMessagePipe(0);
sammc2b0375b2016-12-22 01:26:1746}