[email protected] | e482111a8 | 2014-05-30 03:58:59 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
David Sanders | 527f0ce9 | 2022-03-23 17:42:30 | [diff] [blame] | 5 | #include "base/threading/thread_task_runner_handle.h" |
avi | 246998d8 | 2015-12-22 02:39:04 | [diff] [blame] | 6 | #include "build/build_config.h" |
[email protected] | e482111a8 | 2014-05-30 03:58:59 | [diff] [blame] | 7 | #include "ipc/ipc_channel.h" |
amistry | 3618252 | 2016-06-27 06:34:42 | [diff] [blame] | 8 | #include "ipc/ipc_channel_mojo.h" |
Sigurdur Asgeirsson | d655dd65f | 2019-11-12 19:32:20 | [diff] [blame] | 9 | #include "mojo/public/cpp/bindings/lib/message_quota_checker.h" |
amistry | 9fdf320 | 2016-06-30 06:56:07 | [diff] [blame] | 10 | #include "mojo/public/cpp/system/message_pipe.h" |
[email protected] | e482111a8 | 2014-05-30 03:58:59 | [diff] [blame] | 11 | |
| 12 | namespace IPC { |
| 13 | |
Xiaohan Wang | ab909b3 | 2022-01-12 17:57:39 | [diff] [blame] | 14 | #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) |
sammc | beeed368 | 2016-11-08 23:24:35 | [diff] [blame] | 15 | |
| 16 | namespace { |
| 17 | int g_global_pid = 0; |
| 18 | } |
| 19 | |
| 20 | // static |
| 21 | void Channel::SetGlobalPid(int pid) { |
| 22 | g_global_pid = pid; |
| 23 | } |
| 24 | |
| 25 | // static |
| 26 | int Channel::GetGlobalPid() { |
| 27 | return g_global_pid; |
| 28 | } |
| 29 | |
Xiaohan Wang | ab909b3 | 2022-01-12 17:57:39 | [diff] [blame] | 30 | #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) |
sammc | beeed368 | 2016-11-08 23:24:35 | [diff] [blame] | 31 | |
[email protected] | e482111a8 | 2014-05-30 03:58:59 | [diff] [blame] | 32 | // static |
danakj | 03de39b2 | 2016-04-23 04:21:09 | [diff] [blame] | 33 | std::unique_ptr<Channel> Channel::CreateClient( |
erikchen | 27aa7d8 | 2015-06-16 21:21:04 | [diff] [blame] | 34 | const IPC::ChannelHandle& channel_handle, |
rockot | a34707ca | 2016-07-20 04:28:32 | [diff] [blame] | 35 | Listener* listener, |
| 36 | const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) { |
Xiaohan Wang | 53a51163 | 2022-01-21 18:14:58 | [diff] [blame] | 37 | #if BUILDFLAG(IS_NACL) |
erikchen | 30dc281 | 2015-09-24 03:26:38 | [diff] [blame] | 38 | return Channel::Create(channel_handle, Channel::MODE_CLIENT, listener); |
sammc | beeed368 | 2016-11-08 23:24:35 | [diff] [blame] | 39 | #else |
| 40 | DCHECK(channel_handle.is_mojo_channel_handle()); |
| 41 | return ChannelMojo::Create( |
| 42 | mojo::ScopedMessagePipeHandle(channel_handle.mojo_handle), |
Hajime Hoshi | fe3ecdc | 2017-11-28 03:34:13 | [diff] [blame] | 43 | Channel::MODE_CLIENT, listener, ipc_task_runner, |
Sigurdur Asgeirsson | d655dd65f | 2019-11-12 19:32:20 | [diff] [blame] | 44 | base::ThreadTaskRunnerHandle::Get(), |
| 45 | mojo::internal::MessageQuotaChecker::MaybeCreate()); |
sammc | beeed368 | 2016-11-08 23:24:35 | [diff] [blame] | 46 | #endif |
[email protected] | e482111a8 | 2014-05-30 03:58:59 | [diff] [blame] | 47 | } |
| 48 | |
[email protected] | e482111a8 | 2014-05-30 03:58:59 | [diff] [blame] | 49 | // static |
danakj | 03de39b2 | 2016-04-23 04:21:09 | [diff] [blame] | 50 | std::unique_ptr<Channel> Channel::CreateServer( |
erikchen | 27aa7d8 | 2015-06-16 21:21:04 | [diff] [blame] | 51 | const IPC::ChannelHandle& channel_handle, |
rockot | a34707ca | 2016-07-20 04:28:32 | [diff] [blame] | 52 | Listener* listener, |
| 53 | const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) { |
Xiaohan Wang | 53a51163 | 2022-01-21 18:14:58 | [diff] [blame] | 54 | #if BUILDFLAG(IS_NACL) |
erikchen | 30dc281 | 2015-09-24 03:26:38 | [diff] [blame] | 55 | return Channel::Create(channel_handle, Channel::MODE_SERVER, listener); |
sammc | beeed368 | 2016-11-08 23:24:35 | [diff] [blame] | 56 | #else |
| 57 | DCHECK(channel_handle.is_mojo_channel_handle()); |
| 58 | return ChannelMojo::Create( |
| 59 | mojo::ScopedMessagePipeHandle(channel_handle.mojo_handle), |
Hajime Hoshi | fe3ecdc | 2017-11-28 03:34:13 | [diff] [blame] | 60 | Channel::MODE_SERVER, listener, ipc_task_runner, |
Sigurdur Asgeirsson | d655dd65f | 2019-11-12 19:32:20 | [diff] [blame] | 61 | base::ThreadTaskRunnerHandle::Get(), |
| 62 | mojo::internal::MessageQuotaChecker::MaybeCreate()); |
sammc | beeed368 | 2016-11-08 23:24:35 | [diff] [blame] | 63 | #endif |
[email protected] | e482111a8 | 2014-05-30 03:58:59 | [diff] [blame] | 64 | } |
| 65 | |
Chris Watkins | 2d879af | 2017-11-30 02:11:59 | [diff] [blame] | 66 | Channel::~Channel() = default; |
[email protected] | e482111a8 | 2014-05-30 03:58:59 | [diff] [blame] | 67 | |
rockot | 7c6bf95 | 2016-07-14 00:34:11 | [diff] [blame] | 68 | Channel::AssociatedInterfaceSupport* Channel::GetAssociatedInterfaceSupport() { |
| 69 | return nullptr; |
| 70 | } |
| 71 | |
rockot | 1018875 | 2016-09-08 18:24:56 | [diff] [blame] | 72 | void Channel::Pause() { NOTREACHED(); } |
rockot | 401fb2c | 2016-09-06 18:35:57 | [diff] [blame] | 73 | |
| 74 | void Channel::Unpause(bool flush) { NOTREACHED(); } |
| 75 | |
| 76 | void Channel::Flush() { NOTREACHED(); } |
| 77 | |
erikchen | 9097190 | 2016-04-25 23:45:31 | [diff] [blame] | 78 | void Channel::WillConnect() { |
| 79 | did_start_connect_ = true; |
| 80 | } |
| 81 | |
[email protected] | e482111a8 | 2014-05-30 03:58:59 | [diff] [blame] | 82 | } // namespace IPC |