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 28 matching lines...) Expand all Loading... |
39 | 39 |
40 ResourceMessageParams::~ResourceMessageParams() { | 40 ResourceMessageParams::~ResourceMessageParams() { |
41 } | 41 } |
42 | 42 |
43 void ResourceMessageParams::Serialize(IPC::Message* msg) const { | 43 void ResourceMessageParams::Serialize(IPC::Message* 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 IPC::Message* msg, |
49 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(IPC::Message* msg) const { |
54 IPC::ParamTraits<PP_Resource>::Write(msg, pp_resource_); | 54 IPC::ParamTraits<PP_Resource>::Write(msg, pp_resource_); |
55 IPC::ParamTraits<int32_t>::Write(msg, sequence_); | 55 IPC::ParamTraits<int32_t>::Write(msg, sequence_); |
56 } | 56 } |
57 | 57 |
58 void ResourceMessageParams::WriteHandles(IPC::Message* msg) const { | 58 void ResourceMessageParams::WriteHandles(IPC::Message* msg) const { |
59 IPC::ParamTraits<std::vector<SerializedHandle> >::Write(msg, | 59 IPC::ParamTraits<std::vector<SerializedHandle> >::Write(msg, |
60 handles_->data()); | 60 handles_->data()); |
61 } | 61 } |
62 | 62 |
63 bool ResourceMessageParams::ReadHeader(const IPC::Message* msg, | 63 bool ResourceMessageParams::ReadHeader(const IPC::Message* msg, |
64 PickleIterator* iter) { | 64 base::PickleIterator* iter) { |
65 DCHECK(handles_->data().empty()); | 65 DCHECK(handles_->data().empty()); |
66 handles_->set_should_close(true); | 66 handles_->set_should_close(true); |
67 return IPC::ParamTraits<PP_Resource>::Read(msg, iter, &pp_resource_) && | 67 return IPC::ParamTraits<PP_Resource>::Read(msg, iter, &pp_resource_) && |
68 IPC::ParamTraits<int32_t>::Read(msg, iter, &sequence_); | 68 IPC::ParamTraits<int32_t>::Read(msg, iter, &sequence_); |
69 } | 69 } |
70 | 70 |
71 bool ResourceMessageParams::ReadHandles(const IPC::Message* msg, | 71 bool ResourceMessageParams::ReadHandles(const IPC::Message* msg, |
72 PickleIterator* iter) { | 72 base::PickleIterator* iter) { |
73 return IPC::ParamTraits<std::vector<SerializedHandle> >::Read( | 73 return IPC::ParamTraits<std::vector<SerializedHandle> >::Read( |
74 msg, iter, &handles_->data()); | 74 msg, iter, &handles_->data()); |
75 } | 75 } |
76 | 76 |
77 void ResourceMessageParams::ConsumeHandles() const { | 77 void ResourceMessageParams::ConsumeHandles() const { |
78 // Note: we must not invalidate the handles. This is used for converting | 78 // Note: we must not invalidate the handles. This is used for converting |
79 // handles from the host OS to NaCl, and that conversion will not work if we | 79 // handles from the host OS to NaCl, and that conversion will not work if we |
80 // invalidate the handles (see HandleConverter). | 80 // invalidate the handles (see HandleConverter). |
81 handles_->set_should_close(false); | 81 handles_->set_should_close(false); |
82 } | 82 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 152 |
153 ResourceMessageCallParams::~ResourceMessageCallParams() { | 153 ResourceMessageCallParams::~ResourceMessageCallParams() { |
154 } | 154 } |
155 | 155 |
156 void ResourceMessageCallParams::Serialize(IPC::Message* msg) const { | 156 void ResourceMessageCallParams::Serialize(IPC::Message* msg) const { |
157 ResourceMessageParams::Serialize(msg); | 157 ResourceMessageParams::Serialize(msg); |
158 IPC::ParamTraits<bool>::Write(msg, has_callback_); | 158 IPC::ParamTraits<bool>::Write(msg, has_callback_); |
159 } | 159 } |
160 | 160 |
161 bool ResourceMessageCallParams::Deserialize(const IPC::Message* msg, | 161 bool ResourceMessageCallParams::Deserialize(const IPC::Message* msg, |
162 PickleIterator* iter) { | 162 base::PickleIterator* iter) { |
163 if (!ResourceMessageParams::Deserialize(msg, iter)) | 163 if (!ResourceMessageParams::Deserialize(msg, iter)) |
164 return false; | 164 return false; |
165 return IPC::ParamTraits<bool>::Read(msg, iter, &has_callback_); | 165 return IPC::ParamTraits<bool>::Read(msg, iter, &has_callback_); |
166 } | 166 } |
167 | 167 |
168 ResourceMessageReplyParams::ResourceMessageReplyParams() | 168 ResourceMessageReplyParams::ResourceMessageReplyParams() |
169 : ResourceMessageParams(), | 169 : ResourceMessageParams(), |
170 result_(PP_OK) { | 170 result_(PP_OK) { |
171 } | 171 } |
172 | 172 |
173 ResourceMessageReplyParams::ResourceMessageReplyParams(PP_Resource resource, | 173 ResourceMessageReplyParams::ResourceMessageReplyParams(PP_Resource resource, |
174 int32_t sequence) | 174 int32_t sequence) |
175 : ResourceMessageParams(resource, sequence), | 175 : ResourceMessageParams(resource, sequence), |
176 result_(PP_OK) { | 176 result_(PP_OK) { |
177 } | 177 } |
178 | 178 |
179 ResourceMessageReplyParams::~ResourceMessageReplyParams() { | 179 ResourceMessageReplyParams::~ResourceMessageReplyParams() { |
180 } | 180 } |
181 | 181 |
182 void ResourceMessageReplyParams::Serialize(IPC::Message* msg) const { | 182 void ResourceMessageReplyParams::Serialize(IPC::Message* msg) const { |
183 // Rather than serialize all of ResourceMessageParams first, we serialize all | 183 // Rather than serialize all of ResourceMessageParams first, we serialize all |
184 // non-handle data first, then the handles. When transferring to NaCl on | 184 // non-handle data first, then the handles. When transferring to NaCl on |
185 // Windows, we need to be able to translate Windows-style handles to POSIX- | 185 // Windows, we need to be able to translate Windows-style handles to POSIX- |
186 // style handles, and it's easier to put all the regular stuff at the front. | 186 // style handles, and it's easier to put all the regular stuff at the front. |
187 WriteReplyHeader(msg); | 187 WriteReplyHeader(msg); |
188 WriteHandles(msg); | 188 WriteHandles(msg); |
189 } | 189 } |
190 | 190 |
191 bool ResourceMessageReplyParams::Deserialize(const IPC::Message* msg, | 191 bool ResourceMessageReplyParams::Deserialize(const IPC::Message* msg, |
192 PickleIterator* iter) { | 192 base::PickleIterator* iter) { |
193 return (ReadHeader(msg, iter) && | 193 return (ReadHeader(msg, iter) && |
194 IPC::ParamTraits<int32_t>::Read(msg, iter, &result_) && | 194 IPC::ParamTraits<int32_t>::Read(msg, iter, &result_) && |
195 ReadHandles(msg, iter)); | 195 ReadHandles(msg, iter)); |
196 } | 196 } |
197 | 197 |
198 void ResourceMessageReplyParams::WriteReplyHeader(IPC::Message* msg) const { | 198 void ResourceMessageReplyParams::WriteReplyHeader(IPC::Message* msg) const { |
199 WriteHeader(msg); | 199 WriteHeader(msg); |
200 IPC::ParamTraits<int32_t>::Write(msg, result_); | 200 IPC::ParamTraits<int32_t>::Write(msg, result_); |
201 } | 201 } |
202 | 202 |
203 } // namespace proxy | 203 } // namespace proxy |
204 } // namespace ppapi | 204 } // namespace ppapi |
OLD | NEW |