| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/remote_producer_data_pipe_impl.h" | 5 #include "mojo/edk/system/remote_producer_data_pipe_impl.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "mojo/edk/system/channel.h" | 14 #include "mojo/edk/system/channel.h" |
| 15 #include "mojo/edk/system/channel_endpoint.h" | 15 #include "mojo/edk/system/channel_endpoint.h" |
| 16 #include "mojo/edk/system/configuration.h" | 16 #include "mojo/edk/system/configuration.h" |
| 17 #include "mojo/edk/system/data_pipe.h" | 17 #include "mojo/edk/system/data_pipe.h" |
| 18 #include "mojo/edk/system/message_in_transit.h" | 18 #include "mojo/edk/system/message_in_transit.h" |
| 19 #include "mojo/edk/system/message_in_transit_queue.h" | 19 #include "mojo/edk/system/message_in_transit_queue.h" |
| 20 #include "mojo/edk/system/remote_consumer_data_pipe_impl.h" | 20 #include "mojo/edk/system/remote_consumer_data_pipe_impl.h" |
| 21 #include "mojo/edk/system/remote_data_pipe_ack.h" | 21 #include "mojo/edk/system/remote_data_pipe_ack.h" |
| 22 | 22 |
| 23 using mojo::embedder::ScopedPlatformHandle; |
| 23 using mojo::util::RefPtr; | 24 using mojo::util::RefPtr; |
| 24 | 25 |
| 25 namespace mojo { | 26 namespace mojo { |
| 26 namespace system { | 27 namespace system { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 bool ValidateIncomingMessage(size_t element_num_bytes, | 31 bool ValidateIncomingMessage(size_t element_num_bytes, |
| 31 size_t capacity_num_bytes, | 32 size_t capacity_num_bytes, |
| 32 size_t current_num_bytes, | 33 size_t current_num_bytes, |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 Channel* /*channel*/, | 156 Channel* /*channel*/, |
| 156 size_t* /*max_size*/, | 157 size_t* /*max_size*/, |
| 157 size_t* /*max_platform_handles*/) { | 158 size_t* /*max_platform_handles*/) { |
| 158 NOTREACHED(); | 159 NOTREACHED(); |
| 159 } | 160 } |
| 160 | 161 |
| 161 bool RemoteProducerDataPipeImpl::ProducerEndSerialize( | 162 bool RemoteProducerDataPipeImpl::ProducerEndSerialize( |
| 162 Channel* /*channel*/, | 163 Channel* /*channel*/, |
| 163 void* /*destination*/, | 164 void* /*destination*/, |
| 164 size_t* /*actual_size*/, | 165 size_t* /*actual_size*/, |
| 165 embedder::PlatformHandleVector* /*platform_handles*/) { | 166 std::vector<ScopedPlatformHandle>* /*platform_handles*/) { |
| 166 NOTREACHED(); | 167 NOTREACHED(); |
| 167 return false; | 168 return false; |
| 168 } | 169 } |
| 169 | 170 |
| 170 void RemoteProducerDataPipeImpl::ConsumerClose() { | 171 void RemoteProducerDataPipeImpl::ConsumerClose() { |
| 171 if (producer_open()) | 172 if (producer_open()) |
| 172 Disconnect(); | 173 Disconnect(); |
| 173 current_num_bytes_ = 0; | 174 current_num_bytes_ = 0; |
| 174 } | 175 } |
| 175 | 176 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 size_t* max_platform_handles) { | 299 size_t* max_platform_handles) { |
| 299 *max_size = sizeof(SerializedDataPipeConsumerDispatcher) + | 300 *max_size = sizeof(SerializedDataPipeConsumerDispatcher) + |
| 300 channel->GetSerializedEndpointSize(); | 301 channel->GetSerializedEndpointSize(); |
| 301 *max_platform_handles = 0; | 302 *max_platform_handles = 0; |
| 302 } | 303 } |
| 303 | 304 |
| 304 bool RemoteProducerDataPipeImpl::ConsumerEndSerialize( | 305 bool RemoteProducerDataPipeImpl::ConsumerEndSerialize( |
| 305 Channel* channel, | 306 Channel* channel, |
| 306 void* destination, | 307 void* destination, |
| 307 size_t* actual_size, | 308 size_t* actual_size, |
| 308 embedder::PlatformHandleVector* platform_handles) { | 309 std::vector<ScopedPlatformHandle>* /*platform_handles*/) { |
| 309 SerializedDataPipeConsumerDispatcher* s = | 310 SerializedDataPipeConsumerDispatcher* s = |
| 310 static_cast<SerializedDataPipeConsumerDispatcher*>(destination); | 311 static_cast<SerializedDataPipeConsumerDispatcher*>(destination); |
| 311 s->validated_options = validated_options(); | 312 s->validated_options = validated_options(); |
| 312 void* destination_for_endpoint = static_cast<char*>(destination) + | 313 void* destination_for_endpoint = static_cast<char*>(destination) + |
| 313 sizeof(SerializedDataPipeConsumerDispatcher); | 314 sizeof(SerializedDataPipeConsumerDispatcher); |
| 314 | 315 |
| 315 MessageInTransitQueue message_queue; | 316 MessageInTransitQueue message_queue; |
| 316 ConvertDataToMessages(buffer_.get(), &start_index_, ¤t_num_bytes_, | 317 ConvertDataToMessages(buffer_.get(), &start_index_, ¤t_num_bytes_, |
| 317 &message_queue); | 318 &message_queue); |
| 318 | 319 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 // If the consumer is still open and we still have data, we have to keep the | 461 // If the consumer is still open and we still have data, we have to keep the |
| 461 // buffer around. Currently, we won't free it even if it empties later. (We | 462 // buffer around. Currently, we won't free it even if it empties later. (We |
| 462 // could do this -- requiring a check on every read -- but that seems to be | 463 // could do this -- requiring a check on every read -- but that seems to be |
| 463 // optimizing for the uncommon case.) | 464 // optimizing for the uncommon case.) |
| 464 if (!consumer_open() || !current_num_bytes_) | 465 if (!consumer_open() || !current_num_bytes_) |
| 465 DestroyBuffer(); | 466 DestroyBuffer(); |
| 466 } | 467 } |
| 467 | 468 |
| 468 } // namespace system | 469 } // namespace system |
| 469 } // namespace mojo | 470 } // namespace mojo |
| OLD | NEW |