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