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/resource_message_params.h" | 5 #include "ppapi/proxy/resource_message_params.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
9 #include "ppapi/proxy/ppapi_messages.h" | 9 #include "ppapi/proxy/ppapi_messages.h" |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 ResourceMessageParams::ResourceMessageParams(PP_Resource resource, | 33 ResourceMessageParams::ResourceMessageParams(PP_Resource resource, |
34 int32_t sequence) | 34 int32_t sequence) |
35 : pp_resource_(resource), | 35 : pp_resource_(resource), |
36 sequence_(sequence), | 36 sequence_(sequence), |
37 handles_(new SerializedHandles()) { | 37 handles_(new SerializedHandles()) { |
38 } | 38 } |
39 | 39 |
40 ResourceMessageParams::~ResourceMessageParams() { | 40 ResourceMessageParams::~ResourceMessageParams() { |
41 } | 41 } |
42 | 42 |
43 void ResourceMessageParams::Serialize(IPC::Message* msg) const { | 43 void ResourceMessageParams::Serialize(base::Pickle* msg) const { |
44 WriteHeader(msg); | 44 WriteHeader(msg); |
45 WriteHandles(msg); | 45 WriteHandles(msg); |
46 } | 46 } |
47 | 47 |
48 bool ResourceMessageParams::Deserialize(const IPC::Message* msg, | 48 bool ResourceMessageParams::Deserialize(const base::Pickle* msg, |
49 base::PickleIterator* iter) { | 49 base::PickleIterator* iter) { |
50 return ReadHeader(msg, iter) && ReadHandles(msg, iter); | 50 return ReadHeader(msg, iter) && ReadHandles(msg, iter); |
51 } | 51 } |
52 | 52 |
53 void ResourceMessageParams::WriteHeader(IPC::Message* msg) const { | 53 void ResourceMessageParams::WriteHeader(base::Pickle* msg) const { |
54 IPC::WriteParam(msg, pp_resource_); | 54 IPC::WriteParam(msg, pp_resource_); |
55 IPC::WriteParam(msg, sequence_); | 55 IPC::WriteParam(msg, sequence_); |
56 } | 56 } |
57 | 57 |
58 void ResourceMessageParams::WriteHandles(IPC::Message* msg) const { | 58 void ResourceMessageParams::WriteHandles(base::Pickle* msg) const { |
59 IPC::WriteParam(msg, handles_->data()); | 59 IPC::WriteParam(msg, handles_->data()); |
60 } | 60 } |
61 | 61 |
62 bool ResourceMessageParams::ReadHeader(const IPC::Message* msg, | 62 bool ResourceMessageParams::ReadHeader(const base::Pickle* msg, |
63 base::PickleIterator* iter) { | 63 base::PickleIterator* iter) { |
64 DCHECK(handles_->data().empty()); | 64 DCHECK(handles_->data().empty()); |
65 handles_->set_should_close(true); | 65 handles_->set_should_close(true); |
66 return IPC::ReadParam(msg, iter, &pp_resource_) && | 66 return IPC::ReadParam(msg, iter, &pp_resource_) && |
67 IPC::ReadParam(msg, iter, &sequence_); | 67 IPC::ReadParam(msg, iter, &sequence_); |
68 } | 68 } |
69 | 69 |
70 bool ResourceMessageParams::ReadHandles(const IPC::Message* msg, | 70 bool ResourceMessageParams::ReadHandles(const base::Pickle* msg, |
71 base::PickleIterator* iter) { | 71 base::PickleIterator* iter) { |
72 return IPC::ReadParam(msg, iter, &handles_->data()); | 72 return IPC::ReadParam(msg, iter, &handles_->data()); |
73 } | 73 } |
74 | 74 |
75 void ResourceMessageParams::ConsumeHandles() const { | 75 void ResourceMessageParams::ConsumeHandles() const { |
76 // Note: we must not invalidate the handles. This is used for converting | 76 // Note: we must not invalidate the handles. This is used for converting |
77 // handles from the host OS to NaCl, and that conversion will not work if we | 77 // handles from the host OS to NaCl, and that conversion will not work if we |
78 // invalidate the handles (see HandleConverter). | 78 // invalidate the handles (see HandleConverter). |
79 handles_->set_should_close(false); | 79 handles_->set_should_close(false); |
80 } | 80 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 144 |
145 ResourceMessageCallParams::ResourceMessageCallParams(PP_Resource resource, | 145 ResourceMessageCallParams::ResourceMessageCallParams(PP_Resource resource, |
146 int32_t sequence) | 146 int32_t sequence) |
147 : ResourceMessageParams(resource, sequence), | 147 : ResourceMessageParams(resource, sequence), |
148 has_callback_(0) { | 148 has_callback_(0) { |
149 } | 149 } |
150 | 150 |
151 ResourceMessageCallParams::~ResourceMessageCallParams() { | 151 ResourceMessageCallParams::~ResourceMessageCallParams() { |
152 } | 152 } |
153 | 153 |
154 void ResourceMessageCallParams::Serialize(IPC::Message* msg) const { | 154 void ResourceMessageCallParams::Serialize(base::Pickle* msg) const { |
155 ResourceMessageParams::Serialize(msg); | 155 ResourceMessageParams::Serialize(msg); |
156 IPC::WriteParam(msg, has_callback_); | 156 IPC::WriteParam(msg, has_callback_); |
157 } | 157 } |
158 | 158 |
159 bool ResourceMessageCallParams::Deserialize(const IPC::Message* msg, | 159 bool ResourceMessageCallParams::Deserialize(const base::Pickle* msg, |
160 base::PickleIterator* iter) { | 160 base::PickleIterator* iter) { |
161 if (!ResourceMessageParams::Deserialize(msg, iter)) | 161 if (!ResourceMessageParams::Deserialize(msg, iter)) |
162 return false; | 162 return false; |
163 return IPC::ReadParam(msg, iter, &has_callback_); | 163 return IPC::ReadParam(msg, iter, &has_callback_); |
164 } | 164 } |
165 | 165 |
166 ResourceMessageReplyParams::ResourceMessageReplyParams() | 166 ResourceMessageReplyParams::ResourceMessageReplyParams() |
167 : ResourceMessageParams(), | 167 : ResourceMessageParams(), |
168 result_(PP_OK) { | 168 result_(PP_OK) { |
169 } | 169 } |
170 | 170 |
171 ResourceMessageReplyParams::ResourceMessageReplyParams(PP_Resource resource, | 171 ResourceMessageReplyParams::ResourceMessageReplyParams(PP_Resource resource, |
172 int32_t sequence) | 172 int32_t sequence) |
173 : ResourceMessageParams(resource, sequence), | 173 : ResourceMessageParams(resource, sequence), |
174 result_(PP_OK) { | 174 result_(PP_OK) { |
175 } | 175 } |
176 | 176 |
177 ResourceMessageReplyParams::~ResourceMessageReplyParams() { | 177 ResourceMessageReplyParams::~ResourceMessageReplyParams() { |
178 } | 178 } |
179 | 179 |
180 void ResourceMessageReplyParams::Serialize(IPC::Message* msg) const { | 180 void ResourceMessageReplyParams::Serialize(base::Pickle* msg) const { |
181 // Rather than serialize all of ResourceMessageParams first, we serialize all | 181 // Rather than serialize all of ResourceMessageParams first, we serialize all |
182 // non-handle data first, then the handles. When transferring to NaCl on | 182 // non-handle data first, then the handles. When transferring to NaCl on |
183 // Windows, we need to be able to translate Windows-style handles to POSIX- | 183 // Windows, we need to be able to translate Windows-style handles to POSIX- |
184 // style handles, and it's easier to put all the regular stuff at the front. | 184 // style handles, and it's easier to put all the regular stuff at the front. |
185 WriteReplyHeader(msg); | 185 WriteReplyHeader(msg); |
186 WriteHandles(msg); | 186 WriteHandles(msg); |
187 } | 187 } |
188 | 188 |
189 bool ResourceMessageReplyParams::Deserialize(const IPC::Message* msg, | 189 bool ResourceMessageReplyParams::Deserialize(const base::Pickle* msg, |
190 base::PickleIterator* iter) { | 190 base::PickleIterator* iter) { |
191 return (ReadHeader(msg, iter) && IPC::ReadParam(msg, iter, &result_) && | 191 return (ReadHeader(msg, iter) && IPC::ReadParam(msg, iter, &result_) && |
192 ReadHandles(msg, iter)); | 192 ReadHandles(msg, iter)); |
193 } | 193 } |
194 | 194 |
195 void ResourceMessageReplyParams::WriteReplyHeader(IPC::Message* msg) const { | 195 void ResourceMessageReplyParams::WriteReplyHeader(base::Pickle* msg) const { |
196 WriteHeader(msg); | 196 WriteHeader(msg); |
197 IPC::WriteParam(msg, result_); | 197 IPC::WriteParam(msg, result_); |
198 } | 198 } |
199 | 199 |
200 } // namespace proxy | 200 } // namespace proxy |
201 } // namespace ppapi | 201 } // namespace ppapi |
OLD | NEW |