| 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 | 10 |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 start_index_ += num_bytes; | 437 start_index_ += num_bytes; |
| 438 start_index_ %= capacity_num_bytes(); | 438 start_index_ %= capacity_num_bytes(); |
| 439 current_num_bytes_ -= num_bytes; | 439 current_num_bytes_ -= num_bytes; |
| 440 | 440 |
| 441 if (!producer_open()) { | 441 if (!producer_open()) { |
| 442 DCHECK(!channel_endpoint_); | 442 DCHECK(!channel_endpoint_); |
| 443 return; | 443 return; |
| 444 } | 444 } |
| 445 | 445 |
| 446 RemoteDataPipeAck ack_data = {}; | 446 RemoteDataPipeAck ack_data = {}; |
| 447 ack_data.num_bytes_consumed = num_bytes; | 447 ack_data.num_bytes_consumed = static_cast<uint32_t>(num_bytes); |
| 448 scoped_ptr<MessageInTransit> message( | 448 scoped_ptr<MessageInTransit> message( |
| 449 new MessageInTransit(MessageInTransit::kTypeEndpoint, | 449 new MessageInTransit(MessageInTransit::kTypeEndpoint, |
| 450 MessageInTransit::kSubtypeEndpointDataPipeAck, | 450 MessageInTransit::kSubtypeEndpointDataPipeAck, |
| 451 static_cast<uint32_t>(sizeof(ack_data)), &ack_data)); | 451 static_cast<uint32_t>(sizeof(ack_data)), &ack_data)); |
| 452 if (!channel_endpoint_->EnqueueMessage(message.Pass())) | 452 if (!channel_endpoint_->EnqueueMessage(message.Pass())) |
| 453 Disconnect(); | 453 Disconnect(); |
| 454 } | 454 } |
| 455 | 455 |
| 456 void RemoteProducerDataPipeImpl::Disconnect() { | 456 void RemoteProducerDataPipeImpl::Disconnect() { |
| 457 DCHECK(producer_open()); | 457 DCHECK(producer_open()); |
| 458 DCHECK(channel_endpoint_); | 458 DCHECK(channel_endpoint_); |
| 459 owner()->SetProducerClosedNoLock(); | 459 owner()->SetProducerClosedNoLock(); |
| 460 channel_endpoint_->DetachFromClient(); | 460 channel_endpoint_->DetachFromClient(); |
| 461 channel_endpoint_ = nullptr; | 461 channel_endpoint_ = nullptr; |
| 462 // If the consumer is still open and we still have data, we have to keep the | 462 // If the consumer is still open and we still have data, we have to keep the |
| 463 // buffer around. Currently, we won't free it even if it empties later. (We | 463 // buffer around. Currently, we won't free it even if it empties later. (We |
| 464 // could do this -- requiring a check on every read -- but that seems to be | 464 // could do this -- requiring a check on every read -- but that seems to be |
| 465 // optimizing for the uncommon case.) | 465 // optimizing for the uncommon case.) |
| 466 if (!consumer_open() || !current_num_bytes_) { | 466 if (!consumer_open() || !current_num_bytes_) { |
| 467 // Note: There can only be a two-phase *read* (by the consumer) if we still | 467 // Note: There can only be a two-phase *read* (by the consumer) if we still |
| 468 // have data. | 468 // have data. |
| 469 DCHECK(!consumer_in_two_phase_read()); | 469 DCHECK(!consumer_in_two_phase_read()); |
| 470 DestroyBuffer(); | 470 DestroyBuffer(); |
| 471 } | 471 } |
| 472 } | 472 } |
| 473 | 473 |
| 474 } // namespace system | 474 } // namespace system |
| 475 } // namespace mojo | 475 } // namespace mojo |
| OLD | NEW |