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.cc | |
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.cc')
-rw-r--r-- | device/hid/hid_connection.cc | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/device/hid/hid_connection.cc b/device/hid/hid_connection.cc index 5df2a01..5ff39f3 100644 --- a/device/hid/hid_connection.cc +++ b/device/hid/hid_connection.cc @@ -64,12 +64,21 @@ bool HasProtectedCollection(const HidDeviceInfo& device_info) { } // namespace HidConnection::HidConnection(const HidDeviceInfo& device_info) - : device_info_(device_info) { + : device_info_(device_info), closed_(false) { has_protected_collection_ = HasProtectedCollection(device_info); } HidConnection::~HidConnection() { DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK(closed_); +} + +void HidConnection::Close() { + DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK(!closed_); + + PlatformClose(); + closed_ = true; } void HidConnection::Read(const ReadCallback& callback) { |