summaryrefslogtreecommitdiffstats
path: root/device/hid/hid_connection.h
diff options
context:
space:
mode:
authorreillyg <reillyg@chromium.org>2014-08-26 12:10:15 -0700
committerCommit bot <commit-bot@chromium.org>2014-08-26 19:11:25 +0000
commit0e9bf9bc05be91d727134887b3c453353be1024d (patch)
treed8f05cc95f76c4452abcd1e229e00e27587a6ad0 /device/hid/hid_connection.h
parenteb08cced4cf6c7d271dd506a13cb889aaa6d45ad (diff)
downloadchromium_src-0e9bf9bc05be91d727134887b3c453353be1024d.zip
chromium_src-0e9bf9bc05be91d727134887b3c453353be1024d.tar.gz
chromium_src-0e9bf9bc05be91d727134887b3c453353be1024d.tar.bz2
Don't pass buffers to HidConnection::Read because it knows the size.
The HidConnection knows the appropriate read buffer size and the platform-specific implementation may already have a buffer that it is waiting to return to the next caller. Passing a buffer in is therefore unnecessary, one can be provided in the callback. By standardizing on a buffer format which always includes the report ID as the first byte (even when it is zero) most of the buffer copying can be removed except in the case of OS X's persistent read buffer and getting feature reports on Windows. BUG= Review URL: https://codereview.chromium.org/499713002 Cr-Commit-Position: refs/heads/master@{#291954}
Diffstat (limited to 'device/hid/hid_connection.h')
-rw-r--r--device/hid/hid_connection.h70
1 files changed, 38 insertions, 32 deletions
diff --git a/device/hid/hid_connection.h b/device/hid/hid_connection.h
index 631db1b..9d2503c2 100644
--- a/device/hid/hid_connection.h
+++ b/device/hid/hid_connection.h
@@ -22,23 +22,33 @@ class HidConnection : public base::RefCountedThreadSafe<HidConnection> {
kAnyReportId = 0xFF,
};
- typedef base::Callback<void(bool success, size_t size)> IOCallback;
+ typedef base::Callback<
+ void(bool success, scoped_refptr<net::IOBuffer> buffer, size_t size)>
+ ReadCallback;
+ typedef base::Callback<void(bool success)> WriteCallback;
const HidDeviceInfo& device_info() const { return device_info_; }
bool has_protected_collection() const { return has_protected_collection_; }
const base::ThreadChecker& thread_checker() const { return thread_checker_; }
- void Read(scoped_refptr<net::IOBufferWithSize> buffer,
- const IOCallback& callback);
- void Write(uint8_t report_id,
- scoped_refptr<net::IOBufferWithSize> buffer,
- const IOCallback& callback);
- void GetFeatureReport(uint8_t report_id,
- scoped_refptr<net::IOBufferWithSize> buffer,
- const IOCallback& callback);
- void SendFeatureReport(uint8_t report_id,
- scoped_refptr<net::IOBufferWithSize> buffer,
- const IOCallback& callback);
+ // The report ID (or 0 if report IDs are not supported by the device) is
+ // always returned in the first byte of the buffer.
+ void Read(const ReadCallback& callback);
+
+ // The report ID (or 0 if report IDs are not supported by the device) is
+ // always expected in the first byte of the buffer.
+ void Write(scoped_refptr<net::IOBuffer> buffer,
+ size_t size,
+ const WriteCallback& callback);
+
+ // The report ID is not returned in the buffer.
+ void GetFeatureReport(uint8_t report_id, const ReadCallback& callback);
+
+ // The report ID (or 0 if report IDs are not supported by the device) is
+ // always expected in the first byte of the buffer.
+ void SendFeatureReport(scoped_refptr<net::IOBuffer> buffer,
+ size_t size,
+ const WriteCallback& callback);
protected:
friend class base::RefCountedThreadSafe<HidConnection>;
@@ -46,31 +56,27 @@ class HidConnection : public base::RefCountedThreadSafe<HidConnection> {
explicit HidConnection(const HidDeviceInfo& device_info);
virtual ~HidConnection();
- virtual void PlatformRead(scoped_refptr<net::IOBufferWithSize> buffer,
- const IOCallback& callback) = 0;
- virtual void PlatformWrite(uint8_t report_id,
- scoped_refptr<net::IOBufferWithSize> buffer,
- const IOCallback& callback) = 0;
- virtual void PlatformGetFeatureReport(
- uint8_t report_id,
- scoped_refptr<net::IOBufferWithSize> buffer,
- const IOCallback& callback) = 0;
- virtual void PlatformSendFeatureReport(
- uint8_t report_id,
- scoped_refptr<net::IOBufferWithSize> buffer,
- const IOCallback& callback) = 0;
+ virtual void PlatformRead(const ReadCallback& callback) = 0;
+ virtual void PlatformWrite(scoped_refptr<net::IOBuffer> buffer,
+ size_t size,
+ const WriteCallback& callback) = 0;
+ virtual void PlatformGetFeatureReport(uint8_t report_id,
+ const ReadCallback& callback) = 0;
+ virtual void PlatformSendFeatureReport(scoped_refptr<net::IOBuffer> buffer,
+ size_t size,
+ const WriteCallback& callback) = 0;
// PlatformRead implementation must call this method on read
// success, rather than directly running the callback.
// In case incoming buffer is empty or protected, it is filtered
// and this method returns false. Otherwise it runs the callback
// and returns true.
- bool CompleteRead(scoped_refptr<net::IOBufferWithSize> buffer,
- int bytes_read,
- const IOCallback& callback);
+ bool CompleteRead(scoped_refptr<net::IOBuffer> buffer,
+ size_t size,
+ const ReadCallback& callback);
private:
- bool IsReportIdProtected(const uint8_t report_id);
+ bool IsReportIdProtected(uint8_t report_id);
const HidDeviceInfo device_info_;
bool has_protected_collection_;
@@ -83,15 +89,15 @@ struct PendingHidReport {
PendingHidReport();
~PendingHidReport();
- scoped_refptr<net::IOBufferWithSize> buffer;
+ scoped_refptr<net::IOBuffer> buffer;
+ size_t size;
};
struct PendingHidRead {
PendingHidRead();
~PendingHidRead();
- scoped_refptr<net::IOBufferWithSize> buffer;
- HidConnection::IOCallback callback;
+ HidConnection::ReadCallback callback;
};
} // namespace device