Home | History | Annotate | Download | only in ipc
      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
     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 
     30 // static
     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
     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 
     64 Channel::AssociatedInterfaceSupport* Channel::GetAssociatedInterfaceSupport() {
     65   return nullptr;
     66 }
     67 
     68 void Channel::Pause() { NOTREACHED(); }
     69 
     70 void Channel::Unpause(bool flush) { NOTREACHED(); }
     71 
     72 void Channel::Flush() { NOTREACHED(); }
     73 
     74 void Channel::WillConnect() {
     75   did_start_connect_ = true;
     76 }
     77 
     78 }  // namespace IPC
     79