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 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 int64_t bytes_sent; | 84 int64_t bytes_sent; |
85 int64_t total_bytes_to_be_sent; | 85 int64_t total_bytes_to_be_sent; |
86 int64_t bytes_received; | 86 int64_t bytes_received; |
87 int64_t total_bytes_to_be_received; | 87 int64_t total_bytes_to_be_received; |
88 }; | 88 }; |
89 | 89 |
90 // We put all our handles in a unified structure to make it easy to translate | 90 // We put all our handles in a unified structure to make it easy to translate |
91 // them in NaClIPCAdapter for use in NaCl. | 91 // them in NaClIPCAdapter for use in NaCl. |
92 class PPAPI_PROXY_EXPORT SerializedHandle { | 92 class PPAPI_PROXY_EXPORT SerializedHandle { |
93 public: | 93 public: |
94 enum Type { INVALID, SHARED_MEMORY, SOCKET, CHANNEL_HANDLE }; | 94 enum Type { INVALID, SHARED_MEMORY, SOCKET, CHANNEL_HANDLE, FILE }; |
95 struct Header { | 95 struct Header { |
96 Header() : type(INVALID), size(0) {} | 96 Header() : type(INVALID), size(0) {} |
97 Header(Type type_arg, uint32_t size_arg) | 97 Header(Type type_arg, uint32_t size_arg) |
98 : type(type_arg), size(size_arg) { | 98 : type(type_arg), size(size_arg) { |
99 } | 99 } |
100 Type type; | 100 Type type; |
101 uint32_t size; | 101 uint32_t size; |
102 }; | 102 }; |
103 | 103 |
104 SerializedHandle(); | 104 SerializedHandle(); |
105 // Create an invalid handle of the given type. | 105 // Create an invalid handle of the given type. |
106 explicit SerializedHandle(Type type); | 106 explicit SerializedHandle(Type type); |
107 | 107 |
108 // Create a shared memory handle. | 108 // Create a shared memory handle. |
109 SerializedHandle(const base::SharedMemoryHandle& handle, uint32_t size); | 109 SerializedHandle(const base::SharedMemoryHandle& handle, uint32_t size); |
110 | 110 |
111 // Create a socket or channel handle. | 111 // Create a socket, channel or file handle. |
112 SerializedHandle(const Type type, | 112 SerializedHandle(const Type type, |
113 const IPC::PlatformFileForTransit& descriptor); | 113 const IPC::PlatformFileForTransit& descriptor); |
114 | 114 |
115 Type type() const { return type_; } | 115 Type type() const { return type_; } |
116 bool is_shmem() const { return type_ == SHARED_MEMORY; } | 116 bool is_shmem() const { return type_ == SHARED_MEMORY; } |
117 bool is_socket() const { return type_ == SOCKET; } | 117 bool is_socket() const { return type_ == SOCKET; } |
118 bool is_channel_handle() const { return type_ == CHANNEL_HANDLE; } | 118 bool is_channel_handle() const { return type_ == CHANNEL_HANDLE; } |
| 119 bool is_file() const { return type_ == FILE; } |
119 const base::SharedMemoryHandle& shmem() const { | 120 const base::SharedMemoryHandle& shmem() const { |
120 DCHECK(is_shmem()); | 121 DCHECK(is_shmem()); |
121 return shm_handle_; | 122 return shm_handle_; |
122 } | 123 } |
123 uint32_t size() const { | 124 uint32_t size() const { |
124 DCHECK(is_shmem()); | 125 DCHECK(is_shmem()); |
125 return size_; | 126 return size_; |
126 } | 127 } |
127 const IPC::PlatformFileForTransit& descriptor() const { | 128 const IPC::PlatformFileForTransit& descriptor() const { |
128 DCHECK(is_socket() || is_channel_handle()); | 129 DCHECK(is_socket() || is_channel_handle() || is_file()); |
129 return descriptor_; | 130 return descriptor_; |
130 } | 131 } |
131 void set_shmem(const base::SharedMemoryHandle& handle, uint32_t size) { | 132 void set_shmem(const base::SharedMemoryHandle& handle, uint32_t size) { |
132 type_ = SHARED_MEMORY; | 133 type_ = SHARED_MEMORY; |
133 shm_handle_ = handle; | 134 shm_handle_ = handle; |
134 size_ = size; | 135 size_ = size; |
135 | 136 |
136 descriptor_ = IPC::InvalidPlatformFileForTransit(); | 137 descriptor_ = IPC::InvalidPlatformFileForTransit(); |
137 } | 138 } |
138 void set_socket(const IPC::PlatformFileForTransit& socket) { | 139 void set_socket(const IPC::PlatformFileForTransit& socket) { |
139 type_ = SOCKET; | 140 type_ = SOCKET; |
140 descriptor_ = socket; | 141 descriptor_ = socket; |
141 | 142 |
142 shm_handle_ = base::SharedMemory::NULLHandle(); | 143 shm_handle_ = base::SharedMemory::NULLHandle(); |
143 size_ = 0; | 144 size_ = 0; |
144 } | 145 } |
145 void set_channel_handle(const IPC::PlatformFileForTransit& descriptor) { | 146 void set_channel_handle(const IPC::PlatformFileForTransit& descriptor) { |
146 type_ = CHANNEL_HANDLE; | 147 type_ = CHANNEL_HANDLE; |
147 | 148 |
148 descriptor_ = descriptor; | 149 descriptor_ = descriptor; |
149 shm_handle_ = base::SharedMemory::NULLHandle(); | 150 shm_handle_ = base::SharedMemory::NULLHandle(); |
150 size_ = 0; | 151 size_ = 0; |
151 } | 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 } |
152 void set_null_shmem() { | 160 void set_null_shmem() { |
153 set_shmem(base::SharedMemory::NULLHandle(), 0); | 161 set_shmem(base::SharedMemory::NULLHandle(), 0); |
154 } | 162 } |
155 void set_null_socket() { | 163 void set_null_socket() { |
156 set_socket(IPC::InvalidPlatformFileForTransit()); | 164 set_socket(IPC::InvalidPlatformFileForTransit()); |
157 } | 165 } |
158 void set_null_channel_handle() { | 166 void set_null_channel_handle() { |
159 set_channel_handle(IPC::InvalidPlatformFileForTransit()); | 167 set_channel_handle(IPC::InvalidPlatformFileForTransit()); |
160 } | 168 } |
| 169 void set_null_file_handle() { |
| 170 set_file_handle(IPC::InvalidPlatformFileForTransit()); |
| 171 } |
161 bool IsHandleValid() const; | 172 bool IsHandleValid() const; |
162 | 173 |
163 Header header() const { | 174 Header header() const { |
164 return Header(type_, size_); | 175 return Header(type_, size_); |
165 } | 176 } |
166 | 177 |
167 // Closes the handle and sets it to invalid. | 178 // Closes the handle and sets it to invalid. |
168 void Close(); | 179 void Close(); |
169 | 180 |
170 // Write/Read a Header, which contains all the data except the handle. This | 181 // Write/Read a Header, which contains all the data except the handle. This |
(...skipping 30 matching lines...) Expand all Loading... |
201 typedef base::SharedMemoryHandle ImageHandle; | 212 typedef base::SharedMemoryHandle ImageHandle; |
202 #else | 213 #else |
203 // On X Windows this is a SysV shared memory key. | 214 // On X Windows this is a SysV shared memory key. |
204 typedef int ImageHandle; | 215 typedef int ImageHandle; |
205 #endif | 216 #endif |
206 | 217 |
207 } // namespace proxy | 218 } // namespace proxy |
208 } // namespace ppapi | 219 } // namespace ppapi |
209 | 220 |
210 #endif // PPAPI_PROXY_SERIALIZED_STRUCTS_H_ | 221 #endif // PPAPI_PROXY_SERIALIZED_STRUCTS_H_ |
OLD | NEW |