Skip to content

Commit

Permalink
VirtualDesks: Add metrics for custom desks names
Browse files Browse the repository at this point in the history
This CL adds metrics for custom desks names. Specifically, this cl adds
metrics for the number of the user's desks that have a custom name and
the proportion of the user's desks that have a custom name.

Bug: b:247947271
Change-Id: If98df27c8265026cd1bdfd678b26a4264b92b0a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4000099
Reviewed-by: Daniel Andersson <dandersson@chromium.org>
Commit-Queue: Ben Becker <benbecker@chromium.org>
Reviewed-by: Jimmy Gong <jimmyxgong@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1067352}
  • Loading branch information
Ben Becker authored and Chromium LUCI CQ committed Nov 4, 2022
1 parent b5beedf commit e786293
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ash/wm/desks/desks_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ void DesksController::NotifyAllDesksForContentChanged() {

void DesksController::NotifyDeskNameChanged(const Desk* desk,
const std::u16string& new_name) {
MaybeReportCustomDeskNames();
for (auto& observer : observers_)
observer.OnDeskNameChanged(desk, new_name);
}
Expand Down Expand Up @@ -1683,6 +1684,7 @@ void DesksController::RemoveDeskInternal(const Desk* desk,

UMA_HISTOGRAM_ENUMERATION(kRemoveDeskHistogramName, source);
UMA_HISTOGRAM_ENUMERATION(kRemoveDeskTypeHistogramName, close_type);
MaybeReportCustomDeskNames();

// We should only announce desks are being merged if we are combining desks.
if (close_type == DeskCloseType::kCombineDesks) {
Expand Down Expand Up @@ -2016,4 +2018,18 @@ void DesksController::ReportClosedWindowsCountPerSourceHistogram(
base::UmaHistogramCounts100(desk_removal_source_histogram, windows_closed);
}

void DesksController::MaybeReportCustomDeskNames() const {
// We only want metrics for users with two or more desks.
if (desks_.size() < 2)
return;

int custom_names_count =
base::ranges::count(desks_, true, &Desk::is_name_set_by_user);

base::UmaHistogramCounts100(kNumberOfCustomNamesHistogramName,
custom_names_count);
base::UmaHistogramPercentage(kPercentageOfCustomNamesHistogramName,
custom_names_count * 100 / desks_.size());
}

} // namespace ash
2 changes: 2 additions & 0 deletions ash/wm/desks/desks_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ class ASH_EXPORT DesksController : public chromeos::DesksHelper,
DesksCreationRemovalSource source,
int windows_closed) const;

void MaybeReportCustomDeskNames() const;

std::vector<std::unique_ptr<Desk>> desks_;

Desk* active_desk_ = nullptr;
Expand Down
5 changes: 5 additions & 0 deletions ash/wm/desks/desks_histogram_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ enum class DesksSwitchSource {
constexpr char kNewDeskHistogramName[] = "Ash.Desks.NewDesk2";
constexpr char kDeskSwitchHistogramName[] = "Ash.Desks.DesksSwitch";

constexpr char kNumberOfCustomNamesHistogramName[] =
"Ash.Desks.CustomNameCount";
constexpr char kPercentageOfCustomNamesHistogramName[] =
"Ash.Desks.CustomNamePercentage";

} // namespace ash

#endif // ASH_WM_DESKS_DESKS_HISTOGRAM_ENUMS_H_
66 changes: 66 additions & 0 deletions ash/wm/desks/desks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6390,6 +6390,72 @@ TEST_P(DesksTest, CloseButtonShowsAfterLongPressInTabletMode) {
EXPECT_TRUE(mini_view->close_desk_button()->GetVisible());
}

// Tests that metrics are being recorded when a desk is renamed, when new desks
// are added, and when a desk is being removed.
TEST_P(DesksTest, TestCustomDeskNameMetricsRecording) {
// Actions that should cause the histogram to update.
enum class UpdateSource {
kDeskRenamed,
kDeskAdded,
kDeskRemoved,
};

struct {
const std::string scope_trace;
const UpdateSource update_source;
const int expected_number_of_custom_desks;
const int expected_percentage_of_custom_desks;
} kTestCases[] = {
{"Rename a desk", UpdateSource::kDeskRenamed, 1, 50},
{"Add a desk", UpdateSource::kDeskAdded, 1, 33},
{"Remove a desk", UpdateSource::kDeskRemoved, 1, 50},
};

base::HistogramTester histogram_tester;

// Create a new desk. At this point we should have had one update for the new
// desk addition because adding a new desk requires confirming the new desk's
// name.
NewDesk();
int number_of_updates = 1;
histogram_tester.ExpectTotalCount(kNumberOfCustomNamesHistogramName,
number_of_updates);
histogram_tester.ExpectTotalCount(kPercentageOfCustomNamesHistogramName,
number_of_updates);
const auto& desks = DesksController::Get()->desks();

for (const auto& test_case : kTestCases) {
SCOPED_TRACE(test_case.scope_trace);

switch (test_case.update_source) {
case UpdateSource::kDeskRenamed:
desks[0]->SetName(u"Hello", true);
break;
case UpdateSource::kDeskAdded:
NewDesk();
break;
case UpdateSource::kDeskRemoved:
RemoveDesk(desks.back().get());
break;
}

++number_of_updates;
histogram_tester.ExpectTotalCount(kNumberOfCustomNamesHistogramName,
number_of_updates);
histogram_tester.ExpectTotalCount(kPercentageOfCustomNamesHistogramName,
number_of_updates);

// There should be at least one recording of the expected custom desk count
// and percentage.
EXPECT_NE(0, histogram_tester.GetBucketCount(
kNumberOfCustomNamesHistogramName,
test_case.expected_number_of_custom_desks));
EXPECT_NE(0, histogram_tester.GetBucketCount(
kPercentageOfCustomNamesHistogramName,
test_case.expected_percentage_of_custom_desks));
}
}

class DesksBentoBarTest : public DesksTest {
public:
DesksBentoBarTest() {
Expand Down
20 changes: 20 additions & 0 deletions tools/metrics/histograms/metadata/ash/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,26 @@ chromium-metrics-reviews@google.com.
</summary>
</histogram>

<histogram name="Ash.Desks.CustomNameCount" units="desks"
expires_after="2023-11-01">
<owner>benbecker@google.com</owner>
<owner>janetmac@chromium.org</owner>
<summary>
Emitted when a user with more than one desk changes the name of a desk to
specify how many of the user's desks have custom names.
</summary>
</histogram>

<histogram name="Ash.Desks.CustomNamePercentage" units="%"
expires_after="2023-11-01">
<owner>benbecker@google.com</owner>
<owner>janetmac@chromium.org</owner>
<summary>
Emitted when a user with more than one desk changes the name of a desk to
specify the percentage of the user's desks that have custom names.
</summary>
</histogram>

<histogram name="Ash.Desks.DeskLifetime_{DeskIndex}" units="hr"
expires_after="2023-01-13">
<owner>afakhry@chromium.org</owner>
Expand Down

0 comments on commit e786293

Please sign in to comment.