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