Chromium Code Reviews| 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..d115dee6de982c1890bdfb580277f09bbc631113 |
| --- /dev/null |
| +++ b/chrome/browser/ui/ash/metrics/stylus_metrics_recorder_chromeos.cc |
| @@ -0,0 +1,148 @@ |
| +// 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::WINDOW_TYPE_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 DownEventFormFactor { |
|
sky
2016/09/16 23:20:16
enum class, and avoid duplicating the name, e.g. D
xiaoyinh(OOO Sep 11-29)
2016/09/19 21:19:52
Done.
|
| + DOWN_EVENT_FORMFACTOR_CLAMSHELL = 0, |
| + DOWN_EVENT_FORMFACTOR_TOUCHVIEW, |
| + DOWN_EVENT_FORMFACTOR_COUNT |
| +}; |
| + |
| +// Input type of the down event. This enum is used to back an UMA |
| +// histogram and should be treated as append-only. |
| +enum DownEventSource { |
| + DOWN_EVENT_SOURCE_UNKNOWN = 0, |
| + DOWN_EVENT_SOURCE_MOUSE, |
| + DOWN_EVENT_SOURCE_STYLUS, |
| + DOWN_EVENT_SOURCE_TOUCH, |
| + DOWN_EVENT_SOURCE_COUNT |
| +}; |
| + |
| +// Destination of the down event. This enum is used to back |
| +// an UMA histogram and should be treated as append-only. |
| +enum DownEventDestination { |
| + DOWN_EVENT_DESTINATION_OTHERS = 0, |
| + DOWN_EVENT_DESTINATION_BROWSER, |
| + DOWN_EVENT_DESTINATION_CHROME_APP, |
| + DOWN_EVENT_DESTINATION_ARC_APP, |
| + DOWN_EVENT_DESTINATION_NOTE_TAKING_APP, |
| + DOWN_EVENT_DESTINATION_COUNT |
| +}; |
| + |
| +DownEventDestination GetDownEventDestination(views::Widget* target) { |
| + DownEventDestination dest = DOWN_EVENT_DESTINATION_OTHERS; |
|
sky
2016/09/16 23:20:16
dest is never changed. The code would be cleaner i
xiaoyinh(OOO Sep 11-29)
2016/09/19 21:19:53
Done.
|
| + if (!target) |
| + return dest; |
| + |
| + aura::Window* window = target->GetNativeWindow(); |
| + |
| + if (!window) |
|
sky
2016/09/16 23:20:16
This shouldn't be possible. DCHECK?
xiaoyinh(OOO Sep 11-29)
2016/09/19 21:19:52
Done.
|
| + return dest; |
| + |
| + if (exo::ShellSurface::GetMainSurface(window)) |
| + return DOWN_EVENT_DESTINATION_ARC_APP; |
| + |
| + StylusWindowType window_type = window->GetProperty(kStylusWindowTypeBucket); |
| + |
| + if (window_type == StylusWindowType::WINDOW_TYPE_BROWSER_WINDOW) |
| + return DownEventDestination::DOWN_EVENT_DESTINATION_BROWSER; |
| + |
| + if (window_type == StylusWindowType::WINDOW_TYPE_APP) { |
| + extensions::AppWindow* app_window = |
| + AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(window); |
| + if (app_window && chromeos::IsNoteTakingApp(app_window)) |
| + return DOWN_EVENT_DESTINATION_NOTE_TAKING_APP; |
| + else |
|
sky
2016/09/16 23:20:16
no else (see chromium style guide for details)
xiaoyinh(OOO Sep 11-29)
2016/09/19 21:19:53
Done.
|
| + return DOWN_EVENT_DESTINATION_CHROME_APP; |
| + } |
| + |
| + return dest; |
| +} |
| + |
| +void 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, |
| + DownEventFormFactor::DOWN_EVENT_FORMFACTOR_COUNT); |
| + |
| + DownEventSource input_type = DownEventSource::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); |
| +} |
| + |
| +} // 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 |