• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 #include "build/build_config.h"
6 #include "ipc/ipc_channel.h"
7 #include "ipc/ipc_channel_mojo.h"
8 #include "mojo/public/cpp/system/message_pipe.h"
9 
10 namespace IPC {
11 
12 #if defined(OS_LINUX)
13 
14 namespace {
15 int g_global_pid = 0;
16 }
17 
18 // static
SetGlobalPid(int pid)19 void Channel::SetGlobalPid(int pid) {
20   g_global_pid = pid;
21 }
22 
23 // static
GetGlobalPid()24 int Channel::GetGlobalPid() {
25   return g_global_pid;
26 }
27 
28 #endif  // defined(OS_LINUX)
29 
30 // static
CreateClient(const IPC::ChannelHandle & channel_handle,Listener * listener,const scoped_refptr<base::SingleThreadTaskRunner> & ipc_task_runner)31 std::unique_ptr<Channel> Channel::CreateClient(
32     const IPC::ChannelHandle& channel_handle,
33     Listener* listener,
34     const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) {
35 #if defined(OS_NACL_SFI)
36   return Channel::Create(channel_handle, Channel::MODE_CLIENT, listener);
37 #else
38   DCHECK(channel_handle.is_mojo_channel_handle());
39   return ChannelMojo::Create(
40       mojo::ScopedMessagePipeHandle(channel_handle.mojo_handle),
41       Channel::MODE_CLIENT, listener, ipc_task_runner,
42       base::ThreadTaskRunnerHandle::Get());
43 #endif
44 }
45 
46 // static
CreateServer(const IPC::ChannelHandle & channel_handle,Listener * listener,const scoped_refptr<base::SingleThreadTaskRunner> & ipc_task_runner)47 std::unique_ptr<Channel> Channel::CreateServer(
48     const IPC::ChannelHandle& channel_handle,
49     Listener* listener,
50     const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) {
51 #if defined(OS_NACL_SFI)
52   return Channel::Create(channel_handle, Channel::MODE_SERVER, listener);
53 #else
54   DCHECK(channel_handle.is_mojo_channel_handle());
55   return ChannelMojo::Create(
56       mojo::ScopedMessagePipeHandle(channel_handle.mojo_handle),
57       Channel::MODE_SERVER, listener, ipc_task_runner,
58       base::ThreadTaskRunnerHandle::Get());
59 #endif
60 }
61 
62 Channel::~Channel() = default;
63 
GetAssociatedInterfaceSupport()64 Channel::AssociatedInterfaceSupport* Channel::GetAssociatedInterfaceSupport() {
65   return nullptr;
66 }
67 
Pause()68 void Channel::Pause() { NOTREACHED(); }
69 
Unpause(bool flush)70 void Channel::Unpause(bool flush) { NOTREACHED(); }
71 
Flush()72 void Channel::Flush() { NOTREACHED(); }
73 
WillConnect()74 void Channel::WillConnect() {
75   did_start_connect_ = true;
76 }
77 
78 }  // namespace IPC
79