| 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 EXTENSIONS_BROWSER_API_SERIAL_SERIAL_CONNECTION_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_SERIAL_SERIAL_CONNECTION_H_ |
| 6 #define EXTENSIONS_BROWSER_API_SERIAL_SERIAL_CONNECTION_H_ | 6 #define EXTENSIONS_BROWSER_API_SERIAL_SERIAL_CONNECTION_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "device/serial/serial_io_handler.h" | 14 #include "device/serial/serial_io_handler.h" |
| 15 #include "extensions/browser/api/api_resource.h" | 15 #include "extensions/browser/api/api_resource.h" |
| 16 #include "extensions/browser/api/api_resource_manager.h" | 16 #include "extensions/browser/api/api_resource_manager.h" |
| 17 #include "extensions/common/api/serial.h" | 17 #include "extensions/common/api/serial.h" |
| 18 #include "net/base/io_buffer.h" |
| 18 | 19 |
| 19 using content::BrowserThread; | 20 using content::BrowserThread; |
| 20 | 21 |
| 21 namespace extensions { | 22 namespace extensions { |
| 22 | 23 |
| 23 // Encapsulates an open serial port. | 24 // Encapsulates an open serial port. |
| 24 // NOTE: Instances of this object should only be constructed on the IO thread, | 25 // NOTE: Instances of this object should only be constructed on the IO thread, |
| 25 // and all methods should only be called on the IO thread unless otherwise | 26 // and all methods should only be called on the IO thread unless otherwise |
| 26 // noted. | 27 // noted. |
| 27 class SerialConnection : public ApiResource, | 28 class SerialConnection : public ApiResource, |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 base::TimeDelta delay_; | 134 base::TimeDelta delay_; |
| 134 }; | 135 }; |
| 135 | 136 |
| 136 // Handles a receive timeout. | 137 // Handles a receive timeout. |
| 137 void OnReceiveTimeout(); | 138 void OnReceiveTimeout(); |
| 138 | 139 |
| 139 // Handles a send timeout. | 140 // Handles a send timeout. |
| 140 void OnSendTimeout(); | 141 void OnSendTimeout(); |
| 141 | 142 |
| 142 // Receives read completion notification from the |io_handler_|. | 143 // Receives read completion notification from the |io_handler_|. |
| 143 void OnAsyncReadComplete(const std::string& data, | 144 void OnAsyncReadComplete(int bytes_read, device::serial::ReceiveError error); |
| 144 device::serial::ReceiveError error); | |
| 145 | 145 |
| 146 // Receives write completion notification from the |io_handler_|. | 146 // Receives write completion notification from the |io_handler_|. |
| 147 void OnAsyncWriteComplete(int bytes_sent, device::serial::SendError error); | 147 void OnAsyncWriteComplete(int bytes_sent, device::serial::SendError error); |
| 148 | 148 |
| 149 // The pathname of the serial device. | 149 // The pathname of the serial device. |
| 150 std::string port_; | 150 std::string port_; |
| 151 | 151 |
| 152 // Flag indicating whether or not the connection should persist when | 152 // Flag indicating whether or not the connection should persist when |
| 153 // its host app is suspended. | 153 // its host app is suspended. |
| 154 bool persistent_; | 154 bool persistent_; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 178 SendCompleteCallback send_complete_; | 178 SendCompleteCallback send_complete_; |
| 179 | 179 |
| 180 // Closure which will trigger a receive timeout unless cancelled. Reset on | 180 // Closure which will trigger a receive timeout unless cancelled. Reset on |
| 181 // initialization and after every successful Receive(). | 181 // initialization and after every successful Receive(). |
| 182 scoped_ptr<TimeoutTask> receive_timeout_task_; | 182 scoped_ptr<TimeoutTask> receive_timeout_task_; |
| 183 | 183 |
| 184 // Write timeout closure. Reset on initialization and after every successful | 184 // Write timeout closure. Reset on initialization and after every successful |
| 185 // Send(). | 185 // Send(). |
| 186 scoped_ptr<TimeoutTask> send_timeout_task_; | 186 scoped_ptr<TimeoutTask> send_timeout_task_; |
| 187 | 187 |
| 188 scoped_refptr<net::IOBuffer> receive_buffer_; |
| 189 |
| 188 // Asynchronous I/O handler. | 190 // Asynchronous I/O handler. |
| 189 scoped_refptr<device::SerialIoHandler> io_handler_; | 191 scoped_refptr<device::SerialIoHandler> io_handler_; |
| 190 }; | 192 }; |
| 191 | 193 |
| 192 } // namespace extensions | 194 } // namespace extensions |
| 193 | 195 |
| 194 namespace mojo { | 196 namespace mojo { |
| 195 | 197 |
| 196 template <> | 198 template <> |
| 197 class TypeConverter<device::serial::HostControlSignalsPtr, | 199 class TypeConverter<device::serial::HostControlSignalsPtr, |
| 198 extensions::core_api::serial::HostControlSignals> { | 200 extensions::core_api::serial::HostControlSignals> { |
| 199 public: | 201 public: |
| 200 static device::serial::HostControlSignalsPtr ConvertFrom( | 202 static device::serial::HostControlSignalsPtr ConvertFrom( |
| 201 const extensions::core_api::serial::HostControlSignals& input); | 203 const extensions::core_api::serial::HostControlSignals& input); |
| 202 }; | 204 }; |
| 203 | 205 |
| 204 template <> | 206 template <> |
| 205 class TypeConverter<device::serial::ConnectionOptionsPtr, | 207 class TypeConverter<device::serial::ConnectionOptionsPtr, |
| 206 extensions::core_api::serial::ConnectionOptions> { | 208 extensions::core_api::serial::ConnectionOptions> { |
| 207 public: | 209 public: |
| 208 static device::serial::ConnectionOptionsPtr ConvertFrom( | 210 static device::serial::ConnectionOptionsPtr ConvertFrom( |
| 209 const extensions::core_api::serial::ConnectionOptions& input); | 211 const extensions::core_api::serial::ConnectionOptions& input); |
| 210 }; | 212 }; |
| 211 | 213 |
| 212 } // namespace mojo | 214 } // namespace mojo |
| 213 | 215 |
| 214 #endif // EXTENSIONS_BROWSER_API_SERIAL_SERIAL_CONNECTION_H_ | 216 #endif // EXTENSIONS_BROWSER_API_SERIAL_SERIAL_CONNECTION_H_ |
| OLD | NEW |