0

glic: Fix performance metrics for short responses.

In a short response the web client will call OnResponseStopped() without
first calling OnResponseStarted(). This CL handles this by synthetically
invoking OnResponseStarted() in this case.

Change-Id: Ia96dc0d682ff4d4f9d213c9ecbca557023af81e0
Bug: 391417447, 399151164
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6300792
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1424796}
This commit is contained in:
Erik Chen
2025-02-25 14:04:15 -08:00
committed by Chromium LUCI CQ
parent 9ef2ccd369
commit 46b56e058d
2 changed files with 12 additions and 0 deletions

@ -159,6 +159,7 @@ void GlicMetrics::OnUserInputSubmitted(mojom::WebClientMode mode) {
}
void GlicMetrics::OnResponseStarted() {
response_started_ = true;
base::RecordAction(base::UserMetricsAction("GlicResponseStart"));
// It doesn't make sense to record response start without input submission.
@ -219,6 +220,12 @@ void GlicMetrics::OnResponseStarted() {
}
void GlicMetrics::OnResponseStopped() {
// The client may call "stopped" without "started" for very short responses.
// We synthetically call it ourselves in this case.
if (!input_submitted_time_.is_null() && !response_started_) {
OnResponseStarted();
}
base::RecordAction(base::UserMetricsAction("GlicResponseStop"));
if (input_submitted_time_.is_null()) {
@ -234,6 +241,7 @@ void GlicMetrics::OnResponseStopped() {
input_submitted_time_ = base::TimeTicks();
did_request_context_ = false;
source_id_ = no_url_source_id_;
response_started_ = false;
}
void GlicMetrics::OnSessionTerminated() {

@ -102,6 +102,10 @@ class GlicMetrics {
// value.
bool is_enabled_ = false;
// Set to true in OnResponseStarted() and set to false in OnResponseStopped().
// This is a workaround and should be removed, see crbug.com/399151164.
bool response_started_ = false;
// Holds subscriptions for callbacks.
std::vector<base::CallbackListSubscription> subscriptions_;