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/. */
44
5- import { DELETION_REQUEST_PING_NAME } from "../constants.js" ;
6- import { generateUUIDv4 } from "../utils.js" ;
7- import collectAndStorePing from "../pings/maker.js" ;
8- import Glean from "../glean.js" ;
9-
105/**
116 * The common set of data for creating a new ping.
127 */
@@ -21,64 +16,4 @@ interface CommonPingData {
2116 readonly reasonCodes ?: string [ ]
2217}
2318
24- /**
25- * Stores information about a ping.
26- *
27- * This is required so that given metric data queued on disk we can send
28- * pings with the correct settings, e.g. whether it has a client_id.
29- */
30- class PingType implements CommonPingData {
31- readonly name : string ;
32- readonly includeClientId : boolean ;
33- readonly sendIfEmpty : boolean ;
34- readonly reasonCodes : string [ ] ;
35-
36- constructor ( meta : CommonPingData ) {
37- this . name = meta . name ;
38- this . includeClientId = meta . includeClientId ;
39- this . sendIfEmpty = meta . sendIfEmpty ;
40- this . reasonCodes = meta . reasonCodes ?? [ ] ;
41- }
42-
43- private isDeletionRequest ( ) : boolean {
44- return this . name === DELETION_REQUEST_PING_NAME ;
45- }
46-
47- /**
48- * Collects and submits a ping for eventual uploading.
49- *
50- * The ping content is assembled as soon as possible, but upload is not
51- * guaranteed to happen immediately, as that depends on the upload policies.
52- *
53- * If the ping currently contains no content, it will not be sent,
54- * unless it is configured to be sent if empty.
55- *
56- * @param reason The reason the ping was triggered. Included in the
57- * `ping_info.reason` part of the payload.
58- */
59- submit ( reason ?: string ) : void {
60- Glean . dispatcher . launch ( async ( ) => {
61- if ( ! Glean . initialized ) {
62- console . info ( "Glean must be initialized before submitting pings." ) ;
63- return ;
64- }
65-
66- if ( ! Glean . isUploadEnabled ( ) && ! this . isDeletionRequest ( ) ) {
67- console . info ( "Glean disabled: not submitting pings. Glean may still submit the deletion-request ping." ) ;
68- return ;
69- }
70-
71- let correctedReason = reason ;
72- if ( reason && ! this . reasonCodes . includes ( reason ) ) {
73- console . error ( `Invalid reason code ${ reason } from ${ this . name } . Ignoring.` ) ;
74- correctedReason = undefined ;
75- }
76-
77- const identifier = generateUUIDv4 ( ) ;
78- await collectAndStorePing ( identifier , this , correctedReason ) ;
79- return ;
80- } ) ;
81- }
82- }
83-
84- export default PingType ;
19+ export default CommonPingData ;
0 commit comments