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