summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorlambroslambrou <lambroslambrou@chromium.org>2014-09-26 18:12:44 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-27 01:12:55 +0000
commitf1318ecbfff840702b08eab40d744dc55670610d (patch)
tree648dbc2f0a6e36a9a5d6e50c11b0e0decebcb5b8 /remoting
parent3c37dba2da292e0342d39731d6fe558340521bb5 (diff)
downloadchromium_src-f1318ecbfff840702b08eab40d744dc55670610d.zip
chromium_src-f1318ecbfff840702b08eab40d744dc55670610d.tar.gz
chromium_src-f1318ecbfff840702b08eab40d744dc55670610d.tar.bz2
Android Chromoting: Don't fetch auth token if there's a fetch pending.
Currently, the host list is fetched from the main activity's onStart() handler. If onStart() is triggered again during the process of authentication, this could cause an infinite loop of pending requests. Review URL: https://codereview.chromium.org/607453004 Cr-Commit-Position: refs/heads/master@{#297088}
Diffstat (limited to 'remoting')
-rw-r--r--remoting/android/java/src/org/chromium/chromoting/Chromoting.java21
1 files changed, 20 insertions, 1 deletions
diff --git a/remoting/android/java/src/org/chromium/chromoting/Chromoting.java b/remoting/android/java/src/org/chromium/chromoting/Chromoting.java
index f21efcc..be378904 100644
--- a/remoting/android/java/src/org/chromium/chromoting/Chromoting.java
+++ b/remoting/android/java/src/org/chromium/chromoting/Chromoting.java
@@ -96,6 +96,13 @@ public class Chromoting extends Activity implements JniInterface.ConnectionListe
*/
boolean mTriedNewAuthToken;
+ /**
+ * Flag to track whether a call to AccountManager.getAuthToken() is currently pending.
+ * This avoids infinitely-nested calls in case onStart() gets triggered a second time
+ * while a token is being fetched.
+ */
+ private boolean mWaitingForAuthToken = false;
+
/** Shows a warning explaining that a Google account is required, then closes the activity. */
private void showNoAccountsDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
@@ -292,16 +299,27 @@ public class Chromoting extends Activity implements JniInterface.ConnectionListe
}
private void refreshHostList() {
+ if (mWaitingForAuthToken) {
+ return;
+ }
+
mTriedNewAuthToken = false;
setHostListProgressVisible(true);
// The refresh button simply makes use of the currently-chosen account.
+ requestAuthToken();
+ }
+
+ private void requestAuthToken() {
AccountManager.get(this).getAuthToken(mAccount, TOKEN_SCOPE, null, this, this, null);
+ mWaitingForAuthToken = true;
}
@Override
public void run(AccountManagerFuture<Bundle> future) {
Log.i("auth", "User finished with auth dialogs");
+ mWaitingForAuthToken = false;
+
Bundle result = null;
String explanation = null;
try {
@@ -316,6 +334,7 @@ public class Chromoting extends Activity implements JniInterface.ConnectionListe
}
if (result == null) {
+ setHostListProgressVisible(false);
if (explanation != null) {
Toast.makeText(this, explanation, Toast.LENGTH_LONG).show();
}
@@ -387,7 +406,7 @@ public class Chromoting extends Activity implements JniInterface.ConnectionListe
Log.w("auth", "Requesting renewal of rejected auth token");
authenticator.invalidateAuthToken(mAccount.type, mToken);
mToken = null;
- authenticator.getAuthToken(mAccount, TOKEN_SCOPE, null, this, this, null);
+ requestAuthToken();
// We're not in an error state *yet*.
return;