OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "chrome/browser/extensions/api/serial/serial_connection.h" | 5 #include "chrome/browser/extensions/api/serial/serial_connection.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "chrome/browser/extensions/api/api_resource_manager.h" | 12 #include "chrome/browser/extensions/api/api_resource_manager.h" |
| 13 #include "chrome/common/extensions/api/serial.h" |
| 14 |
| 15 namespace serial = extensions::api::serial; |
13 | 16 |
14 namespace extensions { | 17 namespace extensions { |
15 | 18 |
16 const char kSerialConnectionNotFoundError[] = "Serial connection not found"; | 19 const char kSerialConnectionNotFoundError[] = "Serial connection not found"; |
17 | 20 |
18 static base::LazyInstance<ProfileKeyedAPIFactory< | 21 static base::LazyInstance<ProfileKeyedAPIFactory< |
19 ApiResourceManager<SerialConnection> > > | 22 ApiResourceManager<SerialConnection> > > |
20 g_factory = LAZY_INSTANCE_INITIALIZER; | 23 g_factory = LAZY_INSTANCE_INITIALIZER; |
21 | 24 |
22 // static | 25 // static |
23 template <> | 26 template <> |
24 ProfileKeyedAPIFactory<ApiResourceManager<SerialConnection> >* | 27 ProfileKeyedAPIFactory<ApiResourceManager<SerialConnection> >* |
25 ApiResourceManager<SerialConnection>::GetFactoryInstance() { | 28 ApiResourceManager<SerialConnection>::GetFactoryInstance() { |
26 return &g_factory.Get(); | 29 return &g_factory.Get(); |
27 } | 30 } |
28 | 31 |
29 SerialConnection::SerialConnection(const std::string& port, int bitrate, | 32 SerialConnection::SerialConnection(const std::string& port, int bitrate, |
| 33 serial::DataBit databit, |
| 34 serial::ParityBit parity, |
| 35 serial::StopBit stopbit, |
30 const std::string& owner_extension_id) | 36 const std::string& owner_extension_id) |
31 : ApiResource(owner_extension_id), port_(port), bitrate_(bitrate), | 37 : ApiResource(owner_extension_id), port_(port), bitrate_(bitrate), |
| 38 databit_(databit), parity_(parity), stopbit_(stopbit), |
32 file_(base::kInvalidPlatformFileValue) { | 39 file_(base::kInvalidPlatformFileValue) { |
33 CHECK_GE(bitrate, 0); | 40 CHECK_GE(bitrate, 0); |
34 } | 41 } |
35 | 42 |
36 SerialConnection::~SerialConnection() { | 43 SerialConnection::~SerialConnection() { |
37 Close(); | 44 Close(); |
38 } | 45 } |
39 | 46 |
40 bool SerialConnection::Open() { | 47 bool SerialConnection::Open() { |
41 bool created = false; | 48 bool created = false; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 DCHECK_GE(byte_count, 0); | 84 DCHECK_GE(byte_count, 0); |
78 return base::WritePlatformFileAtCurrentPos(file_, io_buffer->data(), | 85 return base::WritePlatformFileAtCurrentPos(file_, io_buffer->data(), |
79 byte_count); | 86 byte_count); |
80 } | 87 } |
81 | 88 |
82 void SerialConnection::Flush() { | 89 void SerialConnection::Flush() { |
83 base::FlushPlatformFile(file_); | 90 base::FlushPlatformFile(file_); |
84 } | 91 } |
85 | 92 |
86 } // namespace extensions | 93 } // namespace extensions |
OLD | NEW |