| 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.app; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.app.Activity; | 8 import android.app.Activity; |
| 9 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.os.Bundle; | 10 import android.os.Bundle; |
| 11 import android.os.Handler; | 11 import android.os.Handler; |
| 12 import android.text.TextUtils; | 12 import android.text.TextUtils; |
| 13 import android.view.View; | 13 import android.view.View; |
| 14 import android.widget.TextView; | 14 import android.widget.TextView; |
| 15 | 15 |
| 16 import org.chromium.base.CommandLine; | 16 import org.chromium.base.CommandLine; |
| 17 import org.chromium.base.Log; | 17 import org.chromium.base.Log; |
| 18 import org.chromium.base.annotations.SuppressFBWarnings; | 18 import org.chromium.base.annotations.SuppressFBWarnings; |
| 19 import org.chromium.base.library_loader.ProcessInitException; | 19 import org.chromium.base.library_loader.ProcessInitException; |
| 20 import org.chromium.blimp.auth.RetryingTokenSource; | 20 import org.chromium.blimp.app.auth.RetryingTokenSource; |
| 21 import org.chromium.blimp.auth.TokenSource; | 21 import org.chromium.blimp.app.auth.TokenSource; |
| 22 import org.chromium.blimp.auth.TokenSourceImpl; | 22 import org.chromium.blimp.app.auth.TokenSourceImpl; |
| 23 import org.chromium.blimp.app.preferences.PreferencesUtil; |
| 24 import org.chromium.blimp.app.session.BlimpClientSession; |
| 25 import org.chromium.blimp.app.session.EngineInfo; |
| 26 import org.chromium.blimp.app.session.TabControlFeature; |
| 27 import org.chromium.blimp.app.toolbar.Toolbar; |
| 28 import org.chromium.blimp.app.toolbar.ToolbarMenu; |
| 23 import org.chromium.blimp.core.BlimpClientSwitches; | 29 import org.chromium.blimp.core.BlimpClientSwitches; |
| 24 import org.chromium.blimp.preferences.PreferencesUtil; | |
| 25 import org.chromium.blimp.session.BlimpClientSession; | |
| 26 import org.chromium.blimp.session.EngineInfo; | |
| 27 import org.chromium.blimp.session.TabControlFeature; | |
| 28 import org.chromium.blimp.toolbar.Toolbar; | |
| 29 import org.chromium.blimp.toolbar.ToolbarMenu; | |
| 30 import org.chromium.ui.base.WindowAndroid; | 30 import org.chromium.ui.base.WindowAndroid; |
| 31 import org.chromium.ui.widget.Toast; | 31 import org.chromium.ui.widget.Toast; |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * The {@link Activity} for rendering the main Blimp client. This loads the Bli
mp rendering stack | 34 * The {@link Activity} for rendering the main Blimp client. This loads the Bli
mp rendering stack |
| 35 * and displays it. | 35 * and displays it. |
| 36 */ | 36 */ |
| 37 public class BlimpRendererActivity | 37 public class BlimpRendererActivity |
| 38 extends Activity implements BlimpLibraryLoader.Callback, TokenSource.Cal
lback, | 38 extends Activity implements BlimpLibraryLoader.Callback, TokenSource.Cal
lback, |
| 39 BlimpClientSession.ConnectionObserver, | 39 BlimpClientSession.ConnectionObserver, |
| 40 ToolbarMenu.ToolbarMenuDelegate, Toolbar.Too
lbarDelegate { | 40 ToolbarMenu.ToolbarMenuDelegate, Toolbar.Too
lbarDelegate { |
| 41 private static final int ACCOUNT_CHOOSER_INTENT_REQUEST_CODE = 100; | 41 private static final int ACCOUNT_CHOOSER_INTENT_REQUEST_CODE = 100; |
| 42 private static final String TAG = "BlimpRendererActivity"; | 42 private static final String TAG = "BlimpRendActivity"; |
| 43 | 43 |
| 44 // Refresh interval for the debug view in milliseconds. | 44 // Refresh interval for the debug view in milliseconds. |
| 45 private static final int DEBUG_VIEW_REFRESH_INTERVAL = 1000; | 45 private static final int DEBUG_VIEW_REFRESH_INTERVAL = 1000; |
| 46 private static final int BYTES_PER_KILO = 1024; | 46 private static final int BYTES_PER_KILO = 1024; |
| 47 | 47 |
| 48 /** Provides user authentication tokens that can be used to query for engine
assignments. This | 48 /** Provides user authentication tokens that can be used to query for engine
assignments. This |
| 49 * can potentially query GoogleAuthUtil for an OAuth2 authentication token
with userinfo.email | 49 * can potentially query GoogleAuthUtil for an OAuth2 authentication token
with userinfo.email |
| 50 * privileges for a chosen Android account. */ | 50 * privileges for a chosen Android account. */ |
| 51 private TokenSource mTokenSource; | 51 private TokenSource mTokenSource; |
| 52 | 52 |
| 53 private BlimpView mBlimpView; | 53 private BlimpContentsDisplay mBlimpContentsDisplay; |
| 54 private Toolbar mToolbar; | 54 private Toolbar mToolbar; |
| 55 private BlimpClientSession mBlimpClientSession; | 55 private BlimpClientSession mBlimpClientSession; |
| 56 private TabControlFeature mTabControlFeature; | 56 private TabControlFeature mTabControlFeature; |
| 57 private WindowAndroid mWindowAndroid; | 57 private WindowAndroid mWindowAndroid; |
| 58 | 58 |
| 59 private Handler mHandler = new Handler(); | 59 private Handler mHandler = new Handler(); |
| 60 | 60 |
| 61 private boolean mFirstUrlLoadDone = false; | 61 private boolean mFirstUrlLoadDone = false; |
| 62 | 62 |
| 63 // Flag to record the base value of the metrics when the debug view is turne
d on. | 63 // Flag to record the base value of the metrics when the debug view is turne
d on. |
| 64 private boolean mStatsBaseRecorded = false; | 64 private boolean mStatsBaseRecorded = false; |
| 65 private int mSentBase; | 65 private int mSentBase; |
| 66 private int mReceivedBase; | 66 private int mReceivedBase; |
| 67 private int mCommitsBase; | 67 private int mCommitsBase; |
| 68 private int mSent; | 68 private int mSent; |
| 69 private int mReceived; | 69 private int mReceived; |
| 70 private int mCommits; | 70 private int mCommits; |
| 71 private String mToken = null; | 71 private String mToken = null; |
| 72 | 72 |
| 73 @Override | 73 @Override |
| 74 @SuppressFBWarnings("DM_EXIT") // FindBugs doesn't like System.exit(). | 74 @SuppressFBWarnings("DM_EXIT") // FindBugs doesn't like System.exit(). |
| 75 protected void onCreate(Bundle savedInstanceState) { | 75 protected void onCreate(Bundle savedInstanceState) { |
| 76 super.onCreate(savedInstanceState); | 76 super.onCreate(savedInstanceState); |
| 77 buildAndTriggerTokenSourceIfNeeded(); | 77 buildAndTriggerTokenSourceIfNeeded(); |
| 78 try { | 78 try { |
| 79 BlimpLibraryLoader.startAsync(this); | 79 BlimpLibraryLoader.startAsync(this); |
| 80 } catch (ProcessInitException e) { | 80 } catch (ProcessInitException e) { |
| 81 Log.e(TAG, "Native startup exception", e); | 81 Log.e(TAG, "Native startup exception", e); |
| 82 System.exit(-1); | 82 System.exit(-1); |
| 83 return; | 83 return; |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 @Override | 87 @Override |
| 88 protected void onDestroy() { | 88 protected void onDestroy() { |
| 89 if (mTabControlFeature != null) { | 89 if (mTabControlFeature != null) { |
| 90 mTabControlFeature.destroy(); | 90 mTabControlFeature.destroy(); |
| 91 mTabControlFeature = null; | 91 mTabControlFeature = null; |
| 92 } | 92 } |
| 93 | 93 |
| 94 if (mBlimpView != null) { | 94 if (mBlimpContentsDisplay != null) { |
| 95 mBlimpView.destroyRenderer(); | 95 mBlimpContentsDisplay.destroyRenderer(); |
| 96 mBlimpView = null; | 96 mBlimpContentsDisplay = null; |
| 97 } | 97 } |
| 98 | 98 |
| 99 if (mToolbar != null) { | 99 if (mToolbar != null) { |
| 100 mToolbar.destroy(); | 100 mToolbar.destroy(); |
| 101 mToolbar = null; | 101 mToolbar = null; |
| 102 } | 102 } |
| 103 | 103 |
| 104 if (mTokenSource != null) { | 104 if (mTokenSource != null) { |
| 105 mTokenSource.destroy(); | 105 mTokenSource.destroy(); |
| 106 mTokenSource = null; | 106 mTokenSource = null; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 return; | 150 return; |
| 151 } | 151 } |
| 152 | 152 |
| 153 setContentView(R.layout.blimp_main); | 153 setContentView(R.layout.blimp_main); |
| 154 | 154 |
| 155 mWindowAndroid = new WindowAndroid(BlimpRendererActivity.this); | 155 mWindowAndroid = new WindowAndroid(BlimpRendererActivity.this); |
| 156 mBlimpClientSession = | 156 mBlimpClientSession = |
| 157 new BlimpClientSession(PreferencesUtil.findAssignerUrl(this), mW
indowAndroid); | 157 new BlimpClientSession(PreferencesUtil.findAssignerUrl(this), mW
indowAndroid); |
| 158 mBlimpClientSession.addObserver(this); | 158 mBlimpClientSession.addObserver(this); |
| 159 | 159 |
| 160 mBlimpView = (BlimpView) findViewById(R.id.renderer); | 160 mBlimpContentsDisplay = (BlimpContentsDisplay) findViewById(R.id.rendere
r); |
| 161 mBlimpView.initializeRenderer(mBlimpClientSession); | 161 mBlimpContentsDisplay.initializeRenderer(mBlimpClientSession); |
| 162 | 162 |
| 163 mToolbar = (Toolbar) findViewById(R.id.toolbar); | 163 mToolbar = (Toolbar) findViewById(R.id.toolbar); |
| 164 mToolbar.initialize(mBlimpClientSession, this); | 164 mToolbar.initialize(mBlimpClientSession, this); |
| 165 | 165 |
| 166 mTabControlFeature = new TabControlFeature(mBlimpClientSession, mBlimpVi
ew); | 166 mTabControlFeature = new TabControlFeature(mBlimpClientSession, mBlimpCo
ntentsDisplay); |
| 167 | 167 |
| 168 handleUrlFromIntent(getIntent()); | 168 handleUrlFromIntent(getIntent()); |
| 169 | 169 |
| 170 // If Blimp client has command line flag "engine-ip", client will use th
e command line token | 170 // If Blimp client has command line flag "engine-ip", client will use th
e command line token |
| 171 // to connect. See GetAssignmentFromCommandLine() in | 171 // to connect. See GetAssignmentFromCommandLine() in |
| 172 // blimp/client/session/assignment_source.cc | 172 // blimp/client/session/assignment_source.cc |
| 173 // In normal cases, where client uses the engine ip given by the Assigne
r, | 173 // In normal cases, where client uses the engine ip given by the Assigne
r, |
| 174 // connection to the engine is triggered by the successful retrieval of
a token as | 174 // connection to the engine is triggered by the successful retrieval of
a token as |
| 175 // TokenSource.Callback. | 175 // TokenSource.Callback. |
| 176 if (CommandLine.getInstance().hasSwitch(BlimpClientSwitches.ENGINE_IP))
{ | 176 if (CommandLine.getInstance().hasSwitch(BlimpClientSwitches.ENGINE_IP))
{ |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 // TokenSourceImpl. This will exponentially backoff while it tries to ge
t the access | 332 // TokenSourceImpl. This will exponentially backoff while it tries to ge
t the access |
| 333 // token. See {@link RetryingTokenSource} for more information. The un
derlying | 333 // token. See {@link RetryingTokenSource} for more information. The un
derlying |
| 334 // TokenSourceImpl will attempt to query GoogleAuthUtil, but might fail
if there is no | 334 // TokenSourceImpl will attempt to query GoogleAuthUtil, but might fail
if there is no |
| 335 // account selected, in which case it will ask this Activity to show an
account chooser | 335 // account selected, in which case it will ask this Activity to show an
account chooser |
| 336 // and notify it of the selection result. | 336 // and notify it of the selection result. |
| 337 mTokenSource = new RetryingTokenSource(new TokenSourceImpl(this)); | 337 mTokenSource = new RetryingTokenSource(new TokenSourceImpl(this)); |
| 338 mTokenSource.setCallback(this); | 338 mTokenSource.setCallback(this); |
| 339 mTokenSource.getToken(); | 339 mTokenSource.getToken(); |
| 340 } | 340 } |
| 341 } | 341 } |
| OLD | NEW |