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, FILE }; | 88 enum Type { INVALID, SHARED_MEMORY, SOCKET, CHANNEL_HANDLE }; |
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, channel or file handle. | 105 // Create a socket or channel 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; } | |
114 const base::SharedMemoryHandle& shmem() const { | 113 const base::SharedMemoryHandle& shmem() const { |
115 DCHECK(is_shmem()); | 114 DCHECK(is_shmem()); |
116 return shm_handle_; | 115 return shm_handle_; |
117 } | 116 } |
118 uint32_t size() const { | 117 uint32_t size() const { |
119 DCHECK(is_shmem()); | 118 DCHECK(is_shmem()); |
120 return size_; | 119 return size_; |
121 } | 120 } |
122 const IPC::PlatformFileForTransit& descriptor() const { | 121 const IPC::PlatformFileForTransit& descriptor() const { |
123 DCHECK(is_socket() || is_channel_handle() || is_file()); | 122 DCHECK(is_socket() || is_channel_handle()); |
124 return descriptor_; | 123 return descriptor_; |
125 } | 124 } |
126 void set_shmem(const base::SharedMemoryHandle& handle, uint32_t size) { | 125 void set_shmem(const base::SharedMemoryHandle& handle, uint32_t size) { |
127 type_ = SHARED_MEMORY; | 126 type_ = SHARED_MEMORY; |
128 shm_handle_ = handle; | 127 shm_handle_ = handle; |
129 size_ = size; | 128 size_ = size; |
130 | 129 |
131 descriptor_ = IPC::InvalidPlatformFileForTransit(); | 130 descriptor_ = IPC::InvalidPlatformFileForTransit(); |
132 } | 131 } |
133 void set_socket(const IPC::PlatformFileForTransit& socket) { | 132 void set_socket(const IPC::PlatformFileForTransit& socket) { |
134 type_ = SOCKET; | 133 type_ = SOCKET; |
135 descriptor_ = socket; | 134 descriptor_ = socket; |
136 | 135 |
137 shm_handle_ = base::SharedMemory::NULLHandle(); | 136 shm_handle_ = base::SharedMemory::NULLHandle(); |
138 size_ = 0; | 137 size_ = 0; |
139 } | 138 } |
140 void set_channel_handle(const IPC::PlatformFileForTransit& descriptor) { | 139 void set_channel_handle(const IPC::PlatformFileForTransit& descriptor) { |
141 type_ = CHANNEL_HANDLE; | 140 type_ = CHANNEL_HANDLE; |
142 | 141 |
143 descriptor_ = descriptor; | 142 descriptor_ = descriptor; |
144 shm_handle_ = base::SharedMemory::NULLHandle(); | 143 shm_handle_ = base::SharedMemory::NULLHandle(); |
145 size_ = 0; | 144 size_ = 0; |
146 } | 145 } |
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 } | |
154 void set_null_shmem() { | 146 void set_null_shmem() { |
155 set_shmem(base::SharedMemory::NULLHandle(), 0); | 147 set_shmem(base::SharedMemory::NULLHandle(), 0); |
156 } | 148 } |
157 void set_null_socket() { | 149 void set_null_socket() { |
158 set_socket(IPC::InvalidPlatformFileForTransit()); | 150 set_socket(IPC::InvalidPlatformFileForTransit()); |
159 } | 151 } |
160 void set_null_channel_handle() { | 152 void set_null_channel_handle() { |
161 set_channel_handle(IPC::InvalidPlatformFileForTransit()); | 153 set_channel_handle(IPC::InvalidPlatformFileForTransit()); |
162 } | 154 } |
163 void set_null_file_handle() { | |
164 set_file_handle(IPC::InvalidPlatformFileForTransit()); | |
165 } | |
166 bool IsHandleValid() const; | 155 bool IsHandleValid() const; |
167 | 156 |
168 Header header() const { | 157 Header header() const { |
169 return Header(type_, size_); | 158 return Header(type_, size_); |
170 } | 159 } |
171 | 160 |
172 // Closes the handle and sets it to invalid. | 161 // Closes the handle and sets it to invalid. |
173 void Close(); | 162 void Close(); |
174 | 163 |
175 // Write/Read a Header, which contains all the data except the handle. This | 164 // Write/Read a Header, which contains all the data except the handle. This |
(...skipping 30 matching lines...) Expand all Loading... |
206 typedef base::SharedMemoryHandle ImageHandle; | 195 typedef base::SharedMemoryHandle ImageHandle; |
207 #else | 196 #else |
208 // On X Windows this is a SysV shared memory key. | 197 // On X Windows this is a SysV shared memory key. |
209 typedef int ImageHandle; | 198 typedef int ImageHandle; |
210 #endif | 199 #endif |
211 | 200 |
212 } // namespace proxy | 201 } // namespace proxy |
213 } // namespace ppapi | 202 } // namespace ppapi |
214 | 203 |
215 #endif // PPAPI_PROXY_SERIALIZED_STRUCTS_H_ | 204 #endif // PPAPI_PROXY_SERIALIZED_STRUCTS_H_ |
OLD | NEW |