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 #include "device/serial/serial_io_handler.h" | 5 #include "device/serial/serial_io_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 | 11 |
12 namespace device { | 12 namespace device { |
13 | 13 |
14 SerialIoHandler::SerialIoHandler( | 14 SerialIoHandler::SerialIoHandler( |
15 scoped_refptr<base::MessageLoopProxy> file_thread_message_loop) | 15 scoped_refptr<base::MessageLoopProxy> file_thread_message_loop, |
16 : file_thread_message_loop_(file_thread_message_loop) { | 16 scoped_refptr<base::MessageLoopProxy> ui_thread_message_loop) |
17 : file_thread_message_loop_(file_thread_message_loop), | |
18 ui_thread_message_loop_(ui_thread_message_loop) { | |
17 } | 19 } |
18 | 20 |
19 SerialIoHandler::~SerialIoHandler() { | 21 SerialIoHandler::~SerialIoHandler() { |
20 DCHECK(CalledOnValidThread()); | 22 DCHECK(CalledOnValidThread()); |
21 Close(); | 23 Close(); |
22 } | 24 } |
23 | 25 |
24 void SerialIoHandler::Open(const std::string& port, | 26 void SerialIoHandler::Open(const std::string& port, |
25 const OpenCompleteCallback& callback) { | 27 const OpenCompleteCallback& callback) { |
26 DCHECK(CalledOnValidThread()); | 28 DCHECK(CalledOnValidThread()); |
27 DCHECK(open_complete_.is_null()); | 29 DCHECK(open_complete_.is_null()); |
28 open_complete_ = callback; | 30 open_complete_ = callback; |
29 DCHECK(file_thread_message_loop_.get()); | 31 DCHECK(file_thread_message_loop_.get()); |
30 file_thread_message_loop_->PostTask( | 32 DCHECK(ui_thread_message_loop_.get()); |
31 FROM_HERE, | 33 RequestAccess(port, file_thread_message_loop_, ui_thread_message_loop_); |
32 base::Bind(&SerialIoHandler::StartOpen, | 34 } |
33 this, | 35 |
34 port, | 36 void SerialIoHandler::RequestAccess( |
35 base::MessageLoopProxy::current())); | 37 const std::string& port, |
38 scoped_refptr<base::MessageLoopProxy> file_message_loop, | |
39 scoped_refptr<base::MessageLoopProxy> ui_message_loop) { | |
Reilly Grant (use Gerrit)
2014/10/15 00:33:02
Why pass these as parameters when they are availab
Jorge Lucangeli Obes
2014/10/15 00:35:58
Because they're private members and need to be acc
| |
40 OnRequestAccessComplete(port, true /* success */); | |
41 } | |
42 | |
43 void SerialIoHandler::OnRequestAccessComplete(const std::string& port, | |
44 bool success) { | |
45 DCHECK(CalledOnValidThread()); | |
46 if (success) { | |
47 DCHECK(file_thread_message_loop_.get()); | |
48 file_thread_message_loop_->PostTask( | |
49 FROM_HERE, | |
50 base::Bind(&SerialIoHandler::StartOpen, | |
51 this, | |
52 port, | |
53 base::MessageLoopProxy::current())); | |
54 return; | |
55 } else { | |
56 DCHECK(!open_complete_.is_null()); | |
57 OpenCompleteCallback callback = open_complete_; | |
58 open_complete_.Reset(); | |
59 callback.Run(false); | |
60 return; | |
61 } | |
36 } | 62 } |
37 | 63 |
38 void SerialIoHandler::StartOpen( | 64 void SerialIoHandler::StartOpen( |
39 const std::string& port, | 65 const std::string& port, |
40 scoped_refptr<base::MessageLoopProxy> io_message_loop) { | 66 scoped_refptr<base::MessageLoopProxy> io_message_loop) { |
41 DCHECK(!open_complete_.is_null()); | 67 DCHECK(!open_complete_.is_null()); |
42 DCHECK(file_thread_message_loop_->RunsTasksOnCurrentThread()); | 68 DCHECK(file_thread_message_loop_->RunsTasksOnCurrentThread()); |
43 DCHECK(!file_.IsValid()); | 69 DCHECK(!file_.IsValid()); |
44 // It's the responsibility of the API wrapper around SerialIoHandler to | 70 // It's the responsibility of the API wrapper around SerialIoHandler to |
45 // validate the supplied path against the set of valid port names, and | 71 // validate the supplied path against the set of valid port names, and |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 } | 199 } |
174 | 200 |
175 void SerialIoHandler::QueueWriteCompleted(int bytes_written, | 201 void SerialIoHandler::QueueWriteCompleted(int bytes_written, |
176 serial::SendError error) { | 202 serial::SendError error) { |
177 base::MessageLoop::current()->PostTask( | 203 base::MessageLoop::current()->PostTask( |
178 FROM_HERE, | 204 FROM_HERE, |
179 base::Bind(&SerialIoHandler::WriteCompleted, this, bytes_written, error)); | 205 base::Bind(&SerialIoHandler::WriteCompleted, this, bytes_written, error)); |
180 } | 206 } |
181 | 207 |
182 } // namespace device | 208 } // namespace device |
OLD | NEW |