| 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 "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
| 8 #include "ppapi/proxy/ppapi_messages.h" | 9 #include "ppapi/proxy/ppapi_messages.h" |
| 9 | 10 |
| 10 namespace ppapi { | 11 namespace ppapi { |
| 11 namespace proxy { | 12 namespace proxy { |
| 12 | 13 |
| 14 ResourceMessageParams::SerializedHandles::SerializedHandles() |
| 15 : should_close(false) { |
| 16 } |
| 17 |
| 18 ResourceMessageParams::SerializedHandles::~SerializedHandles() { |
| 19 if (should_close) { |
| 20 for (std::vector<SerializedHandle>::iterator iter = data.begin(); |
| 21 iter != data.end(); ++iter) { |
| 22 iter->Close(); |
| 23 } |
| 24 } |
| 25 } |
| 26 |
| 13 ResourceMessageParams::ResourceMessageParams() | 27 ResourceMessageParams::ResourceMessageParams() |
| 14 : pp_resource_(0), | 28 : pp_resource_(0), |
| 15 sequence_(0) { | 29 sequence_(0), |
| 30 handles_(new SerializedHandles()) { |
| 16 } | 31 } |
| 17 | 32 |
| 18 ResourceMessageParams::ResourceMessageParams(PP_Resource resource, | 33 ResourceMessageParams::ResourceMessageParams(PP_Resource resource, |
| 19 int32_t sequence) | 34 int32_t sequence) |
| 20 : pp_resource_(resource), | 35 : pp_resource_(resource), |
| 21 sequence_(sequence) { | 36 sequence_(sequence), |
| 37 handles_(new SerializedHandles()) { |
| 22 } | 38 } |
| 23 | 39 |
| 24 ResourceMessageParams::~ResourceMessageParams() { | 40 ResourceMessageParams::~ResourceMessageParams() { |
| 25 } | 41 } |
| 26 | 42 |
| 27 void ResourceMessageParams::Serialize(IPC::Message* msg) const { | 43 void ResourceMessageParams::Serialize(IPC::Message* msg) const { |
| 28 IPC::ParamTraits<PP_Resource>::Write(msg, pp_resource_); | 44 IPC::ParamTraits<PP_Resource>::Write(msg, pp_resource_); |
| 29 IPC::ParamTraits<int32_t>::Write(msg, sequence_); | 45 IPC::ParamTraits<int32_t>::Write(msg, sequence_); |
| 30 IPC::ParamTraits<std::vector<SerializedHandle> >::Write(msg, handles_); | 46 IPC::ParamTraits<std::vector<SerializedHandle> >::Write(msg, handles_->data); |
| 31 } | 47 } |
| 32 | 48 |
| 33 bool ResourceMessageParams::Deserialize(const IPC::Message* msg, | 49 bool ResourceMessageParams::Deserialize(const IPC::Message* msg, |
| 34 PickleIterator* iter) { | 50 PickleIterator* iter) { |
| 51 DCHECK(handles_->data.empty()); |
| 52 handles_->should_close = true; |
| 35 return IPC::ParamTraits<PP_Resource>::Read(msg, iter, &pp_resource_) && | 53 return IPC::ParamTraits<PP_Resource>::Read(msg, iter, &pp_resource_) && |
| 36 IPC::ParamTraits<int32_t>::Read(msg, iter, &sequence_) && | 54 IPC::ParamTraits<int32_t>::Read(msg, iter, &sequence_) && |
| 37 IPC::ParamTraits<std::vector<SerializedHandle> >::Read( | 55 IPC::ParamTraits<std::vector<SerializedHandle> >::Read( |
| 38 msg, iter, &handles_); | 56 msg, iter, &handles_->data); |
| 39 } | 57 } |
| 40 | 58 |
| 41 const SerializedHandle* ResourceMessageParams::GetHandleOfTypeAtIndex( | 59 SerializedHandle ResourceMessageParams::TakeHandleOfTypeAtIndex( |
| 42 size_t index, | 60 size_t index, |
| 43 SerializedHandle::Type type) const { | 61 SerializedHandle::Type type) const { |
| 44 if (handles_.size() <= index) | 62 SerializedHandle handle; |
| 45 return NULL; | 63 if (index < handles_->data.size() && handles_->data[index].type() == type) { |
| 46 if (handles_[index].type() != type) | 64 handle = handles_->data[index]; |
| 47 return NULL; | 65 handles_->data[index] = SerializedHandle(); |
| 48 return &handles_[index]; | 66 } |
| 67 return handle; |
| 49 } | 68 } |
| 50 | 69 |
| 51 bool ResourceMessageParams::GetSharedMemoryHandleAtIndex( | 70 bool ResourceMessageParams::TakeSharedMemoryHandleAtIndex( |
| 52 size_t index, | 71 size_t index, |
| 53 base::SharedMemoryHandle* handle) const { | 72 base::SharedMemoryHandle* handle) const { |
| 54 const SerializedHandle* serialized = GetHandleOfTypeAtIndex( | 73 SerializedHandle serialized = TakeHandleOfTypeAtIndex( |
| 55 index, SerializedHandle::SHARED_MEMORY); | 74 index, SerializedHandle::SHARED_MEMORY); |
| 56 if (!serialized) | 75 if (!serialized.is_shmem()) |
| 57 return false; | 76 return false; |
| 58 *handle = serialized->shmem(); | 77 *handle = serialized.shmem(); |
| 59 return true; | 78 return true; |
| 60 } | 79 } |
| 61 | 80 |
| 62 bool ResourceMessageParams::GetSocketHandleAtIndex( | 81 bool ResourceMessageParams::TakeSocketHandleAtIndex( |
| 63 size_t index, | 82 size_t index, |
| 64 IPC::PlatformFileForTransit* handle) const { | 83 IPC::PlatformFileForTransit* handle) const { |
| 65 const SerializedHandle* serialized = GetHandleOfTypeAtIndex( | 84 SerializedHandle serialized = TakeHandleOfTypeAtIndex( |
| 66 index, SerializedHandle::SOCKET); | 85 index, SerializedHandle::SOCKET); |
| 67 if (!serialized) | 86 if (!serialized.is_socket()) |
| 68 return false; | 87 return false; |
| 69 *handle = serialized->descriptor(); | 88 *handle = serialized.descriptor(); |
| 70 return true; | 89 return true; |
| 71 } | 90 } |
| 72 | 91 |
| 73 void ResourceMessageParams::AppendHandle(const SerializedHandle& handle) { | 92 void ResourceMessageParams::AppendHandle(const SerializedHandle& handle) const { |
| 74 handles_.push_back(handle); | 93 handles_->data.push_back(handle); |
| 75 } | 94 } |
| 76 | 95 |
| 77 ResourceMessageCallParams::ResourceMessageCallParams() | 96 ResourceMessageCallParams::ResourceMessageCallParams() |
| 78 : ResourceMessageParams(), | 97 : ResourceMessageParams(), |
| 79 has_callback_(0) { | 98 has_callback_(0) { |
| 80 } | 99 } |
| 81 | 100 |
| 82 ResourceMessageCallParams::ResourceMessageCallParams(PP_Resource resource, | 101 ResourceMessageCallParams::ResourceMessageCallParams(PP_Resource resource, |
| 83 int32_t sequence) | 102 int32_t sequence) |
| 84 : ResourceMessageParams(resource, sequence), | 103 : ResourceMessageParams(resource, sequence), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 140 |
| 122 bool ResourceMessageReplyParams::Deserialize(const IPC::Message* msg, | 141 bool ResourceMessageReplyParams::Deserialize(const IPC::Message* msg, |
| 123 PickleIterator* iter) { | 142 PickleIterator* iter) { |
| 124 if (!ResourceMessageParams::Deserialize(msg, iter)) | 143 if (!ResourceMessageParams::Deserialize(msg, iter)) |
| 125 return false; | 144 return false; |
| 126 return IPC::ParamTraits<int32_t>::Read(msg, iter, &result_); | 145 return IPC::ParamTraits<int32_t>::Read(msg, iter, &result_); |
| 127 } | 146 } |
| 128 | 147 |
| 129 } // namespace proxy | 148 } // namespace proxy |
| 130 } // namespace ppapi | 149 } // namespace ppapi |
| OLD | NEW |