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

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: ready for review? Created 8 years, 4 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
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 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,
140 uint32_t size) {
141 type_ = SHARED_MEMORY;
142 shm_handle_ = handle;
143 size_ = size;
144
145 descriptor_ = IPC::InvalidPlatformFileForTransit();
146 }
147 void set_socket(const IPC::PlatformFileForTransit& socket) {
148 type_ = SOCKET;
149 descriptor_ = socket;
150
151 shm_handle_ = base::SharedMemory::NULLHandle();
152 size_ = 0;
153 }
154 void set_null_shmem() {
155 set_shmem(base::SharedMemory::NULLHandle(), 0);
156 }
157 void set_null_socket() {
158 set_socket(IPC::InvalidPlatformFileForTransit());
159 }
160 bool IsHandleValid() const;
161
162 // Write all the data except the handle to the given pickle. This allows us
163 // to write the handle in a platform-specific way, as is necessary in
164 // NaClIPCAdapter to share handles with NaCl from Windows.
165 bool WriteHeader(Pickle* pickle) const;
166
167 private:
168 // The kind of handle we're holding.
169 Type type_;
170
171 // We hold more members than we really need; we can't easily use a union,
172 // because we hold non-POD types. But these types are pretty light-weight. If
173 // we add more complex things later, we should come up with a more memory-
174 // efficient strategy.
175 // These are valid if type == SHARED_MEMORY.
176 base::SharedMemoryHandle shm_handle_;
177 uint32_t size_;
178
179 // This is valid if type == SOCKET.
180 IPC::PlatformFileForTransit descriptor_;
181 };
182
104 #if defined(OS_WIN) 183 #if defined(OS_WIN)
105 typedef HANDLE ImageHandle; 184 typedef HANDLE ImageHandle;
106 #elif defined(OS_MACOSX) || defined(OS_ANDROID) 185 #elif defined(OS_MACOSX) || defined(OS_ANDROID)
107 typedef base::SharedMemoryHandle ImageHandle; 186 typedef base::SharedMemoryHandle ImageHandle;
108 #else 187 #else
109 // On X Windows this is a SysV shared memory key. 188 // On X Windows this is a SysV shared memory key.
110 typedef int ImageHandle; 189 typedef int ImageHandle;
111 #endif 190 #endif
112 191
113 } // namespace proxy 192 } // namespace proxy
114 } // namespace ppapi 193 } // namespace ppapi
115 194
116 #endif // PPAPI_PROXY_SERIALIZED_STRUCTS_H_ 195 #endif // PPAPI_PROXY_SERIALIZED_STRUCTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698