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/serial_io_handler.h" | 5 #include "device/serial/serial_io_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 pending_write_buffer_ = buffer.Pass(); | 107 pending_write_buffer_ = buffer.Pass(); |
108 write_canceled_ = false; | 108 write_canceled_ = false; |
109 AddRef(); | 109 AddRef(); |
110 WriteImpl(); | 110 WriteImpl(); |
111 } | 111 } |
112 | 112 |
113 void SerialIoHandler::ReadCompleted(int bytes_read, | 113 void SerialIoHandler::ReadCompleted(int bytes_read, |
114 serial::ReceiveError error) { | 114 serial::ReceiveError error) { |
115 DCHECK(CalledOnValidThread()); | 115 DCHECK(CalledOnValidThread()); |
116 DCHECK(IsReadPending()); | 116 DCHECK(IsReadPending()); |
| 117 scoped_ptr<WritableBuffer> pending_read_buffer = pending_read_buffer_.Pass(); |
117 if (error == serial::RECEIVE_ERROR_NONE) { | 118 if (error == serial::RECEIVE_ERROR_NONE) { |
118 pending_read_buffer_->Done(bytes_read); | 119 pending_read_buffer->Done(bytes_read); |
119 } else { | 120 } else { |
120 pending_read_buffer_->DoneWithError(bytes_read, error); | 121 pending_read_buffer->DoneWithError(bytes_read, error); |
121 } | 122 } |
122 pending_read_buffer_.reset(); | |
123 Release(); | 123 Release(); |
124 } | 124 } |
125 | 125 |
126 void SerialIoHandler::WriteCompleted(int bytes_written, | 126 void SerialIoHandler::WriteCompleted(int bytes_written, |
127 serial::SendError error) { | 127 serial::SendError error) { |
128 DCHECK(CalledOnValidThread()); | 128 DCHECK(CalledOnValidThread()); |
129 DCHECK(IsWritePending()); | 129 DCHECK(IsWritePending()); |
| 130 scoped_ptr<ReadOnlyBuffer> pending_write_buffer = |
| 131 pending_write_buffer_.Pass(); |
130 if (error == serial::SEND_ERROR_NONE) { | 132 if (error == serial::SEND_ERROR_NONE) { |
131 pending_write_buffer_->Done(bytes_written); | 133 pending_write_buffer->Done(bytes_written); |
132 } else { | 134 } else { |
133 pending_write_buffer_->DoneWithError(bytes_written, error); | 135 pending_write_buffer->DoneWithError(bytes_written, error); |
134 } | 136 } |
135 pending_write_buffer_.reset(); | |
136 Release(); | 137 Release(); |
137 } | 138 } |
138 | 139 |
139 bool SerialIoHandler::IsReadPending() const { | 140 bool SerialIoHandler::IsReadPending() const { |
140 DCHECK(CalledOnValidThread()); | 141 DCHECK(CalledOnValidThread()); |
141 return pending_read_buffer_ != NULL; | 142 return pending_read_buffer_ != NULL; |
142 } | 143 } |
143 | 144 |
144 bool SerialIoHandler::IsWritePending() const { | 145 bool SerialIoHandler::IsWritePending() const { |
145 DCHECK(CalledOnValidThread()); | 146 DCHECK(CalledOnValidThread()); |
(...skipping 26 matching lines...) Expand all Loading... |
172 } | 173 } |
173 | 174 |
174 void SerialIoHandler::QueueWriteCompleted(int bytes_written, | 175 void SerialIoHandler::QueueWriteCompleted(int bytes_written, |
175 serial::SendError error) { | 176 serial::SendError error) { |
176 base::MessageLoop::current()->PostTask( | 177 base::MessageLoop::current()->PostTask( |
177 FROM_HERE, | 178 FROM_HERE, |
178 base::Bind(&SerialIoHandler::WriteCompleted, this, bytes_written, error)); | 179 base::Bind(&SerialIoHandler::WriteCompleted, this, bytes_written, error)); |
179 } | 180 } |
180 | 181 |
181 } // namespace device | 182 } // namespace device |
OLD | NEW |