Skip to content

Commit 77f9b06

Browse files
committed
Bug 1883736 - Add disk size measurements for all logins, keys, certificates and payment methods stores. r=backup-reviewers,mconley
Differential Revision: https://phabricator.services.mozilla.com/D204948
1 parent 9c868d9 commit 77f9b06

File tree

6 files changed

+210
-13
lines changed

6 files changed

+210
-13
lines changed

browser/components/backup/BackupResources.sys.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
44

5+
import { CredentialsAndSecurityBackupResource } from "resource:///modules/backup/CredentialsAndSecurityBackupResource.sys.mjs";
6+
import { PlacesBackupResource } from "resource:///modules/backup/PlacesBackupResource.sys.mjs";
7+
58
/**
69
* Classes exported here are registered as a resource that can be
710
* backed up and restored in the BackupService.
811
*
912
* They must extend the BackupResource base class.
1013
*/
11-
import { PlacesBackupResource } from "resource:///modules/backup/PlacesBackupResource.sys.mjs";
1214

13-
export { PlacesBackupResource };
15+
export { CredentialsAndSecurityBackupResource, PlacesBackupResource };

browser/components/backup/metrics.yaml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,41 @@ browser.backup:
5656
- https://bugzilla.mozilla.org/show_bug.cgi?id=1883642
5757
data_reviews:
5858
- https://bugzilla.mozilla.org/show_bug.cgi?id=1883642
59+
notification_emails:
60+
- mconley@mozilla.com
61+
expires: never
62+
telemetry_mirror: BROWSER_BACKUP_FAVICONS_SIZE
63+
64+
credentials_data_size:
65+
type: quantity
66+
unit: kilobyte
67+
description: >
68+
The total size of logins, payment method, and form autofill related files
69+
in the current profile directory, in kilobytes.
70+
bugs:
71+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1883736
72+
data_reviews:
73+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1883736
5974
data_sensitivity:
6075
- technical
6176
notification_emails:
6277
- mconley@mozilla.com
6378
expires: never
64-
telemetry_mirror: BROWSER_BACKUP_FAVICONS_SIZE
79+
telemetry_mirror: BROWSER_BACKUP_CREDENTIALS_DATA_SIZE
80+
81+
security_data_size:
82+
type: quantity
83+
unit: kilobyte
84+
description: >
85+
The total size of files needed for NSS initialization parameters and security
86+
certificate settings in the current profile directory, in kilobytes.
87+
bugs:
88+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1883736
89+
data_reviews:
90+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1883736
91+
data_sensitivity:
92+
- technical
93+
notification_emails:
94+
- mconley@mozilla.com
95+
expires: never
96+
telemetry_mirror: BROWSER_BACKUP_SECURITY_DATA_SIZE

browser/components/backup/moz.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ EXTRA_JS_MODULES.backup += [
1515
"BackupResources.sys.mjs",
1616
"BackupService.sys.mjs",
1717
"resources/BackupResource.sys.mjs",
18+
"resources/CredentialsAndSecurityBackupResource.sys.mjs",
1819
"resources/PlacesBackupResource.sys.mjs",
1920
]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4+
5+
import { BackupResource } from "resource:///modules/backup/BackupResource.sys.mjs";
6+
7+
/**
8+
* Class representing files needed for logins, payment methods and form autofill within a user profile.
9+
*/
10+
export class CredentialsAndSecurityBackupResource extends BackupResource {
11+
static get key() {
12+
return "credentials_and_security";
13+
}
14+
15+
async measure(profilePath = PathUtils.profileDir) {
16+
const securityFiles = ["cert9.db", "pkcs11.txt"];
17+
let securitySize = 0;
18+
19+
for (let filePath of securityFiles) {
20+
let resourcePath = PathUtils.join(profilePath, filePath);
21+
let resourceSize = await BackupResource.getFileSize(resourcePath);
22+
if (Number.isInteger(resourceSize)) {
23+
securitySize += resourceSize;
24+
}
25+
}
26+
27+
Glean.browserBackup.securityDataSize.set(securitySize);
28+
29+
const credentialsFiles = [
30+
"key4.db",
31+
"logins.json",
32+
"logins-backup.json",
33+
"autofill-profiles.json",
34+
"credentialstate.sqlite",
35+
];
36+
let credentialsSize = 0;
37+
38+
for (let filePath of credentialsFiles) {
39+
let resourcePath = PathUtils.join(profilePath, filePath);
40+
let resourceSize = await BackupResource.getFileSize(resourcePath);
41+
if (Number.isInteger(resourceSize)) {
42+
credentialsSize += resourceSize;
43+
}
44+
}
45+
46+
Glean.browserBackup.credentialsDataSize.set(credentialsSize);
47+
}
48+
}

browser/components/backup/tests/xpcshell/test_measurements.js

Lines changed: 94 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ http://creativecommons.org/publicdomain/zero/1.0/ */
33

44
"use strict";
55

6+
const { BackupResource } = ChromeUtils.importESModule(
7+
"resource:///modules/backup/BackupResource.sys.mjs"
8+
);
69
const { BackupService } = ChromeUtils.importESModule(
710
"resource:///modules/backup/BackupService.sys.mjs"
811
);
9-
12+
const { CredentialsAndSecurityBackupResource } = ChromeUtils.importESModule(
13+
"resource:///modules/backup/CredentialsAndSecurityBackupResource.sys.mjs"
14+
);
1015
const { PlacesBackupResource } = ChromeUtils.importESModule(
1116
"resource:///modules/backup/PlacesBackupResource.sys.mjs"
1217
);
13-
14-
const { BackupResource } = ChromeUtils.importESModule(
15-
"resource:///modules/backup/BackupResource.sys.mjs"
16-
);
17-
1818
const { TelemetryTestUtils } = ChromeUtils.importESModule(
1919
"resource://testing-common/TelemetryTestUtils.sys.mjs"
2020
);
@@ -23,9 +23,6 @@ const { sinon } = ChromeUtils.importESModule(
2323
"resource://testing-common/Sinon.sys.mjs"
2424
);
2525

26-
const EXPECTED_PLACES_DB_SIZE = 5240;
27-
const EXPECTED_FAVICONS_DB_SIZE = 5240;
28-
2926
add_setup(() => {
3027
do_get_profile();
3128
// FOG needs to be initialized in order for data to flow.
@@ -108,8 +105,11 @@ add_task(async function test_profDDiskSpace() {
108105
add_task(async function test_placesBackupResource() {
109106
Services.fog.testResetFOG();
110107

108+
const EXPECTED_PLACES_DB_SIZE = 5240;
109+
const EXPECTED_FAVICONS_DB_SIZE = 5240;
110+
111111
// Create resource files in temporary directory
112-
let tempDir = PathUtils.tempDir;
112+
const tempDir = PathUtils.tempDir;
113113
let tempPlacesDBPath = PathUtils.join(tempDir, "places.sqlite");
114114
let tempFaviconsDBPath = PathUtils.join(tempDir, "favicons.sqlite");
115115
await createKilobyteSizedFile(tempPlacesDBPath, EXPECTED_PLACES_DB_SIZE);
@@ -151,3 +151,87 @@ add_task(async function test_placesBackupResource() {
151151
await IOUtils.remove(tempPlacesDBPath);
152152
await IOUtils.remove(tempFaviconsDBPath);
153153
});
154+
155+
/**
156+
* Tests that we can measure credentials related files in the profile directory.
157+
*/
158+
add_task(async function test_credentialsAndSecurityBackupResource() {
159+
Services.fog.testResetFOG();
160+
161+
const EXPECTED_CREDENTIALS_KILOBYTES_SIZE = 403;
162+
const EXPECTED_SECURITY_KILOBYTES_SIZE = 231;
163+
164+
// Create resource files in temporary directory
165+
const tempDir = PathUtils.tempDir;
166+
167+
// Set up credentials files
168+
const mockCredentialsFiles = new Map([
169+
["key4.db", 300],
170+
["logins.json", 1],
171+
["logins-backup.json", 1],
172+
["autofill-profiles.json", 1],
173+
["credentialstate.sqlite", 100],
174+
]);
175+
176+
for (let [mockFileName, mockFileSize] of mockCredentialsFiles) {
177+
let tempPath = PathUtils.join(tempDir, mockFileName);
178+
await createKilobyteSizedFile(tempPath, mockFileSize);
179+
}
180+
181+
// Set up security files
182+
const mockSecurityFiles = new Map([
183+
["cert9.db", 230],
184+
["pkcs11.txt", 1],
185+
]);
186+
187+
for (let [mockFileName, mockFileSize] of mockSecurityFiles) {
188+
let tempPath = PathUtils.join(tempDir, mockFileName);
189+
await createKilobyteSizedFile(tempPath, mockFileSize);
190+
}
191+
192+
let credentialsAndSecurityBackupResource =
193+
new CredentialsAndSecurityBackupResource();
194+
await credentialsAndSecurityBackupResource.measure(tempDir);
195+
196+
let credentialsMeasurement =
197+
Glean.browserBackup.credentialsDataSize.testGetValue();
198+
let securityMeasurement = Glean.browserBackup.securityDataSize.testGetValue();
199+
let scalars = TelemetryTestUtils.getProcessScalars("parent", false, false);
200+
201+
// Credentials measurements
202+
TelemetryTestUtils.assertScalar(
203+
scalars,
204+
"browser.backup.credentials_data_size",
205+
credentialsMeasurement,
206+
"Glean and telemetry measurements for credentials data should be equal"
207+
);
208+
209+
Assert.equal(
210+
credentialsMeasurement,
211+
EXPECTED_CREDENTIALS_KILOBYTES_SIZE,
212+
"Should have collected the correct glean measurement for credentials files"
213+
);
214+
215+
// Security measurements
216+
TelemetryTestUtils.assertScalar(
217+
scalars,
218+
"browser.backup.security_data_size",
219+
securityMeasurement,
220+
"Glean and telemetry measurements for security data should be equal"
221+
);
222+
Assert.equal(
223+
securityMeasurement,
224+
EXPECTED_SECURITY_KILOBYTES_SIZE,
225+
"Should have collected the correct glean measurement for security files"
226+
);
227+
228+
// Cleanup
229+
for (let mockFileName of mockCredentialsFiles.keys()) {
230+
let tempPath = PathUtils.join(tempDir, mockFileName);
231+
await IOUtils.remove(tempPath);
232+
}
233+
for (let mockFileName of mockSecurityFiles.keys()) {
234+
let tempPath = PathUtils.join(tempDir, mockFileName);
235+
await IOUtils.remove(tempPath);
236+
}
237+
});

toolkit/components/telemetry/Scalars.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,36 @@ browser.backup:
202202
- 'firefox'
203203
record_in_processes:
204204
- 'main'
205+
credentials_data_size:
206+
bug_numbers:
207+
- 1883736
208+
description: >
209+
The total size of logins, payment method, and form autofill related files
210+
in the current profile directory, in kilobytes.
211+
expires: never
212+
kind: uint
213+
notification_emails:
214+
- mconley@mozilla.com
215+
release_channel_collection: opt-out
216+
products:
217+
- 'firefox'
218+
record_in_processes:
219+
- 'main'
220+
security_data_size:
221+
bug_numbers:
222+
- 1883736
223+
description: >
224+
The total size of files needed for NSS initialization parameters and security
225+
certificate settings in the current profile directory, in kilobytes.
226+
expires: never
227+
kind: uint
228+
notification_emails:
229+
- mconley@mozilla.com
230+
release_channel_collection: opt-out
231+
products:
232+
- 'firefox'
233+
record_in_processes:
234+
- 'main'
205235

206236
# The following section contains the browser engagement scalars.
207237
browser.engagement:

0 commit comments

Comments
 (0)