[Breakpad iOS] Add a callback on report upload completion.

This CL adds a result callback on report upload completion.
On failure, Breakpad deletes the configuration file and does retry to
upload a report.
Using this callback, the client will be able to log some metrics and to
act on upload failure.

Bug: 954175
Change-Id: I95a3264b65d4c06ba5d8dde8377440d23f1e2081
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/1572661
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Olivier Robin
2019-04-18 18:06:31 +02:00
committed by Mark Mentovai
parent 8c70c504b2
commit 1fc9cc0d0e
6 changed files with 88 additions and 23 deletions

View File

@@ -42,6 +42,13 @@ extern NSString *const kGoogleServerType;
extern NSString *const kSocorroServerType;
extern NSString *const kDefaultServerType;
// Optional user-defined function that will be called after a network upload
// of a crash report.
// |report_id| will be the id returned by the server, or "ERR" if an error
// occurred.
// |error| will contain the error, or nil if no error occured.
typedef void (^UploadCompletionBlock)(NSString *reportId, NSError *error);
@interface Uploader : NSObject {
@private
NSMutableDictionary *parameters_; // Key value pairs of data (STRONG)
@@ -61,6 +68,12 @@ extern NSString *const kDefaultServerType;
// that are uploaded to the
// crash server with the
// minidump.
UploadCompletionBlock uploadCompletion_; // A block called on network upload
// completion. Parameters are:
// The report ID returned by the
// server,
// the NSError triggered during
// upload.
}
- (id)initWithConfigFile:(const char *)configFile;
@@ -86,4 +99,8 @@ extern NSString *const kDefaultServerType;
// new ID.
- (void)handleNetworkResponse:(NSData *)data withError:(NSError *)error;
// Sets the callback to be called after uploading a crash report to the server.
// Only the latest callback registered will be called.
- (void)setUploadCompletionBlock:(UploadCompletionBlock)uploadCompletion;
@end

View File

@@ -511,6 +511,9 @@ NSDictionary *readConfigurationData(const char *configFile) {
reportID = [[result stringByTrimmingCharactersInSet:trimSet] UTF8String];
[self logUploadWithID:reportID];
}
if (uploadCompletion_) {
uploadCompletion_([NSString stringWithUTF8String:reportID], error);
}
// rename the minidump file according to the id returned from the server
NSString *minidumpDir =
@@ -547,6 +550,11 @@ NSDictionary *readConfigurationData(const char *configFile) {
return [NSURLQueryItem queryItemWithName:queryItemName value:escapedValue];
}
//=============================================================================
- (void)setUploadCompletionBlock:(UploadCompletionBlock)uploadCompletion {
uploadCompletion_ = uploadCompletion;
}
//=============================================================================
- (void)report {
NSURL *url = [NSURL URLWithString:[parameters_ objectForKey:@BREAKPAD_URL]];