Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.blimp; | 5 package org.chromium.blimp; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.Intent; | 8 import android.content.Intent; |
| 9 import android.os.Bundle; | 9 import android.os.Bundle; |
| 10 | 10 |
| 11 import org.chromium.base.Log; | 11 import org.chromium.base.Log; |
| 12 import org.chromium.base.library_loader.ProcessInitException; | 12 import org.chromium.base.library_loader.ProcessInitException; |
| 13 import org.chromium.blimp.auth.RetryingTokenSource; | 13 import org.chromium.blimp.auth.RetryingTokenSource; |
| 14 import org.chromium.blimp.auth.TokenSource; | 14 import org.chromium.blimp.auth.TokenSource; |
| 15 import org.chromium.blimp.auth.TokenSourceImpl; | 15 import org.chromium.blimp.auth.TokenSourceImpl; |
| 16 import org.chromium.blimp.session.BlimpClientSession; | 16 import org.chromium.blimp.session.BlimpClientSession; |
| 17 import org.chromium.blimp.session.TabControlFeature; | 17 import org.chromium.blimp.session.TabControlFeature; |
| 18 import org.chromium.blimp.toolbar.Toolbar; | 18 import org.chromium.blimp.toolbar.Toolbar; |
| 19 import org.chromium.ui.widget.Toast; | 19 import org.chromium.ui.widget.Toast; |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * The {@link Activity} for rendering the main Blimp client. This loads the Bli mp rendering stack | 22 * The {@link Activity} for rendering the main Blimp client. This loads the Bli mp rendering stack |
| 23 * and displays it. | 23 * and displays it. |
| 24 */ | 24 */ |
| 25 public class BlimpRendererActivity extends Activity implements BlimpLibraryLoade r.Callback, | 25 public class BlimpRendererActivity extends Activity |
| 26 TokenSource.Callback { | 26 implements BlimpLibraryLoader.Callback, TokenSource.Callback, BlimpClien tSession.Callback { |
| 27 | |
| 28 private static final int ACCOUNT_CHOOSER_INTENT_REQUEST_CODE = 100; | 27 private static final int ACCOUNT_CHOOSER_INTENT_REQUEST_CODE = 100; |
| 29 private static final String TAG = "Blimp"; | 28 private static final String TAG = "Blimp"; |
| 29 | |
| 30 /** Provides user authentication tokens that can be used to query for engine assignments. This | |
| 31 * can potentially query GoogleAuthUtil for an OAuth2 authentication token with userinfo.email | |
| 32 * privilages for a chosen Android account. */ | |
|
nyquist
2016/02/18 01:58:39
Nit: privileges
David Trainor- moved to gerrit
2016/02/18 16:01:54
Done.
| |
| 30 private TokenSource mTokenSource; | 33 private TokenSource mTokenSource; |
| 34 | |
| 31 private BlimpView mBlimpView; | 35 private BlimpView mBlimpView; |
| 32 private Toolbar mToolbar; | 36 private Toolbar mToolbar; |
| 33 private BlimpClientSession mBlimpClientSession; | 37 private BlimpClientSession mBlimpClientSession; |
| 34 private TabControlFeature mTabControlFeature; | 38 private TabControlFeature mTabControlFeature; |
| 35 | 39 |
| 36 @Override | 40 @Override |
| 37 protected void onCreate(Bundle savedInstanceState) { | 41 protected void onCreate(Bundle savedInstanceState) { |
| 38 super.onCreate(savedInstanceState); | 42 super.onCreate(savedInstanceState); |
| 39 | 43 |
| 44 // Build a TokenSource that will internally retry accessing the underlyi ng TokenSourceImpl. | |
| 45 // This will exponentially backoff while it tries to get the access toke n. See | |
| 46 // {@link org.chromium.blimp.auth.RetryingTokenSource} for more informat ion. The underlying | |
|
nyquist
2016/02/18 01:58:40
Nit: Just {@link RetryingTokenSource}. It's alread
David Trainor- moved to gerrit
2016/02/18 16:01:54
Done.
| |
| 47 // TokenSourceImpl will attempt to query GoogleAuthUtil, but might fail if there is no | |
| 48 // account selected, in which case it will ask this Activity to show an account chooser and | |
| 49 // notify it of the selection result. | |
| 40 mTokenSource = new RetryingTokenSource(new TokenSourceImpl(this)); | 50 mTokenSource = new RetryingTokenSource(new TokenSourceImpl(this)); |
| 41 mTokenSource.setCallback(this); | 51 mTokenSource.setCallback(this); |
| 42 mTokenSource.getToken(); | 52 mTokenSource.getToken(); |
| 43 | 53 |
| 44 try { | 54 try { |
| 45 BlimpLibraryLoader.startAsync(this, this); | 55 BlimpLibraryLoader.startAsync(this, this); |
| 46 } catch (ProcessInitException e) { | 56 } catch (ProcessInitException e) { |
| 47 Log.e(TAG, "Native startup exception", e); | 57 Log.e(TAG, "Native startup exception", e); |
| 48 System.exit(-1); | 58 System.exit(-1); |
| 49 return; | 59 return; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 @Override | 118 @Override |
| 109 public void onStartupComplete(boolean success) { | 119 public void onStartupComplete(boolean success) { |
| 110 if (!success) { | 120 if (!success) { |
| 111 Log.e(TAG, "Native startup failed"); | 121 Log.e(TAG, "Native startup failed"); |
| 112 finish(); | 122 finish(); |
| 113 return; | 123 return; |
| 114 } | 124 } |
| 115 | 125 |
| 116 setContentView(R.layout.blimp_main); | 126 setContentView(R.layout.blimp_main); |
| 117 | 127 |
| 118 mBlimpClientSession = new BlimpClientSession(); | 128 mBlimpClientSession = new BlimpClientSession(this); |
| 119 mBlimpClientSession.connect(); | |
| 120 | 129 |
| 121 mBlimpView = (BlimpView) findViewById(R.id.renderer); | 130 mBlimpView = (BlimpView) findViewById(R.id.renderer); |
| 122 mBlimpView.initializeRenderer(mBlimpClientSession); | 131 mBlimpView.initializeRenderer(mBlimpClientSession); |
| 123 | 132 |
| 124 mToolbar = (Toolbar) findViewById(R.id.toolbar); | 133 mToolbar = (Toolbar) findViewById(R.id.toolbar); |
| 125 mToolbar.initialize(mBlimpClientSession); | 134 mToolbar.initialize(mBlimpClientSession); |
| 126 | 135 |
| 127 mTabControlFeature = new TabControlFeature(mBlimpClientSession, mBlimpVi ew); | 136 mTabControlFeature = new TabControlFeature(mBlimpClientSession, mBlimpVi ew); |
| 128 mToolbar.loadUrl("http://www.google.com/"); | 137 mToolbar.loadUrl("http://www.google.com/"); |
| 129 } | 138 } |
| 130 | 139 |
| 131 // TokenSource.Callback implementation. | 140 // TokenSource.Callback implementation. |
| 132 @Override | 141 @Override |
| 133 public void onTokenReceived(String token) { | 142 public void onTokenReceived(String token) { |
| 134 // TODO(dtrainor): Do something with the token and the assigner! | 143 if (mBlimpClientSession != null) mBlimpClientSession.connect(token); |
| 135 Toast.makeText(this, R.string.signin_get_token_succeeded, Toast.LENGTH_S HORT).show(); | |
| 136 } | 144 } |
| 137 | 145 |
| 138 @Override | 146 @Override |
| 139 public void onTokenUnavailable(boolean isTransient) { | 147 public void onTokenUnavailable(boolean isTransient) { |
| 140 // Ignore isTransient here because we're relying on the auto-retry Token Source. | 148 // Ignore isTransient here because we're relying on the auto-retry Token Source. |
| 141 // TODO(dtrainor): Show a better error dialog/message. | 149 // TODO(dtrainor): Show a better error dialog/message. |
| 142 Toast.makeText(this, R.string.signin_get_token_failed, Toast.LENGTH_LONG ).show(); | 150 Toast.makeText(this, R.string.signin_get_token_failed, Toast.LENGTH_LONG ).show(); |
| 143 finish(); | |
| 144 } | 151 } |
| 145 | 152 |
| 146 @Override | 153 @Override |
| 147 public void onNeedsAccountToBeSelected(Intent suggestedIntent) { | 154 public void onNeedsAccountToBeSelected(Intent suggestedIntent) { |
| 148 startActivityForResult(suggestedIntent, ACCOUNT_CHOOSER_INTENT_REQUEST_C ODE); | 155 startActivityForResult(suggestedIntent, ACCOUNT_CHOOSER_INTENT_REQUEST_C ODE); |
| 149 } | 156 } |
| 157 | |
| 158 // BlimpClientSession.Callback implementation. | |
| 159 @Override | |
| 160 public void onAssignmentReceived(int result, int suggestedMessageResourceId) { | |
| 161 Toast.makeText(this, suggestedMessageResourceId, Toast.LENGTH_LONG).show (); | |
| 162 } | |
| 150 } | 163 } |
| OLD | NEW |