@@ -289,15 +289,26 @@ - (FBLPromise *)deleteUnsentReports {
289
289
290
290
BOOL launchFailure = [self .launchMarker checkForAndCreateLaunchMarker ];
291
291
292
- FIRCLSInternalReport *report = [self setupCurrentReport: executionIdentifier];
292
+ __block FIRCLSInternalReport *report = [self setupCurrentReport: executionIdentifier];
293
293
if (!report) {
294
294
FIRCLSErrorLog (@" Unable to setup a new report" );
295
295
}
296
296
297
- if (![self startCrashReporterWithProfilingReport: report]) {
298
- FIRCLSErrorLog (@" Unable to start crash reporter" );
299
- report = nil ;
300
- }
297
+ FBLPromise<NSNumber *> *reportProfilingPromise;
298
+ reportProfilingPromise =
299
+ [[self startCrashReporterWithProfilingReport: report] then: ^id _Nullable (id _Nullable value) {
300
+ if ([value isEqual: @NO ]) {
301
+ FIRCLSErrorLog (@" Unable to start crash reporter" );
302
+ report = nil ;
303
+ return [FBLPromise resolvedWith: @NO ];
304
+ }
305
+
306
+ // empty for disabled start-up time
307
+ dispatch_async (FIRCLSGetLoggingQueue (), ^{
308
+ FIRCLSUserLoggingWriteInternalKeyValue (FIRCLSStartTimeKey, @" " );
309
+ });
310
+ return [FBLPromise resolvedWith: @YES ];
311
+ }];
301
312
302
313
#if CLS_METRICKIT_SUPPORTED
303
314
if (@available (iOS 15 , *)) {
@@ -317,9 +328,12 @@ - (FBLPromise *)deleteUnsentReports {
317
328
[self beginSettingsWithToken: dataCollectionToken];
318
329
319
330
// Wait for MetricKit data to be available, then continue to send reports and resolve promise.
320
- promise = [[self waitForMetricKitData ]
331
+ promise = [[reportProfilingPromise onQueue: _dispatchQueue
332
+ then: ^id _Nullable (id _Nullable value) {
333
+ return [self waitForMetricKitData ];
334
+ }]
321
335
onQueue: _dispatchQueue
322
- then: ^id _Nullable (id _Nullable metricKitValue ) {
336
+ then: ^id _Nullable (id _Nullable value ) {
323
337
[self beginReportUploadsWithToken: dataCollectionToken blockingSend: launchFailure];
324
338
325
339
// If data collection is enabled, the SDK will not notify the user
@@ -335,36 +349,33 @@ - (FBLPromise *)deleteUnsentReports {
335
349
336
350
// Wait for an action to get sent, either from processReports: or automatic data collection,
337
351
// and for MetricKit data to be available.
338
- promise = [[FBLPromise all: @[ [ self waitForReportAction ], [ self waitForMetricKitData ] ]]
352
+ promise = [[reportProfilingPromise
339
353
onQueue: _dispatchQueue
340
- then: ^id _Nullable (NSArray *_Nullable wrappedActionAndData) {
341
- // Process the actions for the reports on disk.
342
- FIRCLSReportAction action = [[wrappedActionAndData firstObject ] reportActionValue ];
343
-
344
- if (action == FIRCLSReportActionSend) {
345
- FIRCLSDebugLog (@" Sending unsent reports." );
346
- FIRCLSDataCollectionToken *dataCollectionToken =
347
- [FIRCLSDataCollectionToken validToken ];
348
-
349
- [self beginSettingsWithToken: dataCollectionToken];
350
-
351
- [self beginReportUploadsWithToken: dataCollectionToken blockingSend: NO ];
352
-
353
- } else if (action == FIRCLSReportActionDelete) {
354
- FIRCLSDebugLog (@" Deleting unsent reports." );
355
- [self .existingReportManager deleteUnsentReports ];
356
- } else {
357
- FIRCLSErrorLog (@" Unknown report action: %d " , action);
358
- }
359
- return @(report != nil );
360
- }];
361
- }
362
-
363
- if (report != nil ) {
364
- // empty for disabled start-up time
365
- dispatch_async (FIRCLSGetLoggingQueue (), ^{
366
- FIRCLSUserLoggingWriteInternalKeyValue (FIRCLSStartTimeKey, @" " );
367
- });
354
+ then: ^id _Nullable (id _Nullable value) {
355
+ return [FBLPromise all: @[ [self waitForReportAction ], [self waitForMetricKitData ] ]];
356
+ }] onQueue: _dispatchQueue
357
+ then: ^id _Nullable (NSArray *_Nullable wrappedActionAndData) {
358
+ // Process the actions for the reports on disk.
359
+ FIRCLSReportAction action =
360
+ [[wrappedActionAndData firstObject ] reportActionValue ];
361
+
362
+ if (action == FIRCLSReportActionSend) {
363
+ FIRCLSDebugLog (@" Sending unsent reports." );
364
+ FIRCLSDataCollectionToken *dataCollectionToken =
365
+ [FIRCLSDataCollectionToken validToken ];
366
+
367
+ [self beginSettingsWithToken: dataCollectionToken];
368
+
369
+ [self beginReportUploadsWithToken: dataCollectionToken blockingSend: NO ];
370
+
371
+ } else if (action == FIRCLSReportActionDelete) {
372
+ FIRCLSDebugLog (@" Deleting unsent reports." );
373
+ [self .existingReportManager deleteUnsentReports ];
374
+ } else {
375
+ FIRCLSErrorLog (@" Unknown report action: %d " , action);
376
+ }
377
+ return @(report != nil );
378
+ }];
368
379
}
369
380
370
381
// To make the code more predictable and therefore testable, don't resolve the startup promise
@@ -412,24 +423,23 @@ - (void)beginReportUploadsWithToken:(FIRCLSDataCollectionToken *)token
412
423
}
413
424
}
414
425
415
- - (BOOL )startCrashReporterWithProfilingReport : (FIRCLSInternalReport *)report {
426
+ - (FBLPromise<NSNumber *> * )startCrashReporterWithProfilingReport : (FIRCLSInternalReport *)report {
416
427
if (!report) {
417
- return NO ;
418
- }
419
-
420
- if (![self .contextManager setupContextWithReport: report
421
- settings: self .settings
422
- fileManager: _fileManager]) {
423
- return NO ;
428
+ return [FBLPromise resolvedWith: @NO ];
424
429
}
425
430
426
- [self .notificationManager registerNotificationListener ];
431
+ return [[self .contextManager setupContextWithReport: report
432
+ settings: self .settings
433
+ fileManager: _fileManager]
434
+ then: ^id _Nullable (id _Nullable value) {
435
+ [self .notificationManager registerNotificationListener ];
427
436
428
- [self .analyticsManager registerAnalyticsListener ];
437
+ [self .analyticsManager registerAnalyticsListener ];
429
438
430
- [self crashReportingSetupCompleted ];
439
+ [self crashReportingSetupCompleted ];
431
440
432
- return YES ;
441
+ return [FBLPromise resolvedWith: @YES ];
442
+ }];
433
443
}
434
444
435
445
- (void )crashReportingSetupCompleted {
0 commit comments