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

Side by Side Diff: device/serial/serial_io_handler.cc

Issue 2914173002: Removing file_thread_task_runner parameter from SerialIoHandler (Closed)
Patch Set: removed unused variable Created 3 years, 6 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
« no previous file with comments | « device/serial/serial_io_handler.h ('k') | device/serial/serial_io_handler_posix.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.h" 5 #include "device/serial/serial_io_handler.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/task_scheduler/post_task.h"
15 #include "base/task_scheduler/task_traits.h"
14 #include "build/build_config.h" 16 #include "build/build_config.h"
15 17
16 #if defined(OS_CHROMEOS) 18 #if defined(OS_CHROMEOS)
17 #include "chromeos/dbus/dbus_thread_manager.h" 19 #include "chromeos/dbus/dbus_thread_manager.h"
18 #include "chromeos/dbus/permission_broker_client.h" 20 #include "chromeos/dbus/permission_broker_client.h"
19 #endif // defined(OS_CHROMEOS) 21 #endif // defined(OS_CHROMEOS)
20 22
21 namespace device { 23 namespace device {
22 24
23 SerialIoHandler::SerialIoHandler( 25 SerialIoHandler::SerialIoHandler(
24 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
25 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner) 26 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner)
26 : file_thread_task_runner_(file_thread_task_runner), 27 : ui_thread_task_runner_(ui_thread_task_runner) {
27 ui_thread_task_runner_(ui_thread_task_runner) {
28 options_.bitrate = 9600; 28 options_.bitrate = 9600;
29 options_.data_bits = serial::DataBits::EIGHT; 29 options_.data_bits = serial::DataBits::EIGHT;
30 options_.parity_bit = serial::ParityBit::NO_PARITY; 30 options_.parity_bit = serial::ParityBit::NO_PARITY;
31 options_.stop_bits = serial::StopBits::ONE; 31 options_.stop_bits = serial::StopBits::ONE;
32 options_.cts_flow_control = false; 32 options_.cts_flow_control = false;
33 options_.has_cts_flow_control = true; 33 options_.has_cts_flow_control = true;
34 } 34 }
35 35
36 SerialIoHandler::~SerialIoHandler() { 36 SerialIoHandler::~SerialIoHandler() {
37 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); 37 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
38 Close(); 38 Close();
39 } 39 }
40 40
41 void SerialIoHandler::Open(const std::string& port, 41 void SerialIoHandler::Open(const std::string& port,
42 const serial::ConnectionOptions& options, 42 const serial::ConnectionOptions& options,
43 const OpenCompleteCallback& callback) { 43 const OpenCompleteCallback& callback) {
44 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); 44 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
45 DCHECK(open_complete_.is_null()); 45 DCHECK(open_complete_.is_null());
46 open_complete_ = callback; 46 open_complete_ = callback;
47 DCHECK(file_thread_task_runner_.get());
48 DCHECK(ui_thread_task_runner_.get()); 47 DCHECK(ui_thread_task_runner_.get());
49 MergeConnectionOptions(options); 48 MergeConnectionOptions(options);
50 port_ = port; 49 port_ = port;
51 50
52 #if defined(OS_CHROMEOS) 51 #if defined(OS_CHROMEOS)
53 chromeos::PermissionBrokerClient* client = 52 chromeos::PermissionBrokerClient* client =
54 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient(); 53 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient();
55 DCHECK(client) << "Could not get permission_broker client."; 54 DCHECK(client) << "Could not get permission_broker client.";
56 // PermissionBrokerClient should be called on the UI thread. 55 // PermissionBrokerClient should be called on the UI thread.
57 scoped_refptr<base::SingleThreadTaskRunner> task_runner = 56 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
58 base::ThreadTaskRunnerHandle::Get(); 57 base::ThreadTaskRunnerHandle::Get();
59 ui_thread_task_runner_->PostTask( 58 ui_thread_task_runner_->PostTask(
60 FROM_HERE, 59 FROM_HERE,
61 base::Bind( 60 base::Bind(
62 &chromeos::PermissionBrokerClient::OpenPath, base::Unretained(client), 61 &chromeos::PermissionBrokerClient::OpenPath, base::Unretained(client),
63 port, base::Bind(&SerialIoHandler::OnPathOpened, this, task_runner), 62 port, base::Bind(&SerialIoHandler::OnPathOpened, this, task_runner),
64 base::Bind(&SerialIoHandler::OnPathOpenError, this, task_runner))); 63 base::Bind(&SerialIoHandler::OnPathOpenError, this, task_runner)));
65 #else 64 #else
66 file_thread_task_runner_->PostTask( 65 base::PostTaskWithTraits(
67 FROM_HERE, base::Bind(&SerialIoHandler::StartOpen, this, port, 66 FROM_HERE,
68 base::ThreadTaskRunnerHandle::Get())); 67 {base::MayBlock(), base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
68 base::Bind(&SerialIoHandler::StartOpen, this, port,
69 base::ThreadTaskRunnerHandle::Get()));
69 #endif // defined(OS_CHROMEOS) 70 #endif // defined(OS_CHROMEOS)
70 } 71 }
71 72
72 #if defined(OS_CHROMEOS) 73 #if defined(OS_CHROMEOS)
73 74
74 void SerialIoHandler::OnPathOpened( 75 void SerialIoHandler::OnPathOpened(
75 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, 76 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
76 base::ScopedFD fd) { 77 base::ScopedFD fd) {
77 base::File file(fd.release()); 78 base::File file(fd.release());
78 io_thread_task_runner->PostTask( 79 io_thread_task_runner->PostTask(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 if (options.has_cts_flow_control) { 120 if (options.has_cts_flow_control) {
120 DCHECK(options_.has_cts_flow_control); 121 DCHECK(options_.has_cts_flow_control);
121 options_.cts_flow_control = options.cts_flow_control; 122 options_.cts_flow_control = options.cts_flow_control;
122 } 123 }
123 } 124 }
124 125
125 void SerialIoHandler::StartOpen( 126 void SerialIoHandler::StartOpen(
126 const std::string& port, 127 const std::string& port,
127 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) { 128 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) {
128 DCHECK(!open_complete_.is_null()); 129 DCHECK(!open_complete_.is_null());
129 DCHECK(file_thread_task_runner_->RunsTasksInCurrentSequence());
130 DCHECK(!file_.IsValid()); 130 DCHECK(!file_.IsValid());
131 // It's the responsibility of the API wrapper around SerialIoHandler to 131 // It's the responsibility of the API wrapper around SerialIoHandler to
132 // validate the supplied path against the set of valid port names, and 132 // validate the supplied path against the set of valid port names, and
133 // it is a reasonable assumption that serial port names are ASCII. 133 // it is a reasonable assumption that serial port names are ASCII.
134 DCHECK(base::IsStringASCII(port)); 134 DCHECK(base::IsStringASCII(port));
135 base::FilePath path(base::FilePath::FromUTF8Unsafe(MaybeFixUpPortName(port))); 135 base::FilePath path(base::FilePath::FromUTF8Unsafe(MaybeFixUpPortName(port)));
136 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | 136 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
137 base::File::FLAG_EXCLUSIVE_READ | base::File::FLAG_WRITE | 137 base::File::FLAG_EXCLUSIVE_READ | base::File::FLAG_WRITE |
138 base::File::FLAG_EXCLUSIVE_WRITE | base::File::FLAG_ASYNC | 138 base::File::FLAG_EXCLUSIVE_WRITE | base::File::FLAG_ASYNC |
139 base::File::FLAG_TERMINAL_DEVICE; 139 base::File::FLAG_TERMINAL_DEVICE;
(...skipping 23 matching lines...) Expand all
163 163
164 callback.Run(success); 164 callback.Run(success);
165 } 165 }
166 166
167 bool SerialIoHandler::PostOpen() { 167 bool SerialIoHandler::PostOpen() {
168 return true; 168 return true;
169 } 169 }
170 170
171 void SerialIoHandler::Close() { 171 void SerialIoHandler::Close() {
172 if (file_.IsValid()) { 172 if (file_.IsValid()) {
173 DCHECK(file_thread_task_runner_.get()); 173 base::PostTaskWithTraits(
174 file_thread_task_runner_->PostTask(
175 FROM_HERE, 174 FROM_HERE,
175 {base::MayBlock(), base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
176 base::Bind(&SerialIoHandler::DoClose, Passed(std::move(file_)))); 176 base::Bind(&SerialIoHandler::DoClose, Passed(std::move(file_))));
177 } 177 }
178 } 178 }
179 179
180 // static 180 // static
181 void SerialIoHandler::DoClose(base::File port) { 181 void SerialIoHandler::DoClose(base::File port) {
182 // port closed by destructor. 182 // port closed by destructor.
183 } 183 }
184 184
185 void SerialIoHandler::Read(std::unique_ptr<WritableBuffer> buffer) { 185 void SerialIoHandler::Read(std::unique_ptr<WritableBuffer> buffer) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 } 270 }
271 271
272 void SerialIoHandler::QueueWriteCompleted(int bytes_written, 272 void SerialIoHandler::QueueWriteCompleted(int bytes_written,
273 serial::SendError error) { 273 serial::SendError error) {
274 base::ThreadTaskRunnerHandle::Get()->PostTask( 274 base::ThreadTaskRunnerHandle::Get()->PostTask(
275 FROM_HERE, 275 FROM_HERE,
276 base::Bind(&SerialIoHandler::WriteCompleted, this, bytes_written, error)); 276 base::Bind(&SerialIoHandler::WriteCompleted, this, bytes_written, error));
277 } 277 }
278 278
279 } // namespace device 279 } // namespace device
OLDNEW
« no previous file with comments | « device/serial/serial_io_handler.h ('k') | device/serial/serial_io_handler_posix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698