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

Side by Side Diff: extensions/browser/api/serial/serial_connection.h

Issue 369893008: Move the serial API to extensions/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add missing dependency from usb_service to chromeos Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_CONNECTION_H_ 5 #ifndef EXTENSIONS_BROWSER_API_SERIAL_SERIAL_CONNECTION_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_CONNECTION_H_ 6 #define EXTENSIONS_BROWSER_API_SERIAL_SERIAL_CONNECTION_H_
7 7
8 #include <set>
9 #include <string> 8 #include <string>
10 9
11 #include "base/callback.h" 10 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
14 #include "base/message_loop/message_loop.h"
15 #include "base/time/time.h" 12 #include "base/time/time.h"
16 #include "chrome/common/extensions/api/serial.h"
17 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
18 #include "device/serial/serial_io_handler.h" 14 #include "device/serial/serial_io_handler.h"
19 #include "extensions/browser/api/api_resource.h" 15 #include "extensions/browser/api/api_resource.h"
20 #include "extensions/browser/api/api_resource_manager.h" 16 #include "extensions/browser/api/api_resource_manager.h"
17 #include "extensions/common/api/serial.h"
21 18
22 using content::BrowserThread; 19 using content::BrowserThread;
23 20
24 namespace extensions { 21 namespace extensions {
25 22
26 // Encapsulates an open serial port. 23 // Encapsulates an open serial port.
27 // NOTE: Instances of this object should only be constructed on the IO thread, 24 // NOTE: Instances of this object should only be constructed on the IO thread,
28 // and all methods should only be called on the IO thread unless otherwise 25 // and all methods should only be called on the IO thread unless otherwise
29 // noted. 26 // noted.
30 class SerialConnection : public ApiResource, 27 class SerialConnection : public ApiResource,
31 public base::SupportsWeakPtr<SerialConnection> { 28 public base::SupportsWeakPtr<SerialConnection> {
32 public: 29 public:
33 typedef device::SerialIoHandler::OpenCompleteCallback OpenCompleteCallback; 30 typedef device::SerialIoHandler::OpenCompleteCallback OpenCompleteCallback;
34 31
35 // This is the callback type expected by Receive. Note that an error result 32 // This is the callback type expected by Receive. Note that an error result
36 // does not necessarily imply an empty |data| string, since a receive may 33 // does not necessarily imply an empty |data| string, since a receive may
37 // complete partially before being interrupted by an error condition. 34 // complete partially before being interrupted by an error condition.
38 typedef base::Callback< 35 typedef base::Callback<
39 void(const std::string& data, api::serial::ReceiveError error)> 36 void(const std::string& data, core_api::serial::ReceiveError error)>
40 ReceiveCompleteCallback; 37 ReceiveCompleteCallback;
41 38
42 // This is the callback type expected by Send. Note that an error result 39 // This is the callback type expected by Send. Note that an error result
43 // does not necessarily imply 0 bytes sent, since a send may complete 40 // does not necessarily imply 0 bytes sent, since a send may complete
44 // partially before being interrupted by an error condition. 41 // partially before being interrupted by an error condition.
45 typedef base::Callback<void(int bytes_sent, api::serial::SendError error)> 42 typedef base::Callback<
43 void(int bytes_sent, core_api::serial::SendError error)>
46 SendCompleteCallback; 44 SendCompleteCallback;
47 45
48 SerialConnection(const std::string& port, 46 SerialConnection(const std::string& port,
49 const std::string& owner_extension_id); 47 const std::string& owner_extension_id);
50 virtual ~SerialConnection(); 48 virtual ~SerialConnection();
51 49
52 // ApiResource override. 50 // ApiResource override.
53 virtual bool IsPersistent() const OVERRIDE; 51 virtual bool IsPersistent() const OVERRIDE;
54 52
55 void set_persistent(bool persistent) { persistent_ = persistent; } 53 void set_persistent(bool persistent) { persistent_ = persistent; }
(...skipping 28 matching lines...) Expand all
84 // is already pending is a no-op and returns |false| without calling 82 // is already pending is a no-op and returns |false| without calling
85 // |callback|. 83 // |callback|.
86 bool Send(const std::string& data, const SendCompleteCallback& callback); 84 bool Send(const std::string& data, const SendCompleteCallback& callback);
87 85
88 // Flushes input and output buffers. 86 // Flushes input and output buffers.
89 bool Flush() const; 87 bool Flush() const;
90 88
91 // Configures some subset of port options for this connection. 89 // Configures some subset of port options for this connection.
92 // Omitted options are unchanged. Returns |true| iff the configuration 90 // Omitted options are unchanged. Returns |true| iff the configuration
93 // changes were successful. 91 // changes were successful.
94 bool Configure(const api::serial::ConnectionOptions& options); 92 bool Configure(const core_api::serial::ConnectionOptions& options);
95 93
96 // Connection configuration query. Fills values in an existing 94 // Connection configuration query. Fills values in an existing
97 // ConnectionInfo. Returns |true| iff the connection's information 95 // ConnectionInfo. Returns |true| iff the connection's information
98 // was successfully retrieved. 96 // was successfully retrieved.
99 bool GetInfo(api::serial::ConnectionInfo* info) const; 97 bool GetInfo(core_api::serial::ConnectionInfo* info) const;
100 98
101 // Reads current control signals (DCD, CTS, etc.) into an existing 99 // Reads current control signals (DCD, CTS, etc.) into an existing
102 // DeviceControlSignals structure. Returns |true| iff the signals were 100 // DeviceControlSignals structure. Returns |true| iff the signals were
103 // successfully read. 101 // successfully read.
104 bool GetControlSignals( 102 bool GetControlSignals(
105 api::serial::DeviceControlSignals* control_signals) const; 103 core_api::serial::DeviceControlSignals* control_signals) const;
106 104
107 // Sets one or more control signals (DTR and/or RTS). Returns |true| iff 105 // Sets one or more control signals (DTR and/or RTS). Returns |true| iff
108 // the signals were successfully set. Unininitialized flags in the 106 // the signals were successfully set. Unininitialized flags in the
109 // HostControlSignals structure are left unchanged. 107 // HostControlSignals structure are left unchanged.
110 bool SetControlSignals( 108 bool SetControlSignals(
111 const api::serial::HostControlSignals& control_signals); 109 const core_api::serial::HostControlSignals& control_signals);
112 110
113 // Overrides |io_handler_| for testing. 111 // Overrides |io_handler_| for testing.
114 void SetIoHandlerForTest(scoped_refptr<device::SerialIoHandler> handler); 112 void SetIoHandlerForTest(scoped_refptr<device::SerialIoHandler> handler);
115 113
116 static const BrowserThread::ID kThreadId = BrowserThread::IO; 114 static const BrowserThread::ID kThreadId = BrowserThread::IO;
117 115
118 private: 116 private:
119 friend class ApiResourceManager<SerialConnection>; 117 friend class ApiResourceManager<SerialConnection>;
120 static const char* service_name() { return "SerialConnectionManager"; } 118 static const char* service_name() { return "SerialConnectionManager"; }
121 119
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // Asynchronous I/O handler. 188 // Asynchronous I/O handler.
191 scoped_refptr<device::SerialIoHandler> io_handler_; 189 scoped_refptr<device::SerialIoHandler> io_handler_;
192 }; 190 };
193 191
194 } // namespace extensions 192 } // namespace extensions
195 193
196 namespace mojo { 194 namespace mojo {
197 195
198 template <> 196 template <>
199 class TypeConverter<device::serial::HostControlSignalsPtr, 197 class TypeConverter<device::serial::HostControlSignalsPtr,
200 extensions::api::serial::HostControlSignals> { 198 extensions::core_api::serial::HostControlSignals> {
201 public: 199 public:
202 static device::serial::HostControlSignalsPtr ConvertFrom( 200 static device::serial::HostControlSignalsPtr ConvertFrom(
203 const extensions::api::serial::HostControlSignals& input); 201 const extensions::core_api::serial::HostControlSignals& input);
204 }; 202 };
205 203
206 template <> 204 template <>
207 class TypeConverter<device::serial::ConnectionOptionsPtr, 205 class TypeConverter<device::serial::ConnectionOptionsPtr,
208 extensions::api::serial::ConnectionOptions> { 206 extensions::core_api::serial::ConnectionOptions> {
209 public: 207 public:
210 static device::serial::ConnectionOptionsPtr ConvertFrom( 208 static device::serial::ConnectionOptionsPtr ConvertFrom(
211 const extensions::api::serial::ConnectionOptions& input); 209 const extensions::core_api::serial::ConnectionOptions& input);
212 }; 210 };
213 211
214 } // namespace mojo 212 } // namespace mojo
215 213
216 #endif // CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_CONNECTION_H_ 214 #endif // EXTENSIONS_BROWSER_API_SERIAL_SERIAL_CONNECTION_H_
OLDNEW
« no previous file with comments | « extensions/browser/api/serial/serial_apitest.cc ('k') | extensions/browser/api/serial/serial_connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698