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

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

Issue 11894003: PPAPI/NaCl: Move handle extraction code to ppapi/proxy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 7 years, 11 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/serialized_handle.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/logging.h"
12 #include "base/shared_memory.h" 12 #include "base/shared_memory.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "ipc/ipc_platform_file.h"
15 #include "ppapi/c/pp_bool.h" 14 #include "ppapi/c/pp_bool.h"
16 #include "ppapi/c/pp_instance.h" 15 #include "ppapi/c/pp_instance.h"
17 #include "ppapi/c/pp_point.h" 16 #include "ppapi/c/pp_point.h"
18 #include "ppapi/c/pp_rect.h" 17 #include "ppapi/c/pp_rect.h"
19 #include "ppapi/proxy/ppapi_proxy_export.h" 18 #include "ppapi/proxy/ppapi_proxy_export.h"
20 #include "ppapi/shared_impl/host_resource.h" 19 #include "ppapi/shared_impl/host_resource.h"
21 20
22 class Pickle; 21 class Pickle;
23 struct PP_FontDescription_Dev; 22 struct PP_FontDescription_Dev;
24 struct PP_BrowserFont_Trusted_Description; 23 struct PP_BrowserFont_Trusted_Description;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 79
81 struct PPBURLLoader_UpdateProgress_Params { 80 struct PPBURLLoader_UpdateProgress_Params {
82 PP_Instance instance; 81 PP_Instance instance;
83 ppapi::HostResource resource; 82 ppapi::HostResource resource;
84 int64_t bytes_sent; 83 int64_t bytes_sent;
85 int64_t total_bytes_to_be_sent; 84 int64_t total_bytes_to_be_sent;
86 int64_t bytes_received; 85 int64_t bytes_received;
87 int64_t total_bytes_to_be_received; 86 int64_t total_bytes_to_be_received;
88 }; 87 };
89 88
90 // We put all our handles in a unified structure to make it easy to translate
91 // them in NaClIPCAdapter for use in NaCl.
92 class PPAPI_PROXY_EXPORT SerializedHandle {
93 public:
94 enum Type { INVALID, SHARED_MEMORY, SOCKET, CHANNEL_HANDLE, FILE };
95 struct Header {
96 Header() : type(INVALID), size(0) {}
97 Header(Type type_arg, uint32_t size_arg)
98 : type(type_arg), size(size_arg) {
99 }
100 Type type;
101 uint32_t size;
102 };
103
104 SerializedHandle();
105 // Create an invalid handle of the given type.
106 explicit SerializedHandle(Type type);
107
108 // Create a shared memory handle.
109 SerializedHandle(const base::SharedMemoryHandle& handle, uint32_t size);
110
111 // Create a socket, channel or file handle.
112 SerializedHandle(const Type type,
113 const IPC::PlatformFileForTransit& descriptor);
114
115 Type type() const { return type_; }
116 bool is_shmem() const { return type_ == SHARED_MEMORY; }
117 bool is_socket() const { return type_ == SOCKET; }
118 bool is_channel_handle() const { return type_ == CHANNEL_HANDLE; }
119 bool is_file() const { return type_ == FILE; }
120 const base::SharedMemoryHandle& shmem() const {
121 DCHECK(is_shmem());
122 return shm_handle_;
123 }
124 uint32_t size() const {
125 DCHECK(is_shmem());
126 return size_;
127 }
128 const IPC::PlatformFileForTransit& descriptor() const {
129 DCHECK(is_socket() || is_channel_handle() || is_file());
130 return descriptor_;
131 }
132 void set_shmem(const base::SharedMemoryHandle& handle, uint32_t size) {
133 type_ = SHARED_MEMORY;
134 shm_handle_ = handle;
135 size_ = size;
136
137 descriptor_ = IPC::InvalidPlatformFileForTransit();
138 }
139 void set_socket(const IPC::PlatformFileForTransit& socket) {
140 type_ = SOCKET;
141 descriptor_ = socket;
142
143 shm_handle_ = base::SharedMemory::NULLHandle();
144 size_ = 0;
145 }
146 void set_channel_handle(const IPC::PlatformFileForTransit& descriptor) {
147 type_ = CHANNEL_HANDLE;
148
149 descriptor_ = descriptor;
150 shm_handle_ = base::SharedMemory::NULLHandle();
151 size_ = 0;
152 }
153 void set_file_handle(const IPC::PlatformFileForTransit& descriptor) {
154 type_ = FILE;
155
156 descriptor_ = descriptor;
157 shm_handle_ = base::SharedMemory::NULLHandle();
158 size_ = 0;
159 }
160 void set_null_shmem() {
161 set_shmem(base::SharedMemory::NULLHandle(), 0);
162 }
163 void set_null_socket() {
164 set_socket(IPC::InvalidPlatformFileForTransit());
165 }
166 void set_null_channel_handle() {
167 set_channel_handle(IPC::InvalidPlatformFileForTransit());
168 }
169 void set_null_file_handle() {
170 set_file_handle(IPC::InvalidPlatformFileForTransit());
171 }
172 bool IsHandleValid() const;
173
174 Header header() const {
175 return Header(type_, size_);
176 }
177
178 // Closes the handle and sets it to invalid.
179 void Close();
180
181 // Write/Read a Header, which contains all the data except the handle. This
182 // allows us to write the handle in a platform-specific way, as is necessary
183 // in NaClIPCAdapter to share handles with NaCl from Windows.
184 static bool WriteHeader(const Header& hdr, Pickle* pickle);
185 static bool ReadHeader(PickleIterator* iter, Header* hdr);
186
187 private:
188 // The kind of handle we're holding.
189 Type type_;
190
191 // We hold more members than we really need; we can't easily use a union,
192 // because we hold non-POD types. But these types are pretty light-weight. If
193 // we add more complex things later, we should come up with a more memory-
194 // efficient strategy.
195 // These are valid if type == SHARED_MEMORY.
196 base::SharedMemoryHandle shm_handle_;
197 uint32_t size_;
198
199 // This is valid if type == SOCKET || type == CHANNEL_HANDLE.
200 IPC::PlatformFileForTransit descriptor_;
201 };
202
203 struct PPPDecryptor_Buffer { 89 struct PPPDecryptor_Buffer {
204 ppapi::HostResource resource; 90 ppapi::HostResource resource;
205 uint32_t size; 91 uint32_t size;
206 base::SharedMemoryHandle handle; 92 base::SharedMemoryHandle handle;
207 }; 93 };
208 94
209 #if defined(OS_WIN) 95 #if defined(OS_WIN)
210 typedef HANDLE ImageHandle; 96 typedef HANDLE ImageHandle;
211 #elif defined(OS_MACOSX) || defined(OS_ANDROID) 97 #elif defined(OS_MACOSX) || defined(OS_ANDROID)
212 typedef base::SharedMemoryHandle ImageHandle; 98 typedef base::SharedMemoryHandle ImageHandle;
213 #else 99 #else
214 // On X Windows this is a SysV shared memory key. 100 // On X Windows this is a SysV shared memory key.
215 typedef int ImageHandle; 101 typedef int ImageHandle;
216 #endif 102 #endif
217 103
218 } // namespace proxy 104 } // namespace proxy
219 } // namespace ppapi 105 } // namespace ppapi
220 106
221 #endif // PPAPI_PROXY_SERIALIZED_STRUCTS_H_ 107 #endif // PPAPI_PROXY_SERIALIZED_STRUCTS_H_
OLDNEW
« no previous file with comments | « ppapi/proxy/serialized_handle.cc ('k') | ppapi/proxy/serialized_structs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698