diff options
author | reillyg <reillyg@chromium.org> | 2014-10-06 22:40:23 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-07 05:40:40 +0000 |
commit | b321e4f568022a539f87b57dec817d6e23825d9f (patch) | |
tree | 337b78a74e3f8ab10c93b03b577cc500c9dd5ea1 /device/hid/hid_connection_mac.h | |
parent | 875dc1fdfcf23ff64f959f423117fc25fd05b4e4 (diff) | |
download | chromium_src-b321e4f568022a539f87b57dec817d6e23825d9f.zip chromium_src-b321e4f568022a539f87b57dec817d6e23825d9f.tar.gz chromium_src-b321e4f568022a539f87b57dec817d6e23825d9f.tar.bz2 |
Add HidConnection::Close and register OS X callbacks on the UI thread.
The platform implementation of a HID connection may need to cancel I/O
operations when the connection is closed. If this is done during the
object destructor then any pointers held by those pending operations are
immediately invalid. A separate Close method allows the cleanup to
happen while the object is still available to handle asynchronous
cancellation events.
The OS X implementation will take advantage of this immediately to
register and unregister its input report callback from the UI thread to
avoid a race between event delivery and object cleanup. I've added
comments explaining why not all operations on the IOHIDDevice object
could be moved to the UI thread.
BUG=418207
Review URL: https://codereview.chromium.org/615633008
Cr-Commit-Position: refs/heads/master@{#298384}
Diffstat (limited to 'device/hid/hid_connection_mac.h')
-rw-r--r-- | device/hid/hid_connection_mac.h | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/device/hid/hid_connection_mac.h b/device/hid/hid_connection_mac.h index f1ce414..aa23fc9 100644 --- a/device/hid/hid_connection_mac.h +++ b/device/hid/hid_connection_mac.h @@ -15,7 +15,7 @@ #include "device/hid/hid_connection.h" namespace base { -class MessageLoopProxy; +class SingleThreadTaskRunner; } namespace net { @@ -26,12 +26,15 @@ namespace device { class HidConnectionMac : public HidConnection { public: - explicit HidConnectionMac(HidDeviceInfo device_info); + explicit HidConnectionMac( + HidDeviceInfo device_info, + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); private: virtual ~HidConnectionMac(); // HidConnection implementation. + virtual void PlatformClose() override; virtual void PlatformRead(const ReadCallback& callback) override; virtual void PlatformWrite(scoped_refptr<net::IOBuffer> buffer, size_t size, @@ -43,6 +46,8 @@ class HidConnectionMac : public HidConnection { size_t size, const WriteCallback& callback) override; + void StartInputReportCallbacks(); + void StopInputReportCallbacks(); static void InputReportCallback(void* context, IOReturn result, void* sender, @@ -50,18 +55,17 @@ class HidConnectionMac : public HidConnection { uint32_t report_id, uint8_t* report_bytes, CFIndex report_length); + void ProcessInputReport(scoped_refptr<net::IOBufferWithSize> buffer); + void ProcessReadQueue(); - void WriteReport(IOHIDReportType type, + void WriteReport(IOHIDReportType report_type, scoped_refptr<net::IOBuffer> buffer, size_t size, const WriteCallback& callback); - void Flush(); - void ProcessInputReport(scoped_refptr<net::IOBufferWithSize> buffer); - void ProcessReadQueue(); - base::ScopedCFTypeRef<IOHIDDeviceRef> device_; - scoped_refptr<base::MessageLoopProxy> message_loop_; + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; std::vector<uint8_t> inbound_buffer_; std::queue<PendingHidReport> pending_reports_; |