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

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

Issue 10828023: PPAPI/NaCl: Make NaClIPCAdapter transfer handles more generally (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: re-add gyp files Created 8 years, 3 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
« no previous file with comments | « ppapi/proxy/ppb_image_data_proxy.cc ('k') | ppapi/proxy/serialized_structs.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) 2012 The Chromium Authors. All rights reserved. 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 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_STRUCTS_H_ 5 #ifndef PPAPI_PROXY_SERIALIZED_STRUCTS_H_
6 #define PPAPI_PROXY_SERIALIZED_STRUCTS_H_ 6 #define PPAPI_PROXY_SERIALIZED_STRUCTS_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/logging.h"
11 #include "base/shared_memory.h" 12 #include "base/shared_memory.h"
12 #include "build/build_config.h" 13 #include "build/build_config.h"
13 #include "ipc/ipc_platform_file.h" 14 #include "ipc/ipc_platform_file.h"
14 #include "ppapi/c/pp_bool.h" 15 #include "ppapi/c/pp_bool.h"
15 #include "ppapi/c/pp_instance.h" 16 #include "ppapi/c/pp_instance.h"
16 #include "ppapi/c/pp_point.h" 17 #include "ppapi/c/pp_point.h"
17 #include "ppapi/c/pp_rect.h" 18 #include "ppapi/c/pp_rect.h"
18 #include "ppapi/proxy/serialized_var.h" 19 #include "ppapi/proxy/serialized_var.h"
19 #include "ppapi/shared_impl/host_resource.h" 20 #include "ppapi/shared_impl/host_resource.h"
20 21
22 class Pickle;
21 struct PP_FontDescription_Dev; 23 struct PP_FontDescription_Dev;
22 24
23 namespace ppapi { 25 namespace ppapi {
24 namespace proxy { 26 namespace proxy {
25 27
26 class Dispatcher; 28 class Dispatcher;
27 29
28 // PP_FontDescript_Dev has to be redefined with a SerializedVar in place of 30 // PP_FontDescript_Dev has to be redefined with a SerializedVar in place of
29 // the PP_Var used for the face name. 31 // the PP_Var used for the face name.
30 struct PPAPI_PROXY_EXPORT SerializedFontDescription { 32 struct PPAPI_PROXY_EXPORT SerializedFontDescription {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 int64_t bytes_received; 96 int64_t bytes_received;
95 int64_t total_bytes_to_be_received; 97 int64_t total_bytes_to_be_received;
96 }; 98 };
97 99
98 struct PPPVideoCapture_Buffer { 100 struct PPPVideoCapture_Buffer {
99 ppapi::HostResource resource; 101 ppapi::HostResource resource;
100 uint32_t size; 102 uint32_t size;
101 base::SharedMemoryHandle handle; 103 base::SharedMemoryHandle handle;
102 }; 104 };
103 105
106 // We put all our handles in a unified structure to make it easy to translate
107 // them in NaClIPCAdapter for use in NaCl.
108 class PPAPI_PROXY_EXPORT SerializedHandle {
109 public:
110 enum Type { INVALID, SHARED_MEMORY, SOCKET };
111 struct Header {
112 Header() : type(INVALID), size(0) {}
113 Header(Type type_arg, uint32_t size_arg)
114 : type(type_arg), size(size_arg) {
115 }
116 Type type;
117 uint32_t size;
118 };
119
120 SerializedHandle();
121 // Create an invalid handle of the given type.
122 explicit SerializedHandle(Type type);
123
124 // Create a shared memory handle.
125 SerializedHandle(const base::SharedMemoryHandle& handle, uint32_t size);
126
127 // Create a socket handle.
128 // TODO(dmichael): If we have other ways to use FDs later, this would be
129 // ambiguous.
130 explicit SerializedHandle(
131 const IPC::PlatformFileForTransit& socket_descriptor);
132
133 Type type() const { return type_; }
134 bool is_shmem() const { return type_ == SHARED_MEMORY; }
135 bool is_socket() const { return type_ == SOCKET; }
136 const base::SharedMemoryHandle& shmem() const {
137 DCHECK(is_shmem());
138 return shm_handle_;
139 }
140 uint32_t size() const {
141 DCHECK(is_shmem());
142 return size_;
143 }
144 const IPC::PlatformFileForTransit& descriptor() const {
145 DCHECK(is_socket());
146 return descriptor_;
147 }
148 void set_shmem(const base::SharedMemoryHandle& handle, uint32_t size) {
149 type_ = SHARED_MEMORY;
150 shm_handle_ = handle;
151 size_ = size;
152
153 descriptor_ = IPC::InvalidPlatformFileForTransit();
154 }
155 void set_socket(const IPC::PlatformFileForTransit& socket) {
156 type_ = SOCKET;
157 descriptor_ = socket;
158
159 shm_handle_ = base::SharedMemory::NULLHandle();
160 size_ = 0;
161 }
162 void set_null_shmem() {
163 set_shmem(base::SharedMemory::NULLHandle(), 0);
164 }
165 void set_null_socket() {
166 set_socket(IPC::InvalidPlatformFileForTransit());
167 }
168 bool IsHandleValid() const;
169
170 Header header() const {
171 return Header(type_, size_);
172 }
173
174 // Write/Read a Header, which contains all the data except the handle. This
175 // allows us to write the handle in a platform-specific way, as is necessary
176 // in NaClIPCAdapter to share handles with NaCl from Windows.
177 static bool WriteHeader(const Header& hdr, Pickle* pickle);
178 static bool ReadHeader(PickleIterator* iter, Header* hdr);
179
180 private:
181 // The kind of handle we're holding.
182 Type type_;
183
184 // We hold more members than we really need; we can't easily use a union,
185 // because we hold non-POD types. But these types are pretty light-weight. If
186 // we add more complex things later, we should come up with a more memory-
187 // efficient strategy.
188 // These are valid if type == SHARED_MEMORY.
189 base::SharedMemoryHandle shm_handle_;
190 uint32_t size_;
191
192 // This is valid if type == SOCKET.
193 IPC::PlatformFileForTransit descriptor_;
194 };
195
104 // TODO(tomfinegan): This is identical to PPPVideoCapture_Buffer, maybe replace 196 // TODO(tomfinegan): This is identical to PPPVideoCapture_Buffer, maybe replace
105 // both with a single type? 197 // both with a single type?
106 struct PPPDecryptor_Buffer { 198 struct PPPDecryptor_Buffer {
107 ppapi::HostResource resource; 199 ppapi::HostResource resource;
108 uint32_t size; 200 uint32_t size;
109 base::SharedMemoryHandle handle; 201 base::SharedMemoryHandle handle;
110 }; 202 };
111 203
112 #if defined(OS_WIN) 204 #if defined(OS_WIN)
113 typedef HANDLE ImageHandle; 205 typedef HANDLE ImageHandle;
114 #elif defined(OS_MACOSX) || defined(OS_ANDROID) 206 #elif defined(OS_MACOSX) || defined(OS_ANDROID)
115 typedef base::SharedMemoryHandle ImageHandle; 207 typedef base::SharedMemoryHandle ImageHandle;
116 #else 208 #else
117 // On X Windows this is a SysV shared memory key. 209 // On X Windows this is a SysV shared memory key.
118 typedef int ImageHandle; 210 typedef int ImageHandle;
119 #endif 211 #endif
120 212
121 } // namespace proxy 213 } // namespace proxy
122 } // namespace ppapi 214 } // namespace ppapi
123 215
124 #endif // PPAPI_PROXY_SERIALIZED_STRUCTS_H_ 216 #endif // PPAPI_PROXY_SERIALIZED_STRUCTS_H_
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_image_data_proxy.cc ('k') | ppapi/proxy/serialized_structs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698