diff options
Diffstat (limited to 'src/client/ios/BreakpadController.mm')
-rw-r--r-- | src/client/ios/BreakpadController.mm | 104 |
1 files changed, 62 insertions, 42 deletions
diff --git a/src/client/ios/BreakpadController.mm b/src/client/ios/BreakpadController.mm index dd71cff6..01fb5f13 100644 --- a/src/client/ios/BreakpadController.mm +++ b/src/client/ios/BreakpadController.mm @@ -93,11 +93,12 @@ NSString* GetPlatform() { @implementation BreakpadController + (BreakpadController*)sharedInstance { - @synchronized(self) { - static BreakpadController* sharedInstance_ = - [[BreakpadController alloc] initSingleton]; - return sharedInstance_; - } + static dispatch_once_t onceToken; + static BreakpadController* sharedInstance ; + dispatch_once(&onceToken, ^{ + sharedInstance = [[BreakpadController alloc] initSingleton]; + }); + return sharedInstance; } - (id)init { @@ -155,15 +156,19 @@ NSString* GetPlatform() { }); } +- (BOOL)isStarted { + return started_; +} + // This method must be called from the breakpad queue. - (void)threadUnsafeSendReportWithConfiguration:(NSDictionary*)configuration withBreakpadRef:(BreakpadRef)ref { NSAssert(started_, @"The controller must be started before " "threadUnsafeSendReportWithConfiguration is called"); if (breakpadRef_) { - BreakpadUploadReportWithParametersAndConfiguration(breakpadRef_, - uploadTimeParameters_, - configuration); + BreakpadUploadReportWithParametersAndConfiguration( + breakpadRef_, uploadTimeParameters_, configuration, + uploadCompleteCallback_); } } @@ -179,10 +184,9 @@ NSString* GetPlatform() { enableUploads_ = YES; [self sendStoredCrashReports]; } else { + // disable the enableUpload_ flag. + // sendDelay checks this flag and disables the upload of logs by sendStoredCrashReports enableUploads_ = NO; - [NSObject cancelPreviousPerformRequestsWithTarget:self - selector:@selector(sendStoredCrashReports) - object:nil]; } }); } @@ -191,7 +195,7 @@ NSString* GetPlatform() { NSAssert(!started_, @"The controller must not be started when updateConfiguration is called"); [configuration_ addEntriesFromDictionary:configuration]; - NSString* uploadInterval = + NSString *uploadInterval = [configuration_ valueForKey:@BREAKPAD_REPORT_INTERVAL]; if (uploadInterval) [self setUploadInterval:[uploadInterval intValue]]; @@ -202,7 +206,7 @@ NSString* GetPlatform() { @"The controller must not be started when resetConfiguration is called"); [configuration_ autorelease]; configuration_ = [[[NSBundle mainBundle] infoDictionary] mutableCopy]; - NSString* uploadInterval = + NSString *uploadInterval = [configuration_ valueForKey:@BREAKPAD_REPORT_INTERVAL]; [self setUploadInterval:[uploadInterval intValue]]; [self setParametersToAddAtUploadTime:nil]; @@ -239,6 +243,15 @@ NSString* GetPlatform() { }); } +- (void)setUploadCallback:(BreakpadUploadCompletionCallback)callback { + NSAssert(started_, + @"The controller must not be started before setUploadCallback is " + "called"); + dispatch_async(queue_, ^{ + uploadCompleteCallback_ = callback; + }); +} + - (void)removeUploadParameterForKey:(NSString*)key { NSAssert(started_, @"The controller must be started before " "removeUploadParameterForKey is called"); @@ -249,10 +262,8 @@ NSString* GetPlatform() { } - (void)withBreakpadRef:(void(^)(BreakpadRef))callback { - NSAssert(started_, - @"The controller must be started before withBreakpadRef is called"); dispatch_async(queue_, ^{ - callback(breakpadRef_); + callback(started_ ? breakpadRef_ : NULL); }); } @@ -291,6 +302,18 @@ NSString* GetPlatform() { }); } +- (void)getDateOfMostRecentCrashReport:(void(^)(NSDate *))callback { + NSAssert(started_, @"The controller must be started before " + "getDateOfMostRecentCrashReport is called"); + dispatch_async(queue_, ^{ + if (!breakpadRef_) { + callback(nil); + return; + } + callback(BreakpadGetDateOfMostRecentCrashReport(breakpadRef_)); + }); +} + #pragma mark - - (int)sendDelay { @@ -317,38 +340,35 @@ NSString* GetPlatform() { [userDefaults synchronize]; } +// This method must be called from the breakpad queue. - (void)sendStoredCrashReports { - dispatch_async(queue_, ^{ - if (BreakpadGetCrashReportCount(breakpadRef_) == 0) - return; + if (BreakpadGetCrashReportCount(breakpadRef_) == 0) + return; - int timeToWait = [self sendDelay]; + int timeToWait = [self sendDelay]; - // Unable to ever send report. - if (timeToWait == -1) - return; + // Unable to ever send report. + if (timeToWait == -1) + return; - // A report can be sent now. - if (timeToWait == 0) { - [self reportWillBeSent]; - BreakpadUploadNextReportWithParameters(breakpadRef_, - uploadTimeParameters_); + // A report can be sent now. + if (timeToWait == 0) { + [self reportWillBeSent]; + BreakpadUploadNextReportWithParameters(breakpadRef_, uploadTimeParameters_, + uploadCompleteCallback_); - // If more reports must be sent, make sure this method is called again. - if (BreakpadGetCrashReportCount(breakpadRef_) > 0) - timeToWait = uploadIntervalInSeconds_; - } + // If more reports must be sent, make sure this method is called again. + if (BreakpadGetCrashReportCount(breakpadRef_) > 0) + timeToWait = uploadIntervalInSeconds_; + } - // A report must be sent later. - if (timeToWait > 0) { - // performSelector: doesn't work on queue_ - dispatch_async(dispatch_get_main_queue(), ^{ - [self performSelector:@selector(sendStoredCrashReports) - withObject:nil - afterDelay:timeToWait]; - }); - } - }); + // A report must be sent later. + if (timeToWait > 0) { + dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeToWait * NSEC_PER_SEC)); + dispatch_after(delay, queue_, ^{ + [self sendStoredCrashReports]; + }); + } } @end |