Add -[BreakpadController setParametersToAddAtUploadTime:] for iOS.

This provides the ability to add server parameters to a crash report when the
report is uploaded.

Patch by KiYun Roe <kiyun@chromium.org>

BUG=558
R=blundell@chromium.org

Review URL: https://breakpad.appspot.com/974002/

git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1271 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
blundell@chromium.org 2014-01-13 10:40:07 +00:00
parent 3ea04ec479
commit 12528d19bd
4 changed files with 33 additions and 9 deletions

View file

@ -200,7 +200,9 @@ void BreakpadRemoveUploadParameter(BreakpadRef ref, NSString *key);
int BreakpadGetCrashReportCount(BreakpadRef ref); int BreakpadGetCrashReportCount(BreakpadRef ref);
// Upload next report to the server. // Upload next report to the server.
void BreakpadUploadNextReport(BreakpadRef ref); // |server_parameters| is additional server parameters to send (optional).
void BreakpadUploadNextReport(BreakpadRef ref,
NSDictionary *server_parameters = nil);
// Upload a file to the server. |data| is the content of the file to sent. // Upload a file to the server. |data| is the content of the file to sent.
// |server_parameters| is additional server parameters to send. // |server_parameters| is additional server parameters to send.

View file

@ -152,7 +152,7 @@ class Breakpad {
void RemoveKeyValue(NSString *key); void RemoveKeyValue(NSString *key);
NSArray *CrashReportsToUpload(); NSArray *CrashReportsToUpload();
NSString *NextCrashReportToUpload(); NSString *NextCrashReportToUpload();
void UploadNextReport(); void UploadNextReport(NSDictionary *server_parameters);
void UploadData(NSData *data, NSString *name, void UploadData(NSData *data, NSString *name,
NSDictionary *server_parameters); NSDictionary *server_parameters);
NSDictionary *GenerateReport(NSDictionary *server_parameters); NSDictionary *GenerateReport(NSDictionary *server_parameters);
@ -448,13 +448,18 @@ NSString *Breakpad::NextCrashReportToUpload() {
} }
//============================================================================= //=============================================================================
void Breakpad::UploadNextReport() { void Breakpad::UploadNextReport(NSDictionary *server_parameters) {
NSString *configFile = NextCrashReportToUpload(); NSString *configFile = NextCrashReportToUpload();
if (configFile) { if (configFile) {
Uploader *uploader = [[[Uploader alloc] Uploader *uploader = [[[Uploader alloc]
initWithConfigFile:[configFile UTF8String]] autorelease]; initWithConfigFile:[configFile UTF8String]] autorelease];
if (uploader) if (uploader) {
for (NSString *key in server_parameters) {
[uploader addServerParameter:[server_parameters objectForKey:key]
forKey:key];
}
[uploader report]; [uploader report];
}
} }
} }
@ -784,13 +789,14 @@ int BreakpadGetCrashReportCount(BreakpadRef ref) {
} }
//============================================================================= //=============================================================================
void BreakpadUploadNextReport(BreakpadRef ref) { void BreakpadUploadNextReport(BreakpadRef ref,
NSDictionary *server_parameters) {
try { try {
// Not called at exception time // Not called at exception time
Breakpad *breakpad = (Breakpad *)ref; Breakpad *breakpad = (Breakpad *)ref;
if (breakpad) { if (breakpad) {
breakpad->UploadNextReport(); breakpad->UploadNextReport(server_parameters);
} }
} catch(...) { // don't let exceptions leave this C API } catch(...) { // don't let exceptions leave this C API
fprintf(stderr, "BreakpadUploadNextReport() : error\n"); fprintf(stderr, "BreakpadUploadNextReport() : error\n");

View file

@ -62,6 +62,10 @@
// The interval to wait between two uploads. Value is 0 if no upload must be // The interval to wait between two uploads. Value is 0 if no upload must be
// done. // done.
int uploadIntervalInSeconds_; int uploadIntervalInSeconds_;
// The dictionary that contains additional server parameters to send when
// uploading crash reports.
NSDictionary* uploadTimeParameters_;
} }
// Singleton. // Singleton.
@ -84,8 +88,11 @@
// will prevent uploads. // will prevent uploads.
- (void)setUploadInterval:(int)intervalInSeconds; - (void)setUploadInterval:(int)intervalInSeconds;
// Specify a parameter that will be uploaded to the crash server. See // Set additional server parameters to send when uploading crash reports.
// |BreakpadAddUploadParameter|. - (void)setParametersToAddAtUploadTime:(NSDictionary*)uploadTimeParameters;
// Specify an upload parameter that will be added to the crash report when a
// crash report is generated. See |BreakpadAddUploadParameter|.
- (void)addUploadParameter:(NSString*)value forKey:(NSString*)key; - (void)addUploadParameter:(NSString*)value forKey:(NSString*)key;
// Remove a previously-added parameter from the upload parameter set. See // Remove a previously-added parameter from the upload parameter set. See

View file

@ -120,6 +120,7 @@ NSString* GetPlatform() {
assert(!breakpadRef_); assert(!breakpadRef_);
dispatch_release(queue_); dispatch_release(queue_);
[configuration_ release]; [configuration_ release];
[uploadTimeParameters_ release];
[super dealloc]; [super dealloc];
} }
@ -192,6 +193,7 @@ NSString* GetPlatform() {
NSString* uploadInterval = NSString* uploadInterval =
[configuration_ valueForKey:@BREAKPAD_REPORT_INTERVAL]; [configuration_ valueForKey:@BREAKPAD_REPORT_INTERVAL];
[self setUploadInterval:[uploadInterval intValue]]; [self setUploadInterval:[uploadInterval intValue]];
[self setParametersToAddAtUploadTime:nil];
} }
- (void)setUploadingURL:(NSString*)url { - (void)setUploadingURL:(NSString*)url {
@ -209,6 +211,13 @@ NSString* GetPlatform() {
uploadIntervalInSeconds_ = 0; uploadIntervalInSeconds_ = 0;
} }
- (void)setParametersToAddAtUploadTime:(NSDictionary*)uploadTimeParameters {
NSAssert(!started_, @"The controller must not be started when "
"setParametersToAddAtUploadTime is called");
[uploadTimeParameters_ autorelease];
uploadTimeParameters_ = [uploadTimeParameters copy];
}
- (void)addUploadParameter:(NSString*)value forKey:(NSString*)key { - (void)addUploadParameter:(NSString*)value forKey:(NSString*)key {
NSAssert(started_, NSAssert(started_,
@"The controller must be started before addUploadParameter is called"); @"The controller must be started before addUploadParameter is called");
@ -291,7 +300,7 @@ NSString* GetPlatform() {
// A report can be sent now. // A report can be sent now.
if (timeToWait == 0) { if (timeToWait == 0) {
[self reportWillBeSent]; [self reportWillBeSent];
BreakpadUploadNextReport(breakpadRef_); BreakpadUploadNextReport(breakpadRef_, uploadTimeParameters_);
// If more reports must be sent, make sure this method is called again. // If more reports must be sent, make sure this method is called again.
if (BreakpadGetCrashReportCount(breakpadRef_) > 0) if (BreakpadGetCrashReportCount(breakpadRef_) > 0)