Index: chrome/browser/ui/ash/metrics/stylus_metrics_recorder.cc |
diff --git a/chrome/browser/ui/ash/metrics/stylus_metrics_recorder.cc b/chrome/browser/ui/ash/metrics/stylus_metrics_recorder.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9202bc94ee3114e284dd8f0fc89cb0b7ad0fec10 |
--- /dev/null |
+++ b/chrome/browser/ui/ash/metrics/stylus_metrics_recorder.cc |
@@ -0,0 +1,135 @@ |
+// 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.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/events/event_constants.h" |
+#include "ui/views/widget/widget.h" |
+ |
+namespace chromeos { |
+ |
+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); |
+} |
+ |
+void StylusMetricsRecorder::RecordUMA(ui::EventPointerType type, |
+ views::Widget* target) { |
+ DownEventFormFactor form_factor = DOWN_EVENT_FORMFACTOR_CLAMSHELL; |
+ if (ash::WmShell::Get() |
+ ->maximize_mode_controller() |
+ ->IsMaximizeModeWindowManagerEnabled()) { |
+ form_factor = DOWN_EVENT_FORMFACTOR_TOUCHVIEW; |
+ } |
+ UMA_HISTOGRAM_ENUMERATION("Event.DownEventCount.PerFormFactor", form_factor, |
+ DOWN_EVENT_FORMFACTOR_COUNT); |
+ |
+ DownEventSource input_type = DOWN_EVENT_SOURCE_UNKNOWN; |
+ switch (type) { |
+ case ui::EventPointerType::POINTER_TYPE_UNKNOWN: |
+ input_type = DOWN_EVENT_SOURCE_UNKNOWN; |
+ break; |
+ case ui::EventPointerType::POINTER_TYPE_MOUSE: |
+ input_type = DOWN_EVENT_SOURCE_MOUSE; |
+ break; |
+ case ui::EventPointerType::POINTER_TYPE_PEN: |
+ input_type = DOWN_EVENT_SOURCE_STYLUS; |
+ break; |
+ case ui::EventPointerType::POINTER_TYPE_TOUCH: |
+ input_type = DOWN_EVENT_SOURCE_TOUCH; |
+ break; |
+ case ui::EventPointerType::POINTER_TYPE_ERASER: |
+ input_type = DOWN_EVENT_SOURCE_STYLUS; |
+ break; |
+ } |
+ |
+ UMA_HISTOGRAM_ENUMERATION("Event.DownEventCount.PerInput", input_type, |
+ DOWN_EVENT_SOURCE_COUNT); |
+ |
+ DownEventDestination dest = GetDownEventDestination(target); |
+ UMA_HISTOGRAM_ENUMERATION("Event.DownEventCount.PerDestination", dest, |
+ DOWN_EVENT_DESTINATION_COUNT); |
+} |
+ |
+bool StylusMetricsRecorder::IsEventOnShelf(views::Widget* target) { |
+ if (!target) { |
sky
2016/09/13 00:03:26
In general we don't use {} around single line cond
xiaoyinh(OOO Sep 11-29)
2016/09/16 18:41:16
Done.
|
+ return false; |
+ } |
+ |
+ ash::WmWindow* window = ash::WmLookup::Get()->GetWindowForWidget(target); |
+ int container_id = ash::wm::GetContainerForWindow(window)->GetShellWindowId(); |
sky
2016/09/13 00:03:26
Make sure you null check GetContainerForWindow and
xiaoyinh(OOO Sep 11-29)
2016/09/16 18:41:16
Done.
|
+ |
+ // Events on the shelf. |
+ if (container_id == ash::kShellWindowId_ShelfContainer) |
+ return true; |
+ // Events on the status area. |
+ if (container_id == ash::kShellWindowId_StatusContainer) |
+ return true; |
+ // Events on the right click menus. |
+ if (container_id == ash::kShellWindowId_MenuContainer) |
sky
2016/09/13 00:03:26
This hits *all* menus. I don't think you want that
xiaoyinh(OOO Sep 11-29)
2016/09/16 18:41:16
Deleted. Thanks.
|
+ return true; |
+ // Events on the settings trays. |
+ if (container_id == ash::kShellWindowId_SettingBubbleContainer) |
+ return true; |
+ // Events on the overflow bubbles over the shelf. |
+ if (container_id == ash::kShellWindowId_ShelfBubbleContainer) |
+ return true; |
+ |
+ return false; |
+} |
+ |
+DownEventDestination StylusMetricsRecorder::GetDownEventDestination( |
+ views::Widget* target) { |
+ DownEventDestination dest = DOWN_EVENT_DESTINATION_OTHERS; |
+ if (!target) |
+ return dest; |
+ |
+ if (IsEventOnShelf(target)) |
+ return DOWN_EVENT_DESTINATION_SYSTEM_UI; |
+ |
+ aura::Window* window = target->GetNativeWindow(); |
+ |
+ if (exo::ShellSurface::GetMainSurface(window)) |
+ return DOWN_EVENT_DESTINATION_ARC_APP; |
+ |
+ if (window->GetProperty(aura::client::kStylusWindowTypeBucket) == |
xiyuan
2016/09/12 20:15:47
nit: save the result of window->GetProperty(aura::
xiaoyinh(OOO Sep 11-29)
2016/09/16 18:41:16
Done.
|
+ StylusWindowType::WINDOW_TYPE_BROWSER_WINDOW) |
+ return DOWN_EVENT_DESTINATION_WEBSITE; |
+ |
+ if (window->GetProperty(aura::client::kStylusWindowTypeBucket) == |
+ StylusWindowType::WINDOW_TYPE_APP) { |
+ extensions::AppWindow* app_window = |
+ AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(window); |
+ if (app_window && chromeos::IsCurrentAppNoteTakingApp(app_window)) |
+ return DOWN_EVENT_DESTINATION_NOTE_TAKING_APP; |
+ } |
+ |
+ return dest; |
+} |
+ |
+} // namespace chromeos |