summaryrefslogtreecommitdiffstats
path: root/device/hid/hid_device_info.h
diff options
context:
space:
mode:
authorreillyg <reillyg@chromium.org>2015-01-08 19:03:37 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-09 03:04:57 +0000
commitfbff124cc092ce78fe6b9dea129e9c1b8a2736dd (patch)
treed6f8db22097e352d1a9079aada72238dcc24ef68 /device/hid/hid_device_info.h
parent3538e8bc5f7d75b15fe6288d17998b5d0d495080 (diff)
downloadchromium_src-fbff124cc092ce78fe6b9dea129e9c1b8a2736dd.zip
chromium_src-fbff124cc092ce78fe6b9dea129e9c1b8a2736dd.tar.gz
chromium_src-fbff124cc092ce78fe6b9dea129e9c1b8a2736dd.tar.bz2
Convert HidDeviceInfo from a struct to a refcounted class.
The HidDeviceInfo object for a device is passed around a lot, including being copied every time enumeration of a device is requested. Since this data is constant once a device is enumerated it is better to keep one copy around for the device for as long as it is connected. This will make it similar to the device::UsbDevice class. I consider this a pre-requisite for storing more information in HidDeviceInfo such as the raw report descriptor. Later patches will revisit how this object is constructed and possibly reduce the number of friend classes. BUG=442818 Review URL: https://codereview.chromium.org/825523003 Cr-Commit-Position: refs/heads/master@{#310692}
Diffstat (limited to 'device/hid/hid_device_info.h')
-rw-r--r--device/hid/hid_device_info.h63
1 files changed, 50 insertions, 13 deletions
diff --git a/device/hid/hid_device_info.h b/device/hid/hid_device_info.h
index 917a129..7aae955 100644
--- a/device/hid/hid_device_info.h
+++ b/device/hid/hid_device_info.h
@@ -8,6 +8,7 @@
#include <string>
#include <vector>
+#include "base/memory/ref_counted.h"
#include "build/build_config.h"
#include "device/hid/hid_collection_info.h"
@@ -21,28 +22,64 @@ enum HidBusType {
typedef std::string HidDeviceId;
extern const char kInvalidHidDeviceId[];
-struct HidDeviceInfo {
+class HidDeviceInfo : public base::RefCountedThreadSafe<HidDeviceInfo> {
+ public:
HidDeviceInfo();
+
+ // Device identification.
+ const HidDeviceId& device_id() const { return device_id_; }
+ uint16_t vendor_id() const { return vendor_id_; }
+ uint16_t product_id() const { return product_id_; }
+ const std::string& product_name() const { return product_name_; }
+ const std::string& serial_number() const { return serial_number_; }
+ HidBusType bus_type() const { return bus_type_; }
+
+ // Top-Level Collections information.
+ const std::vector<HidCollectionInfo>& collections() const {
+ return collections_;
+ }
+ bool has_report_id() const { return has_report_id_; };
+ size_t max_input_report_size() const { return max_input_report_size_; }
+ size_t max_output_report_size() const { return max_output_report_size_; }
+ size_t max_feature_report_size() const { return max_feature_report_size_; }
+
+#if defined(OS_LINUX)
+ const std::string& device_node() const { return device_node_; }
+#endif
+
+ private:
+ friend class base::RefCountedThreadSafe<HidDeviceInfo>;
+
+ // TODO(reillyg): Define public constructors that make some of these
+ // declarations unnecessary.
+ friend class HidServiceLinux;
+ friend class HidServiceMac;
+ friend class HidServiceWin;
+ friend class MockHidService;
+ friend class HidFilterTest;
+
~HidDeviceInfo();
// Device identification.
- HidDeviceId device_id;
- uint16_t vendor_id;
- uint16_t product_id;
- std::string product_name;
- std::string serial_number;
- HidBusType bus_type;
+ HidDeviceId device_id_;
+ uint16_t vendor_id_;
+ uint16_t product_id_;
+ std::string product_name_;
+ std::string serial_number_;
+ HidBusType bus_type_;
// Top-Level Collections information.
- std::vector<HidCollectionInfo> collections;
- bool has_report_id;
- size_t max_input_report_size;
- size_t max_output_report_size;
- size_t max_feature_report_size;
+ std::vector<HidCollectionInfo> collections_;
+ bool has_report_id_;
+ size_t max_input_report_size_;
+ size_t max_output_report_size_;
+ size_t max_feature_report_size_;
#if defined(OS_LINUX)
- std::string device_node;
+ std::string device_node_;
#endif
+
+ DISALLOW_COPY_AND_ASSIGN(HidDeviceInfo);
};
} // namespace device