Commit 416c98ec authored by Chris Hamilton's avatar Chris Hamilton Committed by Commit Bot

Create TabManager.TabLifetime UKM.

BUG=776376

Change-Id: I85295f70e14f216c11ecf6c334ee2a39990a9672
Reviewed-on: https://chromium-review.googlesource.com/746532
Commit-Queue: Chris Hamilton <chrisha@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513310}
parent 6cd5b164
......@@ -79,6 +79,7 @@ void TabManager::WebContentsData::DidFinishNavigation(
return;
}
tab_data_.navigation_time = navigation_handle->NavigationStart();
ukm_source_id_ = ukm::ConvertToSourceId(navigation_handle->GetNavigationId(),
ukm::SourceIdType::NAVIGATION_ID);
}
......@@ -105,6 +106,8 @@ void TabManager::WebContentsData::WebContentsDestroyed() {
base::TimeDelta::FromDays(1), 100);
}
ReportUKMWhenTabIsClosed();
if (!web_contents()->IsVisible() &&
tab_data_.last_inactive_time != base::TimeTicks::UnixEpoch()) {
ReportUKMWhenBackgroundTabIsClosedOrForegrounded(false);
......@@ -228,6 +231,15 @@ TimeTicks TabManager::WebContentsData::NowTicks() const {
return test_tick_clock_->NowTicks();
}
void TabManager::WebContentsData::ReportUKMWhenTabIsClosed() {
if (!ukm_source_id_)
return;
auto duration = NowTicks() - tab_data_.navigation_time;
ukm::builders::TabManager_TabLifetime(ukm_source_id_)
.SetTimeSinceNavigation(duration.InMilliseconds())
.Record(ukm::UkmRecorder::Get());
}
void TabManager::WebContentsData::
ReportUKMWhenBackgroundTabIsClosedOrForegrounded(bool is_foregrounded) {
if (!ukm_source_id_)
......@@ -243,6 +255,7 @@ TabManager::WebContentsData::Data::Data()
: is_discarded(false),
discard_count(0),
is_recently_audible(false),
navigation_time(TimeTicks::UnixEpoch()),
last_audio_change_time(TimeTicks::UnixEpoch()),
last_discard_time(TimeTicks::UnixEpoch()),
last_reload_time(TimeTicks::UnixEpoch()),
......
......@@ -169,6 +169,9 @@ class TabManager::WebContentsData
int discard_count;
// Is the tab playing audio?
bool is_recently_audible;
// The navigation time associated with this tab. Useful as a reference time
// from which to measure UKM event timings.
base::TimeTicks navigation_time;
// Last time the tab started or stopped playing audio (we record the
// transition time).
base::TimeTicks last_audio_change_time;
......@@ -195,6 +198,7 @@ class TabManager::WebContentsData
// for more details.
base::TimeTicks NowTicks() const;
void ReportUKMWhenTabIsClosed();
void ReportUKMWhenBackgroundTabIsClosedOrForegrounded(bool is_foregrounded);
// Contains all the needed data for the tab.
......
......@@ -1587,4 +1587,18 @@ be describing additional metrics about the same event.
</metric>
</event>
<event name="TabManager.TabLifetime" singular="True">
<owner>chrisha@chromium.org</owner>
<summary>
Collected when a tab is closed, at most once per source.
</summary>
<metric name="TimeSinceNavigation">
<summary>
The time when the tab was closed, expressed as the amount of time in MS
that has elapsed since the main frame navigation providing the content of
the tab.
</summary>
</metric>
</event>
</ukm-configuration>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment