Commit 7d484f28 authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

Add time to click system tray metrics

This CL adds ChromeOS.SystemTray.TimeToClick metrics to both old
SystemTray and UnifiedSystemTray.
TimeToClick is the amount of time a user took from clicking on the
button in status area, to clicking on an item in the system tray bubble.
The system tray view installs TimeToClickRecorder as PreTargetHandler,
and it calls SystemTray::RecordTimeToClick.

TEST=manual(chrome://histograms)
BUG=834462

Change-Id: Id7b599faf9bf53279be228816c39b05170db0d90
Reviewed-on: https://chromium-review.googlesource.com/1018120Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#552930}
parent 48d140d3
......@@ -425,6 +425,17 @@ TrayIME* SystemTray::GetTrayIME() const {
return tray_ime_;
}
void SystemTray::RecordTimeToClick() {
// Ignore if the tray bubble is not opened by click.
if (!last_button_clicked_)
return;
UMA_HISTOGRAM_TIMES("ChromeOS.SystemTray.TimeToClick",
base::TimeTicks::Now() - last_button_clicked_.value());
last_button_clicked_.reset();
}
void SystemTray::CanSwitchAwayFromActiveUser(
base::OnceCallback<void(bool)> callback) {
// If neither screen sharing nor capturing is going on we can immediately
......@@ -532,6 +543,11 @@ void SystemTray::ShowItems(const std::vector<SystemTrayItem*>& items,
// tint the background.
if (full_system_tray_menu_)
SetIsActive(true);
// If the current view is not the default view or opened by click, reset the
// last button click time.
if (detailed || !show_by_click)
last_button_clicked_.reset();
}
void SystemTray::UpdateWebNotifications() {
......@@ -604,6 +620,8 @@ bool SystemTray::PerformAction(const ui::Event& event) {
UserMetricsRecorder::RecordUserClickOnTray(
LoginMetricsRecorder::TrayClickTarget::kSystemTray);
last_button_clicked_ = base::TimeTicks::Now();
if (features::IsSystemTrayUnifiedEnabled()) {
return shelf()->GetStatusAreaWidget()->unified_system_tray()->PerformAction(
event);
......@@ -729,4 +747,16 @@ void SystemTray::RecordSystemMenuMetrics() {
}
}
TimeToClickRecorder::TimeToClickRecorder(SystemTray* tray) : tray_(tray) {}
void TimeToClickRecorder::OnEvent(ui::Event* event) {
// Ignore if the event is neither click nor tap.
if (event->type() != ui::ET_MOUSE_PRESSED &&
event->type() != ui::ET_GESTURE_TAP) {
return;
}
tray_->RecordTimeToClick();
}
} // namespace ash
......@@ -133,6 +133,10 @@ class ASH_EXPORT SystemTray : public TrayBackgroundView {
// Returns TrayIME object if present or null otherwise.
TrayIME* GetTrayIME() const;
// Record TimeToClick metrics and reset |last_button_clicked_|. Called by
// TimeToClickRecorder which is system tray view's PreTargetHandler.
void RecordTimeToClick();
// Determines if it's ok to switch away from the currently active user. Screen
// casting may block this (or at least throw up a confirmation dialog). Calls
// |callback| with the result.
......@@ -224,6 +228,8 @@ class ASH_EXPORT SystemTray : public TrayBackgroundView {
// Note that the value is only valid when |system_bubble_| is true.
bool full_system_tray_menu_ = false;
base::Optional<base::TimeTicks> last_button_clicked_;
// These objects are not owned by this class.
TrayAccessibility* tray_accessibility_ = nullptr;
TrayAudio* tray_audio_ = nullptr;
......@@ -250,6 +256,22 @@ class ASH_EXPORT SystemTray : public TrayBackgroundView {
DISALLOW_COPY_AND_ASSIGN(SystemTray);
};
// An event handler that will be installed as system tray view PreTargetHandler
// to record TimeToClick metrics.
class TimeToClickRecorder : public ui::EventHandler {
public:
TimeToClickRecorder(SystemTray* tray);
~TimeToClickRecorder() override = default;
private:
// ui::EventHandler:
void OnEvent(ui::Event* event) override;
SystemTray* const tray_;
DISALLOW_COPY_AND_ASSIGN(TimeToClickRecorder);
};
} // namespace ash
#endif // ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_
......@@ -199,7 +199,7 @@ void SystemTrayBubble::InitView(views::View* anchor,
init_params->max_height = GetDetailedBubbleMaxHeight();
}
system_tray_view_ = new SystemTrayView(system_tray_type, items);
system_tray_view_ = new SystemTrayView(tray_, system_tray_type, items);
init_params->delegate = tray_;
// Place the bubble on same display as this system tray.
......
......@@ -5,6 +5,7 @@
#include "ash/system/tray/system_tray_view.h"
#include "ash/shell.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_item.h"
#include "base/metrics/histogram_macros.h"
#include "ui/views/layout/box_layout.h"
......@@ -46,10 +47,15 @@ class BottomAlignedBoxLayout : public views::BoxLayout {
} // anonymous namespace
SystemTrayView::SystemTrayView(SystemTrayType system_tray_type,
SystemTrayView::SystemTrayView(SystemTray* system_tray,
SystemTrayType system_tray_type,
const std::vector<ash::SystemTrayItem*>& items)
: items_(items), system_tray_type_(system_tray_type) {
: time_to_click_recorder_(
std::make_unique<TimeToClickRecorder>(system_tray)),
items_(items),
system_tray_type_(system_tray_type) {
SetLayoutManager(std::make_unique<BottomAlignedBoxLayout>());
AddPreTargetHandler(time_to_click_recorder_.get());
}
SystemTrayView::~SystemTrayView() {
......
......@@ -15,7 +15,8 @@ class SystemTrayView : public views::View {
public:
enum SystemTrayType { SYSTEM_TRAY_TYPE_DEFAULT, SYSTEM_TRAY_TYPE_DETAILED };
SystemTrayView(SystemTrayType system_tray_type,
SystemTrayView(SystemTray* system_tray,
SystemTrayType system_tray_type,
const std::vector<ash::SystemTrayItem*>& items);
~SystemTrayView() override;
......@@ -41,6 +42,8 @@ class SystemTrayView : public views::View {
// Tracks the views created in the last call to CreateItemViews().
std::map<SystemTrayItem::UmaType, views::View*> tray_item_view_map_;
std::unique_ptr<ui::EventHandler> time_to_click_recorder_;
std::vector<ash::SystemTrayItem*> items_;
SystemTrayType system_tray_type_;
......
......@@ -70,6 +70,9 @@ UnifiedSystemTrayView* UnifiedSystemTrayController::CreateView() {
std::make_unique<UnifiedBrightnessSliderController>(model_);
unified_view_->AddSliderView(brightness_slider_controller_->CreateView());
time_to_click_recorder_ = std::make_unique<TimeToClickRecorder>(system_tray_);
unified_view_->AddPreTargetHandler(time_to_click_recorder_.get());
return unified_view_;
}
......
......@@ -22,6 +22,7 @@ namespace ash {
class FeaturePodControllerBase;
class SystemTray;
class SystemTrayItem;
class TimeToClickRecorder;
class UnifiedBrightnessSliderController;
class UnifiedVolumeSliderController;
class UnifiedSystemTrayModel;
......@@ -118,6 +119,9 @@ class ASH_EXPORT UnifiedSystemTrayController : public gfx::AnimationDelegate {
std::unique_ptr<UnifiedBrightnessSliderController>
brightness_slider_controller_;
// PreTargetHandler of |unified_view_| to record TimeToClick metrics. Owned.
std::unique_ptr<TimeToClickRecorder> time_to_click_recorder_;
// If the previous state is expanded or not. Only valid during dragging (from
// BeginDrag to EndDrag).
bool was_expanded_ = true;
......
......@@ -10632,6 +10632,14 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary>
</histogram>
<histogram name="ChromeOS.SystemTray.TimeToClick" units="ms">
<owner>tetsui@chromium.org</owner>
<summary>
The amount of time a user took from clicking on the button in status area,
to clicking on an item in the system tray bubble.
</summary>
</histogram>
<histogram name="ChromiumAndroidLinker.BrowserLoadTime" units="ms">
<owner>rsesek@chromium.org</owner>
<summary>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment