xref: /aosp_15_r20/external/cronet/components/nacl/common/nacl_service.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2016 The Chromium Authors
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 
7 #include <memory>
8 #include <string>
9 
10 #include "base/command_line.h"
11 #include "base/task/single_thread_task_runner.h"
12 #include "build/build_config.h"
13 #include "mojo/core/embedder/scoped_ipc_support.h"
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"
18 
19 #if BUILDFLAG(IS_POSIX)
20 #include "base/files/scoped_file.h"
21 #include "base/posix/global_descriptors.h"
22 #include "content/public/common/content_descriptors.h"
23 #endif
24 
25 namespace {
26 
GetMojoInvitation()27 mojo::IncomingInvitation GetMojoInvitation() {
28   mojo::PlatformChannelEndpoint endpoint;
29   endpoint = mojo::PlatformChannelEndpoint(mojo::PlatformHandle(base::ScopedFD(
30       base::GlobalDescriptors::GetInstance()->Get(kMojoIPCChannel))));
31   DCHECK(endpoint.is_valid());
32   return mojo::IncomingInvitation::Accept(std::move(endpoint));
33 }
34 
35 }  // namespace
36 
NaClService(scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner)37 NaClService::NaClService(
38     scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner)
39     : ipc_support_(std::move(ipc_task_runner),
40                    mojo::core::ScopedIPCSupport::ShutdownPolicy::FAST) {}
41 
42 NaClService::~NaClService() = default;
43 
TakeChannelPipe()44 mojo::ScopedMessagePipeHandle NaClService::TakeChannelPipe() {
45   return GetMojoInvitation().ExtractMessagePipe(0);
46 }
47