0

[glic] Log time between sessions

This CL logs the time elapsed between opening the Glic window.

Fixed: 406819491, 407698313
Bug: 391417447
Change-Id: If7b5c1fa69f14b494d007f116e8fa74d01be6f84
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6415812
Commit-Queue: Filipa Senra <fsenra@google.com>
Reviewed-by: Nicola Tommasi <tommasin@chromium.org>
Reviewed-by: Christian Dullweber <dullweber@chromium.org>
Auto-Submit: Filipa Senra <fsenra@google.com>
Reviewed-by: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1442641}
This commit is contained in:
Filipa Senra
2025-04-04 02:47:44 -07:00
committed by Chromium LUCI CQ
parent deaf006c44
commit f748acbd61
5 changed files with 50 additions and 0 deletions

@ -205,6 +205,23 @@ void GlicMetrics::OnGlicWindowOpen(bool attached,
.SetAttached(attached)
.SetInvocationSource(static_cast<int64_t>(source))
.Record(ukm::UkmRecorder::Get());
const base::Time last_dismissed_time =
profile_->GetPrefs()->GetTime(prefs::kGlicWindowLastDismissedTime);
if (!last_dismissed_time.is_null()) {
base::TimeDelta elapsed_time_from_last_session =
base::Time::Now() - last_dismissed_time;
base::UmaHistogramCounts10M(
"Glic.PanelWebUi.ElapsedTimeBetweenSessions",
base::saturated_cast<int>(elapsed_time_from_last_session.InSeconds()));
}
// Update the last dismissed timestamp. The pref might not get updated on
// ungraceful shutdowns. As such, by updating the pref on opening the Glic
// window, the dismissal timestamp will get approximated by the opening
// timestamp, instead of the previously dismissal timestamp.
profile_->GetPrefs()->SetTime(prefs::kGlicWindowLastDismissedTime,
base::Time::Now());
}
void GlicMetrics::OnGlicWindowOpenAndReady() {
@ -278,6 +295,8 @@ void GlicMetrics::OnGlicWindowClose() {
attach_change_count_ = 0;
glic_window_size_timer_.Stop();
profile_->GetPrefs()->SetTime(prefs::kGlicWindowLastDismissedTime,
base::Time::Now());
}
void GlicMetrics::SetControllers(GlicWindowController* window_controller,

@ -559,5 +559,21 @@ TEST_F(GlicMetricsTest, AttachStateChanges) {
histogram_tester_.ExpectBucketCount("Glic.Session.AttachStateChanges", 4, 1);
}
TEST_F(GlicMetricsTest, TimeElapsedBetweenSessions) {
base::TimeDelta elapsed_time = base::Hours(2);
metrics_->OnGlicWindowClose();
task_environment_.FastForwardBy(elapsed_time);
metrics_->OnGlicWindowOpen(/*attached=*/true,
mojom::InvocationSource::kOsButton);
histogram_tester_.ExpectTotalCount(
"Glic.PanelWebUi.ElapsedTimeBetweenSessions",
/*expected_count=*/1);
histogram_tester_.ExpectBucketCount(
"Glic.PanelWebUi.ElapsedTimeBetweenSessions", elapsed_time.InSeconds(),
1);
}
} // namespace
} // namespace glic

@ -17,6 +17,7 @@ void RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(kGlicTabContextEnabled, false);
registry->RegisterIntegerPref(
kGlicCompletedFre, static_cast<int>(prefs::FreStatus::kNotStarted));
registry->RegisterTimePref(kGlicWindowLastDismissedTime, base::Time());
}
void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {

@ -62,6 +62,10 @@ inline constexpr char kGlicTabContextEnabled[] = "glic.tab_context_enabled";
// the FreStatus enum.
inline constexpr char kGlicCompletedFre[] = "glic.completed_fre";
// Time pref that records the last time a user dismissed the Glic window.
inline constexpr char kGlicWindowLastDismissedTime[] =
"glic.window.last_dimissed_time";
void RegisterProfilePrefs(PrefRegistrySimple* registry);
void RegisterLocalStatePrefs(PrefRegistrySimple* registry);

@ -268,6 +268,16 @@ chromium-metrics-reviews@google.com.
</token>
</histogram>
<histogram name="Glic.PanelWebUi.ElapsedTimeBetweenSessions" units="seconds"
expires_after="2026-01-15">
<owner>fsenra@google.com</owner>
<owner>dewittj@google.com</owner>
<summary>
Records the elapsed time between the current and last session. Recorded when
the Glic panel is opened.
</summary>
</histogram>
<histogram name="Glic.PanelWebUi.Size.Area" units="DIPs"
expires_after="2026-01-15">
<owner>fsenra@google.com</owner>