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

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

Issue 1902923002: [remoting android] Refactor OAuthTokenFetcher for reusability (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
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.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.app.ProgressDialog; 8 import android.app.ProgressDialog;
9 import android.content.DialogInterface; 9 import android.content.DialogInterface;
10 import android.content.Intent; 10 import android.content.Intent;
(...skipping 16 matching lines...) Expand all
27 import android.widget.AdapterView; 27 import android.widget.AdapterView;
28 import android.widget.ArrayAdapter; 28 import android.widget.ArrayAdapter;
29 import android.widget.LinearLayout; 29 import android.widget.LinearLayout;
30 import android.widget.ListView; 30 import android.widget.ListView;
31 import android.widget.Toast; 31 import android.widget.Toast;
32 32
33 import org.chromium.base.ApiCompatibilityUtils; 33 import org.chromium.base.ApiCompatibilityUtils;
34 import org.chromium.base.Log; 34 import org.chromium.base.Log;
35 import org.chromium.chromoting.accountswitcher.AccountSwitcher; 35 import org.chromium.chromoting.accountswitcher.AccountSwitcher;
36 import org.chromium.chromoting.accountswitcher.AccountSwitcherFactory; 36 import org.chromium.chromoting.accountswitcher.AccountSwitcherFactory;
37 import org.chromium.chromoting.base.OAuthTokenFetcher;
37 import org.chromium.chromoting.help.HelpContext; 38 import org.chromium.chromoting.help.HelpContext;
38 import org.chromium.chromoting.help.HelpSingleton; 39 import org.chromium.chromoting.help.HelpSingleton;
39 import org.chromium.chromoting.jni.Client; 40 import org.chromium.chromoting.jni.Client;
40 import org.chromium.chromoting.jni.ConnectionListener; 41 import org.chromium.chromoting.jni.ConnectionListener;
41 import org.chromium.chromoting.jni.JniInterface; 42 import org.chromium.chromoting.jni.JniInterface;
42 43
43 import java.util.ArrayList; 44 import java.util.ArrayList;
44 import java.util.Arrays; 45 import java.util.Arrays;
45 46
46 /** 47 /**
47 * The user interface for querying and displaying a user's host list from the di rectory server. It 48 * The user interface for querying and displaying a user's host list from the di rectory server. It
48 * also requests and renews authentication tokens using the system account manag er. 49 * also requests and renews authentication tokens using the system account manag er.
49 */ 50 */
50 public class Chromoting extends AppCompatActivity implements ConnectionListener, 51 public class Chromoting extends AppCompatActivity implements ConnectionListener,
51 AccountSwitcher.Callback, HostListLoader.Callback, View.OnClickListener { 52 AccountSwitcher.Callback, HostListLoader.Callback, View.OnClickListener {
52 private static final String TAG = "Chromoting"; 53 private static final String TAG = "Chromoting";
53 54
54 /** Only accounts of this type will be selectable for authentication. */ 55 /** Only accounts of this type will be selectable for authentication. */
55 private static final String ACCOUNT_TYPE = "com.google"; 56 private static final String ACCOUNT_TYPE = "com.google";
56 57
58 /** Scope to use when fetching the OAuth token. */
59 private static final String TOKEN_SCOPE = "oauth2:https://www.googleapis.com /auth/chromoting "
60 + "https://www.googleapis.com/auth/googletalk";
61
57 /** Result code used for starting {@link DesktopActivity}. */ 62 /** Result code used for starting {@link DesktopActivity}. */
58 public static final int DESKTOP_ACTIVITY = 0; 63 public static final int DESKTOP_ACTIVITY = 0;
59 64
60 /** Result code used for starting {@link CardboardDesktopActivity}. */ 65 /** Result code used for starting {@link CardboardDesktopActivity}. */
61 public static final int CARDBOARD_DESKTOP_ACTIVITY = 1; 66 public static final int CARDBOARD_DESKTOP_ACTIVITY = 1;
62 67
63 /** Preference names for storing selected and recent accounts. */ 68 /** Preference names for storing selected and recent accounts. */
64 private static final String PREFERENCE_SELECTED_ACCOUNT = "account_name"; 69 private static final String PREFERENCE_SELECTED_ACCOUNT = "account_name";
65 private static final String PREFERENCE_RECENT_ACCOUNT_PREFIX = "recent_accou nt_"; 70 private static final String PREFERENCE_RECENT_ACCOUNT_PREFIX = "recent_accou nt_";
66 private static final String PREFERENCE_EXPERIMENTAL_FLAGS = "flags"; 71 private static final String PREFERENCE_EXPERIMENTAL_FLAGS = "flags";
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 mTriedNewAuthToken = false; 492 mTriedNewAuthToken = false;
488 showHostListLoadingIndicator(); 493 showHostListLoadingIndicator();
489 494
490 // The refresh button simply makes use of the currently-chosen account. 495 // The refresh button simply makes use of the currently-chosen account.
491 requestAuthToken(false); 496 requestAuthToken(false);
492 } 497 }
493 498
494 private void requestAuthToken(boolean expireCurrentToken) { 499 private void requestAuthToken(boolean expireCurrentToken) {
495 mWaitingForAuthToken = true; 500 mWaitingForAuthToken = true;
496 501
497 OAuthTokenFetcher fetcher = new OAuthTokenFetcher(this, mAccount, 502 OAuthTokenFetcher fetcher = new OAuthTokenFetcher(this, mAccount, TOKEN_ SCOPE,
498 new OAuthTokenFetcher.Callback() { 503 new OAuthTokenFetcher.Callback() {
499 @Override 504 @Override
500 public void onTokenFetched(String token) { 505 public void onTokenFetched(String token) {
501 mWaitingForAuthToken = false; 506 mWaitingForAuthToken = false;
502 mToken = token; 507 mToken = token;
503 mHostListLoader.retrieveHostList(mToken, Chromoting.this ); 508 mHostListLoader.retrieveHostList(mToken, Chromoting.this );
504 } 509 }
505 510
506 @Override 511 @Override
507 public void onError(int errorResource) { 512 public void onError(OAuthTokenFetcher.Error error) {
508 mWaitingForAuthToken = false; 513 mWaitingForAuthToken = false;
509 updateHostListView(); 514 updateHostListView();
510 String explanation = getString(errorResource); 515 String explanation = getString(error == OAuthTokenFetche r.Error.NETWORK
516 ? R.string.error_network_error : R.string.error_ unexpected);
511 Toast.makeText(Chromoting.this, explanation, Toast.LENGT H_LONG).show(); 517 Toast.makeText(Chromoting.this, explanation, Toast.LENGT H_LONG).show();
512 } 518 }
513 }); 519 });
514 520
515 if (expireCurrentToken) { 521 if (expireCurrentToken) {
516 fetcher.clearAndFetch(mToken); 522 fetcher.clearAndFetch(mToken);
517 mToken = null; 523 mToken = null;
518 } else { 524 } else {
519 fetcher.fetch(); 525 fetcher.fetch();
520 } 526 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 // Unreachable, but required by Google Java style and findbugs. 644 // Unreachable, but required by Google Java style and findbugs.
639 assert false : "Unreached"; 645 assert false : "Unreached";
640 } 646 }
641 647
642 if (dismissProgress && mProgressIndicator != null) { 648 if (dismissProgress && mProgressIndicator != null) {
643 mProgressIndicator.dismiss(); 649 mProgressIndicator.dismiss();
644 mProgressIndicator = null; 650 mProgressIndicator = null;
645 } 651 }
646 } 652 }
647 } 653 }
OLDNEW
« no previous file with comments | « remoting/android/client_java_tmpl.gni ('k') | remoting/android/java/src/org/chromium/chromoting/OAuthTokenFetcher.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698