OLD | NEW |
---|---|
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 Loading... | |
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 SerializedHandle(); | |
112 // Create an invalid handle of the given type. | |
113 explicit SerializedHandle(Type type); | |
114 | |
115 // Create a shared memory handle. | |
116 SerializedHandle(const base::SharedMemoryHandle& handle, uint32_t size); | |
117 | |
118 // Create a socket handle. | |
119 // TODO(dmichael): If we have other ways to use FDs later, this would be | |
120 // ambiguous. | |
121 explicit SerializedHandle( | |
122 const IPC::PlatformFileForTransit& socket_descriptor); | |
123 | |
124 Type type() const { return type_; } | |
125 bool is_shmem() const { return type_ == SHARED_MEMORY; } | |
126 bool is_socket() const { return type_ == SOCKET; } | |
127 const base::SharedMemoryHandle& shmem() const { | |
128 DCHECK(is_shmem()); | |
129 return shm_handle_; | |
130 } | |
131 uint32_t size() const { | |
132 DCHECK(is_shmem()); | |
133 return size_; | |
134 } | |
135 const IPC::PlatformFileForTransit& descriptor() const { | |
136 DCHECK(is_socket()); | |
137 return descriptor_; | |
138 } | |
139 void set_shmem(const base::SharedMemoryHandle& handle, uint32_t size) { | |
140 type_ = SHARED_MEMORY; | |
141 shm_handle_ = handle; | |
142 size_ = size; | |
143 | |
144 descriptor_ = IPC::InvalidPlatformFileForTransit(); | |
145 } | |
146 void set_socket(const IPC::PlatformFileForTransit& socket) { | |
147 type_ = SOCKET; | |
148 descriptor_ = socket; | |
149 | |
150 shm_handle_ = base::SharedMemory::NULLHandle(); | |
151 size_ = 0; | |
152 } | |
153 void set_null_shmem() { | |
154 set_shmem(base::SharedMemory::NULLHandle(), 0); | |
155 } | |
156 void set_null_socket() { | |
157 set_socket(IPC::InvalidPlatformFileForTransit()); | |
158 } | |
159 bool IsHandleValid() const; | |
160 | |
161 | |
162 struct Header { | |
brettw
2012/08/22 23:27:06
I'd define this at the top with the other types.
dmichael (off chromium)
2012/08/23 22:55:14
Done.
| |
163 Header() : type(INVALID), size(0) {} | |
164 Header(Type type_arg, uint32_t size_arg) | |
165 : type(type_arg), size(size_arg) { | |
166 } | |
167 Type type; | |
168 uint32_t size; | |
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_ |
OLD | NEW |