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

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/Chromoting.java

Issue 582873004: Android Chromoting: Remove duplicate code for fetching the host list. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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.chromoting; 5 package org.chromium.chromoting;
6 6
7 import android.accounts.Account; 7 import android.accounts.Account;
8 import android.accounts.AccountManager; 8 import android.accounts.AccountManager;
9 import android.accounts.AccountManagerCallback; 9 import android.accounts.AccountManagerCallback;
10 import android.accounts.AccountManagerFuture; 10 import android.accounts.AccountManagerFuture;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 167
168 @Override 168 @Override
169 protected void onNewIntent(Intent intent) { 169 protected void onNewIntent(Intent intent) {
170 super.onNewIntent(intent); 170 super.onNewIntent(intent);
171 if (mTokenFetcher != null) { 171 if (mTokenFetcher != null) {
172 if (mTokenFetcher.handleTokenFetched(intent)) { 172 if (mTokenFetcher.handleTokenFetched(intent)) {
173 mTokenFetcher = null; 173 mTokenFetcher = null;
174 } 174 }
175 } 175 }
176 } 176 }
177
177 /** 178 /**
178 * Called when the activity becomes visible. This happens on initial launch and whenever the 179 * Called when the activity becomes visible. This happens on initial launch and whenever the
179 * user switches to the activity, for example, by using the window-switcher or when coming from 180 * user switches to the activity, for example, by using the window-switcher or when coming from
180 * the device's lock screen. 181 * the device's lock screen.
181 */ 182 */
182 @Override 183 @Override
183 public void onStart() { 184 public void onStart() {
184 super.onStart(); 185 super.onStart();
185 186
186 mAccounts = AccountManager.get(this).getAccountsByType(ACCOUNT_TYPE); 187 mAccounts = AccountManager.get(this).getAccountsByType(ACCOUNT_TYPE);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 300 }
300 301
301 @Override 302 @Override
302 public void run(AccountManagerFuture<Bundle> future) { 303 public void run(AccountManagerFuture<Bundle> future) {
303 Log.i("auth", "User finished with auth dialogs"); 304 Log.i("auth", "User finished with auth dialogs");
304 Bundle result = null; 305 Bundle result = null;
305 String explanation = null; 306 String explanation = null;
306 try { 307 try {
307 // Here comes our auth token from the Android system. 308 // Here comes our auth token from the Android system.
308 result = future.getResult(); 309 result = future.getResult();
309 String authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
310 Log.i("auth", "Received an auth token from system");
311
312 mToken = authToken;
313
314 mHostListLoader.retrieveHostList(authToken, this);
315 } catch (OperationCanceledException ex) { 310 } catch (OperationCanceledException ex) {
316 // User canceled authentication. No need to report an error. 311 // User canceled authentication. No need to report an error.
317 } catch (AuthenticatorException ex) { 312 } catch (AuthenticatorException ex) {
318 explanation = getString(R.string.error_unexpected); 313 explanation = getString(R.string.error_unexpected);
319 } catch (IOException ex) { 314 } catch (IOException ex) {
320 explanation = getString(R.string.error_network_error); 315 explanation = getString(R.string.error_network_error);
321 } 316 }
322 317
323 if (result == null) { 318 if (result == null) {
324 if (explanation != null) { 319 if (explanation != null) {
325 Toast.makeText(this, explanation, Toast.LENGTH_LONG).show(); 320 Toast.makeText(this, explanation, Toast.LENGTH_LONG).show();
326 } 321 }
327 return; 322 return;
328 } 323 }
329 324
330 String authToken = result.getString(AccountManager.KEY_AUTHTOKEN); 325 mToken = result.getString(AccountManager.KEY_AUTHTOKEN);
331 Log.i("auth", "Received an auth token from system"); 326 Log.i("auth", "Received an auth token from system");
332 327
333 mToken = authToken; 328 mHostListLoader.retrieveHostList(mToken, this);
334
335 mHostListLoader.retrieveHostList(authToken, this);
336 } 329 }
337 330
338 @Override 331 @Override
339 public boolean onNavigationItemSelected(int itemPosition, long itemId) { 332 public boolean onNavigationItemSelected(int itemPosition, long itemId) {
340 mAccount = mAccounts[itemPosition]; 333 mAccount = mAccounts[itemPosition];
341 334
342 getPreferences(MODE_PRIVATE).edit().putString("account_name", mAccount.n ame). 335 getPreferences(MODE_PRIVATE).edit().putString("account_name", mAccount.n ame).
343 putString("account_type", mAccount.type).apply(); 336 putString("account_type", mAccount.type).apply();
344 337
345 // The current host list is no longer valid for the new account, so clea r the list. 338 // The current host list is no longer valid for the new account, so clea r the list.
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 } 471 }
479 }; 472 };
480 return new ThirdPartyTokenFetcher(this, host.getTokenUrlPatterns(), call back); 473 return new ThirdPartyTokenFetcher(this, host.getTokenUrlPatterns(), call back);
481 } 474 }
482 475
483 public void fetchThirdPartyToken(String tokenUrl, String clientId, String sc ope) { 476 public void fetchThirdPartyToken(String tokenUrl, String clientId, String sc ope) {
484 assert mTokenFetcher != null; 477 assert mTokenFetcher != null;
485 mTokenFetcher.fetchToken(tokenUrl, clientId, scope); 478 mTokenFetcher.fetchToken(tokenUrl, clientId, scope);
486 } 479 }
487 } 480 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698