michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=8 et : michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "base/message_loop.h" michael@0: #include "chrome/common/child_process_info.h" michael@0: michael@0: #include "mozilla/ipc/Transport.h" michael@0: michael@0: using namespace base; michael@0: using namespace std; michael@0: michael@0: namespace mozilla { michael@0: namespace ipc { michael@0: michael@0: bool michael@0: CreateTransport(ProcessHandle aProcOne, ProcessHandle /*unused*/, michael@0: TransportDescriptor* aOne, TransportDescriptor* aTwo) michael@0: { michael@0: // This id is used to name the IPC pipe. The pointer passed to this michael@0: // function isn't significant. michael@0: wstring id = ChildProcessInfo::GenerateRandomChannelID(aOne); michael@0: // Use MODE_SERVER to force creation of the pipe michael@0: Transport t(id, Transport::MODE_SERVER, nullptr); michael@0: HANDLE serverPipe = t.GetServerPipeHandle(); michael@0: if (!serverPipe) { michael@0: return false; michael@0: } michael@0: michael@0: // NB: we create the server pipe immediately, instead of just michael@0: // grabbing an ID, on purpose. In the current setup, the client michael@0: // needs to connect to an existing server pipe, so to prevent race michael@0: // conditions, we create the server side here and then dup it to the michael@0: // eventual server process. michael@0: HANDLE serverDup; michael@0: DWORD access = 0; michael@0: DWORD options = DUPLICATE_SAME_ACCESS; michael@0: if (!DuplicateHandle(GetCurrentProcess(), serverPipe, aProcOne, michael@0: &serverDup, michael@0: access, michael@0: FALSE/*not inheritable*/, michael@0: options)) { michael@0: return false; michael@0: } michael@0: michael@0: aOne->mPipeName = aTwo->mPipeName = id; michael@0: aOne->mServerPipe = serverDup; michael@0: aTwo->mServerPipe = INVALID_HANDLE_VALUE; michael@0: return true; michael@0: } michael@0: michael@0: Transport* michael@0: OpenDescriptor(const TransportDescriptor& aTd, Transport::Mode aMode) michael@0: { michael@0: return new Transport(aTd.mPipeName, aTd.mServerPipe, aMode, nullptr); michael@0: } michael@0: michael@0: Transport* michael@0: OpenDescriptor(const FileDescriptor& aFd, Transport::Mode aMode) michael@0: { michael@0: NS_NOTREACHED("Not implemented!"); michael@0: return nullptr; michael@0: } michael@0: michael@0: void michael@0: CloseDescriptor(const TransportDescriptor& aTd) michael@0: { michael@0: CloseHandle(aTd.mServerPipe); michael@0: } michael@0: michael@0: } // namespace ipc michael@0: } // namespace mozilla