-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix handler for multiple calls of -[FIRInstanceID instanceIDWithHandler:] (#2445) #2559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Firebase/InstanceID/FIRInstanceID.m
Outdated
if (aHandler) { | ||
[self.defaultTokenFetchHandler addHandler:aHandler]; | ||
} | ||
|
||
if (self.isFetchingDefaultToken || self.isDefaultTokenFetchScheduled) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need to check this flag or just check if defaultTokenFetchHandler.count > 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, my first try was to replace isFetchingDefaultToken
by checking defaultTokenFetchHandler.count
, but then it is hard to handle retry logic due to the way it is implemented. Also, in this case the handler cannot be optional (which is the case e.g. in #2562). Keeping both, the flag and defaultTokenFetchHandler
allows to make less changes to the existing logic.
Firebase/InstanceID/FIRInstanceID.m
Outdated
if (aHandler) { | ||
[self.defaultTokenFetchHandler addHandler:aHandler]; | ||
} | ||
|
||
if (self.isFetchingDefaultToken || self.isDefaultTokenFetchScheduled) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like you can also get rid of isDefaultTokenFetchScheduled. Because you have the first original call back in and retry just calling with nil.
But if you don't feel comfortable, you can leave it like this for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can see, currently isDefaultTokenFetchScheduled
prevents additional requests to be sent while [self retryIntervalToFetchDefaultToken]
timeout, so, I think, we still need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think since we are adding a new logic to the existing code that could replace the old boolean value. We should do that. We are trying to simplify the iid logic especially your new queue should be able to handle it.
So one way we can do is to have a defaultTokenWithRetry:(BOOL) handler:
So that if it's retry, we always go through, without adding a new handler to the queue. Otherwise, adding it to the queue and check if it's >1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed an update. Would you take a look if it is what you meant?
@chliangGoogle Thank you for the attentive review! The logic looks to me a bit difficult to follow with the current implementation. E.g.
As I mentioned, I would like to discuss possible ways to improve the code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. With a few nit picking.
Firebase/InstanceID/FIRInstanceID.m
Outdated
@@ -860,7 +861,7 @@ - (NSInteger)retryIntervalToFetchDefaultToken { | |||
} | |||
|
|||
- (void)fetchDefaultToken { | |||
if (self.isFetchingDefaultToken) { | |||
if (self.defaultTokenFetchHandler != nil) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might have to merge, this function would not be needed.
- (void)defaultTokenWithHandler:(FIRInstanceIDTokenHandler)handler { | ||
if (self.isFetchingDefaultToken || self.isDefaultTokenFetchScheduled) { | ||
- (void)defaultTokenWithHandler:(nullable FIRInstanceIDTokenHandler)aHandler { | ||
[self defaultTokenWithRetry:NO handler:aHandler]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can get rid of defaultTokenWithHandler: and use the new one instead every where.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer not to use defaultTokenWithRetry:handler:
everywhere because the retry
argument is kind of an implementation detail of defaultTokenWithHandler:
method.
@chliangGoogle Let me know if you still would prefer to get rid of it, I'll create a separate PR for it then.
Conflicts: Firebase/InstanceID/FIRInstanceID.m
This is a fix for #2445:
-[FIRInstanceID instanceIDWithHandler:]
accumulate handlers while there is ongoing request to perform all of them on completion