Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: content/public/common/sandbox_init.cc

Issue 10378057: Broker out PPAPI handle duplication (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "content/public/common/sandbox_init.h"
6
7 namespace content {
8
9 IPC::PlatformFileForTransit BrokerGetFileHandleForProcess(
jschuh 2012/05/10 00:10:57 Cross platform function to make an exact copy of t
10 base::PlatformFile handle,
11 base::ProcessId target_process_id,
12 bool should_close_source) {
13 IPC::PlatformFileForTransit out_handle;
14 #if defined(OS_WIN)
15 DWORD options = DUPLICATE_SAME_ACCESS;
16 if (should_close_source)
17 options |= DUPLICATE_CLOSE_SOURCE;
18 if (!content::BrokerDuplicateHandle(handle, target_process_id, &out_handle,
19 0, options)) {
20 out_handle = IPC::InvalidPlatformFileForTransit();
21 }
22 #elif defined(OS_POSIX)
23 // If asked to close the source, we can simply re-use the source fd instead of
24 // dup()ing and close()ing.
25 // When we're not closing the source, we need to duplicate the handle and take
26 // ownership of that. The reason is that this function is often used to
27 // generate IPC messages, and the handle must remain valid until it's sent to
28 // the other process from the I/O thread. Without the dup, calling code might
29 // close the source handle before the message is sent, creating a race
30 // condition.
31 int fd = should_close_source ? handle : ::dup(handle);
32 out_handle = base::FileDescriptor(fd, true);
33 #else
34 #error Not implemented.
35 #endif
36 return out_handle;
37 }
38
39 } // namespace content
40
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698