blob: 2989b01091d771e0cc1ccc1c2f60bb1a7c810772 [file] [log] [blame]
[email protected]e482111a82014-05-30 03:58:591// 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 Sanders527f0ce92022-03-23 17:42:305#include "base/threading/thread_task_runner_handle.h"
avi246998d82015-12-22 02:39:046#include "build/build_config.h"
[email protected]e482111a82014-05-30 03:58:597#include "ipc/ipc_channel.h"
amistry36182522016-06-27 06:34:428#include "ipc/ipc_channel_mojo.h"
Sigurdur Asgeirssond655dd65f2019-11-12 19:32:209#include "mojo/public/cpp/bindings/lib/message_quota_checker.h"
amistry9fdf3202016-06-30 06:56:0710#include "mojo/public/cpp/system/message_pipe.h"
[email protected]e482111a82014-05-30 03:58:5911
12namespace IPC {
13
Xiaohan Wangab909b32022-01-12 17:57:3914#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
sammcbeeed3682016-11-08 23:24:3515
16namespace {
17int g_global_pid = 0;
18}
19
20// static
21void Channel::SetGlobalPid(int pid) {
22 g_global_pid = pid;
23}
24
25// static
26int Channel::GetGlobalPid() {
27 return g_global_pid;
28}
29
Xiaohan Wangab909b32022-01-12 17:57:3930#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
sammcbeeed3682016-11-08 23:24:3531
[email protected]e482111a82014-05-30 03:58:5932// static
danakj03de39b22016-04-23 04:21:0933std::unique_ptr<Channel> Channel::CreateClient(
erikchen27aa7d82015-06-16 21:21:0434 const IPC::ChannelHandle& channel_handle,
rockota34707ca2016-07-20 04:28:3235 Listener* listener,
36 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) {
Xiaohan Wang53a511632022-01-21 18:14:5837#if BUILDFLAG(IS_NACL)
erikchen30dc2812015-09-24 03:26:3838 return Channel::Create(channel_handle, Channel::MODE_CLIENT, listener);
sammcbeeed3682016-11-08 23:24:3539#else
40 DCHECK(channel_handle.is_mojo_channel_handle());
41 return ChannelMojo::Create(
42 mojo::ScopedMessagePipeHandle(channel_handle.mojo_handle),
Hajime Hoshife3ecdc2017-11-28 03:34:1343 Channel::MODE_CLIENT, listener, ipc_task_runner,
Sigurdur Asgeirssond655dd65f2019-11-12 19:32:2044 base::ThreadTaskRunnerHandle::Get(),
45 mojo::internal::MessageQuotaChecker::MaybeCreate());
sammcbeeed3682016-11-08 23:24:3546#endif
[email protected]e482111a82014-05-30 03:58:5947}
48
[email protected]e482111a82014-05-30 03:58:5949// static
danakj03de39b22016-04-23 04:21:0950std::unique_ptr<Channel> Channel::CreateServer(
erikchen27aa7d82015-06-16 21:21:0451 const IPC::ChannelHandle& channel_handle,
rockota34707ca2016-07-20 04:28:3252 Listener* listener,
53 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) {
Xiaohan Wang53a511632022-01-21 18:14:5854#if BUILDFLAG(IS_NACL)
erikchen30dc2812015-09-24 03:26:3855 return Channel::Create(channel_handle, Channel::MODE_SERVER, listener);
sammcbeeed3682016-11-08 23:24:3556#else
57 DCHECK(channel_handle.is_mojo_channel_handle());
58 return ChannelMojo::Create(
59 mojo::ScopedMessagePipeHandle(channel_handle.mojo_handle),
Hajime Hoshife3ecdc2017-11-28 03:34:1360 Channel::MODE_SERVER, listener, ipc_task_runner,
Sigurdur Asgeirssond655dd65f2019-11-12 19:32:2061 base::ThreadTaskRunnerHandle::Get(),
62 mojo::internal::MessageQuotaChecker::MaybeCreate());
sammcbeeed3682016-11-08 23:24:3563#endif
[email protected]e482111a82014-05-30 03:58:5964}
65
Chris Watkins2d879af2017-11-30 02:11:5966Channel::~Channel() = default;
[email protected]e482111a82014-05-30 03:58:5967
rockot7c6bf952016-07-14 00:34:1168Channel::AssociatedInterfaceSupport* Channel::GetAssociatedInterfaceSupport() {
69 return nullptr;
70}
71
rockot10188752016-09-08 18:24:5672void Channel::Pause() { NOTREACHED(); }
rockot401fb2c2016-09-06 18:35:5773
74void Channel::Unpause(bool flush) { NOTREACHED(); }
75
76void Channel::Flush() { NOTREACHED(); }
77
erikchen90971902016-04-25 23:45:3178void Channel::WillConnect() {
79 did_start_connect_ = true;
80}
81
[email protected]e482111a82014-05-30 03:58:5982} // namespace IPC