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_posix.h" | 5 #include "device/serial/serial_io_handler_posix.h" |
6 | 6 |
7 #include <sys/ioctl.h> | 7 #include <sys/ioctl.h> |
8 #include <termios.h> | 8 #include <termios.h> |
9 | 9 |
10 #include "base/posix/eintr_wrapper.h" | 10 #include "base/posix/eintr_wrapper.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 return false; | 122 return false; |
123 #endif | 123 #endif |
124 } | 124 } |
125 | 125 |
126 } // namespace | 126 } // namespace |
127 | 127 |
128 namespace device { | 128 namespace device { |
129 | 129 |
130 // static | 130 // static |
131 scoped_refptr<SerialIoHandler> SerialIoHandler::Create( | 131 scoped_refptr<SerialIoHandler> SerialIoHandler::Create( |
132 scoped_refptr<base::MessageLoopProxy> file_thread_message_loop, | 132 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, |
133 scoped_refptr<base::MessageLoopProxy> ui_thread_message_loop) { | 133 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner) { |
134 return new SerialIoHandlerPosix(file_thread_message_loop, | 134 return new SerialIoHandlerPosix(file_thread_task_runner, |
135 ui_thread_message_loop); | 135 ui_thread_task_runner); |
136 } | 136 } |
137 | 137 |
138 void SerialIoHandlerPosix::RequestAccess( | 138 void SerialIoHandlerPosix::RequestAccess( |
139 const std::string& port, | 139 const std::string& port, |
140 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 140 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, |
141 scoped_refptr<base::MessageLoopProxy> ui_message_loop) { | 141 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
142 #if defined(OS_LINUX) && defined(OS_CHROMEOS) | 142 #if defined(OS_LINUX) && defined(OS_CHROMEOS) |
143 if (base::SysInfo::IsRunningOnChromeOS()) { | 143 if (base::SysInfo::IsRunningOnChromeOS()) { |
144 chromeos::PermissionBrokerClient* client = | 144 chromeos::PermissionBrokerClient* client = |
145 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient(); | 145 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient(); |
146 if (!client) { | 146 if (!client) { |
147 DVLOG(1) << "Could not get permission_broker client."; | 147 DVLOG(1) << "Could not get permission_broker client."; |
148 OnRequestAccessComplete(port, false /* failure */); | 148 OnRequestAccessComplete(port, false /* failure */); |
149 return; | 149 return; |
150 } | 150 } |
151 // PermissionBrokerClient should be called on the UI thread. | 151 // PermissionBrokerClient should be called on the UI thread. |
152 ui_message_loop->PostTask( | 152 ui_task_runner->PostTask( |
153 FROM_HERE, | 153 FROM_HERE, |
154 base::Bind( | 154 base::Bind( |
155 &chromeos::PermissionBrokerClient::RequestPathAccess, | 155 &chromeos::PermissionBrokerClient::RequestPathAccess, |
156 base::Unretained(client), | 156 base::Unretained(client), port, -1, |
157 port, | |
158 -1, | |
159 base::Bind(&SerialIoHandler::OnRequestAccessComplete, this, port))); | 157 base::Bind(&SerialIoHandler::OnRequestAccessComplete, this, port))); |
160 } else { | 158 } else { |
161 OnRequestAccessComplete(port, true /* success */); | 159 OnRequestAccessComplete(port, true /* success */); |
162 return; | 160 return; |
163 } | 161 } |
164 #else | 162 #else |
165 OnRequestAccessComplete(port, true /* success */); | 163 OnRequestAccessComplete(port, true /* success */); |
166 #endif // defined(OS_LINUX) && defined(OS_CHROMEOS) | 164 #endif // defined(OS_LINUX) && defined(OS_CHROMEOS) |
167 } | 165 } |
168 | 166 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 } | 270 } |
273 | 271 |
274 if (tcsetattr(file().GetPlatformFile(), TCSANOW, &config) != 0) { | 272 if (tcsetattr(file().GetPlatformFile(), TCSANOW, &config) != 0) { |
275 VPLOG(1) << "Failed to set port attributes"; | 273 VPLOG(1) << "Failed to set port attributes"; |
276 return false; | 274 return false; |
277 } | 275 } |
278 return true; | 276 return true; |
279 } | 277 } |
280 | 278 |
281 SerialIoHandlerPosix::SerialIoHandlerPosix( | 279 SerialIoHandlerPosix::SerialIoHandlerPosix( |
282 scoped_refptr<base::MessageLoopProxy> file_thread_message_loop, | 280 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, |
283 scoped_refptr<base::MessageLoopProxy> ui_thread_message_loop) | 281 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner) |
284 : SerialIoHandler(file_thread_message_loop, ui_thread_message_loop), | 282 : SerialIoHandler(file_thread_task_runner, ui_thread_task_runner), |
285 is_watching_reads_(false), | 283 is_watching_reads_(false), |
286 is_watching_writes_(false) { | 284 is_watching_writes_(false) { |
287 } | 285 } |
288 | 286 |
289 SerialIoHandlerPosix::~SerialIoHandlerPosix() { | 287 SerialIoHandlerPosix::~SerialIoHandlerPosix() { |
290 } | 288 } |
291 | 289 |
292 void SerialIoHandlerPosix::OnFileCanReadWithoutBlocking(int fd) { | 290 void SerialIoHandlerPosix::OnFileCanReadWithoutBlocking(int fd) { |
293 DCHECK(CalledOnValidThread()); | 291 DCHECK(CalledOnValidThread()); |
294 DCHECK_EQ(fd, file().GetPlatformFile()); | 292 DCHECK_EQ(fd, file().GetPlatformFile()); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 (config.c_cflag & CSTOPB) ? serial::STOP_BITS_TWO : serial::STOP_BITS_ONE; | 452 (config.c_cflag & CSTOPB) ? serial::STOP_BITS_TWO : serial::STOP_BITS_ONE; |
455 info->cts_flow_control = (config.c_cflag & CRTSCTS) != 0; | 453 info->cts_flow_control = (config.c_cflag & CRTSCTS) != 0; |
456 return info.Pass(); | 454 return info.Pass(); |
457 } | 455 } |
458 | 456 |
459 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { | 457 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { |
460 return port_name; | 458 return port_name; |
461 } | 459 } |
462 | 460 |
463 } // namespace device | 461 } // namespace device |
OLD | NEW |