| 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 <utility> |
| 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "mojo/edk/system/configuration.h" | 10 #include "mojo/edk/system/configuration.h" |
| 9 #include "mojo/edk/system/message_in_transit.h" | 11 #include "mojo/edk/system/message_in_transit.h" |
| 10 #include "mojo/edk/system/raw_channel.h" | 12 #include "mojo/edk/system/raw_channel.h" |
| 11 | 13 |
| 12 namespace mojo { | 14 namespace mojo { |
| 13 namespace edk { | 15 namespace edk { |
| 14 | 16 |
| 15 // The maximum amount of space needed per platform handle. | 17 // The maximum amount of space needed per platform handle. |
| 16 // (|{Channel,RawChannel}::GetSerializedPlatformHandleSize()| should always | 18 // (|{Channel,RawChannel}::GetSerializedPlatformHandleSize()| should always |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 current_offset = MessageInTransit::RoundUpMessageAlignment(current_offset); | 181 current_offset = MessageInTransit::RoundUpMessageAlignment(current_offset); |
| 180 } | 182 } |
| 181 | 183 |
| 182 // There's no aligned realloc, so it's no good way to release unused space (if | 184 // There's no aligned realloc, so it's no good way to release unused space (if |
| 183 // we overshot our estimated space requirements). | 185 // we overshot our estimated space requirements). |
| 184 buffer_size_ = current_offset; | 186 buffer_size_ = current_offset; |
| 185 | 187 |
| 186 // |dispatchers_| will be destroyed as it goes out of scope. | 188 // |dispatchers_| will be destroyed as it goes out of scope. |
| 187 } | 189 } |
| 188 | 190 |
| 189 TransportData::TransportData( | 191 TransportData::TransportData(ScopedPlatformHandleVectorPtr platform_handles, |
| 190 ScopedPlatformHandleVectorPtr platform_handles, | 192 size_t serialized_platform_handle_size) |
| 191 size_t serialized_platform_handle_size) | 193 : buffer_size_(), platform_handles_(std::move(platform_handles)) { |
| 192 : buffer_size_(), platform_handles_(platform_handles.Pass()) { | |
| 193 buffer_size_ = MessageInTransit::RoundUpMessageAlignment( | 194 buffer_size_ = MessageInTransit::RoundUpMessageAlignment( |
| 194 sizeof(Header) + | 195 sizeof(Header) + |
| 195 platform_handles_->size() * serialized_platform_handle_size); | 196 platform_handles_->size() * serialized_platform_handle_size); |
| 196 buffer_.reset(static_cast<char*>( | 197 buffer_.reset(static_cast<char*>( |
| 197 base::AlignedAlloc(buffer_size_, MessageInTransit::kMessageAlignment))); | 198 base::AlignedAlloc(buffer_size_, MessageInTransit::kMessageAlignment))); |
| 198 memset(buffer_.get(), 0, buffer_size_); | 199 memset(buffer_.get(), 0, buffer_size_); |
| 199 | 200 |
| 200 Header* header = reinterpret_cast<Header*>(buffer_.get()); | 201 Header* header = reinterpret_cast<Header*>(buffer_.get()); |
| 201 header->platform_handle_table_offset = static_cast<uint32_t>(sizeof(Header)); | 202 header->platform_handle_table_offset = static_cast<uint32_t>(sizeof(Header)); |
| 202 header->num_platform_handles = | 203 header->num_platform_handles = |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 // Should already have been checked by |ValidateBuffer()|: | 320 // Should already have been checked by |ValidateBuffer()|: |
| 320 DCHECK_EQ(offset % MessageInTransit::kMessageAlignment, 0u); | 321 DCHECK_EQ(offset % MessageInTransit::kMessageAlignment, 0u); |
| 321 DCHECK_LE(offset, buffer_size); | 322 DCHECK_LE(offset, buffer_size); |
| 322 DCHECK_LE(offset + size, buffer_size); | 323 DCHECK_LE(offset + size, buffer_size); |
| 323 | 324 |
| 324 const void* source = static_cast<const char*>(buffer) + offset; | 325 const void* source = static_cast<const char*>(buffer) + offset; |
| 325 (*dispatchers)[i] = Dispatcher::TransportDataAccess::Deserialize( | 326 (*dispatchers)[i] = Dispatcher::TransportDataAccess::Deserialize( |
| 326 handle_table[i].type, source, size, platform_handles.get()); | 327 handle_table[i].type, source, size, platform_handles.get()); |
| 327 } | 328 } |
| 328 | 329 |
| 329 return dispatchers.Pass(); | 330 return dispatchers; |
| 330 } | 331 } |
| 331 | 332 |
| 332 } // namespace edk | 333 } // namespace edk |
| 333 } // namespace mojo | 334 } // namespace mojo |
| OLD | NEW |