| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.chrome.browser.signin; | 5 package org.chromium.chrome.browser.signin; |
| 6 | 6 |
| 7 import android.content.Context; | |
| 8 | |
| 9 import com.google.android.gms.auth.GoogleAuthException; | 7 import com.google.android.gms.auth.GoogleAuthException; |
| 10 import com.google.android.gms.auth.GoogleAuthUtil; | 8 import com.google.android.gms.auth.GoogleAuthUtil; |
| 11 | 9 |
| 10 import org.chromium.base.ContextUtils; |
| 12 import org.chromium.base.Log; | 11 import org.chromium.base.Log; |
| 13 import org.chromium.base.ThreadUtils; | 12 import org.chromium.base.ThreadUtils; |
| 14 import org.chromium.base.VisibleForTesting; | 13 import org.chromium.base.VisibleForTesting; |
| 15 import org.chromium.chrome.browser.externalauth.ExternalAuthUtils; | 14 import org.chromium.chrome.browser.externalauth.ExternalAuthUtils; |
| 16 import org.chromium.chrome.browser.externalauth.UserRecoverableErrorHandler; | 15 import org.chromium.chrome.browser.externalauth.UserRecoverableErrorHandler; |
| 17 | 16 |
| 18 import java.io.IOException; | 17 import java.io.IOException; |
| 19 | 18 |
| 20 /** | 19 /** |
| 21 * Returns a stable id that can be used to identify a Google Account. This | 20 * Returns a stable id that can be used to identify a Google Account. This |
| (...skipping 10 matching lines...) Expand all Loading... |
| 32 | 31 |
| 33 /** | 32 /** |
| 34 * Returns a stable id for the account associated with the given email addre
ss. | 33 * Returns a stable id for the account associated with the given email addre
ss. |
| 35 * If an account with the given email address is not installed on the device | 34 * If an account with the given email address is not installed on the device |
| 36 * then null is returned. | 35 * then null is returned. |
| 37 * | 36 * |
| 38 * This method will throw IllegalStateException if called on the main thread
. | 37 * This method will throw IllegalStateException if called on the main thread
. |
| 39 * | 38 * |
| 40 * @param accountName The email address of a Google account. | 39 * @param accountName The email address of a Google account. |
| 41 */ | 40 */ |
| 42 public String getAccountId(Context ctx, String accountName) { | 41 public String getAccountId(String accountName) { |
| 43 try { | 42 try { |
| 44 return GoogleAuthUtil.getAccountId(ctx, accountName); | 43 return GoogleAuthUtil.getAccountId(ContextUtils.getApplicationContex
t(), accountName); |
| 45 } catch (IOException | GoogleAuthException ex) { | 44 } catch (IOException | GoogleAuthException ex) { |
| 46 Log.e("cr.AccountIdProvider", "AccountIdProvider.getAccountId", ex); | 45 Log.e("cr.AccountIdProvider", "AccountIdProvider.getAccountId", ex); |
| 47 return null; | 46 return null; |
| 48 } | 47 } |
| 49 } | 48 } |
| 50 | 49 |
| 51 /** | 50 /** |
| 52 * Returns whether the AccountIdProvider can be used. | 51 * Returns whether the AccountIdProvider can be used. |
| 53 * Since the AccountIdProvider queries Google Play services, this basically
checks whether | 52 * Since the AccountIdProvider queries Google Play services, this basically
checks whether |
| 54 * Google Play services is available. | 53 * Google Play services is available. |
| 55 */ | 54 */ |
| 56 public boolean canBeUsed(Context ctx) { | 55 public boolean canBeUsed() { |
| 57 return ExternalAuthUtils.getInstance().canUseGooglePlayServices( | 56 return ExternalAuthUtils.getInstance().canUseGooglePlayServices( |
| 58 ctx, new UserRecoverableErrorHandler.Silent()); | 57 ContextUtils.getApplicationContext(), new UserRecoverableErrorHa
ndler.Silent()); |
| 59 } | 58 } |
| 60 | 59 |
| 61 /** | 60 /** |
| 62 * Gets the global account Id provider. | 61 * Gets the global account Id provider. |
| 63 */ | 62 */ |
| 64 public static AccountIdProvider getInstance() { | 63 public static AccountIdProvider getInstance() { |
| 65 ThreadUtils.assertOnUiThread(); | 64 ThreadUtils.assertOnUiThread(); |
| 66 if (sProvider == null) sProvider = new AccountIdProvider(); | 65 if (sProvider == null) sProvider = new AccountIdProvider(); |
| 67 return sProvider; | 66 return sProvider; |
| 68 } | 67 } |
| 69 | 68 |
| 70 /** | 69 /** |
| 71 * For testing purposes only, allows to set the provider even if it has alre
ady been | 70 * For testing purposes only, allows to set the provider even if it has alre
ady been |
| 72 * initialized. | 71 * initialized. |
| 73 */ | 72 */ |
| 74 @VisibleForTesting | 73 @VisibleForTesting |
| 75 public static void setInstanceForTest(AccountIdProvider provider) { | 74 public static void setInstanceForTest(AccountIdProvider provider) { |
| 76 ThreadUtils.assertOnUiThread(); | 75 ThreadUtils.assertOnUiThread(); |
| 77 sProvider = provider; | 76 sProvider = provider; |
| 78 } | 77 } |
| 79 } | 78 } |
| 80 | 79 |
| OLD | NEW |