Commit ba2d79d6 authored by tdresser@chromium.org's avatar tdresser@chromium.org

Include external touchscreen vid/pid in UMA hardware profile

Previously we looked at including the touchscreen name in the UMA
hardware profile: https://codereview.chromium.org/23619085/.

As that posed a privacy concern, this patch includes the vid/pid
instead.

BUG=248910

Review URL: https://codereview.chromium.org/103893005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244210 0039d316-1c4b-4281-b951-d872f2087c98
parent 0c977433
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include "device/bluetooth/bluetooth_adapter_factory.h" #include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/bluetooth_device.h" #include "device/bluetooth/bluetooth_device.h"
#include "gpu/config/gpu_info.h" #include "gpu/config/gpu_info.h"
#include "ui/events/event_utils.h"
#include "ui/gfx/screen.h" #include "ui/gfx/screen.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -66,6 +67,7 @@ extern "C" IMAGE_DOS_HEADER __ImageBase; ...@@ -66,6 +67,7 @@ extern "C" IMAGE_DOS_HEADER __ImageBase;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/login/user_manager.h" #include "chrome/browser/chromeos/login/user_manager.h"
#include "ui/events/x/touch_factory_x11.h"
#endif #endif
using content::GpuDataManager; using content::GpuDataManager;
...@@ -380,6 +382,19 @@ PairedDevice::Type AsBluetoothDeviceType( ...@@ -380,6 +382,19 @@ PairedDevice::Type AsBluetoothDeviceType(
NOTREACHED(); NOTREACHED();
return PairedDevice::DEVICE_UNKNOWN; return PairedDevice::DEVICE_UNKNOWN;
} }
void WriteExternalTouchscreensProto(SystemProfileProto::Hardware* hardware) {
std::set<std::pair<int, int> > touchscreen_ids =
ui::TouchFactory::GetInstance()->GetTouchscreenIds();
for (std::set<std::pair<int, int> >::iterator it = touchscreen_ids.begin();
it != touchscreen_ids.end();
++it) {
SystemProfileProto::Hardware::TouchScreen* touchscreen =
hardware->add_external_touchscreen();
touchscreen->set_vendor_id(it->first);
touchscreen->set_product_id(it->second);
}
}
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
// Round a timestamp measured in seconds since epoch to one with a granularity // Round a timestamp measured in seconds since epoch to one with a granularity
...@@ -801,6 +816,9 @@ void MetricsLog::RecordEnvironment( ...@@ -801,6 +816,9 @@ void MetricsLog::RecordEnvironment(
uma_proto()->add_perf_data()->Swap(&perf_data_proto); uma_proto()->add_perf_data()->Swap(&perf_data_proto);
WriteBluetoothProto(hardware); WriteBluetoothProto(hardware);
hardware->set_internal_display_supports_touch(
ui::InternalDisplaySupportsTouch());
WriteExternalTouchscreensProto(hardware);
UpdateMultiProfileUserCount(); UpdateMultiProfileUserCount();
#endif #endif
......
...@@ -83,7 +83,7 @@ message SystemProfileProto { ...@@ -83,7 +83,7 @@ message SystemProfileProto {
} }
optional OS os = 5; optional OS os = 5;
// Next tag for Hardware: 14 // Next tag for Hardware: 16
// Information on the user's hardware. // Information on the user's hardware.
message Hardware { message Hardware {
// The CPU architecture (x86, PowerPC, x86_64, ...) // The CPU architecture (x86, PowerPC, x86_64, ...)
...@@ -219,6 +219,19 @@ message SystemProfileProto { ...@@ -219,6 +219,19 @@ message SystemProfileProto {
repeated PairedDevice paired_device = 3; repeated PairedDevice paired_device = 3;
} }
optional Bluetooth bluetooth = 11; optional Bluetooth bluetooth = 11;
// Whether the internal display produces touch events.
optional bool internal_display_supports_touch = 14;
// Vendor ids and product ids of external touchscreens.
message TouchScreen {
// Touch screen vendor id.
optional uint32 vendor_id = 1;
// Touch screen product id.
optional uint32 product_id = 2;
}
// Lists vendor and product ids of external touchscreens.
repeated TouchScreen external_touchscreen = 15;
} }
optional Hardware hardware = 6; optional Hardware hardware = 6;
......
...@@ -26,6 +26,10 @@ base::TimeDelta EventTimeForNow() { ...@@ -26,6 +26,10 @@ base::TimeDelta EventTimeForNow() {
} }
bool ShouldDefaultToNaturalScroll() { bool ShouldDefaultToNaturalScroll() {
return InternalDisplaySupportsTouch();
}
bool InternalDisplaySupportsTouch() {
gfx::Screen* screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE); gfx::Screen* screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE);
if (!screen) if (!screen)
return false; return false;
......
...@@ -133,6 +133,9 @@ EVENTS_EXPORT bool IsNaturalScrollEnabled(); ...@@ -133,6 +133,9 @@ EVENTS_EXPORT bool IsNaturalScrollEnabled();
// Returns whether natural scrolling should be used for touchpad. // Returns whether natural scrolling should be used for touchpad.
EVENTS_EXPORT bool ShouldDefaultToNaturalScroll(); EVENTS_EXPORT bool ShouldDefaultToNaturalScroll();
// Returns whether or not the internal display produces touch events.
EVENTS_EXPORT bool InternalDisplaySupportsTouch();
// Was this event generated by a touchpad device? // Was this event generated by a touchpad device?
// The caller is responsible for ensuring that this is a mouse/touchpad event // The caller is responsible for ensuring that this is a mouse/touchpad event
// before calling this function. // before calling this function.
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "ui/events/x/touch_factory_x11.h" #include "ui/events/x/touch_factory_x11.h"
#include <X11/Xatom.h>
#include <X11/cursorfont.h> #include <X11/cursorfont.h>
#include <X11/extensions/XInput.h> #include <X11/extensions/XInput.h>
#include <X11/extensions/XInput2.h> #include <X11/extensions/XInput2.h>
...@@ -81,6 +82,7 @@ void TouchFactory::UpdateDeviceList(Display* display) { ...@@ -81,6 +82,7 @@ void TouchFactory::UpdateDeviceList(Display* display) {
touch_device_available_ = false; touch_device_available_ = false;
touch_device_lookup_.reset(); touch_device_lookup_.reset();
touch_device_list_.clear(); touch_device_list_.clear();
touchscreen_ids_.clear();
max_touch_points_ = -1; max_touch_points_ = -1;
#if !defined(USE_XI2_MT) #if !defined(USE_XI2_MT)
...@@ -131,6 +133,7 @@ void TouchFactory::UpdateDeviceList(Display* display) { ...@@ -131,6 +133,7 @@ void TouchFactory::UpdateDeviceList(Display* display) {
reinterpret_cast<XITouchClassInfo *>(xiclassinfo); reinterpret_cast<XITouchClassInfo *>(xiclassinfo);
// Only care direct touch device (such as touch screen) right now // Only care direct touch device (such as touch screen) right now
if (tci->mode == XIDirectTouch) { if (tci->mode == XIDirectTouch) {
CacheTouchscreenIds(display, devinfo->deviceid);
touch_device_lookup_[devinfo->deviceid] = true; touch_device_lookup_[devinfo->deviceid] = true;
touch_device_list_[devinfo->deviceid] = true; touch_device_list_[devinfo->deviceid] = true;
touch_device_available_ = true; touch_device_available_ = true;
...@@ -268,4 +271,40 @@ void TouchFactory::SetPointerDeviceForTest( ...@@ -268,4 +271,40 @@ void TouchFactory::SetPointerDeviceForTest(
} }
} }
void TouchFactory::CacheTouchscreenIds(Display* display, int device_id) {
XDevice* device = XOpenDevice(display, device_id);
Atom actual_type_return;
int actual_format_return;
unsigned long nitems_return;
unsigned long bytes_after_return;
unsigned char *prop_return;
const char kDeviceProductIdString[] = "Device Product ID";
Atom device_product_id_atom =
XInternAtom(display, kDeviceProductIdString, false);
if (device_product_id_atom != None &&
XGetDeviceProperty(display, device, device_product_id_atom, 0, 2,
False, XA_INTEGER, &actual_type_return,
&actual_format_return, &nitems_return,
&bytes_after_return, &prop_return) == Success) {
if (actual_type_return == XA_INTEGER &&
actual_format_return == 32 &&
nitems_return == 2) {
// An actual_format_return of 32 implies that the returned data is an
// array of longs. See the description of |prop_return| in `man
// XGetDeviceProperty` for details.
long* ptr = reinterpret_cast<long*>(prop_return);
// Internal displays will have a vid and pid of 0. Ignore them.
// ptr[0] is the vid, and ptr[1] is the pid.
if (ptr[0] || ptr[1])
touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1]));
}
XFree(prop_return);
}
XCloseDevice(display, device);
}
} // namespace ui } // namespace ui
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <bitset> #include <bitset>
#include <map> #include <map>
#include <set>
#include <vector> #include <vector>
#include "base/timer/timer.h" #include "base/timer/timer.h"
...@@ -72,6 +73,11 @@ class EVENTS_BASE_EXPORT TouchFactory { ...@@ -72,6 +73,11 @@ class EVENTS_BASE_EXPORT TouchFactory {
// Whether any touch device is currently present and enabled. // Whether any touch device is currently present and enabled.
bool IsTouchDevicePresent(); bool IsTouchDevicePresent();
// Pairs of <vendor id, product id> of external touch screens.
const std::set<std::pair<int, int> >& GetTouchscreenIds() const {
return touchscreen_ids_;
}
// Return maximum simultaneous touch points supported by device. // Return maximum simultaneous touch points supported by device.
int GetMaxTouchPoints() const; int GetMaxTouchPoints() const;
...@@ -89,6 +95,8 @@ class EVENTS_BASE_EXPORT TouchFactory { ...@@ -89,6 +95,8 @@ class EVENTS_BASE_EXPORT TouchFactory {
// Requirement for Singleton // Requirement for Singleton
friend struct DefaultSingletonTraits<TouchFactory>; friend struct DefaultSingletonTraits<TouchFactory>;
void CacheTouchscreenIds(Display* display, int id);
// NOTE: To keep track of touch devices, we currently maintain a lookup table // NOTE: To keep track of touch devices, we currently maintain a lookup table
// to quickly decide if a device is a touch device or not. We also maintain a // to quickly decide if a device is a touch device or not. We also maintain a
// list of the touch devices. Ideally, there will be only one touch device, // list of the touch devices. Ideally, there will be only one touch device,
...@@ -111,6 +119,9 @@ class EVENTS_BASE_EXPORT TouchFactory { ...@@ -111,6 +119,9 @@ class EVENTS_BASE_EXPORT TouchFactory {
// Indicates whether touch events are explicitly disabled. // Indicates whether touch events are explicitly disabled.
bool touch_events_disabled_; bool touch_events_disabled_;
// Indicates whether the device's internal display produces touch events.
bool internal_display_supports_touch_;
// The list of touch devices. For testing/debugging purposes, a single-pointer // The list of touch devices. For testing/debugging purposes, a single-pointer
// device (mouse or touch screen without sufficient X/driver support for MT) // device (mouse or touch screen without sufficient X/driver support for MT)
// can sometimes be treated as a touch device. The key in the map represents // can sometimes be treated as a touch device. The key in the map represents
...@@ -118,6 +129,9 @@ class EVENTS_BASE_EXPORT TouchFactory { ...@@ -118,6 +129,9 @@ class EVENTS_BASE_EXPORT TouchFactory {
// capable. // capable.
std::map<int, bool> touch_device_list_; std::map<int, bool> touch_device_list_;
// Touch screen <vid, pid>s.
std::set<std::pair<int, int> > touchscreen_ids_;
// Maximum simultaneous touch points supported by device. In the case of // Maximum simultaneous touch points supported by device. In the case of
// devices with multiple digitizers (e.g. multiple touchscreens), the value // devices with multiple digitizers (e.g. multiple touchscreens), the value
// is the maximum of the set of maximum supported contacts by each individual // is the maximum of the set of maximum supported contacts by each individual
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment