| 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..f17261384c8dd11c355ac9f0ef5fb7c4b6f5b8dd
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/ash/metrics/stylus_metrics_recorder.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.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 {
|
| + 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;
|
| + if (!target)
|
| + return dest;
|
| +
|
| + aura::Window* window = target->GetNativeWindow();
|
| +
|
| + if (!window)
|
| + 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
|
| + 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
|
|
|