Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(473)

Side by Side Diff: ash/common/system/chromeos/palette/common_palette_tool.cc

Issue 2308823002: Add UMA stats for pen palette (Closed)
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/common/system/chromeos/palette/common_palette_tool.h" 5 #include "ash/common/system/chromeos/palette/common_palette_tool.h"
6 6
7 #include "ash/common/shelf/shelf_constants.h" 7 #include "ash/common/shelf/shelf_constants.h"
8 #include "ash/common/system/chromeos/palette/palette_ids.h" 8 #include "ash/common/system/chromeos/palette/palette_ids.h"
9 #include "ash/common/system/chromeos/palette/palette_tool_manager.h" 9 #include "ash/common/system/chromeos/palette/palette_tool_manager.h"
10 #include "ash/common/system/tray/hover_highlight_view.h" 10 #include "ash/common/system/tray/hover_highlight_view.h"
11 #include "ash/common/system/tray/view_click_listener.h" 11 #include "ash/common/system/tray/view_click_listener.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/histogram_macros.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "grit/ash_resources.h" 15 #include "grit/ash_resources.h"
15 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/color_palette.h" 17 #include "ui/gfx/color_palette.h"
17 #include "ui/gfx/paint_vector_icon.h" 18 #include "ui/gfx/paint_vector_icon.h"
18 #include "ui/gfx/vector_icons_public.h" 19 #include "ui/gfx/vector_icons_public.h"
19 #include "ui/views/border.h" 20 #include "ui/views/border.h"
20 21
21 namespace ash { 22 namespace ash {
22 namespace { 23 namespace {
23 24
24 // Size of the icons in DP. 25 // Size of the icons in DP.
25 const int kIconSize = 20; 26 const int kIconSize = 20;
26 27
27 // Distance between the icon and the check from the egdes in DP. 28 // Distance between the icon and the check from the egdes in DP.
28 const int kMarginFromEdges = 14; 29 const int kMarginFromEdges = 14;
29 30
30 // Extra distance between the icon and the left edge in DP. 31 // Extra distance between the icon and the left edge in DP.
31 const int kExtraMarginFromLeftEdge = 4; 32 const int kExtraMarginFromLeftEdge = 4;
32 33
33 // Distance between the icon and the name of the tool in DP. 34 // Distance between the icon and the name of the tool in DP.
34 const int kMarginBetweenIconAndText = 18; 35 const int kMarginBetweenIconAndText = 18;
35 36
37 void AddHistogramTimes(PaletteToolId id, base::TimeDelta duration) {
38 if (id == PaletteToolId::LASER_POINTER) {
39 UMA_HISTOGRAM_CUSTOM_TIMES("Ash.Shelf.Palette.InLaserPointerMode", duration,
40 base::TimeDelta::FromMilliseconds(100),
41 base::TimeDelta::FromHours(1), 50);
42 } else if (id == PaletteToolId::MAGNIFY) {
43 UMA_HISTOGRAM_CUSTOM_TIMES("Ash.Shelf.Palette.InMagnifyMode", duration,
44 base::TimeDelta::FromMilliseconds(100),
45 base::TimeDelta::FromHours(1), 50);
46 }
47 }
48
36 } // namespace 49 } // namespace
37 50
38 CommonPaletteTool::CommonPaletteTool(Delegate* delegate) 51 CommonPaletteTool::CommonPaletteTool(Delegate* delegate)
39 : PaletteTool(delegate) {} 52 : PaletteTool(delegate) {}
40 53
41 CommonPaletteTool::~CommonPaletteTool() {} 54 CommonPaletteTool::~CommonPaletteTool() {}
42 55
43 views::View* CommonPaletteTool::CreateView() { 56 views::View* CommonPaletteTool::CreateView() {
44 // TODO(jdufault): Use real strings. 57 // TODO(jdufault): Use real strings.
45 return CreateDefaultView( 58 return CreateDefaultView(
46 base::ASCIIToUTF16("[TODO] " + PaletteToolIdToString(GetToolId()))); 59 base::ASCIIToUTF16("[TODO] " + PaletteToolIdToString(GetToolId())));
47 } 60 }
48 61
49 void CommonPaletteTool::OnViewDestroyed() { 62 void CommonPaletteTool::OnViewDestroyed() {
50 highlight_view_ = nullptr; 63 highlight_view_ = nullptr;
51 } 64 }
52 65
53 void CommonPaletteTool::OnEnable() { 66 void CommonPaletteTool::OnEnable() {
54 PaletteTool::OnEnable(); 67 PaletteTool::OnEnable();
68 start_time_ = base::TimeTicks::Now();
55 69
56 if (highlight_view_) { 70 if (highlight_view_) {
57 highlight_view_->SetHighlight(true); 71 highlight_view_->SetHighlight(true);
58 highlight_view_->SetRightIconVisible(true); 72 highlight_view_->SetRightIconVisible(true);
59 } 73 }
60 } 74 }
61 75
62 void CommonPaletteTool::OnDisable() { 76 void CommonPaletteTool::OnDisable() {
63 PaletteTool::OnDisable(); 77 PaletteTool::OnDisable();
78 AddHistogramTimes(GetToolId(), base::TimeTicks::Now() - start_time_);
64 79
65 if (highlight_view_) { 80 if (highlight_view_) {
66 highlight_view_->SetHighlight(false); 81 highlight_view_->SetHighlight(false);
67 highlight_view_->SetRightIconVisible(false); 82 highlight_view_->SetRightIconVisible(false);
68 } 83 }
69 } 84 }
70 85
71 void CommonPaletteTool::OnViewClicked(views::View* sender) { 86 void CommonPaletteTool::OnViewClicked(views::View* sender) {
72 if (enabled()) 87 delegate()->RecordPaletteOptionsUsage(
88 PaletteToolIdToPaletteTrayOptions(GetToolId()));
89 if (enabled()) {
73 delegate()->DisableTool(GetToolId()); 90 delegate()->DisableTool(GetToolId());
74 else 91 delegate()->RecordPaletteModeCancellation(
92 PaletteToolIdToPaletteModeCancelType(GetToolId(),
93 false /*is_switched*/));
94 } else {
75 delegate()->EnableTool(GetToolId()); 95 delegate()->EnableTool(GetToolId());
96 }
76 } 97 }
77 98
78 views::View* CommonPaletteTool::CreateDefaultView(const base::string16& name) { 99 views::View* CommonPaletteTool::CreateDefaultView(const base::string16& name) {
79 gfx::ImageSkia icon = 100 gfx::ImageSkia icon =
80 CreateVectorIcon(GetPaletteIcon(), kIconSize, gfx::kChromeIconGrey); 101 CreateVectorIcon(GetPaletteIcon(), kIconSize, gfx::kChromeIconGrey);
81 gfx::ImageSkia check = CreateVectorIcon(gfx::VectorIconId::CHECK_CIRCLE, 102 gfx::ImageSkia check = CreateVectorIcon(gfx::VectorIconId::CHECK_CIRCLE,
82 kIconSize, gfx::kGoogleGreen700); 103 kIconSize, gfx::kGoogleGreen700);
83 104
84 highlight_view_ = new HoverHighlightView(this); 105 highlight_view_ = new HoverHighlightView(this);
85 highlight_view_->SetBorder( 106 highlight_view_->SetBorder(
86 views::Border::CreateEmptyBorder(0, kExtraMarginFromLeftEdge, 0, 0)); 107 views::Border::CreateEmptyBorder(0, kExtraMarginFromLeftEdge, 0, 0));
87 highlight_view_->AddIconAndLabelCustomSize(icon, name, false, kIconSize, 108 highlight_view_->AddIconAndLabelCustomSize(icon, name, false, kIconSize,
88 kMarginFromEdges, 109 kMarginFromEdges,
89 kMarginBetweenIconAndText); 110 kMarginBetweenIconAndText);
90 highlight_view_->AddRightIcon(check, kIconSize); 111 highlight_view_->AddRightIcon(check, kIconSize);
91 112
92 if (enabled()) 113 if (enabled())
93 highlight_view_->SetHighlight(true); 114 highlight_view_->SetHighlight(true);
94 else 115 else
95 highlight_view_->SetRightIconVisible(false); 116 highlight_view_->SetRightIconVisible(false);
96 117
97 return highlight_view_; 118 return highlight_view_;
98 } 119 }
99 120
100 } // namespace ash 121 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698