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

Side by Side Diff: device/serial/serial_io_handler_win.h

Issue 1439443002: Reland: Add code to deal with serial device disconnection detection on Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated code to call thread helper from UI thread Created 5 years, 1 month 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
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 #ifndef DEVICE_SERIAL_SERIAL_IO_HANDLER_WIN_H_ 5 #ifndef DEVICE_SERIAL_SERIAL_IO_HANDLER_WIN_H_
6 #define DEVICE_SERIAL_SERIAL_IO_HANDLER_WIN_H_ 6 #define DEVICE_SERIAL_SERIAL_IO_HANDLER_WIN_H_
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "device/serial/serial_io_handler.h" 12 #include "device/serial/serial_io_handler.h"
13 13
14 namespace device { 14 namespace device {
15 15
16 class SerialIoHandlerWin : public SerialIoHandler, 16 class SerialIoHandlerWin : public SerialIoHandler,
17 public base::MessageLoopForIO::IOHandler { 17 public base::MessageLoopForIO::IOHandler {
18 public:
19 class UiThreadHelper;
Reilly Grant (use Gerrit) 2015/11/11 20:43:59 This class should be private.
juncai 2015/11/12 05:27:08 Done.
20
18 protected: 21 protected:
19 // SerialIoHandler implementation. 22 // SerialIoHandler implementation.
20 void ReadImpl() override; 23 void ReadImpl() override;
21 void WriteImpl() override; 24 void WriteImpl() override;
22 void CancelReadImpl() override; 25 void CancelReadImpl() override;
23 void CancelWriteImpl() override; 26 void CancelWriteImpl() override;
24 bool ConfigurePortImpl() override; 27 bool ConfigurePortImpl() override;
25 bool Flush() const override; 28 bool Flush() const override;
26 serial::DeviceControlSignalsPtr GetControlSignals() const override; 29 serial::DeviceControlSignalsPtr GetControlSignals() const override;
27 bool SetControlSignals( 30 bool SetControlSignals(
28 const serial::HostControlSignals& control_signals) override; 31 const serial::HostControlSignals& control_signals) override;
29 serial::ConnectionInfoPtr GetPortInfo() const override; 32 serial::ConnectionInfoPtr GetPortInfo() const override;
30 bool SetBreak() override; 33 bool SetBreak() override;
31 bool ClearBreak() override; 34 bool ClearBreak() override;
32 bool PostOpen() override; 35 bool PostOpen() override;
33 36
34 private: 37 private:
35 friend class SerialIoHandler; 38 friend class SerialIoHandler;
36 39
37 explicit SerialIoHandlerWin( 40 explicit SerialIoHandlerWin(
38 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, 41 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
39 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner); 42 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner);
40 ~SerialIoHandlerWin() override; 43 ~SerialIoHandlerWin() override;
41 44
42 // base::MessageLoopForIO::IOHandler implementation. 45 // base::MessageLoopForIO::IOHandler implementation.
43 void OnIOCompleted(base::MessageLoopForIO::IOContext* context, 46 void OnIOCompleted(base::MessageLoopForIO::IOContext* context,
44 DWORD bytes_transfered, 47 DWORD bytes_transfered,
45 DWORD error) override; 48 DWORD error) override;
46 49
50 void RemoveDevice(const std::string& device_path);
Reilly Grant (use Gerrit) 2015/11/11 20:43:59 s/RemoveDevice/OnDeviceRemoved/
juncai 2015/11/12 05:27:08 Done.
51
47 // Context used for asynchronous WaitCommEvent calls. 52 // Context used for asynchronous WaitCommEvent calls.
48 scoped_ptr<base::MessageLoopForIO::IOContext> comm_context_; 53 scoped_ptr<base::MessageLoopForIO::IOContext> comm_context_;
49 54
50 // Context used for overlapped reads. 55 // Context used for overlapped reads.
51 scoped_ptr<base::MessageLoopForIO::IOContext> read_context_; 56 scoped_ptr<base::MessageLoopForIO::IOContext> read_context_;
52 57
53 // Context used for overlapped writes. 58 // Context used for overlapped writes.
54 scoped_ptr<base::MessageLoopForIO::IOContext> write_context_; 59 scoped_ptr<base::MessageLoopForIO::IOContext> write_context_;
55 60
56 // Asynchronous event mask state 61 // Asynchronous event mask state
57 DWORD event_mask_; 62 DWORD event_mask_;
58 63
59 // Indicates if a pending read is waiting on initial data arrival via 64 // Indicates if a pending read is waiting on initial data arrival via
60 // WaitCommEvent, as opposed to waiting on actual ReadFile completion 65 // WaitCommEvent, as opposed to waiting on actual ReadFile completion
61 // after a corresponding WaitCommEvent has completed. 66 // after a corresponding WaitCommEvent has completed.
62 bool is_comm_pending_; 67 bool is_comm_pending_;
63 68
69 // The helper lives on the UI thread and holds a weak reference back to the
70 // handler that owns it.
71 UiThreadHelper* helper_;
72 base::WeakPtrFactory<SerialIoHandlerWin> weak_factory_;
73
64 DISALLOW_COPY_AND_ASSIGN(SerialIoHandlerWin); 74 DISALLOW_COPY_AND_ASSIGN(SerialIoHandlerWin);
65 }; 75 };
66 76
67 } // namespace device 77 } // namespace device
68 78
69 #endif // DEVICE_SERIAL_SERIAL_IO_HANDLER_WIN_H_ 79 #endif // DEVICE_SERIAL_SERIAL_IO_HANDLER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698