Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Unified Diff: blimp/client/android/java/src/org/chromium/blimp/BlimpRendererActivity.java

Issue 1373943002: Add sign-in and token retrieval to Blimp (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed DEPS issue Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: blimp/client/android/java/src/org/chromium/blimp/BlimpRendererActivity.java
diff --git a/blimp/client/android/java/src/org/chromium/blimp/BlimpRendererActivity.java b/blimp/client/android/java/src/org/chromium/blimp/BlimpRendererActivity.java
index 7cc4e66f4e51f6a7373124b3f06c1007b531efd0..f0327176706257ac38f4306ffd460eb2b51e2933 100644
--- a/blimp/client/android/java/src/org/chromium/blimp/BlimpRendererActivity.java
+++ b/blimp/client/android/java/src/org/chromium/blimp/BlimpRendererActivity.java
@@ -5,22 +5,36 @@
package org.chromium.blimp;
import android.app.Activity;
+import android.content.Intent;
import android.os.Bundle;
import org.chromium.base.Log;
import org.chromium.base.library_loader.ProcessInitException;
+import org.chromium.blimp.auth.RetryingTokenSource;
+import org.chromium.blimp.auth.TokenSource;
+import org.chromium.blimp.auth.TokenSourceImpl;
+import org.chromium.ui.widget.Toast;
/**
* The {@link Activity} for rendering the main Blimp client. This loads the Blimp rendering stack
* and displays it.
*/
-public class BlimpRendererActivity extends Activity implements BlimpLibraryLoader.Callback {
- private static final String TAG = "cr.Blimp";
+public class BlimpRendererActivity extends Activity implements BlimpLibraryLoader.Callback,
+ TokenSource.Callback {
+
+ private static final int ACCOUNT_CHOOSER_INTENT_REQUEST_CODE = 100;
+ private static final String TAG = "Blimp";
+ private TokenSource mTokenSource;
private BlimpView mBlimpView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+
+ mTokenSource = new RetryingTokenSource(new TokenSourceImpl(this));
+ mTokenSource.setCallback(this);
+ mTokenSource.getToken();
+
try {
BlimpLibraryLoader.startAsync(this, this);
} catch (ProcessInitException e) {
@@ -37,9 +51,28 @@ public class BlimpRendererActivity extends Activity implements BlimpLibraryLoade
mBlimpView = null;
}
+ if (mTokenSource != null) {
+ mTokenSource.destroy();
+ mTokenSource = null;
+ }
+
super.onDestroy();
}
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ switch (requestCode) {
+ case ACCOUNT_CHOOSER_INTENT_REQUEST_CODE:
+ if (resultCode == RESULT_OK) {
+ mTokenSource.onAccountSelected(data);
+ mTokenSource.getToken();
+ } else {
+ onTokenUnavailable(false);
+ }
+ break;
+ }
+ }
+
// BlimpLibraryLoader.Callback implementation.
@Override
public void onStartupComplete(boolean success) {
@@ -53,4 +86,24 @@ public class BlimpRendererActivity extends Activity implements BlimpLibraryLoade
mBlimpView = (BlimpView) findViewById(R.id.renderer);
mBlimpView.initializeRenderer();
}
+
+ // TokenSource.Callback implementation.
+ @Override
+ public void onTokenReceived(String token) {
+ // TODO(dtrainor): Do something with the token and the assigner!
+ Toast.makeText(this, R.string.signin_get_token_succeeded, Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
+ public void onTokenUnavailable(boolean isTransient) {
+ // Ignore isTransient here because we're relying on the auto-retry TokenSource.
+ // TODO(dtrainor): Show a better error dialog/message.
+ Toast.makeText(this, R.string.signin_get_token_failed, Toast.LENGTH_LONG).show();
+ finish();
+ }
+
+ @Override
+ public void onNeedsAccountToBeSelected(Intent suggestedIntent) {
+ startActivityForResult(suggestedIntent, ACCOUNT_CHOOSER_INTENT_REQUEST_CODE);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698