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/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 case FILE: | 83 case FILE: |
84 base::File file_closer = IPC::PlatformFileForTransitToFile(descriptor_); | 84 base::File file_closer = IPC::PlatformFileForTransitToFile(descriptor_); |
85 break; | 85 break; |
86 // No default so the compiler will warn us if a new type is added. | 86 // No default so the compiler will warn us if a new type is added. |
87 } | 87 } |
88 } | 88 } |
89 *this = SerializedHandle(); | 89 *this = SerializedHandle(); |
90 } | 90 } |
91 | 91 |
92 // static | 92 // static |
93 bool SerializedHandle::WriteHeader(const Header& hdr, Pickle* pickle) { | 93 bool SerializedHandle::WriteHeader(const Header& hdr, base::Pickle* pickle) { |
94 if (!pickle->WriteInt(hdr.type)) | 94 if (!pickle->WriteInt(hdr.type)) |
95 return false; | 95 return false; |
96 if (hdr.type == SHARED_MEMORY) { | 96 if (hdr.type == SHARED_MEMORY) { |
97 if (!pickle->WriteUInt32(hdr.size)) | 97 if (!pickle->WriteUInt32(hdr.size)) |
98 return false; | 98 return false; |
99 } | 99 } |
100 if (hdr.type == FILE) { | 100 if (hdr.type == FILE) { |
101 if (!pickle->WriteInt(hdr.open_flags) || !pickle->WriteInt(hdr.file_io)) | 101 if (!pickle->WriteInt(hdr.open_flags) || !pickle->WriteInt(hdr.file_io)) |
102 return false; | 102 return false; |
103 } | 103 } |
104 return true; | 104 return true; |
105 } | 105 } |
106 | 106 |
107 // static | 107 // static |
108 bool SerializedHandle::ReadHeader(PickleIterator* iter, Header* hdr) { | 108 bool SerializedHandle::ReadHeader(base::PickleIterator* iter, Header* hdr) { |
109 *hdr = Header(INVALID, 0, 0, 0); | 109 *hdr = Header(INVALID, 0, 0, 0); |
110 int type = 0; | 110 int type = 0; |
111 if (!iter->ReadInt(&type)) | 111 if (!iter->ReadInt(&type)) |
112 return false; | 112 return false; |
113 bool valid_type = false; | 113 bool valid_type = false; |
114 switch (type) { | 114 switch (type) { |
115 case SHARED_MEMORY: { | 115 case SHARED_MEMORY: { |
116 uint32 size = 0; | 116 uint32 size = 0; |
117 if (!iter->ReadUInt32(&size)) | 117 if (!iter->ReadUInt32(&size)) |
118 return false; | 118 return false; |
(...skipping 16 matching lines...) Expand all Loading... |
135 break; | 135 break; |
136 // No default so the compiler will warn us if a new type is added. | 136 // No default so the compiler will warn us if a new type is added. |
137 } | 137 } |
138 if (valid_type) | 138 if (valid_type) |
139 hdr->type = Type(type); | 139 hdr->type = Type(type); |
140 return valid_type; | 140 return valid_type; |
141 } | 141 } |
142 | 142 |
143 } // namespace proxy | 143 } // namespace proxy |
144 } // namespace ppapi | 144 } // namespace ppapi |
OLD | NEW |