Chromium Code Reviews| Index: ash/metrics/pointer_metrics_recorder.cc |
| diff --git a/ash/metrics/pointer_metrics_recorder.cc b/ash/metrics/pointer_metrics_recorder.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b48e9845940a0cac50a1be83d46823c29353cbaa |
| --- /dev/null |
| +++ b/ash/metrics/pointer_metrics_recorder.cc |
| @@ -0,0 +1,108 @@ |
| +// 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 "ash/metrics/pointer_metrics_recorder.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 "ash/shared/app_types.h" |
| +#include "base/metrics/histogram_macros.h" |
| +#include "ui/aura/client/aura_constants.h" |
| +#include "ui/events/event_constants.h" |
| +#include "ui/views/widget/widget.h" |
| + |
| +namespace ash { |
| + |
| +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, |
|
Daniel Erat
2016/09/27 19:15:10
nit: "CLAMSHELL" instead of "CLAM_SHELL" (since it
xiaoyinh(OOO Sep 11-29)
2016/09/29 20:37:43
Done.
|
| + TOUCH_VIEW, |
| + FORM_FACTOR_COUNT, |
| +}; |
| + |
| +// 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, |
| +}; |
| + |
| +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::FORM_FACTOR_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)); |
| + |
| + if (!target) |
| + return; |
| + |
| + aura::Window* window = target->GetNativeWindow(); |
| + DCHECK(window); |
| + |
| + int window_type = window->GetProperty(aura::client::kAppType); |
| + UMA_HISTOGRAM_ENUMERATION( |
| + "Event.DownEventCount.PerDestination", window_type, |
| + static_cast<base::HistogramBase::Sample>(AppType::APP_COUNT)); |
| +} |
| + |
| +} // namespace |
| + |
| +PointerMetricsRecorder::PointerMetricsRecorder() { |
| + ash::WmShell::Get()->AddPointerWatcher( |
| + this, views::PointerWatcherEventTypes::BASIC); |
| +} |
| + |
| +PointerMetricsRecorder::~PointerMetricsRecorder() { |
| + ash::WmShell::Get()->RemovePointerWatcher(this); |
| +} |
| + |
| +void PointerMetricsRecorder::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 ash |