Add assertion on initialization sequence.
The order at which to call the controller methods is: 1) Any method that change the configuration_ field 2) start 3) Any other method This change adds assertion that it is done correctly. Review URL: https://breakpad.appspot.com/499003 git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1085 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
parent
f6864d2ead
commit
ac9324da7a
2 changed files with 24 additions and 0 deletions
|
@ -55,6 +55,10 @@
|
||||||
// Whether or not crash reports should be uploaded.
|
// Whether or not crash reports should be uploaded.
|
||||||
BOOL enableUploads_;
|
BOOL enableUploads_;
|
||||||
|
|
||||||
|
// Whether the controller has been started on the main thread. This is only
|
||||||
|
// used to assert the initialization order is correct.
|
||||||
|
BOOL started_;
|
||||||
|
|
||||||
// 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_;
|
||||||
|
|
|
@ -110,6 +110,7 @@ NSString* GetPlatform() {
|
||||||
queue_ = dispatch_queue_create("com.google.BreakpadQueue", NULL);
|
queue_ = dispatch_queue_create("com.google.BreakpadQueue", NULL);
|
||||||
configuration_ = [[[NSBundle mainBundle] infoDictionary] mutableCopy];
|
configuration_ = [[[NSBundle mainBundle] infoDictionary] mutableCopy];
|
||||||
enableUploads_ = NO;
|
enableUploads_ = NO;
|
||||||
|
started_ = NO;
|
||||||
NSString* uploadInterval =
|
NSString* uploadInterval =
|
||||||
[configuration_ valueForKey:@BREAKPAD_REPORT_INTERVAL];
|
[configuration_ valueForKey:@BREAKPAD_REPORT_INTERVAL];
|
||||||
[self setUploadInterval:[uploadInterval intValue]];
|
[self setUploadInterval:[uploadInterval intValue]];
|
||||||
|
@ -135,6 +136,8 @@ NSString* GetPlatform() {
|
||||||
BreakpadAddUploadParameter(breakpadRef_, @"platform", GetPlatform());
|
BreakpadAddUploadParameter(breakpadRef_, @"platform", GetPlatform());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
NSAssert(!started_, @"Start cannot be called more than once.");
|
||||||
|
started_ = YES;
|
||||||
if (onCurrentThread)
|
if (onCurrentThread)
|
||||||
startBlock();
|
startBlock();
|
||||||
else
|
else
|
||||||
|
@ -142,6 +145,9 @@ NSString* GetPlatform() {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)stop {
|
- (void)stop {
|
||||||
|
NSAssert(started_,
|
||||||
|
@"The controller must be started before it can be stopped");
|
||||||
|
started_ = NO;
|
||||||
dispatch_sync(queue_, ^{
|
dispatch_sync(queue_, ^{
|
||||||
if (breakpadRef_) {
|
if (breakpadRef_) {
|
||||||
BreakpadRelease(breakpadRef_);
|
BreakpadRelease(breakpadRef_);
|
||||||
|
@ -151,6 +157,8 @@ NSString* GetPlatform() {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setUploadingEnabled:(BOOL)enabled {
|
- (void)setUploadingEnabled:(BOOL)enabled {
|
||||||
|
NSAssert(started_,
|
||||||
|
@"The controller must be started before setUploadingEnabled is called");
|
||||||
dispatch_async(queue_, ^{
|
dispatch_async(queue_, ^{
|
||||||
if (enabled == enableUploads_)
|
if (enabled == enableUploads_)
|
||||||
return;
|
return;
|
||||||
|
@ -169,6 +177,8 @@ NSString* GetPlatform() {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)updateConfiguration:(NSDictionary*)configuration {
|
- (void)updateConfiguration:(NSDictionary*)configuration {
|
||||||
|
NSAssert(!started_,
|
||||||
|
@"The controller must not be started when updateConfiguration is called");
|
||||||
[configuration_ addEntriesFromDictionary:configuration];
|
[configuration_ addEntriesFromDictionary:configuration];
|
||||||
NSString* uploadInterval =
|
NSString* uploadInterval =
|
||||||
[configuration_ valueForKey:@BREAKPAD_REPORT_INTERVAL];
|
[configuration_ valueForKey:@BREAKPAD_REPORT_INTERVAL];
|
||||||
|
@ -177,10 +187,14 @@ NSString* GetPlatform() {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setUploadingURL:(NSString*)url {
|
- (void)setUploadingURL:(NSString*)url {
|
||||||
|
NSAssert(!started_,
|
||||||
|
@"The controller must not be started when setUploadingURL is called");
|
||||||
[configuration_ setValue:url forKey:@BREAKPAD_URL];
|
[configuration_ setValue:url forKey:@BREAKPAD_URL];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setUploadInterval:(int)intervalInSeconds {
|
- (void)setUploadInterval:(int)intervalInSeconds {
|
||||||
|
NSAssert(!started_,
|
||||||
|
@"The controller must not be started when setUploadInterval is called");
|
||||||
[configuration_ removeObjectForKey:@BREAKPAD_REPORT_INTERVAL];
|
[configuration_ removeObjectForKey:@BREAKPAD_REPORT_INTERVAL];
|
||||||
uploadIntervalInSeconds_ = intervalInSeconds;
|
uploadIntervalInSeconds_ = intervalInSeconds;
|
||||||
if (uploadIntervalInSeconds_ < 0)
|
if (uploadIntervalInSeconds_ < 0)
|
||||||
|
@ -188,6 +202,8 @@ NSString* GetPlatform() {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)addUploadParameter:(NSString*)value forKey:(NSString*)key {
|
- (void)addUploadParameter:(NSString*)value forKey:(NSString*)key {
|
||||||
|
NSAssert(started_,
|
||||||
|
@"The controller must be started before addUploadParameter is called");
|
||||||
dispatch_async(queue_, ^{
|
dispatch_async(queue_, ^{
|
||||||
if (breakpadRef_)
|
if (breakpadRef_)
|
||||||
BreakpadAddUploadParameter(breakpadRef_, key, value);
|
BreakpadAddUploadParameter(breakpadRef_, key, value);
|
||||||
|
@ -195,6 +211,8 @@ NSString* GetPlatform() {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeUploadParameterForKey:(NSString*)key {
|
- (void)removeUploadParameterForKey:(NSString*)key {
|
||||||
|
NSAssert(started_, @"The controller must be started before "
|
||||||
|
"removeUploadParameterForKey is called");
|
||||||
dispatch_async(queue_, ^{
|
dispatch_async(queue_, ^{
|
||||||
if (breakpadRef_)
|
if (breakpadRef_)
|
||||||
BreakpadRemoveUploadParameter(breakpadRef_, key);
|
BreakpadRemoveUploadParameter(breakpadRef_, key);
|
||||||
|
@ -202,6 +220,8 @@ NSString* GetPlatform() {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)withBreakpadRef:(void(^)(BreakpadRef))callback {
|
- (void)withBreakpadRef:(void(^)(BreakpadRef))callback {
|
||||||
|
NSAssert(started_,
|
||||||
|
@"The controller must be started before withBreakpadRef is called");
|
||||||
dispatch_async(queue_, ^{
|
dispatch_async(queue_, ^{
|
||||||
callback(breakpadRef_);
|
callback(breakpadRef_);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue