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/1406301
Reviewed-by: Michael Wasserman <msw@chromium.org>
Reviewed-by: James Cook <jamescook@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#622129}
diff --git a/ash/BUILD.gn b/ash/BUILD.gn
index ae5f1ff..07fb30c 100644
--- a/ash/BUILD.gn
+++ b/ash/BUILD.gn
@@ -1055,8 +1055,6 @@
     "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",
diff --git a/ash/public/cpp/BUILD.gn b/ash/public/cpp/BUILD.gn
index 10d1f54..7d5e4860 100644
--- a/ash/public/cpp/BUILD.gn
+++ b/ash/public/cpp/BUILD.gn
@@ -112,6 +112,8 @@
     "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",
diff --git a/ash/touch/touch_uma.cc b/ash/public/cpp/touch_uma.cc
similarity index 92%
rename from ash/touch/touch_uma.cc
rename to ash/public/cpp/touch_uma.cc
index 8782b2f..d8f5409 100644
--- a/ash/touch/touch_uma.cc
+++ b/ash/public/cpp/touch_uma.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,76 +26,17 @@
 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 {
 
-void TouchUMA::RecordGestureEvent(aura::Window* target,
-                                  const ui::GestureEvent& event) {
-  GestureActionType action = FindGestureActionType(target, event);
-  RecordGestureAction(action);
-
-  if (event.type() == ui::ET_GESTURE_END &&
-      event.details().touch_points() == 2) {
-    WindowTouchDetails* details = target->GetProperty(kWindowTouchDetails);
-    if (!details) {
-      LOG(ERROR) << "Window received gesture events without receiving any touch"
-                    " events";
-      return;
-    }
-    details->last_mt_time_ = event.time_stamp();
-  }
-}
-
-void TouchUMA::RecordGestureAction(GestureActionType action) {
-  if (action == GESTURE_UNKNOWN || action >= GESTURE_ACTION_COUNT)
-    return;
-  UMA_HISTOGRAM_ENUMERATION("Ash.GestureTarget", action, GESTURE_ACTION_COUNT);
-}
-
-void TouchUMA::RecordTouchEvent(aura::Window* target,
-                                const ui::TouchEvent& event) {
-  WindowTouchDetails* details = target->GetProperty(kWindowTouchDetails);
-  if (!details) {
-    details = new WindowTouchDetails;
-    target->SetProperty(kWindowTouchDetails, details);
-  }
-
-  if (event.type() == ui::ET_TOUCH_PRESSED) {
-    base::RecordAction(base::UserMetricsAction("Touchscreen_Down"));
-
-    if (details->last_release_time_) {
-      // Measuring the interval between a touch-release and the next
-      // touch-start is probably less useful when doing multi-touch (e.g.
-      // gestures, or multi-touch friendly apps). So count this only if the user
-      // hasn't done any multi-touch during the last 30 seconds.
-      base::TimeDelta diff = event.time_stamp() -
-                             details->last_mt_time_.value_or(base::TimeTicks());
-      if (diff.InSeconds() > 30) {
-        base::TimeDelta gap = event.time_stamp() - *details->last_release_time_;
-        UMA_HISTOGRAM_COUNTS_10000("Ash.TouchStartAfterEnd",
-                                   gap.InMilliseconds());
-      }
-    }
-  } else if (event.type() == ui::ET_TOUCH_RELEASED) {
-    details->last_release_time_ = event.time_stamp();
-  }
-}
-
-TouchUMA::TouchUMA() = default;
-
-TouchUMA::~TouchUMA() = default;
-
-GestureActionType TouchUMA::FindGestureActionType(
-    aura::Window* window,
-    const ui::GestureEvent& event) {
+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;
@@ -129,4 +70,61 @@
   return GESTURE_UNKNOWN;
 }
 
+}  // namespace
+
+// static
+void TouchUMA::RecordGestureEvent(aura::Window* target,
+                                  const ui::GestureEvent& event) {
+  GestureActionType action = FindGestureActionType(target, event);
+  RecordGestureAction(action);
+
+  if (event.type() == ui::ET_GESTURE_END &&
+      event.details().touch_points() == 2) {
+    WindowTouchDetails* details = target->GetProperty(kWindowTouchDetails);
+    if (!details) {
+      LOG(ERROR) << "Window received gesture events without receiving any touch"
+                    " events";
+      return;
+    }
+    details->last_mt_time_ = event.time_stamp();
+  }
+}
+
+// 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);
+  if (!details) {
+    details = new WindowTouchDetails;
+    target->SetProperty(kWindowTouchDetails, details);
+  }
+
+  if (event.type() == ui::ET_TOUCH_PRESSED) {
+    base::RecordAction(base::UserMetricsAction("Touchscreen_Down"));
+
+    if (details->last_release_time_) {
+      // Measuring the interval between a touch-release and the next
+      // touch-start is probably less useful when doing multi-touch (e.g.
+      // gestures, or multi-touch friendly apps). So count this only if the user
+      // hasn't done any multi-touch during the last 30 seconds.
+      base::TimeDelta diff = event.time_stamp() -
+                             details->last_mt_time_.value_or(base::TimeTicks());
+      if (diff.InSeconds() > 30) {
+        base::TimeDelta gap = event.time_stamp() - *details->last_release_time_;
+        UMA_HISTOGRAM_COUNTS_10000("Ash.TouchStartAfterEnd",
+                                   gap.InMilliseconds());
+      }
+    }
+  } else if (event.type() == ui::ET_TOUCH_RELEASED) {
+    details->last_release_time_ = event.time_stamp();
+  }
+}
+
 }  // namespace ash
diff --git a/ash/public/cpp/touch_uma.h b/ash/public/cpp/touch_uma.h
new file mode 100644
index 0000000..6bcef74
--- /dev/null
+++ b/ash/public/cpp/touch_uma.h
@@ -0,0 +1,39 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_PUBLIC_CPP_TOUCH_UMA_H_
+#define ASH_PUBLIC_CPP_TOUCH_UMA_H_
+
+#include "ash/public/cpp/ash_public_export.h"
+#include "ash/public/cpp/gesture_action_type.h"
+#include "base/macros.h"
+
+namespace aura {
+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_PUBLIC_EXPORT TouchUMA {
+ public:
+  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:
+  DISALLOW_IMPLICIT_CONSTRUCTORS(TouchUMA);
+};
+
+}  // namespace ash
+
+#endif  // ASH_PUBLIC_CPP_TOUCH_UMA_H_
diff --git a/ash/touch/touch_uma.h b/ash/touch/touch_uma.h
deleted file mode 100644
index 29ad516..0000000
--- a/ash/touch/touch_uma.h
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// 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_
-
-#include "ash/ash_export.h"
-#include "ash/public/cpp/gesture_action_type.h"
-#include "base/macros.h"
-#include "base/memory/singleton.h"
-
-namespace aura {
-class Window;
-}
-
-namespace ui {
-class GestureEvent;
-class TouchEvent;
-}
-
-namespace ash {
-
-// Records some touch/gesture event specific details (e.g. what gestures are
-// targeted to which components etc.)
-class ASH_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);
-
- 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);
-};
-
-}  // namespace ash
-
-#endif  // ASH_TOUCH_TOUCH_OBSERVER_UMA_H_
diff --git a/ash/wm/system_gesture_event_filter.cc b/ash/wm/system_gesture_event_filter.cc
index 64bf530..58fe730 100644
--- a/ash/wm/system_gesture_event_filter.cc
+++ b/ash/wm/system_gesture_event_filter.cc
@@ -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::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
diff --git a/ash/wm/workspace/workspace_event_handler.cc b/ash/wm/workspace/workspace_event_handler.cc
index f9bc5caa..df843e6e 100644
--- a/ash/wm/workspace/workspace_event_handler.cc
+++ b/ash/wm/workspace/workspace_event_handler.cc
@@ -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 @@
     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();
diff --git a/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc b/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc
index af1906e6..7ea89fd 100644
--- a/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc
+++ b/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc
@@ -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 @@
   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;