Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: device/serial/serial_io_handler.cc

Issue 2905153002: Move off of deprecated base::NonThreadSafe in device/ (Closed)
Patch Set: ThreadChecker => SequenceChecker Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/serial/serial_io_handler.h ('k') | device/serial/serial_io_handler_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 16 matching lines...) Expand all
27 ui_thread_task_runner_(ui_thread_task_runner) { 27 ui_thread_task_runner_(ui_thread_task_runner) {
28 options_.bitrate = 9600; 28 options_.bitrate = 9600;
29 options_.data_bits = serial::DataBits::EIGHT; 29 options_.data_bits = serial::DataBits::EIGHT;
30 options_.parity_bit = serial::ParityBit::NO_PARITY; 30 options_.parity_bit = serial::ParityBit::NO_PARITY;
31 options_.stop_bits = serial::StopBits::ONE; 31 options_.stop_bits = serial::StopBits::ONE;
32 options_.cts_flow_control = false; 32 options_.cts_flow_control = false;
33 options_.has_cts_flow_control = true; 33 options_.has_cts_flow_control = true;
34 } 34 }
35 35
36 SerialIoHandler::~SerialIoHandler() { 36 SerialIoHandler::~SerialIoHandler() {
37 DCHECK(CalledOnValidThread()); 37 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
38 Close(); 38 Close();
39 } 39 }
40 40
41 void SerialIoHandler::Open(const std::string& port, 41 void SerialIoHandler::Open(const std::string& port,
42 const serial::ConnectionOptions& options, 42 const serial::ConnectionOptions& options,
43 const OpenCompleteCallback& callback) { 43 const OpenCompleteCallback& callback) {
44 DCHECK(CalledOnValidThread()); 44 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
45 DCHECK(open_complete_.is_null()); 45 DCHECK(open_complete_.is_null());
46 open_complete_ = callback; 46 open_complete_ = callback;
47 DCHECK(file_thread_task_runner_.get()); 47 DCHECK(file_thread_task_runner_.get());
48 DCHECK(ui_thread_task_runner_.get()); 48 DCHECK(ui_thread_task_runner_.get());
49 MergeConnectionOptions(options); 49 MergeConnectionOptions(options);
50 port_ = port; 50 port_ = port;
51 51
52 #if defined(OS_CHROMEOS) 52 #if defined(OS_CHROMEOS)
53 chromeos::PermissionBrokerClient* client = 53 chromeos::PermissionBrokerClient* client =
54 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient(); 54 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient();
(...skipping 29 matching lines...) Expand all
84 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, 84 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
85 const std::string& error_name, 85 const std::string& error_name,
86 const std::string& error_message) { 86 const std::string& error_message) {
87 io_thread_task_runner->PostTask( 87 io_thread_task_runner->PostTask(
88 FROM_HERE, base::Bind(&SerialIoHandler::ReportPathOpenError, this, 88 FROM_HERE, base::Bind(&SerialIoHandler::ReportPathOpenError, this,
89 error_name, error_message)); 89 error_name, error_message));
90 } 90 }
91 91
92 void SerialIoHandler::ReportPathOpenError(const std::string& error_name, 92 void SerialIoHandler::ReportPathOpenError(const std::string& error_name,
93 const std::string& error_message) { 93 const std::string& error_message) {
94 DCHECK(CalledOnValidThread()); 94 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
95 DCHECK(!open_complete_.is_null()); 95 DCHECK(!open_complete_.is_null());
96 LOG(ERROR) << "Permission broker failed to open '" << port_ 96 LOG(ERROR) << "Permission broker failed to open '" << port_
97 << "': " << error_name << ": " << error_message; 97 << "': " << error_name << ": " << error_message;
98 OpenCompleteCallback callback = open_complete_; 98 OpenCompleteCallback callback = open_complete_;
99 open_complete_.Reset(); 99 open_complete_.Reset();
100 callback.Run(false); 100 callback.Run(false);
101 } 101 }
102 102
103 #endif 103 #endif
104 104
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | 136 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
137 base::File::FLAG_EXCLUSIVE_READ | base::File::FLAG_WRITE | 137 base::File::FLAG_EXCLUSIVE_READ | base::File::FLAG_WRITE |
138 base::File::FLAG_EXCLUSIVE_WRITE | base::File::FLAG_ASYNC | 138 base::File::FLAG_EXCLUSIVE_WRITE | base::File::FLAG_ASYNC |
139 base::File::FLAG_TERMINAL_DEVICE; 139 base::File::FLAG_TERMINAL_DEVICE;
140 base::File file(path, flags); 140 base::File file(path, flags);
141 io_task_runner->PostTask(FROM_HERE, base::Bind(&SerialIoHandler::FinishOpen, 141 io_task_runner->PostTask(FROM_HERE, base::Bind(&SerialIoHandler::FinishOpen,
142 this, base::Passed(&file))); 142 this, base::Passed(&file)));
143 } 143 }
144 144
145 void SerialIoHandler::FinishOpen(base::File file) { 145 void SerialIoHandler::FinishOpen(base::File file) {
146 DCHECK(CalledOnValidThread()); 146 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
147 DCHECK(!open_complete_.is_null()); 147 DCHECK(!open_complete_.is_null());
148 OpenCompleteCallback callback = open_complete_; 148 OpenCompleteCallback callback = open_complete_;
149 open_complete_.Reset(); 149 open_complete_.Reset();
150 150
151 if (!file.IsValid()) { 151 if (!file.IsValid()) {
152 LOG(ERROR) << "Failed to open serial port: " 152 LOG(ERROR) << "Failed to open serial port: "
153 << base::File::ErrorToString(file.error_details()); 153 << base::File::ErrorToString(file.error_details());
154 callback.Run(false); 154 callback.Run(false);
155 return; 155 return;
156 } 156 }
(...skipping 19 matching lines...) Expand all
176 base::Bind(&SerialIoHandler::DoClose, Passed(std::move(file_)))); 176 base::Bind(&SerialIoHandler::DoClose, Passed(std::move(file_))));
177 } 177 }
178 } 178 }
179 179
180 // static 180 // static
181 void SerialIoHandler::DoClose(base::File port) { 181 void SerialIoHandler::DoClose(base::File port) {
182 // port closed by destructor. 182 // port closed by destructor.
183 } 183 }
184 184
185 void SerialIoHandler::Read(std::unique_ptr<WritableBuffer> buffer) { 185 void SerialIoHandler::Read(std::unique_ptr<WritableBuffer> buffer) {
186 DCHECK(CalledOnValidThread()); 186 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
187 DCHECK(!IsReadPending()); 187 DCHECK(!IsReadPending());
188 pending_read_buffer_ = std::move(buffer); 188 pending_read_buffer_ = std::move(buffer);
189 read_canceled_ = false; 189 read_canceled_ = false;
190 AddRef(); 190 AddRef();
191 ReadImpl(); 191 ReadImpl();
192 } 192 }
193 193
194 void SerialIoHandler::Write(std::unique_ptr<ReadOnlyBuffer> buffer) { 194 void SerialIoHandler::Write(std::unique_ptr<ReadOnlyBuffer> buffer) {
195 DCHECK(CalledOnValidThread()); 195 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
196 DCHECK(!IsWritePending()); 196 DCHECK(!IsWritePending());
197 pending_write_buffer_ = std::move(buffer); 197 pending_write_buffer_ = std::move(buffer);
198 write_canceled_ = false; 198 write_canceled_ = false;
199 AddRef(); 199 AddRef();
200 WriteImpl(); 200 WriteImpl();
201 } 201 }
202 202
203 void SerialIoHandler::ReadCompleted(int bytes_read, 203 void SerialIoHandler::ReadCompleted(int bytes_read,
204 serial::ReceiveError error) { 204 serial::ReceiveError error) {
205 DCHECK(CalledOnValidThread()); 205 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
206 DCHECK(IsReadPending()); 206 DCHECK(IsReadPending());
207 std::unique_ptr<WritableBuffer> pending_read_buffer = 207 std::unique_ptr<WritableBuffer> pending_read_buffer =
208 std::move(pending_read_buffer_); 208 std::move(pending_read_buffer_);
209 if (error == serial::ReceiveError::NONE) { 209 if (error == serial::ReceiveError::NONE) {
210 pending_read_buffer->Done(bytes_read); 210 pending_read_buffer->Done(bytes_read);
211 } else { 211 } else {
212 pending_read_buffer->DoneWithError(bytes_read, static_cast<int32_t>(error)); 212 pending_read_buffer->DoneWithError(bytes_read, static_cast<int32_t>(error));
213 } 213 }
214 Release(); 214 Release();
215 } 215 }
216 216
217 void SerialIoHandler::WriteCompleted(int bytes_written, 217 void SerialIoHandler::WriteCompleted(int bytes_written,
218 serial::SendError error) { 218 serial::SendError error) {
219 DCHECK(CalledOnValidThread()); 219 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
220 DCHECK(IsWritePending()); 220 DCHECK(IsWritePending());
221 std::unique_ptr<ReadOnlyBuffer> pending_write_buffer = 221 std::unique_ptr<ReadOnlyBuffer> pending_write_buffer =
222 std::move(pending_write_buffer_); 222 std::move(pending_write_buffer_);
223 if (error == serial::SendError::NONE) { 223 if (error == serial::SendError::NONE) {
224 pending_write_buffer->Done(bytes_written); 224 pending_write_buffer->Done(bytes_written);
225 } else { 225 } else {
226 pending_write_buffer->DoneWithError(bytes_written, 226 pending_write_buffer->DoneWithError(bytes_written,
227 static_cast<int32_t>(error)); 227 static_cast<int32_t>(error));
228 } 228 }
229 Release(); 229 Release();
230 } 230 }
231 231
232 bool SerialIoHandler::IsReadPending() const { 232 bool SerialIoHandler::IsReadPending() const {
233 DCHECK(CalledOnValidThread()); 233 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
234 return pending_read_buffer_ != NULL; 234 return pending_read_buffer_ != NULL;
235 } 235 }
236 236
237 bool SerialIoHandler::IsWritePending() const { 237 bool SerialIoHandler::IsWritePending() const {
238 DCHECK(CalledOnValidThread()); 238 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
239 return pending_write_buffer_ != NULL; 239 return pending_write_buffer_ != NULL;
240 } 240 }
241 241
242 void SerialIoHandler::CancelRead(serial::ReceiveError reason) { 242 void SerialIoHandler::CancelRead(serial::ReceiveError reason) {
243 DCHECK(CalledOnValidThread()); 243 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
244 if (IsReadPending() && !read_canceled_) { 244 if (IsReadPending() && !read_canceled_) {
245 read_canceled_ = true; 245 read_canceled_ = true;
246 read_cancel_reason_ = reason; 246 read_cancel_reason_ = reason;
247 CancelReadImpl(); 247 CancelReadImpl();
248 } 248 }
249 } 249 }
250 250
251 void SerialIoHandler::CancelWrite(serial::SendError reason) { 251 void SerialIoHandler::CancelWrite(serial::SendError reason) {
252 DCHECK(CalledOnValidThread()); 252 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
253 if (IsWritePending() && !write_canceled_) { 253 if (IsWritePending() && !write_canceled_) {
254 write_canceled_ = true; 254 write_canceled_ = true;
255 write_cancel_reason_ = reason; 255 write_cancel_reason_ = reason;
256 CancelWriteImpl(); 256 CancelWriteImpl();
257 } 257 }
258 } 258 }
259 259
260 bool SerialIoHandler::ConfigurePort(const serial::ConnectionOptions& options) { 260 bool SerialIoHandler::ConfigurePort(const serial::ConnectionOptions& options) {
261 MergeConnectionOptions(options); 261 MergeConnectionOptions(options);
262 return ConfigurePortImpl(); 262 return ConfigurePortImpl();
263 } 263 }
264 264
265 void SerialIoHandler::QueueReadCompleted(int bytes_read, 265 void SerialIoHandler::QueueReadCompleted(int bytes_read,
266 serial::ReceiveError error) { 266 serial::ReceiveError error) {
267 base::ThreadTaskRunnerHandle::Get()->PostTask( 267 base::ThreadTaskRunnerHandle::Get()->PostTask(
268 FROM_HERE, 268 FROM_HERE,
269 base::Bind(&SerialIoHandler::ReadCompleted, this, bytes_read, error)); 269 base::Bind(&SerialIoHandler::ReadCompleted, this, bytes_read, error));
270 } 270 }
271 271
272 void SerialIoHandler::QueueWriteCompleted(int bytes_written, 272 void SerialIoHandler::QueueWriteCompleted(int bytes_written,
273 serial::SendError error) { 273 serial::SendError error) {
274 base::ThreadTaskRunnerHandle::Get()->PostTask( 274 base::ThreadTaskRunnerHandle::Get()->PostTask(
275 FROM_HERE, 275 FROM_HERE,
276 base::Bind(&SerialIoHandler::WriteCompleted, this, bytes_written, error)); 276 base::Bind(&SerialIoHandler::WriteCompleted, this, bytes_written, error));
277 } 277 }
278 278
279 } // namespace device 279 } // namespace device
OLDNEW
« no previous file with comments | « device/serial/serial_io_handler.h ('k') | device/serial/serial_io_handler_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698