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

Side by Side Diff: ppapi/proxy/serialized_handle.h

Issue 1548813002: Switch to standard integer types in ppapi/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 4 years, 12 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 | « ppapi/proxy/serialized_flash_menu.cc ('k') | ppapi/proxy/serialized_handle.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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 PPAPI_PROXY_SERIALIZED_HANDLES_H_ 5 #ifndef PPAPI_PROXY_SERIALIZED_HANDLES_H_
6 #define PPAPI_PROXY_SERIALIZED_HANDLES_H_ 6 #define PPAPI_PROXY_SERIALIZED_HANDLES_H_
7 7
8 #include <stdint.h>
9
8 #include <string> 10 #include <string>
9 #include <vector> 11 #include <vector>
10 12
11 #include "base/atomicops.h" 13 #include "base/atomicops.h"
12 #include "base/basictypes.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
15 #include "base/memory/shared_memory.h" 16 #include "base/memory/shared_memory.h"
16 #include "build/build_config.h" 17 #include "build/build_config.h"
17 #include "ipc/ipc_platform_file.h" 18 #include "ipc/ipc_platform_file.h"
18 #include "ppapi/c/pp_resource.h" 19 #include "ppapi/c/pp_resource.h"
19 #include "ppapi/proxy/ppapi_proxy_export.h" 20 #include "ppapi/proxy/ppapi_proxy_export.h"
20 21
21 namespace base { 22 namespace base {
22 class Pickle; 23 class Pickle;
23 } 24 }
24 25
25 namespace ppapi { 26 namespace ppapi {
26 namespace proxy { 27 namespace proxy {
27 28
28 // SerializedHandle is a unified structure for holding a handle (e.g., a shared 29 // SerializedHandle is a unified structure for holding a handle (e.g., a shared
29 // memory handle, socket descriptor, etc). This is useful for passing handles in 30 // memory handle, socket descriptor, etc). This is useful for passing handles in
30 // resource messages and also makes it easier to translate handles in 31 // resource messages and also makes it easier to translate handles in
31 // NaClIPCAdapter for use in NaCl. 32 // NaClIPCAdapter for use in NaCl.
32 class PPAPI_PROXY_EXPORT SerializedHandle { 33 class PPAPI_PROXY_EXPORT SerializedHandle {
33 public: 34 public:
34 enum Type { INVALID, SHARED_MEMORY, SOCKET, FILE }; 35 enum Type { INVALID, SHARED_MEMORY, SOCKET, FILE };
35 // Header contains the fields that we send in IPC messages, apart from the 36 // Header contains the fields that we send in IPC messages, apart from the
36 // actual handle. See comments on the SerializedHandle fields below. 37 // actual handle. See comments on the SerializedHandle fields below.
37 struct Header { 38 struct Header {
38 Header() : type(INVALID), size(0), open_flags(0) {} 39 Header() : type(INVALID), size(0), open_flags(0) {}
39 Header(Type type_arg, 40 Header(Type type_arg,
40 uint32 size_arg, 41 uint32_t size_arg,
41 int32 open_flags_arg, 42 int32_t open_flags_arg,
42 PP_Resource file_io_arg) 43 PP_Resource file_io_arg)
43 : type(type_arg), 44 : type(type_arg),
44 size(size_arg), 45 size(size_arg),
45 open_flags(open_flags_arg), 46 open_flags(open_flags_arg),
46 file_io(file_io_arg) { 47 file_io(file_io_arg) {}
47 }
48 48
49 Type type; 49 Type type;
50 uint32 size; 50 uint32_t size;
51 int32 open_flags; 51 int32_t open_flags;
52 PP_Resource file_io; 52 PP_Resource file_io;
53 }; 53 };
54 54
55 SerializedHandle(); 55 SerializedHandle();
56 // Create an invalid handle of the given type. 56 // Create an invalid handle of the given type.
57 explicit SerializedHandle(Type type); 57 explicit SerializedHandle(Type type);
58 58
59 // Create a shared memory handle. 59 // Create a shared memory handle.
60 SerializedHandle(const base::SharedMemoryHandle& handle, uint32 size); 60 SerializedHandle(const base::SharedMemoryHandle& handle, uint32_t size);
61 61
62 // Create a socket or file handle. 62 // Create a socket or file handle.
63 SerializedHandle(const Type type, 63 SerializedHandle(const Type type,
64 const IPC::PlatformFileForTransit& descriptor); 64 const IPC::PlatformFileForTransit& descriptor);
65 65
66 Type type() const { return type_; } 66 Type type() const { return type_; }
67 bool is_shmem() const { return type_ == SHARED_MEMORY; } 67 bool is_shmem() const { return type_ == SHARED_MEMORY; }
68 bool is_socket() const { return type_ == SOCKET; } 68 bool is_socket() const { return type_ == SOCKET; }
69 bool is_file() const { return type_ == FILE; } 69 bool is_file() const { return type_ == FILE; }
70 const base::SharedMemoryHandle& shmem() const { 70 const base::SharedMemoryHandle& shmem() const {
71 DCHECK(is_shmem()); 71 DCHECK(is_shmem());
72 return shm_handle_; 72 return shm_handle_;
73 } 73 }
74 uint32 size() const { 74 uint32_t size() const {
75 DCHECK(is_shmem()); 75 DCHECK(is_shmem());
76 return size_; 76 return size_;
77 } 77 }
78 const IPC::PlatformFileForTransit& descriptor() const { 78 const IPC::PlatformFileForTransit& descriptor() const {
79 DCHECK(is_socket() || is_file()); 79 DCHECK(is_socket() || is_file());
80 return descriptor_; 80 return descriptor_;
81 } 81 }
82 int32 open_flags() const { 82 int32_t open_flags() const { return open_flags_; }
83 return open_flags_;
84 }
85 PP_Resource file_io() const { 83 PP_Resource file_io() const {
86 return file_io_; 84 return file_io_;
87 } 85 }
88 void set_shmem(const base::SharedMemoryHandle& handle, uint32 size) { 86 void set_shmem(const base::SharedMemoryHandle& handle, uint32_t size) {
89 type_ = SHARED_MEMORY; 87 type_ = SHARED_MEMORY;
90 shm_handle_ = handle; 88 shm_handle_ = handle;
91 size_ = size; 89 size_ = size;
92 90
93 descriptor_ = IPC::InvalidPlatformFileForTransit(); 91 descriptor_ = IPC::InvalidPlatformFileForTransit();
94 } 92 }
95 void set_socket(const IPC::PlatformFileForTransit& socket) { 93 void set_socket(const IPC::PlatformFileForTransit& socket) {
96 type_ = SOCKET; 94 type_ = SOCKET;
97 descriptor_ = socket; 95 descriptor_ = socket;
98 96
99 shm_handle_ = base::SharedMemory::NULLHandle(); 97 shm_handle_ = base::SharedMemory::NULLHandle();
100 size_ = 0; 98 size_ = 0;
101 } 99 }
102 void set_file_handle(const IPC::PlatformFileForTransit& descriptor, 100 void set_file_handle(const IPC::PlatformFileForTransit& descriptor,
103 int32 open_flags, 101 int32_t open_flags,
104 PP_Resource file_io) { 102 PP_Resource file_io) {
105 type_ = FILE; 103 type_ = FILE;
106 104
107 descriptor_ = descriptor; 105 descriptor_ = descriptor;
108 shm_handle_ = base::SharedMemory::NULLHandle(); 106 shm_handle_ = base::SharedMemory::NULLHandle();
109 size_ = 0; 107 size_ = 0;
110 open_flags_ = open_flags; 108 open_flags_ = open_flags;
111 file_io_ = file_io; 109 file_io_ = file_io;
112 } 110 }
113 void set_null_shmem() { 111 void set_null_shmem() {
(...skipping 23 matching lines...) Expand all
137 private: 135 private:
138 // The kind of handle we're holding. 136 // The kind of handle we're holding.
139 Type type_; 137 Type type_;
140 138
141 // We hold more members than we really need; we can't easily use a union, 139 // We hold more members than we really need; we can't easily use a union,
142 // because we hold non-POD types. But these types are pretty light-weight. If 140 // because we hold non-POD types. But these types are pretty light-weight. If
143 // we add more complex things later, we should come up with a more memory- 141 // we add more complex things later, we should come up with a more memory-
144 // efficient strategy. 142 // efficient strategy.
145 // These are valid if type == SHARED_MEMORY. 143 // These are valid if type == SHARED_MEMORY.
146 base::SharedMemoryHandle shm_handle_; 144 base::SharedMemoryHandle shm_handle_;
147 uint32 size_; 145 uint32_t size_;
148 146
149 // This is valid if type == SOCKET || type == FILE. 147 // This is valid if type == SOCKET || type == FILE.
150 IPC::PlatformFileForTransit descriptor_; 148 IPC::PlatformFileForTransit descriptor_;
151 149
152 // The following fields are valid if type == FILE. 150 // The following fields are valid if type == FILE.
153 int32 open_flags_; 151 int32_t open_flags_;
154 // This is non-zero if file writes require quota checking. 152 // This is non-zero if file writes require quota checking.
155 PP_Resource file_io_; 153 PP_Resource file_io_;
156 }; 154 };
157 155
158 } // namespace proxy 156 } // namespace proxy
159 } // namespace ppapi 157 } // namespace ppapi
160 158
161 #endif // PPAPI_PROXY_SERIALIZED_HANDLES_H_ 159 #endif // PPAPI_PROXY_SERIALIZED_HANDLES_H_
OLDNEW
« no previous file with comments | « ppapi/proxy/serialized_flash_menu.cc ('k') | ppapi/proxy/serialized_handle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698