Commit e09a9b07 authored by sheckylin's avatar sheckylin Committed by Commit bot

Dump property values for the touch log source

The CL dumps gesture property values for touch devices that run
with the CrOS gesture library. The format is designed to be
backward-compatible with the X11 behaviour.

Contributed by sheckylin@chromium.org

BUG=450159
TEST=samus ChromeOS build

Committed: https://crrev.com/8b1fb4fdf2b13b71e969cd541e500549163f742b
Cr-Commit-Position: refs/heads/master@{#313446}

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

Cr-Commit-Position: refs/heads/master@{#313555}
parent b0306a48
...@@ -6,12 +6,17 @@ ...@@ -6,12 +6,17 @@
#include "ash/touch/touch_hud_debug.h" #include "ash/touch/touch_hud_debug.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/json/json_string_value_serializer.h" #include "base/json/json_string_value_serializer.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/process/launch.h" #include "base/process/launch.h"
#include "components/feedback/feedback_util.h" #include "components/feedback/feedback_util.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "ui/ozone/public/input_controller.h"
#include "ui/ozone/public/ozone_platform.h"
using content::BrowserThread; using content::BrowserThread;
...@@ -19,7 +24,26 @@ namespace { ...@@ -19,7 +24,26 @@ namespace {
const char kHUDLogDataKey[] = "hud_log"; const char kHUDLogDataKey[] = "hud_log";
void GetTouchLogsOzone(system_logs::SystemLogsResponse* response) { // The prefix "hack-33025" was historically chosen in http://crbug.com/139715.
// We continue to go with it in order to be compatible with the existing touch
// log processing toolchain.
const char kDeviceStatusLogDataKey[] = "hack-33025-touchpad";
// Callback for handing the outcome of GetTouchDeviceStatus(). Appends the
// collected log to the SystemLogsResponse map.
void OnStatusLogCollected(scoped_ptr<system_logs::SystemLogsResponse> response,
const system_logs::SysLogsSourceCallback& callback,
scoped_ptr<std::string> log) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(*response)[kDeviceStatusLogDataKey] = *log;
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(callback, base::Owned(response.release())));
}
// Collect touch HUD debug logs. This needs to be done on the UI thread.
void CollectTouchHudDebugLog(system_logs::SystemLogsResponse* response) {
scoped_ptr<base::DictionaryValue> dictionary = scoped_ptr<base::DictionaryValue> dictionary =
ash::TouchHudDebug::GetAllAsDictionary(); ash::TouchHudDebug::GetAllAsDictionary();
if (!dictionary->empty()) { if (!dictionary->empty()) {
...@@ -29,10 +53,6 @@ void GetTouchLogsOzone(system_logs::SystemLogsResponse* response) { ...@@ -29,10 +53,6 @@ void GetTouchLogsOzone(system_logs::SystemLogsResponse* response) {
if (json.Serialize(*dictionary) && !touch_log.empty()) if (json.Serialize(*dictionary) && !touch_log.empty())
(*response)[kHUDLogDataKey] = touch_log; (*response)[kHUDLogDataKey] = touch_log;
} }
// TODO(sheckylin): Add ozone touch log collection implementation. See
// http://crbug.com/400022.
NOTIMPLEMENTED();
} }
} // namespace } // namespace
...@@ -43,10 +63,12 @@ void TouchLogSource::Fetch(const SysLogsSourceCallback& callback) { ...@@ -43,10 +63,12 @@ void TouchLogSource::Fetch(const SysLogsSourceCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
SystemLogsResponse* response = new SystemLogsResponse; scoped_ptr<SystemLogsResponse> response(new SystemLogsResponse);
BrowserThread::PostBlockingPoolTaskAndReply( CollectTouchHudDebugLog(response.get());
FROM_HERE, base::Bind(&GetTouchLogsOzone, response),
base::Bind(callback, base::Owned(response))); // Collect touch device status logs.
ui::OzonePlatform::GetInstance()->GetInputController()->GetTouchDeviceStatus(
base::Bind(&OnStatusLogCollected, base::Passed(&response), callback));
} }
} // namespace system_logs } // namespace system_logs
...@@ -4,9 +4,13 @@ ...@@ -4,9 +4,13 @@
#include "ui/events/ozone/evdev/input_controller_evdev.h" #include "ui/events/ozone/evdev/input_controller_evdev.h"
#include <algorithm>
#include <linux/input.h> #include <linux/input.h>
#include <vector> #include <vector>
#include "base/bind.h"
#include "base/strings/stringprintf.h"
#include "base/thread_task_runner_handle.h"
#include "ui/events/ozone/evdev/event_factory_evdev.h" #include "ui/events/ozone/evdev/event_factory_evdev.h"
#include "ui/events/ozone/evdev/mouse_button_map_evdev.h" #include "ui/events/ozone/evdev/mouse_button_map_evdev.h"
...@@ -40,6 +44,74 @@ void SetGestureBoolProperty(GesturePropertyProvider* provider, ...@@ -40,6 +44,74 @@ void SetGestureBoolProperty(GesturePropertyProvider* provider,
property->SetBoolValue(values); property->SetBoolValue(values);
} }
} }
// Return the values in an array in one string. Used for touch logging.
template <typename T>
std::string DumpArrayProperty(const std::vector<T>& value, const char* format) {
std::string ret;
for (size_t i = 0; i < value.size(); ++i) {
if (i > 0)
ret.append(", ");
ret.append(base::StringPrintf(format, value[i]));
}
return ret;
}
// Return the values in a gesture property in one string. Used for touch
// logging.
std::string DumpGesturePropertyValue(GesturesProp* property) {
switch (property->type()) {
case GesturePropertyProvider::PT_INT:
return DumpArrayProperty(property->GetIntValue(), "%d");
break;
case GesturePropertyProvider::PT_SHORT:
return DumpArrayProperty(property->GetShortValue(), "%d");
break;
case GesturePropertyProvider::PT_BOOL:
return DumpArrayProperty(property->GetBoolValue(), "%d");
break;
case GesturePropertyProvider::PT_STRING:
return "\"" + property->GetStringValue() + "\"";
break;
case GesturePropertyProvider::PT_REAL:
return DumpArrayProperty(property->GetDoubleValue(), "%lf");
break;
default:
NOTREACHED();
break;
}
return std::string();
}
// Dump touch device property values to a string.
void DumpTouchDeviceStatus(EventFactoryEvdev* event_factory,
GesturePropertyProvider* provider,
std::string* status) {
// We use DT_ALL since we want gesture property values for all devices that
// run with the gesture library, not just mice or touchpads.
std::vector<int> ids;
event_factory->GetDeviceIdsByType(DT_ALL, &ids);
// Dump the property names and values for each device.
for (size_t i = 0; i < ids.size(); ++i) {
std::vector<std::string> names = provider->GetPropertyNamesById(ids[i]);
status->append("\n");
status->append(base::StringPrintf("ID %d:\n", ids[i]));
status->append(base::StringPrintf(
"Device \'%s\':\n", provider->GetDeviceNameById(ids[i]).c_str()));
// Note that, unlike X11, we don't maintain the "atom" concept here.
// Therefore, the property name indices we output here shouldn't be treated
// as unique identifiers of the properties.
std::sort(names.begin(), names.end());
for (size_t j = 0; j < names.size(); ++j) {
status->append(base::StringPrintf("\t%s (%zu):", names[j].c_str(), j));
GesturesProp* property = provider->GetProperty(ids[i], names[j]);
status->append("\t" + DumpGesturePropertyValue(property) + '\n');
}
}
}
#endif #endif
} // namespace } // namespace
...@@ -184,4 +256,18 @@ void InputControllerEvdev::SetTapToClickPaused(bool state) { ...@@ -184,4 +256,18 @@ void InputControllerEvdev::SetTapToClickPaused(bool state) {
SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state); SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state);
} }
void InputControllerEvdev::GetTouchDeviceStatus(
const GetTouchDeviceStatusReply& reply) {
scoped_ptr<std::string> status(new std::string);
#if defined(USE_EVDEV_GESTURES)
std::string* status_ptr = status.get();
base::ThreadTaskRunnerHandle::Get()->PostTaskAndReply(
FROM_HERE, base::Bind(&DumpTouchDeviceStatus, event_factory_,
gesture_property_provider_, status_ptr),
base::Bind(reply, base::Passed(&status)));
#else
reply.Run(status.Pass());
#endif
}
} // namespace ui } // namespace ui
...@@ -55,6 +55,7 @@ class EVENTS_OZONE_EVDEV_EXPORT InputControllerEvdev : public InputController { ...@@ -55,6 +55,7 @@ class EVENTS_OZONE_EVDEV_EXPORT InputControllerEvdev : public InputController {
void SetMouseSensitivity(int value) override; void SetMouseSensitivity(int value) override;
void SetPrimaryButtonRight(bool right) override; void SetPrimaryButtonRight(bool right) override;
void SetTapToClickPaused(bool state) override; void SetTapToClickPaused(bool state) override;
void GetTouchDeviceStatus(const GetTouchDeviceStatusReply& reply) override;
void DisableInternalTouchpad() override; void DisableInternalTouchpad() override;
void EnableInternalTouchpad() override; void EnableInternalTouchpad() override;
void DisableInternalKeyboardExceptKeys( void DisableInternalKeyboardExceptKeys(
......
...@@ -877,6 +877,30 @@ GesturesProp* GesturePropertyProvider::GetProperty(const DeviceId device_id, ...@@ -877,6 +877,30 @@ GesturesProp* GesturePropertyProvider::GetProperty(const DeviceId device_id,
return FindProperty(device_id, name); return FindProperty(device_id, name);
} }
std::vector<std::string> GesturePropertyProvider::GetPropertyNamesById(
const DeviceId device_id) {
internal::GestureDevicePropertyData* device_data =
device_data_map_.get(device_id);
if (!device_data)
return std::vector<std::string>();
// Dump all property names of the device.
std::vector<std::string> names;
for (internal::ScopedPropertiesMap::const_iterator it =
device_data->properties.begin();
it != device_data->properties.end(); ++it)
names.push_back(it->first);
return names;
}
std::string GesturePropertyProvider::GetDeviceNameById(
const DeviceId device_id) {
DeviceMap::const_iterator it = device_map_.find(device_id);
if (it == device_map_.end())
return std::string();
return std::string(it->second->info.name);
}
void GesturePropertyProvider::RegisterDevice(const DeviceId id, void GesturePropertyProvider::RegisterDevice(const DeviceId id,
const DevicePtr device) { const DevicePtr device) {
DeviceMap::const_iterator it = device_map_.find(id); DeviceMap::const_iterator it = device_map_.find(id);
......
...@@ -96,6 +96,13 @@ class EVENTS_OZONE_EVDEV_EXPORT GesturePropertyProvider { ...@@ -96,6 +96,13 @@ class EVENTS_OZONE_EVDEV_EXPORT GesturePropertyProvider {
// clicked "OK"). // clicked "OK").
GesturesProp* GetProperty(const DeviceId device_id, const std::string& name); GesturesProp* GetProperty(const DeviceId device_id, const std::string& name);
// Get the names of all properties of one device. Mostly used for the logging
// purpose.
std::vector<std::string> GetPropertyNamesById(const DeviceId device_id);
// Get the (Evdev) device name. Mostly used for the logging purpose.
std::string GetDeviceNameById(const DeviceId device_id);
private: private:
friend class GesturesPropFunctionsWrapper; friend class GesturesPropFunctionsWrapper;
......
...@@ -36,6 +36,7 @@ class StubInputController : public InputController { ...@@ -36,6 +36,7 @@ class StubInputController : public InputController {
void SetMouseSensitivity(int value) override; void SetMouseSensitivity(int value) override;
void SetPrimaryButtonRight(bool right) override; void SetPrimaryButtonRight(bool right) override;
void SetTapToClickPaused(bool state) override; void SetTapToClickPaused(bool state) override;
void GetTouchDeviceStatus(const GetTouchDeviceStatusReply& reply) override;
void DisableInternalTouchpad() override; void DisableInternalTouchpad() override;
void EnableInternalTouchpad() override; void EnableInternalTouchpad() override;
void DisableInternalKeyboardExceptKeys( void DisableInternalKeyboardExceptKeys(
...@@ -124,6 +125,11 @@ void StubInputController::SetTapToClickPaused(bool state) { ...@@ -124,6 +125,11 @@ void StubInputController::SetTapToClickPaused(bool state) {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
void StubInputController::GetTouchDeviceStatus(
const GetTouchDeviceStatusReply& reply) {
reply.Run(scoped_ptr<std::string>(new std::string));
}
void StubInputController::DisableInternalTouchpad() { void StubInputController::DisableInternalTouchpad() {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
......
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
#define UI_OZONE_PUBLIC_INPUT_CONTROLLER_H_ #define UI_OZONE_PUBLIC_INPUT_CONTROLLER_H_
#include <set> #include <set>
#include <string>
#include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "ui/ozone/ozone_export.h" #include "ui/ozone/ozone_export.h"
...@@ -26,6 +28,9 @@ enum class DomCode; ...@@ -26,6 +28,9 @@ enum class DomCode;
// script that is originally located at /opt/google/chrome/. // script that is originally located at /opt/google/chrome/.
class OZONE_EXPORT InputController { class OZONE_EXPORT InputController {
public: public:
typedef base::Callback<void(scoped_ptr<std::string>)>
GetTouchDeviceStatusReply;
InputController() {} InputController() {}
virtual ~InputController() {} virtual ~InputController() {}
...@@ -55,6 +60,9 @@ class OZONE_EXPORT InputController { ...@@ -55,6 +60,9 @@ class OZONE_EXPORT InputController {
virtual void SetMouseSensitivity(int value) = 0; virtual void SetMouseSensitivity(int value) = 0;
virtual void SetPrimaryButtonRight(bool right) = 0; virtual void SetPrimaryButtonRight(bool right) = 0;
// Touch log collection.
virtual void GetTouchDeviceStatus(const GetTouchDeviceStatusReply& reply) = 0;
// Temporarily enable/disable Tap-to-click. Used to enhance the user // Temporarily enable/disable Tap-to-click. Used to enhance the user
// experience in some use cases (e.g., typing, watching video). // experience in some use cases (e.g., typing, watching video).
virtual void SetTapToClickPaused(bool state) = 0; virtual void SetTapToClickPaused(bool state) = 0;
......
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