Commit cc693d13 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Refactor ash::TouchUMA

- make it a collection of statics instead of a singleton object
- move to //ash/public
- use it in BrowserNonClientFrameViewAsh to match
  ash::WorkspaceEventHandler

Bug: none
Change-Id: I64f290e63f6f729239b52a67f84c39e62f04c4f1
Reviewed-on: https://chromium-review.googlesource.com/c/1406301Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#622129}
parent e7a484c5
......@@ -1055,8 +1055,6 @@ component("ash") {
"touch/touch_devices_controller.cc",
"touch/touch_devices_controller.h",
"touch/touch_observer_hud.cc",
"touch/touch_uma.cc",
"touch/touch_uma.h",
"tray_action/tray_action.cc",
"tray_action/tray_action.h",
"tray_action/tray_action_observer.h",
......
......@@ -112,6 +112,8 @@ component("cpp") {
"system_tray_focus_observer.h",
"tablet_mode.cc",
"tablet_mode.h",
"touch_uma.cc",
"touch_uma.h",
"wallpaper_types.h",
"window_animation_types.h",
"window_pin_type.cc",
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/touch/touch_uma.h"
#include "ash/public/cpp/touch_uma.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
......@@ -26,17 +26,53 @@ struct WindowTouchDetails {
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(WindowTouchDetails,
kWindowTouchDetails,
NULL);
}
} // namespace
DEFINE_UI_CLASS_PROPERTY_TYPE(WindowTouchDetails*);
namespace ash {
// static
TouchUMA* TouchUMA::GetInstance() {
return base::Singleton<TouchUMA>::get();
namespace {
GestureActionType FindGestureActionType(aura::Window* window,
const ui::GestureEvent& event) {
if (!window || window->GetRootWindow() == window) {
if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN)
return GESTURE_BEZEL_SCROLL;
if (event.type() == ui::ET_GESTURE_BEGIN)
return GESTURE_BEZEL_DOWN;
return GESTURE_UNKNOWN;
}
std::string name = window ? window->GetName() : std::string();
const char kWallpaperView[] = "WallpaperView";
if (name == kWallpaperView) {
if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN)
return GESTURE_DESKTOP_SCROLL;
if (event.type() == ui::ET_GESTURE_PINCH_BEGIN)
return GESTURE_DESKTOP_PINCH;
return GESTURE_UNKNOWN;
}
const char kWebPage[] = "RenderWidgetHostViewAura";
if (name == kWebPage) {
if (event.type() == ui::ET_GESTURE_PINCH_BEGIN)
return GESTURE_WEBPAGE_PINCH;
if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN)
return GESTURE_WEBPAGE_SCROLL;
if (event.type() == ui::ET_GESTURE_TAP)
return GESTURE_WEBPAGE_TAP;
return GESTURE_UNKNOWN;
}
return GESTURE_UNKNOWN;
}
} // namespace
// static
void TouchUMA::RecordGestureEvent(aura::Window* target,
const ui::GestureEvent& event) {
GestureActionType action = FindGestureActionType(target, event);
......@@ -54,12 +90,14 @@ void TouchUMA::RecordGestureEvent(aura::Window* target,
}
}
// static
void TouchUMA::RecordGestureAction(GestureActionType action) {
if (action == GESTURE_UNKNOWN || action >= GESTURE_ACTION_COUNT)
return;
UMA_HISTOGRAM_ENUMERATION("Ash.GestureTarget", action, GESTURE_ACTION_COUNT);
}
// static
void TouchUMA::RecordTouchEvent(aura::Window* target,
const ui::TouchEvent& event) {
WindowTouchDetails* details = target->GetProperty(kWindowTouchDetails);
......@@ -89,44 +127,4 @@ void TouchUMA::RecordTouchEvent(aura::Window* target,
}
}
TouchUMA::TouchUMA() = default;
TouchUMA::~TouchUMA() = default;
GestureActionType TouchUMA::FindGestureActionType(
aura::Window* window,
const ui::GestureEvent& event) {
if (!window || window->GetRootWindow() == window) {
if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN)
return GESTURE_BEZEL_SCROLL;
if (event.type() == ui::ET_GESTURE_BEGIN)
return GESTURE_BEZEL_DOWN;
return GESTURE_UNKNOWN;
}
std::string name = window ? window->GetName() : std::string();
const char kWallpaperView[] = "WallpaperView";
if (name == kWallpaperView) {
if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN)
return GESTURE_DESKTOP_SCROLL;
if (event.type() == ui::ET_GESTURE_PINCH_BEGIN)
return GESTURE_DESKTOP_PINCH;
return GESTURE_UNKNOWN;
}
const char kWebPage[] = "RenderWidgetHostViewAura";
if (name == kWebPage) {
if (event.type() == ui::ET_GESTURE_PINCH_BEGIN)
return GESTURE_WEBPAGE_PINCH;
if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN)
return GESTURE_WEBPAGE_SCROLL;
if (event.type() == ui::ET_GESTURE_TAP)
return GESTURE_WEBPAGE_TAP;
return GESTURE_UNKNOWN;
}
return GESTURE_UNKNOWN;
}
} // namespace ash
......@@ -2,13 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_TOUCH_TOUCH_OBSERVER_UMA_H_
#define ASH_TOUCH_TOUCH_OBSERVER_UMA_H_
#ifndef ASH_PUBLIC_CPP_TOUCH_UMA_H_
#define ASH_PUBLIC_CPP_TOUCH_UMA_H_
#include "ash/ash_export.h"
#include "ash/public/cpp/ash_public_export.h"
#include "ash/public/cpp/gesture_action_type.h"
#include "base/macros.h"
#include "base/memory/singleton.h"
namespace aura {
class Window;
......@@ -17,35 +16,24 @@ class Window;
namespace ui {
class GestureEvent;
class TouchEvent;
}
} // namespace ui
namespace ash {
// Records some touch/gesture event specific details (e.g. what gestures are
// targeted to which components etc.)
class ASH_EXPORT TouchUMA {
class ASH_PUBLIC_EXPORT TouchUMA {
public:
// Returns the singleton instance.
static TouchUMA* GetInstance();
void RecordGestureEvent(aura::Window* target, const ui::GestureEvent& event);
void RecordGestureAction(GestureActionType action);
void RecordTouchEvent(aura::Window* target, const ui::TouchEvent& event);
static void RecordGestureEvent(aura::Window* target,
const ui::GestureEvent& event);
static void RecordGestureAction(GestureActionType action);
static void RecordTouchEvent(aura::Window* target,
const ui::TouchEvent& event);
private:
friend struct base::DefaultSingletonTraits<TouchUMA>;
TouchUMA();
~TouchUMA();
GestureActionType FindGestureActionType(aura::Window* window,
const ui::GestureEvent& event);
base::TimeTicks last_touch_down_time_;
DISALLOW_COPY_AND_ASSIGN(TouchUMA);
DISALLOW_IMPLICIT_CONSTRUCTORS(TouchUMA);
};
} // namespace ash
#endif // ASH_TOUCH_TOUCH_OBSERVER_UMA_H_
#endif // ASH_PUBLIC_CPP_TOUCH_UMA_H_
......@@ -4,7 +4,7 @@
#include "ash/wm/system_gesture_event_filter.h"
#include "ash/touch/touch_uma.h"
#include "ash/public/cpp/touch_uma.h"
#include "ash/wm/gestures/overview_gesture_handler.h"
#include "base/metrics/user_metrics.h"
#include "ui/aura/window.h"
......@@ -36,12 +36,12 @@ void SystemGestureEventFilter::OnScrollEvent(ui::ScrollEvent* event) {
void SystemGestureEventFilter::OnTouchEvent(ui::TouchEvent* event) {
aura::Window* target = static_cast<aura::Window*>(event->target());
TouchUMA::GetInstance()->RecordTouchEvent(target, *event);
TouchUMA::RecordTouchEvent(target, *event);
}
void SystemGestureEventFilter::OnGestureEvent(ui::GestureEvent* event) {
aura::Window* target = static_cast<aura::Window*>(event->target());
TouchUMA::GetInstance()->RecordGestureEvent(target, *event);
TouchUMA::RecordGestureEvent(target, *event);
}
} // namespace ash
......@@ -4,7 +4,7 @@
#include "ash/wm/workspace/workspace_event_handler.h"
#include "ash/touch/touch_uma.h"
#include "ash/public/cpp/touch_uma.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "ash/wm/wm_event.h"
......@@ -87,14 +87,14 @@ void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) {
return;
if (event->details().tap_count() != 2) {
TouchUMA::GetInstance()->RecordGestureAction(GESTURE_FRAMEVIEW_TAP);
TouchUMA::RecordGestureAction(GESTURE_FRAMEVIEW_TAP);
return;
}
if (click_component_ == previous_target_component) {
base::RecordAction(
base::UserMetricsAction("Caption_GestureTogglesMaximize"));
TouchUMA::GetInstance()->RecordGestureAction(GESTURE_MAXIMIZE_DOUBLETAP);
TouchUMA::RecordGestureAction(GESTURE_MAXIMIZE_DOUBLETAP);
const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION);
wm::GetWindowState(target)->OnWMEvent(&wm_event);
event->StopPropagation();
......
......@@ -15,12 +15,14 @@
#include "ash/public/cpp/default_frame_header.h"
#include "ash/public/cpp/frame_utils.h"
#include "ash/public/cpp/tablet_mode.h"
#include "ash/public/cpp/touch_uma.h"
#include "ash/public/cpp/window_pin_type.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/public/interfaces/constants.mojom.h"
#include "ash/public/interfaces/window_state_type.mojom.h"
#include "ash/wm/window_util.h" // mash-ok
#include "base/command_line.h"
#include "base/metrics/user_metrics.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/profiles/profiles_state.h"
......@@ -522,10 +524,13 @@ void BrowserNonClientFrameViewAsh::OnGestureEvent(ui::GestureEvent* event) {
switch (event->type()) {
case ui::ET_GESTURE_TAP:
if (event->details().tap_count() == 2) {
// TODO(estade): need to log TouchUMA for GESTURE_MAXIMIZE_DOUBLETAP and
// GESTURE_FRAMEVIEW_TAP, as in WorkspaceEventHandler.
ash_window_manager_->MaximizeWindowByCaptionClick(
GetServerWindowId(), ui::mojom::PointerKind::TOUCH);
base::RecordAction(
base::UserMetricsAction("Caption_GestureTogglesMaximize"));
ash::TouchUMA::RecordGestureAction(ash::GESTURE_MAXIMIZE_DOUBLETAP);
} else {
ash::TouchUMA::RecordGestureAction(ash::GESTURE_FRAMEVIEW_TAP);
}
break;
......
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