Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/main/java/com/google/firebase/FirebaseApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public class FirebaseApp {
private static final Map<String, FirebaseApp> instances = new HashMap<>();

public static final String DEFAULT_APP_NAME = "[DEFAULT]";
private static final long TOKEN_REFRESH_INTERVAL_MILLIS = TimeUnit.MINUTES.toMillis(55);

static final TokenRefresher.Factory DEFAULT_TOKEN_REFRESHER_FACTORY =
new TokenRefresher.Factory();
Expand Down Expand Up @@ -339,10 +338,13 @@ Task<GetTokenResult> getToken(boolean forceRefresh) {
@Override
public GetTokenResult then(@NonNull Task<GoogleOAuthAccessToken> task)
throws Exception {
GetTokenResult newToken = new GetTokenResult(task.getResult().getAccessToken());
GoogleOAuthAccessToken googleOAuthToken = task.getResult();
GetTokenResult newToken = new GetTokenResult(googleOAuthToken.getAccessToken());
GetTokenResult oldToken = currentToken.get();
List<AuthStateListener> listenersCopy = null;
if (!newToken.equals(oldToken)) {
long refreshDelay = googleOAuthToken.getExpiryTime() - clock.now()
- TimeUnit.MINUTES.toMillis(5);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this code below to where it's actually used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

synchronized (lock) {
if (deleted.get()) {
return newToken;
Expand All @@ -353,7 +355,9 @@ public GetTokenResult then(@NonNull Task<GoogleOAuthAccessToken> task)
// access to the token refresher.
if (currentToken.compareAndSet(oldToken, newToken)) {
listenersCopy = ImmutableList.copyOf(authStateListeners);
tokenRefresher.scheduleRefresh(TOKEN_REFRESH_INTERVAL_MILLIS);
if (refreshDelay > 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<= 0 would likely indicate a bug, right? Should we at least log a message? If we were confident it should never happen, I'd throw an Exception... but I guess a developer-provided credentials class could generate tokens that expire in less than 5 minutes or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a log statement

tokenRefresher.scheduleRefresh(refreshDelay);
}
}
}
}
Expand Down