Index: chrome/browser/ui/ash/metrics/stylus_metrics_recorder_chromeos.cc |
diff --git a/chrome/browser/ui/ash/metrics/stylus_metrics_recorder_chromeos.cc b/chrome/browser/ui/ash/metrics/stylus_metrics_recorder_chromeos.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c6bf92a12295b00a9658a3604dea7b8e90cc86c5 |
--- /dev/null |
+++ b/chrome/browser/ui/ash/metrics/stylus_metrics_recorder_chromeos.cc |
@@ -0,0 +1,151 @@ |
+// Copyright 2016 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. |
+ |
+#include "chrome/browser/ui/ash/metrics/stylus_metrics_recorder_chromeos.h" |
+ |
+#include "ash/common/shell_window_ids.h" |
+#include "ash/common/wm/container_finder.h" |
+#include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
+#include "ash/common/wm_lookup.h" |
+#include "ash/common/wm_shell.h" |
+#include "ash/common/wm_window.h" |
+#include "base/metrics/histogram_macros.h" |
+#include "chrome/browser/apps/app_window_registry_util.h" |
+#include "chrome/browser/chromeos/note_taking_app_utils.h" |
+#include "components/exo/shell_surface.h" |
+#include "extensions/browser/app_window/app_window.h" |
+#include "ui/aura/window_property.h" |
+#include "ui/events/event_constants.h" |
+#include "ui/views/widget/widget.h" |
+ |
+DECLARE_WINDOW_PROPERTY_TYPE(chromeos::StylusWindowType); |
+ |
+namespace chromeos { |
+ |
+DEFINE_WINDOW_PROPERTY_KEY(StylusWindowType, |
+ kStylusWindowTypeBucket, |
+ StylusWindowType::OTHERS); |
+ |
+namespace { |
+ |
+// Form factor of the down event. This enum is used to back an UMA histogram |
+// and should be treated as append-only. |
+enum class DownEventFormFactor { |
+ CLAM_SHELL = 0, |
+ TOUCH_VIEW, |
+ FORMFACTOR_COUNT, |
Daniel Erat
2016/09/19 22:08:47
nit: FORM_FACTOR_COUNT (to match enum name)
xiaoyinh(OOO Sep 11-29)
2016/09/27 17:57:44
Done.
|
+}; |
+ |
+// Input type of the down event. This enum is used to back an UMA |
+// histogram and should be treated as append-only. |
+enum class DownEventSource { |
+ UNKNOWN = 0, |
+ MOUSE, |
+ STYLUS, |
+ TOUCH, |
+ SOURCE_COUNT, |
+}; |
+ |
+// Destination of the down event. This enum is used to back |
+// an UMA histogram and should be treated as append-only. |
+enum class DownEventDestination { |
+ OTHERS = 0, |
+ BROWSER, |
+ CHROME_APP, |
+ ARC_APP, |
+ NOTE_TAKING_APP, |
+ DESTINATION_COUNT, |
+}; |
+ |
+DownEventDestination GetDownEventDestination(views::Widget* target) { |
+ if (!target) |
+ return DownEventDestination::OTHERS; |
+ |
+ aura::Window* window = target->GetNativeWindow(); |
+ DCHECK(window); |
+ |
+ if (exo::ShellSurface::GetMainSurface(window)) |
+ return DownEventDestination::ARC_APP; |
+ |
+ StylusWindowType window_type = window->GetProperty(kStylusWindowTypeBucket); |
+ |
+ if (window_type == StylusWindowType::BROWSER_WINDOW) |
+ return DownEventDestination::BROWSER; |
+ |
+ if (window_type == StylusWindowType::APP) { |
+ extensions::AppWindow* app_window = |
+ AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(window); |
+ if (app_window && chromeos::IsNoteTakingApp(app_window)) |
+ return DownEventDestination::NOTE_TAKING_APP; |
+ return DownEventDestination::CHROME_APP; |
+ } |
+ |
+ return DownEventDestination::OTHERS; |
+} |
+ |
+void RecordUMA(ui::EventPointerType type, views::Widget* target) { |
+ DownEventFormFactor form_factor = DownEventFormFactor::CLAM_SHELL; |
+ if (ash::WmShell::Get() |
+ ->maximize_mode_controller() |
+ ->IsMaximizeModeWindowManagerEnabled()) { |
+ form_factor = DownEventFormFactor::TOUCH_VIEW; |
+ } |
+ UMA_HISTOGRAM_ENUMERATION( |
+ "Event.DownEventCount.PerFormFactor", |
+ static_cast<base::HistogramBase::Sample>(form_factor), |
+ static_cast<base::HistogramBase::Sample>( |
+ DownEventFormFactor::FORMFACTOR_COUNT)); |
+ |
+ DownEventSource input_type = DownEventSource::UNKNOWN; |
+ switch (type) { |
+ case ui::EventPointerType::POINTER_TYPE_UNKNOWN: |
+ input_type = DownEventSource::UNKNOWN; |
+ break; |
+ case ui::EventPointerType::POINTER_TYPE_MOUSE: |
+ input_type = DownEventSource::MOUSE; |
+ break; |
+ case ui::EventPointerType::POINTER_TYPE_PEN: |
+ input_type = DownEventSource::STYLUS; |
+ break; |
+ case ui::EventPointerType::POINTER_TYPE_TOUCH: |
+ input_type = DownEventSource::TOUCH; |
+ break; |
+ case ui::EventPointerType::POINTER_TYPE_ERASER: |
+ input_type = DownEventSource::STYLUS; |
+ break; |
+ } |
+ |
+ UMA_HISTOGRAM_ENUMERATION( |
+ "Event.DownEventCount.PerInput", |
+ static_cast<base::HistogramBase::Sample>(input_type), |
+ static_cast<base::HistogramBase::Sample>(DownEventSource::SOURCE_COUNT)); |
+ |
+ DownEventDestination dest = GetDownEventDestination(target); |
+ UMA_HISTOGRAM_ENUMERATION("Event.DownEventCount.PerDestination", |
+ static_cast<base::HistogramBase::Sample>(dest), |
+ static_cast<base::HistogramBase::Sample>( |
+ DownEventDestination::DESTINATION_COUNT)); |
+} |
+ |
+} // namespace |
+ |
+StylusMetricsRecorder::StylusMetricsRecorder() { |
+ ash::WmShell::Get()->AddPointerWatcher( |
+ this, views::PointerWatcherEventTypes::BASIC); |
+} |
+ |
+StylusMetricsRecorder::~StylusMetricsRecorder() { |
+ ash::WmShell::Get()->RemovePointerWatcher(this); |
+} |
+ |
+void StylusMetricsRecorder::OnPointerEventObserved( |
+ const ui::PointerEvent& event, |
+ const gfx::Point& location_in_screen, |
+ views::Widget* target) { |
+ if (event.type() != ui::ET_POINTER_DOWN) |
+ return; |
+ RecordUMA(event.pointer_details().pointer_type, target); |
+} |
+ |
+} // namespace chromeos |