| 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 #ifndef DEVICE_SERIAL_SERIAL_IO_HANDLER_H_ | 5 #ifndef DEVICE_SERIAL_SERIAL_IO_HANDLER_H_ |
| 6 #define DEVICE_SERIAL_SERIAL_IO_HANDLER_H_ | 6 #define DEVICE_SERIAL_SERIAL_IO_HANDLER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/files/file.h" | 13 #include "base/files/file.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/sequence_checker.h" |
| 16 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 17 #include "base/threading/non_thread_safe.h" | |
| 18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "device/serial/buffer.h" | 20 #include "device/serial/buffer.h" |
| 21 #include "device/serial/serial.mojom.h" | 21 #include "device/serial/serial.mojom.h" |
| 22 | 22 |
| 23 namespace device { | 23 namespace device { |
| 24 | 24 |
| 25 // Provides a simplified interface for performing asynchronous I/O on serial | 25 // Provides a simplified interface for performing asynchronous I/O on serial |
| 26 // devices by hiding platform-specific MessageLoop interfaces. Pending I/O | 26 // devices by hiding platform-specific MessageLoop interfaces. Pending I/O |
| 27 // operations hold a reference to this object until completion so that memory | 27 // operations hold a reference to this object until completion so that memory |
| 28 // doesn't disappear out from under the OS. | 28 // doesn't disappear out from under the OS. |
| 29 class SerialIoHandler : public base::NonThreadSafe, | 29 class SerialIoHandler : public base::RefCounted<SerialIoHandler> { |
| 30 public base::RefCounted<SerialIoHandler> { | |
| 31 public: | 30 public: |
| 32 // Constructs an instance of some platform-specific subclass. | 31 // Constructs an instance of some platform-specific subclass. |
| 33 static scoped_refptr<SerialIoHandler> Create( | 32 static scoped_refptr<SerialIoHandler> Create( |
| 34 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, | 33 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, |
| 35 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner); | 34 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner); |
| 36 | 35 |
| 37 typedef base::Callback<void(bool success)> OpenCompleteCallback; | 36 typedef base::Callback<void(bool success)> OpenCompleteCallback; |
| 38 | 37 |
| 39 // Initiates an asynchronous Open of the device. | 38 // Initiates an asynchronous Open of the device. |
| 40 virtual void Open(const std::string& port, | 39 virtual void Open(const std::string& port, |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 base::SingleThreadTaskRunner* file_thread_task_runner() const { | 198 base::SingleThreadTaskRunner* file_thread_task_runner() const { |
| 200 return file_thread_task_runner_.get(); | 199 return file_thread_task_runner_.get(); |
| 201 } | 200 } |
| 202 | 201 |
| 203 base::SingleThreadTaskRunner* ui_thread_task_runner() const { | 202 base::SingleThreadTaskRunner* ui_thread_task_runner() const { |
| 204 return ui_thread_task_runner_.get(); | 203 return ui_thread_task_runner_.get(); |
| 205 } | 204 } |
| 206 | 205 |
| 207 const std::string& port() const { return port_; } | 206 const std::string& port() const { return port_; } |
| 208 | 207 |
| 208 SEQUENCE_CHECKER(sequence_checker_); |
| 209 |
| 209 private: | 210 private: |
| 210 friend class base::RefCounted<SerialIoHandler>; | 211 friend class base::RefCounted<SerialIoHandler>; |
| 211 | 212 |
| 212 void MergeConnectionOptions(const serial::ConnectionOptions& options); | 213 void MergeConnectionOptions(const serial::ConnectionOptions& options); |
| 213 | 214 |
| 214 // Continues an Open operation on the FILE thread. | 215 // Continues an Open operation on the FILE thread. |
| 215 void StartOpen(const std::string& port, | 216 void StartOpen(const std::string& port, |
| 216 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); | 217 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); |
| 217 | 218 |
| 218 // Finalizes an Open operation (continued from StartOpen) on the IO thread. | 219 // Finalizes an Open operation (continued from StartOpen) on the IO thread. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 246 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner_; | 247 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner_; |
| 247 | 248 |
| 248 std::string port_; | 249 std::string port_; |
| 249 | 250 |
| 250 DISALLOW_COPY_AND_ASSIGN(SerialIoHandler); | 251 DISALLOW_COPY_AND_ASSIGN(SerialIoHandler); |
| 251 }; | 252 }; |
| 252 | 253 |
| 253 } // namespace device | 254 } // namespace device |
| 254 | 255 |
| 255 #endif // DEVICE_SERIAL_SERIAL_IO_HANDLER_H_ | 256 #endif // DEVICE_SERIAL_SERIAL_IO_HANDLER_H_ |
| OLD | NEW |