| 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 "ash/common/metrics/pointer_metrics_recorder.h" |
| 6 |
| 7 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 8 #include "ash/common/wm_lookup.h" |
| 9 #include "ash/common/wm_shell.h" |
| 10 #include "ash/common/wm_window.h" |
| 11 #include "ash/shared/app_types.h" |
| 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "ui/events/event_constants.h" |
| 14 #include "ui/views/widget/widget.h" |
| 15 |
| 16 namespace ash { |
| 17 |
| 18 namespace { |
| 19 |
| 20 // Form factor of the down event. This enum is used to back an UMA histogram |
| 21 // and should be treated as append-only. |
| 22 enum class DownEventFormFactor { |
| 23 CLAMSHELL = 0, |
| 24 TOUCH_VIEW, |
| 25 FORM_FACTOR_COUNT, |
| 26 }; |
| 27 |
| 28 // Input type of the down event. This enum is used to back an UMA |
| 29 // histogram and should be treated as append-only. |
| 30 enum class DownEventSource { |
| 31 UNKNOWN = 0, |
| 32 MOUSE, |
| 33 STYLUS, |
| 34 TOUCH, |
| 35 SOURCE_COUNT, |
| 36 }; |
| 37 |
| 38 void RecordUMA(ui::EventPointerType type, views::Widget* target) { |
| 39 DownEventFormFactor form_factor = DownEventFormFactor::CLAMSHELL; |
| 40 if (ash::WmShell::Get() |
| 41 ->maximize_mode_controller() |
| 42 ->IsMaximizeModeWindowManagerEnabled()) { |
| 43 form_factor = DownEventFormFactor::TOUCH_VIEW; |
| 44 } |
| 45 UMA_HISTOGRAM_ENUMERATION( |
| 46 "Event.DownEventCount.PerFormFactor", |
| 47 static_cast<base::HistogramBase::Sample>(form_factor), |
| 48 static_cast<base::HistogramBase::Sample>( |
| 49 DownEventFormFactor::FORM_FACTOR_COUNT)); |
| 50 |
| 51 DownEventSource input_type = DownEventSource::UNKNOWN; |
| 52 switch (type) { |
| 53 case ui::EventPointerType::POINTER_TYPE_UNKNOWN: |
| 54 input_type = DownEventSource::UNKNOWN; |
| 55 break; |
| 56 case ui::EventPointerType::POINTER_TYPE_MOUSE: |
| 57 input_type = DownEventSource::MOUSE; |
| 58 break; |
| 59 case ui::EventPointerType::POINTER_TYPE_PEN: |
| 60 input_type = DownEventSource::STYLUS; |
| 61 break; |
| 62 case ui::EventPointerType::POINTER_TYPE_TOUCH: |
| 63 input_type = DownEventSource::TOUCH; |
| 64 break; |
| 65 case ui::EventPointerType::POINTER_TYPE_ERASER: |
| 66 input_type = DownEventSource::STYLUS; |
| 67 break; |
| 68 } |
| 69 |
| 70 UMA_HISTOGRAM_ENUMERATION( |
| 71 "Event.DownEventCount.PerInput", |
| 72 static_cast<base::HistogramBase::Sample>(input_type), |
| 73 static_cast<base::HistogramBase::Sample>(DownEventSource::SOURCE_COUNT)); |
| 74 |
| 75 if (!target) |
| 76 return; |
| 77 |
| 78 WmWindow* window = WmLookup::Get()->GetWindowForWidget(target); |
| 79 DCHECK(window); |
| 80 |
| 81 UMA_HISTOGRAM_ENUMERATION("Event.DownEventCount.PerDestination", |
| 82 window->GetAppType(), kAppCount); |
| 83 } |
| 84 |
| 85 } // namespace |
| 86 |
| 87 PointerMetricsRecorder::PointerMetricsRecorder() { |
| 88 ash::WmShell::Get()->AddPointerWatcher( |
| 89 this, views::PointerWatcherEventTypes::BASIC); |
| 90 } |
| 91 |
| 92 PointerMetricsRecorder::~PointerMetricsRecorder() { |
| 93 ash::WmShell::Get()->RemovePointerWatcher(this); |
| 94 } |
| 95 |
| 96 void PointerMetricsRecorder::OnPointerEventObserved( |
| 97 const ui::PointerEvent& event, |
| 98 const gfx::Point& location_in_screen, |
| 99 views::Widget* target) { |
| 100 if (event.type() != ui::ET_POINTER_DOWN) |
| 101 return; |
| 102 RecordUMA(event.pointer_details().pointer_type, target); |
| 103 } |
| 104 |
| 105 } // namespace ash |
| OLD | NEW |