Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
Generate token url on IO thread (#1003)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhugman authored and Elise Richards committed Oct 21, 2019
1 parent a55db69 commit a36ba93
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions app/src/main/java/mozilla/lockbox/store/AccountStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import android.webkit.WebStorage
import android.webkit.WebView
import io.reactivex.Observable
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.internal.util.HalfSerializer.onNext
import io.reactivex.rxkotlin.addTo
import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.ReplaySubject
import io.reactivex.subjects.Subject
import kotlinx.coroutines.CoroutineExceptionHandler
Expand Down Expand Up @@ -226,8 +226,7 @@ open class AccountStore(
// restarted) or a token refresh.
// 1. Update the rest of the app.
val credentials = generateSyncCredentials(token, isNewLogin)
val syncCredentialSubject = syncCredentials as Subject
syncCredentialSubject.onNext(credentials.asOptional())
credentials.subscribe(syncCredentials as Subject)

// 2. Store this token in the secure preferences.
securePreferences.putString(Constant.Key.accessToken, token.toJSONObject().toString())
Expand All @@ -250,10 +249,15 @@ open class AccountStore(
}, msDelay)
}

private fun generateSyncCredentials(oauthInfo: AccessTokenInfo, isNew: Boolean): SyncCredentials? {
val fxa = fxa ?: return null
val tokenServerURL = fxa.getTokenServerEndpointURL()
return FxASyncCredentials(oauthInfo, tokenServerURL, isNew)
private fun generateSyncCredentials(oauthInfo: AccessTokenInfo, isNew: Boolean): Observable<Optional<SyncCredentials>> {
return Observable.just(Unit)
.observeOn(Schedulers.io())
.map {
fxa?.let {
val url = it.getTokenServerEndpointURL()
FxASyncCredentials(oauthInfo, url, isNew) as SyncCredentials
}.asOptional()
}
}

private fun generateNewFirefoxAccount() {
Expand Down

0 comments on commit a36ba93

Please sign in to comment.