| 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 "device/serial/data_sender.h" | 5 #include "device/serial/data_sender.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 const int32_t fatal_error_value_; | 55 const int32_t fatal_error_value_; |
| 56 | 56 |
| 57 // The number of bytes sent to the DataSink. | 57 // The number of bytes sent to the DataSink. |
| 58 uint32_t bytes_sent_; | 58 uint32_t bytes_sent_; |
| 59 | 59 |
| 60 // The number of bytes acked. | 60 // The number of bytes acked. |
| 61 uint32_t bytes_acked_; | 61 uint32_t bytes_acked_; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 DataSender::DataSender(mojo::InterfacePtr<serial::DataSink> sink, | 64 DataSender::DataSender(mojo::InterfacePtr<serial::DataSink> sink, |
| 65 mojo::InterfaceRequest<serial::DataSinkClient> client, | |
| 66 uint32_t buffer_size, | 65 uint32_t buffer_size, |
| 67 int32_t fatal_error_value) | 66 int32_t fatal_error_value) |
| 68 : sink_(sink.Pass()), | 67 : sink_(sink.Pass()), |
| 69 client_(this, client.Pass()), | |
| 70 fatal_error_value_(fatal_error_value), | 68 fatal_error_value_(fatal_error_value), |
| 71 available_buffer_capacity_(buffer_size), | 69 available_buffer_capacity_(buffer_size), |
| 72 shut_down_(false) { | 70 shut_down_(false) { |
| 73 sink_.set_error_handler(this); | 71 sink_.set_error_handler(this); |
| 72 sink_.set_client(this); |
| 74 sink_->Init(buffer_size); | 73 sink_->Init(buffer_size); |
| 75 client_.set_error_handler(this); | |
| 76 } | 74 } |
| 77 | 75 |
| 78 DataSender::~DataSender() { | 76 DataSender::~DataSender() { |
| 79 ShutDown(); | 77 ShutDown(); |
| 80 } | 78 } |
| 81 | 79 |
| 82 bool DataSender::Send(const base::StringPiece& data, | 80 bool DataSender::Send(const base::StringPiece& data, |
| 83 const DataSentCallback& callback, | 81 const DataSentCallback& callback, |
| 84 const SendErrorCallback& error_callback) { | 82 const SendErrorCallback& error_callback) { |
| 85 DCHECK(!callback.is_null() && !error_callback.is_null()); | 83 DCHECK(!callback.is_null() && !error_callback.is_null()); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 bytes_acked_ += *num_bytes; | 247 bytes_acked_ += *num_bytes; |
| 250 if (bytes_acked_ > bytes_sent_) { | 248 if (bytes_acked_ > bytes_sent_) { |
| 251 *num_bytes = bytes_acked_ - bytes_sent_; | 249 *num_bytes = bytes_acked_ - bytes_sent_; |
| 252 bytes_acked_ = bytes_sent_; | 250 bytes_acked_ = bytes_sent_; |
| 253 } else { | 251 } else { |
| 254 *num_bytes = 0; | 252 *num_bytes = 0; |
| 255 } | 253 } |
| 256 } | 254 } |
| 257 | 255 |
| 258 } // namespace device | 256 } // namespace device |
| OLD | NEW |