use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.
the class OAuth2TokenService method getOAuth2AccessTokenWithTimeout.
/**
* Call this method to retrieve an OAuth2 access token for the given account and scope. This
* method times out after the specified timeout, and will return null if that happens.
*
* Given that this is a blocking method call, this should never be called from the UI thread.
*
* @param account the account to get the access token for.
* @param scope The scope to get an auth token for (without Android-style 'oauth2:' prefix).
* @param timeout the timeout.
* @param unit the unit for |timeout|.
*/
@VisibleForTesting
public static String getOAuth2AccessTokenWithTimeout(Context context, Account account, String scope, long timeout, TimeUnit unit) {
assert !ThreadUtils.runningOnUiThread();
final AtomicReference<String> result = new AtomicReference<String>();
final Semaphore semaphore = new Semaphore(0);
getOAuth2AccessToken(context, account, scope, new AccountManagerHelper.GetAuthTokenCallback() {
@Override
public void tokenAvailable(String token) {
result.set(token);
semaphore.release();
}
@Override
public void tokenUnavailable(boolean isTransientError) {
result.set(null);
semaphore.release();
}
});
try {
if (semaphore.tryAcquire(timeout, unit)) {
return result.get();
} else {
Log.d(TAG, "Failed to retrieve auth token within timeout (" + timeout + " + " + unit.name() + ")");
return null;
}
} catch (InterruptedException e) {
Log.w(TAG, "Got interrupted while waiting for auth token");
return null;
}
}
use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.
the class FeatureUtilities method hasGoogleAccountAuthenticator.
@VisibleForTesting
static boolean hasGoogleAccountAuthenticator(Context context) {
if (sHasGoogleAccountAuthenticator == null) {
AccountManagerHelper accountHelper = AccountManagerHelper.get(context);
sHasGoogleAccountAuthenticator = accountHelper.hasGoogleAccountAuthenticator();
}
return sHasGoogleAccountAuthenticator;
}
Aggregations