Skip to content

Commit b8cd7ea

Browse files
Bug 1848459 - add telemetry to count closed tabs lost in session restore r=sfoster,sessionstore-reviewers
* Add histogram to sessionrestore code to count how often and the number of closed tabs that aren't saved on window close due to no open saveable tabs * Add test coverage Differential Revision: https://phabricator.services.mozilla.com/D193055
1 parent 4ab2bf8 commit b8cd7ea

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

browser/components/sessionstore/SessionStore.sys.mjs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,7 +2360,7 @@ var SessionStoreInternal = {
23602360
// It's possible that a tab switched its privacy state at some point
23612361
// before our flush, so we need to filter again.
23622362
lazy.PrivacyFilter.filterPrivateTabs(winData);
2363-
this.maybeSaveClosedWindow(winData, isLastWindow);
2363+
this.maybeSaveClosedWindow(winData, isLastWindow, true);
23642364

23652365
if (!isLastWindow && winData.closedId > -1) {
23662366
this._addClosedAction(
@@ -2439,7 +2439,7 @@ var SessionStoreInternal = {
24392439
* to call this method again asynchronously (for example, after
24402440
* a window flush).
24412441
*/
2442-
maybeSaveClosedWindow(winData, isLastWindow) {
2442+
maybeSaveClosedWindow(winData, isLastWindow, recordTelemetry = false) {
24432443
// Make sure SessionStore is still running, and make sure that we
24442444
// haven't chosen to forget this window.
24452445
if (
@@ -2498,6 +2498,14 @@ var SessionStoreInternal = {
24982498
}
24992499
if (alreadyStored) {
25002500
this._removeClosedWindow(winIndex);
2501+
return;
2502+
}
2503+
// we only do this after the TabStateFlusher promise resolves in ssi_onClose
2504+
if (recordTelemetry) {
2505+
let closedTabsHistogram = Services.telemetry.getHistogramById(
2506+
"FX_SESSION_RESTORE_CLOSED_TABS_NOT_SAVED"
2507+
);
2508+
closedTabsHistogram.add(winData._closedTabs.length);
25012509
}
25022510
}
25032511
}

browser/components/sessionstore/test/browser_closed_tabs_closed_windows.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/* This Source Code Form is subject to the terms of the Mozilla Public
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4-
4+
const { TelemetryTestUtils } = ChromeUtils.import(
5+
"resource://testing-common/TelemetryTestUtils.jsm"
6+
);
57
const TEST_URLS = [
68
"http://mochi.test:8888/browser/",
79
"https://www.example.com/",
@@ -74,17 +76,37 @@ async function prepareClosedData() {
7476
closedIds.tab5 =
7577
SessionStore.getClosedTabDataForWindow(privateWin)[0].closedId;
7678

79+
const testWindow6 = await BrowserTestUtils.openNewBrowserWindow();
80+
81+
const testWindow7 = await BrowserTestUtils.openNewBrowserWindow();
82+
await openAndCloseTab(testWindow7, TEST_URLS[4]);
83+
84+
let closedTabsHistogram = TelemetryTestUtils.getAndClearHistogram(
85+
"FX_SESSION_RESTORE_CLOSED_TABS_NOT_SAVED"
86+
);
87+
7788
await BrowserTestUtils.closeWindow(testWindow1);
7889
closedIds.testWindow1 = SessionStore.getClosedWindowData()[0].closedId;
7990
await BrowserTestUtils.closeWindow(testWindow2);
91+
8092
closedIds.testWindow2 = SessionStore.getClosedWindowData()[0].closedId;
8193
await BrowserTestUtils.closeWindow(testWindow3);
94+
8295
closedIds.testWindow3 = SessionStore.getClosedWindowData()[0].closedId;
8396
await BrowserTestUtils.closeWindow(privateWin);
8497
Assert.ok(
8598
closedIds.testWindow2 > closedIds.testWindow1,
8699
"We got the closedIds in the expected order"
87100
);
101+
102+
await BrowserTestUtils.closeWindow(testWindow6);
103+
TelemetryTestUtils.assertHistogram(closedTabsHistogram, 0, 1);
104+
closedTabsHistogram.clear();
105+
106+
await BrowserTestUtils.closeWindow(testWindow7);
107+
TelemetryTestUtils.assertHistogram(closedTabsHistogram, 1, 1);
108+
closedTabsHistogram.clear();
109+
88110
return closedIds;
89111
}
90112

toolkit/components/telemetry/Histograms.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9307,6 +9307,17 @@
93079307
"n_values": 50,
93089308
"description": "Session restore: Number of tabs restored eagerly in the session that has just been restored."
93099309
},
9310+
"FX_SESSION_RESTORE_CLOSED_TABS_NOT_SAVED": {
9311+
"record_in_processes": ["main", "content"],
9312+
"products": ["firefox"],
9313+
"expires_in_version": "127",
9314+
"alert_emails": ["firefox-view-engineers@mozilla.com"],
9315+
"releaseChannelCollection": "opt-out",
9316+
"bug_numbers": [1848459],
9317+
"kind": "enumerated",
9318+
"n_values": 25,
9319+
"description": "Session restore: Number of closed tabs that are NOT saved due to lack of open tabs worth saving on window close."
9320+
},
93109321
"FX_TABLETMODE_PAGE_LOAD": {
93119322
"record_in_processes": ["main", "content"],
93129323
"products": ["firefox", "fennec"],

0 commit comments

Comments
 (0)