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 #include "ppapi/proxy/serialized_structs.h" | 5 #include "ppapi/proxy/serialized_structs.h" |
6 | 6 |
7 #include "base/pickle.h" | 7 #include "base/pickle.h" |
8 #include "base/platform_file.h" | 8 #include "base/platform_file.h" |
9 #include "base/shared_memory.h" | 9 #include "base/shared_memory.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 SerializedHandle::SerializedHandle( | 127 SerializedHandle::SerializedHandle( |
128 Type type, | 128 Type type, |
129 const IPC::PlatformFileForTransit& socket_descriptor) | 129 const IPC::PlatformFileForTransit& socket_descriptor) |
130 : type_(type), | 130 : type_(type), |
131 shm_handle_(base::SharedMemory::NULLHandle()), | 131 shm_handle_(base::SharedMemory::NULLHandle()), |
132 size_(0), | 132 size_(0), |
133 descriptor_(socket_descriptor) { | 133 descriptor_(socket_descriptor) { |
134 } | 134 } |
135 | 135 |
136 bool SerializedHandle::IsHandleValid() const { | 136 bool SerializedHandle::IsHandleValid() const { |
137 if (type_ == SHARED_MEMORY) | 137 switch (type_) { |
138 return base::SharedMemory::IsHandleValid(shm_handle_); | 138 case SHARED_MEMORY: |
139 else if (type_ == SOCKET || type_ == CHANNEL_HANDLE) | 139 return base::SharedMemory::IsHandleValid(shm_handle_); |
140 return !(IPC::InvalidPlatformFileForTransit() == descriptor_); | 140 case SOCKET: |
| 141 case CHANNEL_HANDLE: |
| 142 case FILE: |
| 143 return !(IPC::InvalidPlatformFileForTransit() == descriptor_); |
| 144 case INVALID: |
| 145 return false; |
| 146 // No default so the compiler will warn us if a new type is added. |
| 147 } |
141 return false; | 148 return false; |
142 } | 149 } |
143 | 150 |
144 void SerializedHandle::Close() { | 151 void SerializedHandle::Close() { |
145 if (IsHandleValid()) { | 152 if (IsHandleValid()) { |
146 switch (type_) { | 153 switch (type_) { |
147 case INVALID: | 154 case INVALID: |
148 NOTREACHED(); | 155 NOTREACHED(); |
149 break; | 156 break; |
150 case SHARED_MEMORY: | 157 case SHARED_MEMORY: |
151 base::SharedMemory::CloseHandle(shm_handle_); | 158 base::SharedMemory::CloseHandle(shm_handle_); |
152 break; | 159 break; |
153 case SOCKET: | 160 case SOCKET: |
154 case CHANNEL_HANDLE: | 161 case CHANNEL_HANDLE: |
| 162 case FILE: |
155 base::PlatformFile file = | 163 base::PlatformFile file = |
156 IPC::PlatformFileForTransitToPlatformFile(descriptor_); | 164 IPC::PlatformFileForTransitToPlatformFile(descriptor_); |
157 #if !defined(OS_NACL) | 165 #if !defined(OS_NACL) |
158 base::ClosePlatformFile(file); | 166 base::ClosePlatformFile(file); |
159 #else | 167 #else |
160 close(file); | 168 close(file); |
161 #endif | 169 #endif |
162 break; | 170 break; |
163 // No default so the compiler will warn us if a new type is added. | 171 // No default so the compiler will warn us if a new type is added. |
164 } | 172 } |
(...skipping 23 matching lines...) Expand all Loading... |
188 case SHARED_MEMORY: { | 196 case SHARED_MEMORY: { |
189 uint32_t size = 0; | 197 uint32_t size = 0; |
190 if (!iter->ReadUInt32(&size)) | 198 if (!iter->ReadUInt32(&size)) |
191 return false; | 199 return false; |
192 hdr->size = size; | 200 hdr->size = size; |
193 valid_type = true; | 201 valid_type = true; |
194 break; | 202 break; |
195 } | 203 } |
196 case SOCKET: | 204 case SOCKET: |
197 case CHANNEL_HANDLE: | 205 case CHANNEL_HANDLE: |
| 206 case FILE: |
198 case INVALID: | 207 case INVALID: |
199 valid_type = true; | 208 valid_type = true; |
200 break; | 209 break; |
201 // No default so the compiler will warn us if a new type is added. | 210 // No default so the compiler will warn us if a new type is added. |
202 } | 211 } |
203 if (valid_type) | 212 if (valid_type) |
204 hdr->type = Type(type); | 213 hdr->type = Type(type); |
205 return valid_type; | 214 return valid_type; |
206 } | 215 } |
207 | 216 |
208 } // namespace proxy | 217 } // namespace proxy |
209 } // namespace ppapi | 218 } // namespace ppapi |
OLD | NEW |