| 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" |
| 9 #include "base/shared_memory.h" |
| 10 #include "build/build_config.h" |
| 11 #include "ipc/ipc_platform_file.h" |
| 8 #include "ppapi/c/dev/ppb_font_dev.h" | 12 #include "ppapi/c/dev/ppb_font_dev.h" |
| 9 #include "ppapi/c/pp_file_info.h" | 13 #include "ppapi/c/pp_file_info.h" |
| 10 #include "ppapi/c/pp_rect.h" | 14 #include "ppapi/c/pp_rect.h" |
| 11 #include "ppapi/shared_impl/var.h" | 15 #include "ppapi/shared_impl/var.h" |
| 12 | 16 |
| 17 #if defined(OS_NACL) |
| 18 #include <unistd.h> |
| 19 #endif |
| 20 |
| 13 namespace ppapi { | 21 namespace ppapi { |
| 14 namespace proxy { | 22 namespace proxy { |
| 15 | 23 |
| 16 SerializedFontDescription::SerializedFontDescription() | 24 SerializedFontDescription::SerializedFontDescription() |
| 17 : face(), | 25 : face(), |
| 18 family(0), | 26 family(0), |
| 19 size(0), | 27 size(0), |
| 20 weight(0), | 28 weight(0), |
| 21 italic(PP_FALSE), | 29 italic(PP_FALSE), |
| 22 small_caps(PP_FALSE), | 30 small_caps(PP_FALSE), |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 } | 107 } |
| 100 | 108 |
| 101 bool SerializedHandle::IsHandleValid() const { | 109 bool SerializedHandle::IsHandleValid() const { |
| 102 if (type_ == SHARED_MEMORY) | 110 if (type_ == SHARED_MEMORY) |
| 103 return base::SharedMemory::IsHandleValid(shm_handle_); | 111 return base::SharedMemory::IsHandleValid(shm_handle_); |
| 104 else if (type_ == SOCKET || type_ == CHANNEL_HANDLE) | 112 else if (type_ == SOCKET || type_ == CHANNEL_HANDLE) |
| 105 return !(IPC::InvalidPlatformFileForTransit() == descriptor_); | 113 return !(IPC::InvalidPlatformFileForTransit() == descriptor_); |
| 106 return false; | 114 return false; |
| 107 } | 115 } |
| 108 | 116 |
| 117 void SerializedHandle::Close() { |
| 118 if (IsHandleValid()) { |
| 119 switch (type_) { |
| 120 case INVALID: |
| 121 NOTREACHED(); |
| 122 break; |
| 123 case SHARED_MEMORY: |
| 124 base::SharedMemory::CloseHandle(shm_handle_); |
| 125 break; |
| 126 case SOCKET: |
| 127 case CHANNEL_HANDLE: |
| 128 base::PlatformFile file = |
| 129 IPC::PlatformFileForTransitToPlatformFile(descriptor_); |
| 130 #if !defined(OS_NACL) |
| 131 base::ClosePlatformFile(file); |
| 132 #else |
| 133 close(file); |
| 134 #endif |
| 135 break; |
| 136 // No default so the compiler will warn us if a new type is added. |
| 137 } |
| 138 } |
| 139 *this = SerializedHandle(); |
| 140 } |
| 141 |
| 109 // static | 142 // static |
| 110 bool SerializedHandle::WriteHeader(const Header& hdr, Pickle* pickle) { | 143 bool SerializedHandle::WriteHeader(const Header& hdr, Pickle* pickle) { |
| 111 if (!pickle->WriteInt(hdr.type)) | 144 if (!pickle->WriteInt(hdr.type)) |
| 112 return false; | 145 return false; |
| 113 if (hdr.type == SHARED_MEMORY) { | 146 if (hdr.type == SHARED_MEMORY) { |
| 114 if (!pickle->WriteUInt32(hdr.size)) | 147 if (!pickle->WriteUInt32(hdr.size)) |
| 115 return false; | 148 return false; |
| 116 } | 149 } |
| 117 return true; | 150 return true; |
| 118 } | 151 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 140 break; | 173 break; |
| 141 // No default so the compiler will warn us if a new type is added. | 174 // No default so the compiler will warn us if a new type is added. |
| 142 } | 175 } |
| 143 if (valid_type) | 176 if (valid_type) |
| 144 hdr->type = Type(type); | 177 hdr->type = Type(type); |
| 145 return valid_type; | 178 return valid_type; |
| 146 } | 179 } |
| 147 | 180 |
| 148 } // namespace proxy | 181 } // namespace proxy |
| 149 } // namespace ppapi | 182 } // namespace ppapi |
| OLD | NEW |