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_source_sender.h" | 5 #include "device/serial/data_source_sender.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
| 9 #include <utility> |
9 | 10 |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 | 13 |
13 namespace device { | 14 namespace device { |
14 | 15 |
15 // Represents a send that is not yet fulfilled. | 16 // Represents a send that is not yet fulfilled. |
16 class DataSourceSender::PendingSend { | 17 class DataSourceSender::PendingSend { |
17 public: | 18 public: |
18 PendingSend(DataSourceSender* sender, const ReadyCallback& callback); | 19 PendingSend(DataSourceSender* sender, const ReadyCallback& callback); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 70 |
70 char* buffer_; | 71 char* buffer_; |
71 uint32_t buffer_size_; | 72 uint32_t buffer_size_; |
72 }; | 73 }; |
73 | 74 |
74 DataSourceSender::DataSourceSender( | 75 DataSourceSender::DataSourceSender( |
75 mojo::InterfaceRequest<serial::DataSource> source, | 76 mojo::InterfaceRequest<serial::DataSource> source, |
76 mojo::InterfacePtr<serial::DataSourceClient> client, | 77 mojo::InterfacePtr<serial::DataSourceClient> client, |
77 const ReadyCallback& ready_callback, | 78 const ReadyCallback& ready_callback, |
78 const ErrorCallback& error_callback) | 79 const ErrorCallback& error_callback) |
79 : binding_(this, source.Pass()), | 80 : binding_(this, std::move(source)), |
80 client_(client.Pass()), | 81 client_(std::move(client)), |
81 ready_callback_(ready_callback), | 82 ready_callback_(ready_callback), |
82 error_callback_(error_callback), | 83 error_callback_(error_callback), |
83 available_buffer_capacity_(0), | 84 available_buffer_capacity_(0), |
84 paused_(false), | 85 paused_(false), |
85 shut_down_(false), | 86 shut_down_(false), |
86 weak_factory_(this) { | 87 weak_factory_(this) { |
87 DCHECK(!ready_callback.is_null() && !error_callback.is_null()); | 88 DCHECK(!ready_callback.is_null() && !error_callback.is_null()); |
88 binding_.set_connection_error_handler( | 89 binding_.set_connection_error_handler( |
89 base::Bind(&DataSourceSender::OnConnectionError, base::Unretained(this))); | 90 base::Bind(&DataSourceSender::OnConnectionError, base::Unretained(this))); |
90 client_.set_connection_error_handler( | 91 client_.set_connection_error_handler( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 156 |
156 void DataSourceSender::DoneInternal(const std::vector<char>& data) { | 157 void DataSourceSender::DoneInternal(const std::vector<char>& data) { |
157 DCHECK(pending_send_); | 158 DCHECK(pending_send_); |
158 if (shut_down_) | 159 if (shut_down_) |
159 return; | 160 return; |
160 | 161 |
161 available_buffer_capacity_ -= static_cast<uint32_t>(data.size()); | 162 available_buffer_capacity_ -= static_cast<uint32_t>(data.size()); |
162 if (!data.empty()) { | 163 if (!data.empty()) { |
163 mojo::Array<uint8_t> data_to_send(data.size()); | 164 mojo::Array<uint8_t> data_to_send(data.size()); |
164 std::copy(data.begin(), data.end(), &data_to_send[0]); | 165 std::copy(data.begin(), data.end(), &data_to_send[0]); |
165 client_->OnData(data_to_send.Pass()); | 166 client_->OnData(std::move(data_to_send)); |
166 } | 167 } |
167 pending_send_.reset(); | 168 pending_send_.reset(); |
168 } | 169 } |
169 | 170 |
170 void DataSourceSender::DispatchFatalError() { | 171 void DataSourceSender::DispatchFatalError() { |
171 if (shut_down_) | 172 if (shut_down_) |
172 return; | 173 return; |
173 | 174 |
174 error_callback_.Run(); | 175 error_callback_.Run(); |
175 ShutDown(); | 176 ShutDown(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 uint32_t bytes_written, | 243 uint32_t bytes_written, |
243 int32_t error) { | 244 int32_t error) { |
244 DCHECK(sender_.get()); | 245 DCHECK(sender_.get()); |
245 PendingSend* send = pending_send_; | 246 PendingSend* send = pending_send_; |
246 pending_send_ = nullptr; | 247 pending_send_ = nullptr; |
247 send->DoneWithError(bytes_written, error); | 248 send->DoneWithError(bytes_written, error); |
248 sender_ = nullptr; | 249 sender_ = nullptr; |
249 } | 250 } |
250 | 251 |
251 } // namespace device | 252 } // namespace device |
OLD | NEW |