Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=8 et :
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "base/message_loop.h"
9 #include "chrome/common/child_process_info.h"
11 #include "mozilla/ipc/Transport.h"
13 using namespace base;
14 using namespace std;
16 namespace mozilla {
17 namespace ipc {
19 bool
20 CreateTransport(ProcessHandle aProcOne, ProcessHandle /*unused*/,
21 TransportDescriptor* aOne, TransportDescriptor* aTwo)
22 {
23 // This id is used to name the IPC pipe. The pointer passed to this
24 // function isn't significant.
25 wstring id = ChildProcessInfo::GenerateRandomChannelID(aOne);
26 // Use MODE_SERVER to force creation of the pipe
27 Transport t(id, Transport::MODE_SERVER, nullptr);
28 HANDLE serverPipe = t.GetServerPipeHandle();
29 if (!serverPipe) {
30 return false;
31 }
33 // NB: we create the server pipe immediately, instead of just
34 // grabbing an ID, on purpose. In the current setup, the client
35 // needs to connect to an existing server pipe, so to prevent race
36 // conditions, we create the server side here and then dup it to the
37 // eventual server process.
38 HANDLE serverDup;
39 DWORD access = 0;
40 DWORD options = DUPLICATE_SAME_ACCESS;
41 if (!DuplicateHandle(GetCurrentProcess(), serverPipe, aProcOne,
42 &serverDup,
43 access,
44 FALSE/*not inheritable*/,
45 options)) {
46 return false;
47 }
49 aOne->mPipeName = aTwo->mPipeName = id;
50 aOne->mServerPipe = serverDup;
51 aTwo->mServerPipe = INVALID_HANDLE_VALUE;
52 return true;
53 }
55 Transport*
56 OpenDescriptor(const TransportDescriptor& aTd, Transport::Mode aMode)
57 {
58 return new Transport(aTd.mPipeName, aTd.mServerPipe, aMode, nullptr);
59 }
61 Transport*
62 OpenDescriptor(const FileDescriptor& aFd, Transport::Mode aMode)
63 {
64 NS_NOTREACHED("Not implemented!");
65 return nullptr;
66 }
68 void
69 CloseDescriptor(const TransportDescriptor& aTd)
70 {
71 CloseHandle(aTd.mServerPipe);
72 }
74 } // namespace ipc
75 } // namespace mozilla