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

Side by Side Diff: ipc/ipc_platform_file.h

Issue 2846293002: Make PlatformFileForTransit its own class on Windows. (Closed)
Patch Set: Change message serialization to write nothing if the handle isn't valid. Created 3 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
« no previous file with comments | « ipc/ipc_message_utils.cc ('k') | ipc/ipc_platform_file.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef IPC_IPC_PLATFORM_FILE_H_ 5 #ifndef IPC_IPC_PLATFORM_FILE_H_
6 #define IPC_IPC_PLATFORM_FILE_H_ 6 #define IPC_IPC_PLATFORM_FILE_H_
7 7
8 #include "base/files/file.h" 8 #include "base/files/file.h"
9 #include "base/process/process.h" 9 #include "base/process/process.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "ipc/ipc_export.h" 11 #include "ipc/ipc_export.h"
12 12
13 #if defined(OS_POSIX) 13 #if defined(OS_POSIX)
14 #include "base/file_descriptor_posix.h" 14 #include "base/file_descriptor_posix.h"
15 #endif 15 #endif
16 16
17 #if defined(OS_WIN)
18 #include "base/memory/shared_memory_handle.h"
19 #endif
20
21 namespace IPC { 17 namespace IPC {
22 18
23 #if defined(OS_WIN) 19 #if defined(OS_WIN)
24 // The semantics for IPC transfer of a SharedMemoryHandle are exactly the same 20 class IPC_EXPORT PlatformFileForTransit {
25 // as for a PlatformFileForTransit. The object wraps a HANDLE, and has some 21 public:
26 // metadata that indicates the process to which the HANDLE belongs. 22 // Creates an invalid platform file.
27 using PlatformFileForTransit = base::SharedMemoryHandle; 23 PlatformFileForTransit();
24
25 // Creates a platform file that takes unofficial ownership of |handle|. Note
26 // that ownership is not handled by a Scoped* class due to usage patterns of
27 // this class and its POSIX counterpart [base::FileDescriptor]. When this
28 // class is used as an input to an IPC message, the IPC subsystem will close
29 // |handle|. When this class is used as the output from an IPC message, the
30 // receiver is expected to take ownership of |handle|.
31 explicit PlatformFileForTransit(HANDLE handle);
32
33 // Comparison operators.
34 bool operator==(const PlatformFileForTransit& platform_file) const;
35 bool operator!=(const PlatformFileForTransit& platform_file) const;
36
37 HANDLE GetHandle() const;
38 bool IsValid() const;
39
40 private:
41 HANDLE handle_;
42 };
28 #elif defined(OS_POSIX) 43 #elif defined(OS_POSIX)
29 typedef base::FileDescriptor PlatformFileForTransit; 44 typedef base::FileDescriptor PlatformFileForTransit;
30 #endif 45 #endif
31 46
32 inline PlatformFileForTransit InvalidPlatformFileForTransit() { 47 inline PlatformFileForTransit InvalidPlatformFileForTransit() {
33 #if defined(OS_WIN) 48 #if defined(OS_WIN)
34 return PlatformFileForTransit(); 49 return PlatformFileForTransit();
35 #elif defined(OS_POSIX) 50 #elif defined(OS_POSIX)
36 return base::FileDescriptor(); 51 return base::FileDescriptor();
37 #endif 52 #endif
(...skipping 24 matching lines...) Expand all
62 bool close_source_handle); 77 bool close_source_handle);
63 78
64 // Creates a new handle that can be passed through IPC. The result must be 79 // Creates a new handle that can be passed through IPC. The result must be
65 // passed to the IPC layer as part of a message, or else it will leak. 80 // passed to the IPC layer as part of a message, or else it will leak.
66 // Note that this function takes ownership of |file|. 81 // Note that this function takes ownership of |file|.
67 IPC_EXPORT PlatformFileForTransit TakePlatformFileForTransit(base::File file); 82 IPC_EXPORT PlatformFileForTransit TakePlatformFileForTransit(base::File file);
68 83
69 } // namespace IPC 84 } // namespace IPC
70 85
71 #endif // IPC_IPC_PLATFORM_FILE_H_ 86 #endif // IPC_IPC_PLATFORM_FILE_H_
OLDNEW
« no previous file with comments | « ipc/ipc_message_utils.cc ('k') | ipc/ipc_platform_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698