| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_handle.h" | 5 #include "ppapi/proxy/serialized_handle.h" |
| 6 | 6 |
| 7 #include "base/memory/shared_memory.h" | 7 #include "base/memory/shared_memory.h" |
| 8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
| 9 #include "base/platform_file.h" | 9 #include "base/platform_file.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 descriptor_(socket_descriptor), | 54 descriptor_(socket_descriptor), |
| 55 open_flags_(0), | 55 open_flags_(0), |
| 56 file_io_(0) { | 56 file_io_(0) { |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool SerializedHandle::IsHandleValid() const { | 59 bool SerializedHandle::IsHandleValid() const { |
| 60 switch (type_) { | 60 switch (type_) { |
| 61 case SHARED_MEMORY: | 61 case SHARED_MEMORY: |
| 62 return base::SharedMemory::IsHandleValid(shm_handle_); | 62 return base::SharedMemory::IsHandleValid(shm_handle_); |
| 63 case SOCKET: | 63 case SOCKET: |
| 64 case CHANNEL_HANDLE: | |
| 65 case FILE: | 64 case FILE: |
| 66 return !(IPC::InvalidPlatformFileForTransit() == descriptor_); | 65 return !(IPC::InvalidPlatformFileForTransit() == descriptor_); |
| 67 case INVALID: | 66 case INVALID: |
| 68 return false; | 67 return false; |
| 69 // No default so the compiler will warn us if a new type is added. | 68 // No default so the compiler will warn us if a new type is added. |
| 70 } | 69 } |
| 71 return false; | 70 return false; |
| 72 } | 71 } |
| 73 | 72 |
| 74 void SerializedHandle::Close() { | 73 void SerializedHandle::Close() { |
| 75 if (IsHandleValid()) { | 74 if (IsHandleValid()) { |
| 76 switch (type_) { | 75 switch (type_) { |
| 77 case INVALID: | 76 case INVALID: |
| 78 NOTREACHED(); | 77 NOTREACHED(); |
| 79 break; | 78 break; |
| 80 case SHARED_MEMORY: | 79 case SHARED_MEMORY: |
| 81 base::SharedMemory::CloseHandle(shm_handle_); | 80 base::SharedMemory::CloseHandle(shm_handle_); |
| 82 break; | 81 break; |
| 83 case SOCKET: | 82 case SOCKET: |
| 84 case CHANNEL_HANDLE: | |
| 85 case FILE: | 83 case FILE: |
| 86 base::PlatformFile file = | 84 base::PlatformFile file = |
| 87 IPC::PlatformFileForTransitToPlatformFile(descriptor_); | 85 IPC::PlatformFileForTransitToPlatformFile(descriptor_); |
| 88 #if !defined(OS_NACL) | 86 #if !defined(OS_NACL) |
| 89 base::ClosePlatformFile(file); | 87 base::ClosePlatformFile(file); |
| 90 #else | 88 #else |
| 91 close(file); | 89 close(file); |
| 92 #endif | 90 #endif |
| 93 break; | 91 break; |
| 94 // No default so the compiler will warn us if a new type is added. | 92 // No default so the compiler will warn us if a new type is added. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 case FILE: { | 129 case FILE: { |
| 132 int open_flags = 0; | 130 int open_flags = 0; |
| 133 PP_Resource file_io = 0; | 131 PP_Resource file_io = 0; |
| 134 if (!iter->ReadInt(&open_flags) || !iter->ReadInt(&file_io)) | 132 if (!iter->ReadInt(&open_flags) || !iter->ReadInt(&file_io)) |
| 135 return false; | 133 return false; |
| 136 hdr->open_flags = open_flags; | 134 hdr->open_flags = open_flags; |
| 137 hdr->file_io = file_io; | 135 hdr->file_io = file_io; |
| 138 valid_type = true; | 136 valid_type = true; |
| 139 } | 137 } |
| 140 case SOCKET: | 138 case SOCKET: |
| 141 case CHANNEL_HANDLE: | |
| 142 case INVALID: | 139 case INVALID: |
| 143 valid_type = true; | 140 valid_type = true; |
| 144 break; | 141 break; |
| 145 // No default so the compiler will warn us if a new type is added. | 142 // No default so the compiler will warn us if a new type is added. |
| 146 } | 143 } |
| 147 if (valid_type) | 144 if (valid_type) |
| 148 hdr->type = Type(type); | 145 hdr->type = Type(type); |
| 149 return valid_type; | 146 return valid_type; |
| 150 } | 147 } |
| 151 | 148 |
| 152 } // namespace proxy | 149 } // namespace proxy |
| 153 } // namespace ppapi | 150 } // namespace ppapi |
| OLD | NEW |