Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/ash/metrics/stylus_metrics_recorder_chromeos.h" | |
| 6 | |
| 7 #include "ash/common/shell_window_ids.h" | |
| 8 #include "ash/common/wm/container_finder.h" | |
| 9 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | |
| 10 #include "ash/common/wm_lookup.h" | |
| 11 #include "ash/common/wm_shell.h" | |
| 12 #include "ash/common/wm_window.h" | |
| 13 #include "base/metrics/histogram_macros.h" | |
| 14 #include "chrome/browser/apps/app_window_registry_util.h" | |
| 15 #include "chrome/browser/chromeos/note_taking_app_utils.h" | |
| 16 #include "components/exo/shell_surface.h" | |
| 17 #include "extensions/browser/app_window/app_window.h" | |
| 18 #include "ui/aura/window_property.h" | |
| 19 #include "ui/events/event_constants.h" | |
| 20 #include "ui/views/widget/widget.h" | |
| 21 | |
| 22 DECLARE_WINDOW_PROPERTY_TYPE(chromeos::StylusWindowType); | |
| 23 | |
| 24 namespace chromeos { | |
| 25 | |
| 26 DEFINE_WINDOW_PROPERTY_KEY(StylusWindowType, | |
| 27 kStylusWindowTypeBucket, | |
| 28 StylusWindowType::OTHERS); | |
| 29 | |
| 30 namespace { | |
| 31 | |
| 32 // Form factor of the down event. This enum is used to back an UMA histogram | |
| 33 // and should be treated as append-only. | |
| 34 enum class DownEventFormFactor { | |
| 35 CLAM_SHELL = 0, | |
| 36 TOUCH_VIEW, | |
| 37 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.
| |
| 38 }; | |
| 39 | |
| 40 // Input type of the down event. This enum is used to back an UMA | |
| 41 // histogram and should be treated as append-only. | |
| 42 enum class DownEventSource { | |
| 43 UNKNOWN = 0, | |
| 44 MOUSE, | |
| 45 STYLUS, | |
| 46 TOUCH, | |
| 47 SOURCE_COUNT, | |
| 48 }; | |
| 49 | |
| 50 // Destination of the down event. This enum is used to back | |
| 51 // an UMA histogram and should be treated as append-only. | |
| 52 enum class DownEventDestination { | |
| 53 OTHERS = 0, | |
| 54 BROWSER, | |
| 55 CHROME_APP, | |
| 56 ARC_APP, | |
| 57 NOTE_TAKING_APP, | |
| 58 DESTINATION_COUNT, | |
| 59 }; | |
| 60 | |
| 61 DownEventDestination GetDownEventDestination(views::Widget* target) { | |
| 62 if (!target) | |
| 63 return DownEventDestination::OTHERS; | |
| 64 | |
| 65 aura::Window* window = target->GetNativeWindow(); | |
| 66 DCHECK(window); | |
| 67 | |
| 68 if (exo::ShellSurface::GetMainSurface(window)) | |
| 69 return DownEventDestination::ARC_APP; | |
| 70 | |
| 71 StylusWindowType window_type = window->GetProperty(kStylusWindowTypeBucket); | |
| 72 | |
| 73 if (window_type == StylusWindowType::BROWSER_WINDOW) | |
| 74 return DownEventDestination::BROWSER; | |
| 75 | |
| 76 if (window_type == StylusWindowType::APP) { | |
| 77 extensions::AppWindow* app_window = | |
| 78 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(window); | |
| 79 if (app_window && chromeos::IsNoteTakingApp(app_window)) | |
| 80 return DownEventDestination::NOTE_TAKING_APP; | |
| 81 return DownEventDestination::CHROME_APP; | |
| 82 } | |
| 83 | |
| 84 return DownEventDestination::OTHERS; | |
| 85 } | |
| 86 | |
| 87 void RecordUMA(ui::EventPointerType type, views::Widget* target) { | |
| 88 DownEventFormFactor form_factor = DownEventFormFactor::CLAM_SHELL; | |
| 89 if (ash::WmShell::Get() | |
| 90 ->maximize_mode_controller() | |
| 91 ->IsMaximizeModeWindowManagerEnabled()) { | |
| 92 form_factor = DownEventFormFactor::TOUCH_VIEW; | |
| 93 } | |
| 94 UMA_HISTOGRAM_ENUMERATION( | |
| 95 "Event.DownEventCount.PerFormFactor", | |
| 96 static_cast<base::HistogramBase::Sample>(form_factor), | |
| 97 static_cast<base::HistogramBase::Sample>( | |
| 98 DownEventFormFactor::FORMFACTOR_COUNT)); | |
| 99 | |
| 100 DownEventSource input_type = DownEventSource::UNKNOWN; | |
| 101 switch (type) { | |
| 102 case ui::EventPointerType::POINTER_TYPE_UNKNOWN: | |
| 103 input_type = DownEventSource::UNKNOWN; | |
| 104 break; | |
| 105 case ui::EventPointerType::POINTER_TYPE_MOUSE: | |
| 106 input_type = DownEventSource::MOUSE; | |
| 107 break; | |
| 108 case ui::EventPointerType::POINTER_TYPE_PEN: | |
| 109 input_type = DownEventSource::STYLUS; | |
| 110 break; | |
| 111 case ui::EventPointerType::POINTER_TYPE_TOUCH: | |
| 112 input_type = DownEventSource::TOUCH; | |
| 113 break; | |
| 114 case ui::EventPointerType::POINTER_TYPE_ERASER: | |
| 115 input_type = DownEventSource::STYLUS; | |
| 116 break; | |
| 117 } | |
| 118 | |
| 119 UMA_HISTOGRAM_ENUMERATION( | |
| 120 "Event.DownEventCount.PerInput", | |
| 121 static_cast<base::HistogramBase::Sample>(input_type), | |
| 122 static_cast<base::HistogramBase::Sample>(DownEventSource::SOURCE_COUNT)); | |
| 123 | |
| 124 DownEventDestination dest = GetDownEventDestination(target); | |
| 125 UMA_HISTOGRAM_ENUMERATION("Event.DownEventCount.PerDestination", | |
| 126 static_cast<base::HistogramBase::Sample>(dest), | |
| 127 static_cast<base::HistogramBase::Sample>( | |
| 128 DownEventDestination::DESTINATION_COUNT)); | |
| 129 } | |
| 130 | |
| 131 } // namespace | |
| 132 | |
| 133 StylusMetricsRecorder::StylusMetricsRecorder() { | |
| 134 ash::WmShell::Get()->AddPointerWatcher( | |
| 135 this, views::PointerWatcherEventTypes::BASIC); | |
| 136 } | |
| 137 | |
| 138 StylusMetricsRecorder::~StylusMetricsRecorder() { | |
| 139 ash::WmShell::Get()->RemovePointerWatcher(this); | |
| 140 } | |
| 141 | |
| 142 void StylusMetricsRecorder::OnPointerEventObserved( | |
| 143 const ui::PointerEvent& event, | |
| 144 const gfx::Point& location_in_screen, | |
| 145 views::Widget* target) { | |
| 146 if (event.type() != ui::ET_POINTER_DOWN) | |
| 147 return; | |
| 148 RecordUMA(event.pointer_details().pointer_type, target); | |
| 149 } | |
| 150 | |
| 151 } // namespace chromeos | |
| OLD | NEW |