| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/edk/system/transport_data.h" | 5 #include "mojo/edk/system/transport_data.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "mojo/edk/system/channel.h" | 10 #include "mojo/edk/system/channel.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 MessageInTransit::kMessageAlignment == | 53 MessageInTransit::kMessageAlignment == |
| 54 0, | 54 0, |
| 55 "kMaxSerializedDispatcherSize not a multiple of alignment"); | 55 "kMaxSerializedDispatcherSize not a multiple of alignment"); |
| 56 static_assert(sizeof(HandleTableEntry) % | 56 static_assert(sizeof(HandleTableEntry) % |
| 57 MessageInTransit::kMessageAlignment == | 57 MessageInTransit::kMessageAlignment == |
| 58 0, | 58 0, |
| 59 "sizeof(MessageInTransit::HandleTableEntry) not a multiple of " | 59 "sizeof(MessageInTransit::HandleTableEntry) not a multiple of " |
| 60 "alignment"); | 60 "alignment"); |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 TransportData::TransportData(scoped_ptr<DispatcherVector> dispatchers, | 63 TransportData::TransportData(std::unique_ptr<DispatcherVector> dispatchers, |
| 64 Channel* channel) | 64 Channel* channel) |
| 65 : buffer_size_() { | 65 : buffer_size_() { |
| 66 DCHECK(dispatchers); | 66 DCHECK(dispatchers); |
| 67 DCHECK(channel); | 67 DCHECK(channel); |
| 68 | 68 |
| 69 const size_t num_handles = dispatchers->size(); | 69 const size_t num_handles = dispatchers->size(); |
| 70 DCHECK_GT(num_handles, 0u); | 70 DCHECK_GT(num_handles, 0u); |
| 71 | 71 |
| 72 // The offset to the start of the (Mojo) handle table. | 72 // The offset to the start of the (Mojo) handle table. |
| 73 const size_t handle_table_start_offset = sizeof(Header); | 73 const size_t handle_table_start_offset = sizeof(Header); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 DCHECK(num_platform_handles); | 299 DCHECK(num_platform_handles); |
| 300 DCHECK(platform_handle_table); | 300 DCHECK(platform_handle_table); |
| 301 | 301 |
| 302 const Header* header = static_cast<const Header*>(transport_data_buffer); | 302 const Header* header = static_cast<const Header*>(transport_data_buffer); |
| 303 *num_platform_handles = header->num_platform_handles; | 303 *num_platform_handles = header->num_platform_handles; |
| 304 *platform_handle_table = static_cast<const char*>(transport_data_buffer) + | 304 *platform_handle_table = static_cast<const char*>(transport_data_buffer) + |
| 305 header->platform_handle_table_offset; | 305 header->platform_handle_table_offset; |
| 306 } | 306 } |
| 307 | 307 |
| 308 // static | 308 // static |
| 309 scoped_ptr<DispatcherVector> TransportData::DeserializeDispatchers( | 309 std::unique_ptr<DispatcherVector> TransportData::DeserializeDispatchers( |
| 310 const void* buffer, | 310 const void* buffer, |
| 311 size_t buffer_size, | 311 size_t buffer_size, |
| 312 embedder::ScopedPlatformHandleVectorPtr platform_handles, | 312 embedder::ScopedPlatformHandleVectorPtr platform_handles, |
| 313 Channel* channel) { | 313 Channel* channel) { |
| 314 DCHECK(buffer); | 314 DCHECK(buffer); |
| 315 DCHECK_GT(buffer_size, 0u); | 315 DCHECK_GT(buffer_size, 0u); |
| 316 DCHECK(channel); | 316 DCHECK(channel); |
| 317 | 317 |
| 318 const Header* header = static_cast<const Header*>(buffer); | 318 const Header* header = static_cast<const Header*>(buffer); |
| 319 const size_t num_handles = header->num_handles; | 319 const size_t num_handles = header->num_handles; |
| 320 scoped_ptr<DispatcherVector> dispatchers(new DispatcherVector(num_handles)); | 320 std::unique_ptr<DispatcherVector> dispatchers( |
| 321 new DispatcherVector(num_handles)); |
| 321 | 322 |
| 322 const HandleTableEntry* handle_table = | 323 const HandleTableEntry* handle_table = |
| 323 reinterpret_cast<const HandleTableEntry*>( | 324 reinterpret_cast<const HandleTableEntry*>( |
| 324 static_cast<const char*>(buffer) + sizeof(Header)); | 325 static_cast<const char*>(buffer) + sizeof(Header)); |
| 325 for (size_t i = 0; i < num_handles; i++) { | 326 for (size_t i = 0; i < num_handles; i++) { |
| 326 size_t offset = handle_table[i].offset; | 327 size_t offset = handle_table[i].offset; |
| 327 size_t size = handle_table[i].size; | 328 size_t size = handle_table[i].size; |
| 328 // Should already have been checked by |ValidateBuffer()|: | 329 // Should already have been checked by |ValidateBuffer()|: |
| 329 DCHECK_EQ(offset % MessageInTransit::kMessageAlignment, 0u); | 330 DCHECK_EQ(offset % MessageInTransit::kMessageAlignment, 0u); |
| 330 DCHECK_LE(offset, buffer_size); | 331 DCHECK_LE(offset, buffer_size); |
| 331 DCHECK_LE(offset + size, buffer_size); | 332 DCHECK_LE(offset + size, buffer_size); |
| 332 | 333 |
| 333 const void* source = static_cast<const char*>(buffer) + offset; | 334 const void* source = static_cast<const char*>(buffer) + offset; |
| 334 (*dispatchers)[i] = Dispatcher::TransportDataAccess::Deserialize( | 335 (*dispatchers)[i] = Dispatcher::TransportDataAccess::Deserialize( |
| 335 channel, handle_table[i].type, source, size, platform_handles.get()); | 336 channel, handle_table[i].type, source, size, platform_handles.get()); |
| 336 } | 337 } |
| 337 | 338 |
| 338 return dispatchers.Pass(); | 339 return dispatchers; |
| 339 } | 340 } |
| 340 | 341 |
| 341 } // namespace system | 342 } // namespace system |
| 342 } // namespace mojo | 343 } // namespace mojo |
| OLD | NEW |