Commit 50a94860 authored by xiaoyinh's avatar xiaoyinh Committed by Commit bot

Add UMA stats for pen palette

This CL adds the following metrics:
1. Usage of each pen palette option
2. Usage of each pen palette option on auto-open
3. Length of time spent in each mode
4. count of Mode cancellation

BUG=643798

Review-Url: https://codereview.chromium.org/2308823002
Cr-Commit-Position: refs/heads/master@{#418645}
parent 86e4f0c4
......@@ -10,6 +10,7 @@
#include "ash/common/system/tray/hover_highlight_view.h"
#include "ash/common/system/tray/view_click_listener.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/utf_string_conversions.h"
#include "grit/ash_resources.h"
#include "ui/base/resource/resource_bundle.h"
......@@ -33,6 +34,18 @@ const int kExtraMarginFromLeftEdge = 4;
// Distance between the icon and the name of the tool in DP.
const int kMarginBetweenIconAndText = 18;
void AddHistogramTimes(PaletteToolId id, base::TimeDelta duration) {
if (id == PaletteToolId::LASER_POINTER) {
UMA_HISTOGRAM_CUSTOM_TIMES("Ash.Shelf.Palette.InLaserPointerMode", duration,
base::TimeDelta::FromMilliseconds(100),
base::TimeDelta::FromHours(1), 50);
} else if (id == PaletteToolId::MAGNIFY) {
UMA_HISTOGRAM_CUSTOM_TIMES("Ash.Shelf.Palette.InMagnifyMode", duration,
base::TimeDelta::FromMilliseconds(100),
base::TimeDelta::FromHours(1), 50);
}
}
} // namespace
CommonPaletteTool::CommonPaletteTool(Delegate* delegate)
......@@ -52,6 +65,7 @@ void CommonPaletteTool::OnViewDestroyed() {
void CommonPaletteTool::OnEnable() {
PaletteTool::OnEnable();
start_time_ = base::TimeTicks::Now();
if (highlight_view_) {
highlight_view_->SetHighlight(true);
......@@ -61,6 +75,7 @@ void CommonPaletteTool::OnEnable() {
void CommonPaletteTool::OnDisable() {
PaletteTool::OnDisable();
AddHistogramTimes(GetToolId(), base::TimeTicks::Now() - start_time_);
if (highlight_view_) {
highlight_view_->SetHighlight(false);
......@@ -69,10 +84,16 @@ void CommonPaletteTool::OnDisable() {
}
void CommonPaletteTool::OnViewClicked(views::View* sender) {
if (enabled())
delegate()->RecordPaletteOptionsUsage(
PaletteToolIdToPaletteTrayOptions(GetToolId()));
if (enabled()) {
delegate()->DisableTool(GetToolId());
else
delegate()->RecordPaletteModeCancellation(
PaletteToolIdToPaletteModeCancelType(GetToolId(),
false /*is_switched*/));
} else {
delegate()->EnableTool(GetToolId());
}
}
views::View* CommonPaletteTool::CreateDefaultView(const base::string16& name) {
......
......@@ -8,6 +8,7 @@
#include "ash/common/system/chromeos/palette/palette_tool.h"
#include "ash/common/system/tray/view_click_listener.h"
#include "base/strings/string16.h"
#include "base/time/time.h"
namespace gfx {
struct VectorIcon;
......@@ -42,6 +43,10 @@ class CommonPaletteTool : public PaletteTool, public ash::ViewClickListener {
private:
HoverHighlightView* highlight_view_ = nullptr;
// start_time_ is initialized when the tool becomes active.
// Used for recording UMA metrics.
base::TimeTicks start_time_;
DISALLOW_COPY_AND_ASSIGN(CommonPaletteTool);
};
......
......@@ -20,6 +20,8 @@ class MockPaletteToolDelegate : public PaletteTool::Delegate {
MOCK_METHOD1(DisableTool, void(PaletteToolId tool_id));
MOCK_METHOD0(HidePalette, void());
MOCK_METHOD0(GetWindow, WmWindow*());
MOCK_METHOD1(RecordPaletteOptionsUsage, void(PaletteTrayOptions option));
MOCK_METHOD1(RecordPaletteModeCancellation, void(PaletteModeCancelType type));
};
} // namespace ash
......
......@@ -39,4 +39,38 @@ std::string PaletteGroupToString(PaletteGroup group) {
return std::string();
}
PaletteTrayOptions PaletteToolIdToPaletteTrayOptions(PaletteToolId tool_id) {
switch (tool_id) {
case PaletteToolId::NONE:
return PALETTE_OPTIONS_COUNT;
case PaletteToolId::CREATE_NOTE:
return PALETTE_NEW_NOTE;
case PaletteToolId::CAPTURE_REGION:
return PALETTE_CAPTURE_REGION;
case PaletteToolId::CAPTURE_SCREEN:
return PALETTE_CAPTURE_SCREEN;
case PaletteToolId::LASER_POINTER:
return PALETTE_LASER_POINTER;
case PaletteToolId::MAGNIFY:
return PALETTE_MAGNIFY;
}
NOTREACHED();
return PALETTE_OPTIONS_COUNT;
}
PaletteModeCancelType PaletteToolIdToPaletteModeCancelType(
PaletteToolId tool_id,
bool is_switched) {
PaletteModeCancelType type = PALETTE_MODE_CANCEL_TYPE_COUNT;
if (tool_id == PaletteToolId::LASER_POINTER) {
return is_switched ? PALETTE_MODE_LASER_POINTER_SWITCHED
: PALETTE_MODE_LASER_POINTER_CANCELLED;
} else if (tool_id == PaletteToolId::MAGNIFY) {
return is_switched ? PALETTE_MODE_MAGNIFY_SWITCHED
: PALETTE_MODE_MAGNIFY_CANCELLED;
}
return type;
}
} // namespace ash
......@@ -27,10 +27,42 @@ enum class PaletteToolId {
MAGNIFY,
};
// Usage of each pen palette option. This enum is used to back an UMA histogram
// and should be treated as append-only.
enum PaletteTrayOptions {
PALETTE_CLOSED_NO_ACTION = 0,
PALETTE_SETTINGS_BUTTON,
PALETTE_HELP_BUTTON,
PALETTE_CAPTURE_REGION,
PALETTE_CAPTURE_SCREEN,
PALETTE_NEW_NOTE,
PALETTE_MAGNIFY,
PALETTE_LASER_POINTER,
PALETTE_OPTIONS_COUNT
};
// Type of palette mode cancellation. This enum is used to back an UMA histogram
// and should be treated as append-only.
enum PaletteModeCancelType {
PALETTE_MODE_LASER_POINTER_CANCELLED = 0,
PALETTE_MODE_LASER_POINTER_SWITCHED,
PALETTE_MODE_MAGNIFY_CANCELLED,
PALETTE_MODE_MAGNIFY_SWITCHED,
PALETTE_MODE_CANCEL_TYPE_COUNT
};
// Helper functions that convert PaletteToolIds and PaletteGroups to strings.
ASH_EXPORT std::string PaletteToolIdToString(PaletteToolId tool_id);
ASH_EXPORT std::string PaletteGroupToString(PaletteGroup group);
// Helper functions that convert PaletteToolIds to PaletteTrayOptions.
ASH_EXPORT PaletteTrayOptions
PaletteToolIdToPaletteTrayOptions(PaletteToolId tool_id);
// Helper functions that convert PaletteToolIds to PaletteModeCancelType.
ASH_EXPORT PaletteModeCancelType
PaletteToolIdToPaletteModeCancelType(PaletteToolId tool_id, bool is_switched);
} // namespace ash
#endif // ASH_COMMON_SYSTEM_CHROMEOS_PALETTE_PALETTE_IDS_H_
......@@ -10,6 +10,7 @@
#include <vector>
#include "ash/ash_export.h"
#include "ash/common/system/chromeos/palette/palette_ids.h"
#include "base/callback.h"
#include "base/macros.h"
#include "ui/gfx/vector_icon_types.h"
......@@ -52,6 +53,12 @@ class ASH_EXPORT PaletteTool {
// Returns the root window.
virtual WmWindow* GetWindow() = 0;
// Record usage of each pen palette option.
virtual void RecordPaletteOptionsUsage(PaletteTrayOptions option) = 0;
// Record mode cancellation of pen palette.
virtual void RecordPaletteModeCancellation(PaletteModeCancelType type) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(Delegate);
};
......
......@@ -9,6 +9,7 @@
#include "ash/common/system/chromeos/palette/palette_tool.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "base/bind.h"
#include "base/metrics/histogram_macros.h"
namespace ash {
......@@ -38,8 +39,11 @@ void PaletteToolManager::ActivateTool(PaletteToolId tool_id) {
if (new_tool == previous_tool)
return;
if (previous_tool)
if (previous_tool) {
previous_tool->OnDisable();
RecordPaletteModeCancellation(PaletteToolIdToPaletteModeCancelType(
previous_tool->GetToolId(), true /*is_switched*/));
}
active_tools_[new_tool->GetGroup()] = new_tool;
new_tool->OnEnable();
......@@ -118,6 +122,15 @@ WmWindow* PaletteToolManager::GetWindow() {
return delegate_->GetWindow();
}
void PaletteToolManager::RecordPaletteOptionsUsage(PaletteTrayOptions option) {
return delegate_->RecordPaletteOptionsUsage(option);
}
void PaletteToolManager::RecordPaletteModeCancellation(
PaletteModeCancelType type) {
return delegate_->RecordPaletteModeCancellation(type);
}
PaletteTool* PaletteToolManager::FindToolById(PaletteToolId tool_id) const {
for (const std::unique_ptr<PaletteTool>& tool : tools_) {
if (tool->GetToolId() == tool_id)
......
......@@ -48,6 +48,12 @@ class ASH_EXPORT PaletteToolManager : public PaletteTool::Delegate {
// Return the window associated with this palette.
virtual WmWindow* GetWindow() = 0;
// Record usage of each pen palette option.
virtual void RecordPaletteOptionsUsage(ash::PaletteTrayOptions option) = 0;
// Record mode cancellation of pen palette.
virtual void RecordPaletteModeCancellation(PaletteModeCancelType type) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(Delegate);
};
......@@ -90,6 +96,8 @@ class ASH_EXPORT PaletteToolManager : public PaletteTool::Delegate {
void DisableTool(PaletteToolId tool_id) override;
void HidePalette() override;
WmWindow* GetWindow() override;
void RecordPaletteOptionsUsage(ash::PaletteTrayOptions option) override;
void RecordPaletteModeCancellation(PaletteModeCancelType type) override;
PaletteTool* FindToolById(PaletteToolId tool_id) const;
......
......@@ -58,6 +58,8 @@ class PaletteToolManagerTest : public ::testing::Test,
NOTREACHED();
return nullptr;
}
void RecordPaletteOptionsUsage(PaletteTrayOptions option) override {}
void RecordPaletteModeCancellation(PaletteModeCancelType type) override {}
// PaletteTool::Delegate:
void EnableTool(PaletteToolId tool_id) override {}
......
......@@ -18,6 +18,7 @@
#include "ash/common/wm_root_window_controller.h"
#include "ash/common/wm_shell.h"
#include "ash/common/wm_window.h"
#include "base/metrics/histogram_macros.h"
#include "grit/ash_resources.h"
#include "grit/ash_strings.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -108,9 +109,13 @@ class TitleView : public views::View, public views::ButtonListener {
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override {
if (sender == settings_button_) {
palette_tray_->RecordPaletteOptionsUsage(
PaletteTrayOptions::PALETTE_SETTINGS_BUTTON);
WmShell::Get()->system_tray_delegate()->ShowPaletteSettings();
palette_tray_->HidePalette();
} else if (sender == help_button_) {
palette_tray_->RecordPaletteOptionsUsage(
PaletteTrayOptions::PALETTE_HELP_BUTTON);
WmShell::Get()->system_tray_delegate()->ShowPaletteHelp();
palette_tray_->HidePalette();
} else {
......@@ -173,7 +178,9 @@ PaletteTray::~PaletteTray() {
bool PaletteTray::PerformAction(const ui::Event& event) {
if (bubble_) {
bubble_.reset();
if (num_actions_in_bubble_ == 0)
RecordPaletteOptionsUsage(PaletteTrayOptions::PALETTE_CLOSED_NO_ACTION);
HidePalette();
return true;
}
......@@ -243,7 +250,9 @@ void PaletteTray::OnLockStateChanged(bool locked) {
}
void PaletteTray::ClickedOutsideBubble() {
bubble_.reset();
if (num_actions_in_bubble_ == 0)
RecordPaletteOptionsUsage(PaletteTrayOptions::PALETTE_CLOSED_NO_ACTION);
HidePalette();
}
base::string16 PaletteTray::GetAccessibleNameForTray() {
......@@ -252,7 +261,7 @@ base::string16 PaletteTray::GetAccessibleNameForTray() {
void PaletteTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) {
if (bubble_->bubble_view() == bubble_view)
bubble_.reset();
HidePalette();
}
void PaletteTray::BubbleViewDestroyed() {
......@@ -310,14 +319,38 @@ void PaletteTray::HideBubble(const views::TrayBubbleView* bubble_view) {
}
void PaletteTray::HidePalette() {
is_bubble_auto_opened_ = false;
num_actions_in_bubble_ = 0;
bubble_.reset();
}
void PaletteTray::RecordPaletteOptionsUsage(PaletteTrayOptions option) {
DCHECK_NE(option, PaletteTrayOptions::PALETTE_OPTIONS_COUNT);
if (is_bubble_auto_opened_) {
UMA_HISTOGRAM_ENUMERATION("Ash.Shelf.Palette.Usage.AutoOpened", option,
PaletteTrayOptions::PALETTE_OPTIONS_COUNT);
} else {
UMA_HISTOGRAM_ENUMERATION("Ash.Shelf.Palette.Usage", option,
PaletteTrayOptions::PALETTE_OPTIONS_COUNT);
}
}
void PaletteTray::RecordPaletteModeCancellation(PaletteModeCancelType type) {
if (type == PaletteModeCancelType::PALETTE_MODE_CANCEL_TYPE_COUNT)
return;
UMA_HISTOGRAM_ENUMERATION(
"Ash.Shelf.Palette.ModeCancellation", type,
PaletteModeCancelType::PALETTE_MODE_CANCEL_TYPE_COUNT);
}
bool PaletteTray::ShouldBlockShelfAutoHide() const {
return !!bubble_;
}
void PaletteTray::OnActiveToolChanged() {
++num_actions_in_bubble_;
UpdateTrayIcon();
}
......@@ -361,10 +394,12 @@ void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) {
if (!WmShell::Get()->palette_delegate()->ShouldAutoOpenPalette())
return;
if (stylus_state == ui::StylusState::REMOVED && !bubble_)
if (stylus_state == ui::StylusState::REMOVED && !bubble_) {
is_bubble_auto_opened_ = true;
ShowPalette();
else if (stylus_state == ui::StylusState::INSERTED && bubble_)
bubble_.reset();
} else if (stylus_state == ui::StylusState::INSERTED && bubble_) {
HidePalette();
}
}
void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) {
......
......@@ -61,6 +61,8 @@ class ASH_EXPORT PaletteTray : public TrayBackgroundView,
// PaletteToolManager::Delegate:
void HidePalette() override;
void RecordPaletteOptionsUsage(PaletteTrayOptions option) override;
void RecordPaletteModeCancellation(PaletteModeCancelType type) override;
// Returns true if the shelf should not autohide.
bool ShouldBlockShelfAutoHide() const;
......@@ -121,6 +123,13 @@ class ASH_EXPORT PaletteTray : public TrayBackgroundView,
// Weak pointer, will be parented by TrayContainer for its lifetime.
views::ImageView* icon_;
// Used to indicate whether the palette bubble is automatically opened by a
// stylus eject event.
bool is_bubble_auto_opened_ = false;
// Number of actions in pen palette bubble.
int num_actions_in_bubble_ = 0;
base::WeakPtrFactory<PaletteTray> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(PaletteTray);
......
......@@ -1512,6 +1512,43 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary>
</histogram>
<histogram name="Ash.Shelf.Palette.InLaserPointerMode" units="ms">
<owner>xiaoyinh@chromium.org</owner>
<summary>
Tracks the amount of time spend in Palette laser point mode.
</summary>
</histogram>
<histogram name="Ash.Shelf.Palette.InMagnifyMode" units="ms">
<owner>xiaoyinh@chromium.org</owner>
<summary>Tracks the amount of time spend in Palette Magnify mode.</summary>
</histogram>
<histogram name="Ash.Shelf.Palette.ModeCancellation"
enum="PaletteModeCancelType">
<owner>xiaoyinh@chromium.org</owner>
<summary>
Tracks the number of times a palette mode is explicitly cancelled or
switched out of.
</summary>
</histogram>
<histogram name="Ash.Shelf.Palette.Usage" enum="PaletteTrayOptions">
<owner>xiaoyinh@chromium.org</owner>
<summary>
Tracks the usage of each pen palette option when palette is not
automatically opened by a stylus eject event.
</summary>
</histogram>
<histogram name="Ash.Shelf.Palette.Usage.AutoOpened" enum="PaletteTrayOptions">
<owner>xiaoyinh@chromium.org</owner>
<summary>
Tracks the usage of each pen palette option when palette is automatically
opened by a stylus eject event.
</summary>
</histogram>
<histogram name="Ash.Shelf.TimeBetweenNavigateToTaskSwitches" units="seconds">
<owner>bruthig@google.com</owner>
<owner>tdanderson@google.com</owner>
......@@ -90025,6 +90062,24 @@ To add a new entry, add it with any value and run test to compute valid value.
<int value="8" label="Unknown"/>
</enum>
<enum name="PaletteModeCancelType" type="int">
<int value="0" label="Palette laser pointer mode is cancelled."/>
<int value="1" label="Palette laser pointer mode is switched out of"/>
<int value="2" label="Palette magnify mode is cancelled."/>
<int value="3" label="Palette magnify mode is switched out of."/>
</enum>
<enum name="PaletteTrayOptions" type="int">
<int value="0" label="Palette being closed or dismissed with no action"/>
<int value="1" label="Click on the settings button"/>
<int value="2" label="Click on the help button"/>
<int value="3" label="Capture region"/>
<int value="4" label="Capture screen"/>
<int value="5" label="Add new note"/>
<int value="6" label="Magnifying glass mode"/>
<int value="7" label="Laser pointer mode"/>
</enum>
<enum name="PanningModelType" type="int">
<int value="0" label="equalpower"/>
<int value="1" label="HRTF"/>
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