1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/side_panel/side_panel_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/strings/strcat.h"
#include "base/time/time.h"
#include "chrome/browser/history_clusters/history_clusters_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window/public/browser_window_features.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/side_panel/bookmarks/bookmarks_side_panel_coordinator.h"
#include "chrome/browser/ui/views/side_panel/extensions/extension_side_panel_manager.h"
#include "chrome/browser/ui/views/side_panel/history/history_side_panel_coordinator.h"
#include "chrome/browser/ui/views/side_panel/history_clusters/history_clusters_side_panel_coordinator.h"
#include "chrome/browser/ui/views/side_panel/reading_list/reading_list_side_panel_coordinator.h"
#include "chrome/browser/ui/views/side_panel/side_panel_content_proxy.h"
#include "chrome/browser/ui/views/side_panel/side_panel_coordinator.h"
#include "chrome/browser/ui/views/side_panel/side_panel_registry.h"
#include "chrome/browser/ui/views/side_panel/side_panel_ui.h"
#include "components/history_clusters/core/features.h"
#include "components/history_clusters/core/history_clusters_service.h"
#include "components/prefs/pref_service.h"
#include "ui/accessibility/accessibility_features.h"
#include "ui/actions/actions.h"
// static
void SidePanelUtil::PopulateGlobalEntries(Browser* browser,
SidePanelRegistry* window_registry) {
// Add reading list.
ReadingListSidePanelCoordinator::GetOrCreateForBrowser(browser)
->CreateAndRegisterEntry(window_registry);
// Add bookmarks.
browser->browser_window_features()
->bookmarks_side_panel_coordinator()
->CreateAndRegisterEntry(window_registry);
// Add history clusters.
if (HistoryClustersSidePanelCoordinator::IsSupported(browser->profile()) &&
!HistorySidePanelCoordinator::IsSupported()) {
HistoryClustersSidePanelCoordinator::GetOrCreateForBrowser(browser)
->CreateAndRegisterEntry(window_registry);
}
// Add history.
if (HistorySidePanelCoordinator::IsSupported()) {
browser->browser_window_features()
->history_side_panel_coordinator()
->CreateAndRegisterEntry(window_registry);
}
}
SidePanelContentProxy* SidePanelUtil::GetSidePanelContentProxy(
views::View* content_view) {
if (!content_view->GetProperty(kSidePanelContentProxyKey)) {
content_view->SetProperty(
kSidePanelContentProxyKey,
std::make_unique<SidePanelContentProxy>(true).release());
}
return content_view->GetProperty(kSidePanelContentProxyKey);
}
void SidePanelUtil::RecordSidePanelOpen(
std::optional<SidePanelUtil::SidePanelOpenTrigger> trigger) {
base::RecordAction(base::UserMetricsAction("SidePanel.Show"));
if (trigger.has_value()) {
base::UmaHistogramEnumeration("SidePanel.OpenTrigger", trigger.value());
}
}
void SidePanelUtil::RecordSidePanelShowOrChangeEntryTrigger(
std::optional<SidePanelUtil::SidePanelOpenTrigger> trigger) {
if (trigger.has_value()) {
base::UmaHistogramEnumeration("SidePanel.OpenOrChangeEntryTrigger",
trigger.value());
}
}
void SidePanelUtil::RecordSidePanelClosed(base::TimeTicks opened_timestamp) {
base::RecordAction(base::UserMetricsAction("SidePanel.Hide"));
base::UmaHistogramLongTimes("SidePanel.OpenDuration",
base::TimeTicks::Now() - opened_timestamp);
}
void SidePanelUtil::RecordSidePanelResizeMetrics(SidePanelEntry::Id id,
int side_panel_contents_width,
int browser_window_width) {
std::string entry_name = SidePanelEntryIdToHistogramName(id);
// Metrics per-id and overall for side panel width after resize.
base::UmaHistogramCounts10000(
base::StrCat({"SidePanel.", entry_name, ".ResizedWidth"}),
side_panel_contents_width);
base::UmaHistogramCounts10000("SidePanel.ResizedWidth",
side_panel_contents_width);
// Metrics per-id and overall for side panel width after resize as a
// percentage of browser width.
int width_percentage = side_panel_contents_width * 100 / browser_window_width;
base::UmaHistogramPercentage(
base::StrCat({"SidePanel.", entry_name, ".ResizedWidthPercentage"}),
width_percentage);
base::UmaHistogramPercentage("SidePanel.ResizedWidthPercentage",
width_percentage);
}
void SidePanelUtil::RecordNewTabButtonClicked(SidePanelEntry::Id id) {
base::RecordComputedAction(
base::StrCat({"SidePanel.", SidePanelEntryIdToHistogramName(id),
".NewTabButtonClicked"}));
}
void SidePanelUtil::RecordEntryShownMetrics(
SidePanelEntry::Id id,
base::TimeTicks load_started_timestamp) {
base::RecordComputedAction(base::StrCat(
{"SidePanel.", SidePanelEntryIdToHistogramName(id), ".Shown"}));
if (load_started_timestamp != base::TimeTicks()) {
base::UmaHistogramLongTimes(
base::StrCat({"SidePanel.", SidePanelEntryIdToHistogramName(id),
".TimeFromEntryTriggerToShown"}),
base::TimeTicks::Now() - load_started_timestamp);
}
}
void SidePanelUtil::RecordEntryHiddenMetrics(SidePanelEntry::Id id,
base::TimeTicks shown_timestamp) {
base::UmaHistogramLongTimes(
base::StrCat({"SidePanel.", SidePanelEntryIdToHistogramName(id),
".ShownDuration"}),
base::TimeTicks::Now() - shown_timestamp);
}
void SidePanelUtil::RecordEntryShowTriggeredMetrics(
Browser* browser,
SidePanelEntry::Id id,
std::optional<SidePanelUtil::SidePanelOpenTrigger> trigger) {
if (trigger.has_value()) {
base::UmaHistogramEnumeration(
base::StrCat({"SidePanel.", SidePanelEntryIdToHistogramName(id),
".ShowTriggered"}),
trigger.value());
}
}
void SidePanelUtil::RecordComboboxShown() {
base::UmaHistogramBoolean("SidePanel.ComboboxMenuShown", true);
}
void SidePanelUtil::RecordPinnedButtonClicked(SidePanelEntry::Id id,
bool is_pinned) {
base::RecordComputedAction(base::StrCat(
{"SidePanel.", SidePanelEntryIdToHistogramName(id), ".",
is_pinned ? "Pinned" : "Unpinned", ".BySidePanelHeaderButton"}));
}
void SidePanelUtil::RecordSidePanelAnimationMetrics(
base::TimeDelta largest_step_time) {
base::UmaHistogramTimes("SidePanel.TimeOfLongestAnimationStep",
largest_step_time);
}
|