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

Unified Diff: device/hid/hid_connection.h

Issue 499713002: Don't pass buffers to HidConnection::Read because it knows the size. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed rockot@'s nits. Created 6 years, 4 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | device/hid/hid_connection.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/hid/hid_connection.h
diff --git a/device/hid/hid_connection.h b/device/hid/hid_connection.h
index 631db1bebe16e4ce709e2d0c4535ec432bef1b88..9d2503c275285c8e528b60dd7fd8ac7e0803006e 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
« no previous file with comments | « no previous file | device/hid/hid_connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698