From 315d1368a7f38071b7ff79dd813a07ea9d157a30 Mon Sep 17 00:00:00 2001 From: Evan Bernstein Date: Thu, 4 Oct 2018 14:46:45 -0700 Subject: Adds method to get the date of the most recent iOS crash report. Also adds method to determine if breakpad is started. Change-Id: I272765e7ac6bbc07d77ca2d8dcc34d51c205116e Reviewed-on: https://chromium-review.googlesource.com/c/1260625 Reviewed-by: Joshua Peraza --- src/client/ios/Breakpad.mm | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/client/ios/Breakpad.mm') diff --git a/src/client/ios/Breakpad.mm b/src/client/ios/Breakpad.mm index c2a4202a..d7dc78c6 100644 --- a/src/client/ios/Breakpad.mm +++ b/src/client/ios/Breakpad.mm @@ -161,6 +161,7 @@ class Breakpad { NSArray *CrashReportsToUpload(); NSString *NextCrashReportToUpload(); NSDictionary *NextCrashReportConfiguration(); + NSDate *DateOfMostRecentCrashReport(); void UploadNextReport(NSDictionary *server_parameters); void UploadReportWithConfiguration(NSDictionary *configuration, NSDictionary *server_parameters); @@ -467,6 +468,30 @@ NSDictionary *Breakpad::NextCrashReportConfiguration() { return [Uploader readConfigurationDataFromFile:NextCrashReportToUpload()]; } +//============================================================================= +NSDate *Breakpad::DateOfMostRecentCrashReport() { + NSString *directory = KeyValue(@BREAKPAD_DUMP_DIRECTORY); + if (!directory) { + return nil; + } + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSArray *dirContents = [fileManager contentsOfDirectoryAtPath:directory error:nil]; + NSArray *dumps = [dirContents filteredArrayUsingPredicate:[NSPredicate + predicateWithFormat:@"self ENDSWITH '.dmp'"]]; + NSDate *mostRecentCrashReportDate = nil; + for (NSString *dump in dumps) { + NSString *filePath = [directory stringByAppendingPathComponent:dump]; + NSDate *crashReportDate = + [[fileManager attributesOfItemAtPath:filePath error:nil] fileCreationDate]; + if (!mostRecentCrashReportDate) { + mostRecentCrashReportDate = crashReportDate; + } else if (crashReportDate) { + mostRecentCrashReportDate = [mostRecentCrashReportDate laterDate:crashReportDate]; + } + } + return mostRecentCrashReportDate; +} + //============================================================================= void Breakpad::HandleNetworkResponse(NSDictionary *configuration, NSData *data, @@ -840,6 +865,19 @@ NSDictionary *BreakpadGetNextReportConfiguration(BreakpadRef ref) { return nil; } +//============================================================================= +NSDate *BreakpadGetDateOfMostRecentCrashReport(BreakpadRef ref) { + try { + Breakpad *breakpad = (Breakpad *)ref; + if (breakpad) { + return breakpad->DateOfMostRecentCrashReport(); + } + } catch (...) { // don't let exceptions leave this C API + fprintf(stderr, "BreakpadGetDateOfMostRecentCrashReport() : error\n"); + } + return nil; +} + //============================================================================= void BreakpadUploadReportWithParametersAndConfiguration( BreakpadRef ref, -- cgit v1.2.1