| 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/raw_channel.h" | 5 #include "mojo/edk/system/raw_channel.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "mojo/edk/system/message_in_transit.h" | 16 #include "mojo/edk/system/message_in_transit.h" |
| 17 #include "mojo/edk/system/transport_data.h" | 17 #include "mojo/edk/system/transport_data.h" |
| 18 | 18 |
| 19 using mojo::embedder::ScopedPlatformHandle; | 19 using mojo::platform::PlatformHandle; |
| 20 using mojo::platform::ScopedPlatformHandle; |
| 20 using mojo::util::MutexLocker; | 21 using mojo::util::MutexLocker; |
| 21 | 22 |
| 22 namespace mojo { | 23 namespace mojo { |
| 23 namespace system { | 24 namespace system { |
| 24 | 25 |
| 25 const size_t kReadSize = 4096; | 26 const size_t kReadSize = 4096; |
| 26 | 27 |
| 27 // RawChannel::ReadBuffer ------------------------------------------------------ | 28 // RawChannel::ReadBuffer ------------------------------------------------------ |
| 28 | 29 |
| 29 RawChannel::ReadBuffer::ReadBuffer() : buffer_(kReadSize), num_valid_bytes_(0) { | 30 RawChannel::ReadBuffer::ReadBuffer() : buffer_(kReadSize), num_valid_bytes_(0) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 if (platform_handles_offset_ >= all_platform_handles->size()) { | 69 if (platform_handles_offset_ >= all_platform_handles->size()) { |
| 69 DCHECK_EQ(platform_handles_offset_, all_platform_handles->size()); | 70 DCHECK_EQ(platform_handles_offset_, all_platform_handles->size()); |
| 70 return false; | 71 return false; |
| 71 } | 72 } |
| 72 | 73 |
| 73 return true; | 74 return true; |
| 74 } | 75 } |
| 75 | 76 |
| 76 void RawChannel::WriteBuffer::GetPlatformHandlesToSend( | 77 void RawChannel::WriteBuffer::GetPlatformHandlesToSend( |
| 77 size_t* num_platform_handles, | 78 size_t* num_platform_handles, |
| 78 embedder::PlatformHandle** platform_handles, | 79 PlatformHandle** platform_handles, |
| 79 void** serialization_data) { | 80 void** serialization_data) { |
| 80 DCHECK(HavePlatformHandlesToSend()); | 81 DCHECK(HavePlatformHandlesToSend()); |
| 81 | 82 |
| 82 MessageInTransit* message = message_queue_.PeekMessage(); | 83 MessageInTransit* message = message_queue_.PeekMessage(); |
| 83 TransportData* transport_data = message->transport_data(); | 84 TransportData* transport_data = message->transport_data(); |
| 84 std::vector<ScopedPlatformHandle>* all_platform_handles = | 85 std::vector<ScopedPlatformHandle>* all_platform_handles = |
| 85 transport_data->platform_handles(); | 86 transport_data->platform_handles(); |
| 86 *num_platform_handles = | 87 *num_platform_handles = |
| 87 all_platform_handles->size() - platform_handles_offset_; | 88 all_platform_handles->size() - platform_handles_offset_; |
| 88 *platform_handles = reinterpret_cast<embedder::PlatformHandle*>( | 89 *platform_handles = reinterpret_cast<PlatformHandle*>( |
| 89 &(*all_platform_handles)[platform_handles_offset_]); | 90 &(*all_platform_handles)[platform_handles_offset_]); |
| 90 | 91 |
| 91 if (serialized_platform_handle_size_ > 0) { | 92 if (serialized_platform_handle_size_ > 0) { |
| 92 size_t serialization_data_offset = | 93 size_t serialization_data_offset = |
| 93 transport_data->platform_handle_table_offset(); | 94 transport_data->platform_handle_table_offset(); |
| 94 serialization_data_offset += | 95 serialization_data_offset += |
| 95 platform_handles_offset_ * serialized_platform_handle_size_; | 96 platform_handles_offset_ * serialized_platform_handle_size_; |
| 96 *serialization_data = static_cast<char*>(transport_data->buffer()) + | 97 *serialization_data = static_cast<char*>(transport_data->buffer()) + |
| 97 serialization_data_offset; | 98 serialization_data_offset; |
| 98 } else { | 99 } else { |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 | 509 |
| 509 write_stopped_ = true; | 510 write_stopped_ = true; |
| 510 write_buffer_->message_queue_.Clear(); | 511 write_buffer_->message_queue_.Clear(); |
| 511 write_buffer_->platform_handles_offset_ = 0; | 512 write_buffer_->platform_handles_offset_ = 0; |
| 512 write_buffer_->data_offset_ = 0; | 513 write_buffer_->data_offset_ = 0; |
| 513 return false; | 514 return false; |
| 514 } | 515 } |
| 515 | 516 |
| 516 } // namespace system | 517 } // namespace system |
| 517 } // namespace mojo | 518 } // namespace mojo |
| OLD | NEW |