ipc_channel.cc (1820B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style license that can be 5 // found in the LICENSE file. 6 7 #include "ipc_channel.h" 8 9 #include "base/message_loop.h" 10 #include "mozilla/ipc/ProtocolUtils.h" 11 12 #ifdef XP_WIN 13 # include "chrome/common/ipc_channel_win.h" 14 #else 15 # include "chrome/common/ipc_channel_posix.h" 16 #endif 17 #ifdef XP_DARWIN 18 # include "chrome/common/ipc_channel_mach.h" 19 #endif 20 21 namespace IPC { 22 23 Channel::Channel() 24 : chan_cap_("ChannelImpl::SendMutex", 25 MessageLoopForIO::current()->SerialEventTarget()) {} 26 27 Channel::~Channel() = default; 28 29 already_AddRefed<Channel> Channel::Create(ChannelHandle pipe, Mode mode, 30 base::ProcessId other_pid) { 31 if (auto* handle = std::get_if<mozilla::UniqueFileHandle>(&pipe)) { 32 #ifdef XP_WIN 33 return mozilla::MakeAndAddRef<ChannelWin>(std::move(*handle), mode, 34 other_pid); 35 #else 36 return mozilla::MakeAndAddRef<ChannelPosix>(std::move(*handle), mode, 37 other_pid); 38 #endif 39 } 40 #if XP_DARWIN 41 if (auto* receive = std::get_if<mozilla::UniqueMachReceiveRight>(&pipe)) { 42 return mozilla::MakeAndAddRef<ChannelMach>(std::move(*receive), nullptr, 43 mode, other_pid); 44 } 45 if (auto* send = std::get_if<mozilla::UniqueMachSendRight>(&pipe)) { 46 return mozilla::MakeAndAddRef<ChannelMach>(nullptr, std::move(*send), mode, 47 other_pid); 48 } 49 #endif 50 MOZ_ASSERT_UNREACHABLE("unhandled pipe type"); 51 return nullptr; 52 } 53 54 } // namespace IPC