@@ -16,7 +16,6 @@ import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
16
16
const lazy = { } ;
17
17
ChromeUtils . defineESModuleGetters ( lazy , {
18
18
MacAttribution : "resource:///modules/MacAttribution.sys.mjs" ,
19
- UpdateUtils : "resource://gre/modules/UpdateUtils.sys.mjs" ,
20
19
} ) ;
21
20
ChromeUtils . defineLazyGetter ( lazy , "log" , ( ) => {
22
21
let { ConsoleAPI } = ChromeUtils . importESModule (
@@ -82,49 +81,6 @@ export var AttributionCode = {
82
81
let file = Services . dirsvc . get ( "GreD" , Ci . nsIFile ) ;
83
82
file . append ( "postSigningData" ) ;
84
83
return file ;
85
- } else if ( AppConstants . platform == "macosx" ) {
86
- // There's no `UpdRootD` in xpcshell tests. Some existing tests override
87
- // it, which is onerous and difficult to share across tests. When testing,
88
- // if it's not defined, fallback to a nested subdirectory of the xpcshell
89
- // temp directory. Nesting more closely replicates the situation where the
90
- // update directory does not (yet) exist, testing a scenario witnessed in
91
- // development.
92
- let file ;
93
- try {
94
- file = Services . dirsvc . get ( "UpdRootD" , Ci . nsIFile ) ;
95
- } catch ( ex ) {
96
- // It's most common to test for the profile dir, even though we actually
97
- // are using the temp dir.
98
- if (
99
- ex instanceof Ci . nsIException &&
100
- ex . result == Cr . NS_ERROR_FAILURE &&
101
- Services . env . exists ( "XPCSHELL_TEST_PROFILE_DIR" )
102
- ) {
103
- let path = Services . env . get ( "XPCSHELL_TEST_TEMP_DIR" ) ;
104
- file = Cc [ "@mozilla.org/file/local;1" ] . createInstance ( Ci . nsIFile ) ;
105
- file . initWithPath ( path ) ;
106
- file . append ( "nested_UpdRootD_1" ) ;
107
- file . append ( "nested_UpdRootD_2" ) ;
108
- } else {
109
- throw ex ;
110
- }
111
- }
112
- // Note: this file is in a location that includes the absolute path
113
- // to the running install, and the filename includes the update channel.
114
- // To ensure consistency regardless of when `attributionFile` is accessed we
115
- // explicitly do not include partner IDs that may be part of the full update channel.
116
- // These are not necessarily applied when this is first accessed, and we want to
117
- // ensure consistency between early and late accesses.
118
- // Partner builds never contain attribution information, so this has no known
119
- // consequences.
120
- // For example:
121
- // ~/Library/Caches/Mozilla/updates/Applications/Firefox/macAttributionDataCache-release
122
- // This is done to ensure that attribution data is preserved through a
123
- // pave over install of an install on the same channel.
124
- file . append (
125
- "macAttributionDataCache-" + lazy . UpdateUtils . getUpdateChannel ( false )
126
- ) ;
127
- return file ;
128
84
}
129
85
130
86
return null ;
@@ -135,8 +91,8 @@ export var AttributionCode = {
135
91
* @param {String } code to write.
136
92
*/
137
93
async writeAttributionFile ( code ) {
138
- // Writing attribution files is only used as part of test code, and Mac
139
- // attribution, so bailing here for MSIX builds is no big deal.
94
+ // Writing attribution files is only used as part of test code
95
+ // so bailing here for MSIX builds is no big deal.
140
96
if (
141
97
AppConstants . platform === "win" &&
142
98
Services . sysinfo . getProperty ( "hasWinPackageId" )
@@ -228,14 +184,12 @@ export var AttributionCode = {
228
184
} ,
229
185
230
186
async _getMacAttrDataAsync ( ) {
231
- let attributionFile = this . attributionFile ;
232
-
233
187
// On macOS, we fish the attribution data from an extended attribute on
234
188
// the .app bundle directory.
235
189
try {
236
190
let attrStr = await lazy . MacAttribution . getAttributionString ( ) ;
237
191
lazy . log . debug (
238
- `getAttrDataAsync: macOS attribution getAttributionString: "${ attrStr } "`
192
+ `_getMacAttrDataAsync: getAttributionString: "${ attrStr } "`
239
193
) ;
240
194
241
195
gCachedAttrData = this . parseAttributionCode ( attrStr ) ;
@@ -261,22 +215,6 @@ export var AttributionCode = {
261
215
`macOS attribution data is ${ JSON . stringify ( gCachedAttrData ) } `
262
216
) ;
263
217
264
- // We only want to try to fetch the attribution string once on macOS
265
- try {
266
- let code = this . serializeAttributionData ( gCachedAttrData ) ;
267
- lazy . log . debug ( `macOS attribution data serializes as "${ code } "` ) ;
268
- await this . writeAttributionFile ( code ) ;
269
- } catch ( ex ) {
270
- lazy . log . debug ( `Caught exception writing "${ attributionFile . path } "` , ex ) ;
271
- Services . telemetry
272
- . getHistogramById ( "BROWSER_ATTRIBUTION_ERRORS" )
273
- . add ( "write_error" ) ;
274
- return gCachedAttrData ;
275
- }
276
-
277
- lazy . log . debug (
278
- `Returning after successfully writing "${ attributionFile . path } "`
279
- ) ;
280
218
return gCachedAttrData ;
281
219
} ,
282
220
@@ -308,6 +246,10 @@ export var AttributionCode = {
308
246
* strip "utm_" while retrieving the params.
309
247
*/
310
248
async getAttrDataAsync ( ) {
249
+ if ( AppConstants . platform != "win" && AppConstants . platform != "macosx" ) {
250
+ // This platform doesn't support attribution.
251
+ return gCachedAttrData ;
252
+ }
311
253
if ( gCachedAttrData != null ) {
312
254
lazy . log . debug (
313
255
`getAttrDataAsync: attribution is cached: ${ JSON . stringify (
@@ -329,37 +271,25 @@ export var AttributionCode = {
329
271
}
330
272
331
273
gCachedAttrData = { } ;
332
- let attributionFile = this . attributionFile ;
333
- if ( ! attributionFile ) {
334
- // This platform doesn't support attribution.
335
- lazy . log . debug (
336
- `getAttrDataAsync: no attribution (attributionFile is null)`
337
- ) ;
338
- return gCachedAttrData ;
339
- }
340
274
341
- if (
342
- AppConstants . platform == "macosx" &&
343
- ! ( await AttributionIOUtils . exists ( attributionFile . path ) )
344
- ) {
345
- lazy . log . debug (
346
- `getAttrDataAsync: macOS && !exists("${ attributionFile . path } ")`
347
- ) ;
275
+ if ( AppConstants . platform == "macosx" ) {
276
+ lazy . log . debug ( `getAttrDataAsync: macOS` ) ;
348
277
return this . _getMacAttrDataAsync ( ) ;
349
278
}
350
279
351
- lazy . log . debug (
352
- `getAttrDataAsync: !macOS || !exists("${ attributionFile . path } ")`
353
- ) ;
280
+ lazy . log . debug ( "getAttrDataAsync: !macOS" ) ;
354
281
282
+ let attributionFile = this . attributionFile ;
355
283
let bytes ;
356
284
try {
357
285
if (
358
286
AppConstants . platform === "win" &&
359
287
Services . sysinfo . getProperty ( "hasWinPackageId" )
360
288
) {
289
+ lazy . log . debug ( "getAttrDataAsync: MSIX" ) ;
361
290
bytes = await this . _getWindowsMSIXAttrDataAsync ( ) ;
362
291
} else {
292
+ lazy . log . debug ( "getAttrDataAsync: NSIS" ) ;
363
293
bytes = await this . _getWindowsNSISAttrDataAsync ( ) ;
364
294
}
365
295
} catch ( ex ) {
@@ -429,12 +359,15 @@ export var AttributionCode = {
429
359
* or if the file couldn't be deleted (the promise is never rejected).
430
360
*/
431
361
async deleteFileAsync ( ) {
432
- try {
433
- await IOUtils . remove ( this . attributionFile . path ) ;
434
- } catch ( ex ) {
435
- // The attribution file may already have been deleted,
436
- // or it may have never been installed at all;
437
- // failure to delete it isn't an error.
362
+ // There is no cache file on macOS
363
+ if ( AppConstants . platform == "win" ) {
364
+ try {
365
+ await IOUtils . remove ( this . attributionFile . path ) ;
366
+ } catch ( ex ) {
367
+ // The attribution file may already have been deleted,
368
+ // or it may have never been installed at all;
369
+ // failure to delete it isn't an error.
370
+ }
438
371
}
439
372
} ,
440
373
0 commit comments