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

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

Issue 10912011: Change NaCl IPC PPAPI proxy startup to support a NaCl-Browser process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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_audio_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
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 struct PPPVideoCapture_Buffer { 100 struct PPPVideoCapture_Buffer {
101 ppapi::HostResource resource; 101 ppapi::HostResource resource;
102 uint32_t size; 102 uint32_t size;
103 base::SharedMemoryHandle handle; 103 base::SharedMemoryHandle handle;
104 }; 104 };
105 105
106 // We put all our handles in a unified structure to make it easy to translate 106 // We put all our handles in a unified structure to make it easy to translate
107 // them in NaClIPCAdapter for use in NaCl. 107 // them in NaClIPCAdapter for use in NaCl.
108 class PPAPI_PROXY_EXPORT SerializedHandle { 108 class PPAPI_PROXY_EXPORT SerializedHandle {
109 public: 109 public:
110 enum Type { INVALID, SHARED_MEMORY, SOCKET }; 110 enum Type { INVALID, SHARED_MEMORY, SOCKET, CHANNEL_HANDLE };
111 struct Header { 111 struct Header {
112 Header() : type(INVALID), size(0) {} 112 Header() : type(INVALID), size(0) {}
113 Header(Type type_arg, uint32_t size_arg) 113 Header(Type type_arg, uint32_t size_arg)
114 : type(type_arg), size(size_arg) { 114 : type(type_arg), size(size_arg) {
115 } 115 }
116 Type type; 116 Type type;
117 uint32_t size; 117 uint32_t size;
118 }; 118 };
119 119
120 SerializedHandle(); 120 SerializedHandle();
121 // Create an invalid handle of the given type. 121 // Create an invalid handle of the given type.
122 explicit SerializedHandle(Type type); 122 explicit SerializedHandle(Type type);
123 123
124 // Create a shared memory handle. 124 // Create a shared memory handle.
125 SerializedHandle(const base::SharedMemoryHandle& handle, uint32_t size); 125 SerializedHandle(const base::SharedMemoryHandle& handle, uint32_t size);
126 126
127 // Create a socket handle. 127 // Create a socket or channel handle.
128 // TODO(dmichael): If we have other ways to use FDs later, this would be 128 SerializedHandle(const Type type,
129 // ambiguous. 129 const IPC::PlatformFileForTransit& descriptor);
130 explicit SerializedHandle(
131 const IPC::PlatformFileForTransit& socket_descriptor);
132 130
133 Type type() const { return type_; } 131 Type type() const { return type_; }
134 bool is_shmem() const { return type_ == SHARED_MEMORY; } 132 bool is_shmem() const { return type_ == SHARED_MEMORY; }
135 bool is_socket() const { return type_ == SOCKET; } 133 bool is_socket() const { return type_ == SOCKET; }
134 bool is_channel_handle() const { return type_ == CHANNEL_HANDLE; }
136 const base::SharedMemoryHandle& shmem() const { 135 const base::SharedMemoryHandle& shmem() const {
137 DCHECK(is_shmem()); 136 DCHECK(is_shmem());
138 return shm_handle_; 137 return shm_handle_;
139 } 138 }
140 uint32_t size() const { 139 uint32_t size() const {
141 DCHECK(is_shmem()); 140 DCHECK(is_shmem());
142 return size_; 141 return size_;
143 } 142 }
144 const IPC::PlatformFileForTransit& descriptor() const { 143 const IPC::PlatformFileForTransit& descriptor() const {
145 DCHECK(is_socket()); 144 DCHECK(is_socket() || is_channel_handle());
146 return descriptor_; 145 return descriptor_;
147 } 146 }
148 void set_shmem(const base::SharedMemoryHandle& handle, uint32_t size) { 147 void set_shmem(const base::SharedMemoryHandle& handle, uint32_t size) {
149 type_ = SHARED_MEMORY; 148 type_ = SHARED_MEMORY;
150 shm_handle_ = handle; 149 shm_handle_ = handle;
151 size_ = size; 150 size_ = size;
152 151
153 descriptor_ = IPC::InvalidPlatformFileForTransit(); 152 descriptor_ = IPC::InvalidPlatformFileForTransit();
154 } 153 }
155 void set_socket(const IPC::PlatformFileForTransit& socket) { 154 void set_socket(const IPC::PlatformFileForTransit& socket) {
156 type_ = SOCKET; 155 type_ = SOCKET;
157 descriptor_ = socket; 156 descriptor_ = socket;
158 157
159 shm_handle_ = base::SharedMemory::NULLHandle(); 158 shm_handle_ = base::SharedMemory::NULLHandle();
160 size_ = 0; 159 size_ = 0;
161 } 160 }
161 void set_channel_handle(const IPC::PlatformFileForTransit& descriptor) {
162 type_ = CHANNEL_HANDLE;
163
164 descriptor_ = descriptor;
165 shm_handle_ = base::SharedMemory::NULLHandle();
166 size_ = 0;
167 }
162 void set_null_shmem() { 168 void set_null_shmem() {
163 set_shmem(base::SharedMemory::NULLHandle(), 0); 169 set_shmem(base::SharedMemory::NULLHandle(), 0);
164 } 170 }
165 void set_null_socket() { 171 void set_null_socket() {
166 set_socket(IPC::InvalidPlatformFileForTransit()); 172 set_socket(IPC::InvalidPlatformFileForTransit());
167 } 173 }
174 void set_null_channel_handle() {
175 set_channel_handle(IPC::InvalidPlatformFileForTransit());
176 }
168 bool IsHandleValid() const; 177 bool IsHandleValid() const;
169 178
170 Header header() const { 179 Header header() const {
171 return Header(type_, size_); 180 return Header(type_, size_);
172 } 181 }
173 182
174 // Write/Read a Header, which contains all the data except the handle. This 183 // 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 184 // allows us to write the handle in a platform-specific way, as is necessary
176 // in NaClIPCAdapter to share handles with NaCl from Windows. 185 // in NaClIPCAdapter to share handles with NaCl from Windows.
177 static bool WriteHeader(const Header& hdr, Pickle* pickle); 186 static bool WriteHeader(const Header& hdr, Pickle* pickle);
178 static bool ReadHeader(PickleIterator* iter, Header* hdr); 187 static bool ReadHeader(PickleIterator* iter, Header* hdr);
179 188
180 private: 189 private:
181 // The kind of handle we're holding. 190 // The kind of handle we're holding.
182 Type type_; 191 Type type_;
183 192
184 // We hold more members than we really need; we can't easily use a union, 193 // 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 194 // 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- 195 // we add more complex things later, we should come up with a more memory-
187 // efficient strategy. 196 // efficient strategy.
188 // These are valid if type == SHARED_MEMORY. 197 // These are valid if type == SHARED_MEMORY.
189 base::SharedMemoryHandle shm_handle_; 198 base::SharedMemoryHandle shm_handle_;
190 uint32_t size_; 199 uint32_t size_;
191 200
192 // This is valid if type == SOCKET. 201 // This is valid if type == SOCKET || type == CHANNEL_HANDLE.
193 IPC::PlatformFileForTransit descriptor_; 202 IPC::PlatformFileForTransit descriptor_;
194 }; 203 };
195 204
196 // TODO(tomfinegan): This is identical to PPPVideoCapture_Buffer, maybe replace 205 // TODO(tomfinegan): This is identical to PPPVideoCapture_Buffer, maybe replace
197 // both with a single type? 206 // both with a single type?
198 struct PPPDecryptor_Buffer { 207 struct PPPDecryptor_Buffer {
199 ppapi::HostResource resource; 208 ppapi::HostResource resource;
200 uint32_t size; 209 uint32_t size;
201 base::SharedMemoryHandle handle; 210 base::SharedMemoryHandle handle;
202 }; 211 };
203 212
204 #if defined(OS_WIN) 213 #if defined(OS_WIN)
205 typedef HANDLE ImageHandle; 214 typedef HANDLE ImageHandle;
206 #elif defined(OS_MACOSX) || defined(OS_ANDROID) 215 #elif defined(OS_MACOSX) || defined(OS_ANDROID)
207 typedef base::SharedMemoryHandle ImageHandle; 216 typedef base::SharedMemoryHandle ImageHandle;
208 #else 217 #else
209 // On X Windows this is a SysV shared memory key. 218 // On X Windows this is a SysV shared memory key.
210 typedef int ImageHandle; 219 typedef int ImageHandle;
211 #endif 220 #endif
212 221
213 } // namespace proxy 222 } // namespace proxy
214 } // namespace ppapi 223 } // namespace ppapi
215 224
216 #endif // PPAPI_PROXY_SERIALIZED_STRUCTS_H_ 225 #endif // PPAPI_PROXY_SERIALIZED_STRUCTS_H_
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_audio_proxy.cc ('k') | ppapi/proxy/serialized_structs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698