| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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.sync.signin; | 5 package org.chromium.components.sync.signin; |
| 6 | |
| 7 | 6 |
| 8 import android.Manifest; | 7 import android.Manifest; |
| 9 import android.accounts.Account; | 8 import android.accounts.Account; |
| 10 import android.accounts.AuthenticatorDescription; | 9 import android.accounts.AuthenticatorDescription; |
| 11 import android.content.Context; | 10 import android.content.Context; |
| 12 import android.content.pm.PackageManager; | 11 import android.content.pm.PackageManager; |
| 13 import android.os.AsyncTask; | 12 import android.os.AsyncTask; |
| 14 import android.os.Process; | 13 import android.os.Process; |
| 15 | 14 |
| 16 import org.chromium.base.Callback; | 15 import org.chromium.base.Callback; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 38 private static final String GMAIL_COM = "gmail.com"; | 37 private static final String GMAIL_COM = "gmail.com"; |
| 39 | 38 |
| 40 private static final String GOOGLEMAIL_COM = "googlemail.com"; | 39 private static final String GOOGLEMAIL_COM = "googlemail.com"; |
| 41 | 40 |
| 42 public static final String GOOGLE_ACCOUNT_TYPE = "com.google"; | 41 public static final String GOOGLE_ACCOUNT_TYPE = "com.google"; |
| 43 | 42 |
| 44 /** | 43 /** |
| 45 * An account feature (corresponding to a Gaia service flag) that specifies
whether the account | 44 * An account feature (corresponding to a Gaia service flag) that specifies
whether the account |
| 46 * is a child account. | 45 * is a child account. |
| 47 */ | 46 */ |
| 48 @VisibleForTesting public static final String FEATURE_IS_CHILD_ACCOUNT_KEY =
"service_uca"; | 47 @VisibleForTesting |
| 48 public static final String FEATURE_IS_CHILD_ACCOUNT_KEY = "service_uca"; |
| 49 | 49 |
| 50 private static final Object sLock = new Object(); | 50 private static final Object sLock = new Object(); |
| 51 | 51 |
| 52 private static AccountManagerHelper sAccountManagerHelper; | 52 private static AccountManagerHelper sAccountManagerHelper; |
| 53 | 53 |
| 54 private final AccountManagerDelegate mAccountManager; | 54 private final AccountManagerDelegate mAccountManager; |
| 55 | 55 |
| 56 private Context mApplicationContext; | 56 private Context mApplicationContext; |
| 57 | 57 |
| 58 /** | 58 /** |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 callback.tokenAvailable(token); | 308 callback.tokenAvailable(token); |
| 309 } | 309 } |
| 310 @Override | 310 @Override |
| 311 public void onFailure(boolean isTransientError) { | 311 public void onFailure(boolean isTransientError) { |
| 312 callback.tokenUnavailable(isTransientError); | 312 callback.tokenUnavailable(isTransientError); |
| 313 } | 313 } |
| 314 }); | 314 }); |
| 315 } | 315 } |
| 316 | 316 |
| 317 public boolean hasGetAccountsPermission() { | 317 public boolean hasGetAccountsPermission() { |
| 318 return mApplicationContext.checkPermission(Manifest.permission.GET_ACCOU
NTS, | 318 return mApplicationContext.checkPermission( |
| 319 Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_G
RANTED; | 319 Manifest.permission.GET_ACCOUNTS, Process.myPid(), Proces
s.myUid()) |
| 320 == PackageManager.PERMISSION_GRANTED; |
| 320 } | 321 } |
| 321 | 322 |
| 322 /** | 323 /** |
| 323 * Invalidates the old token (if non-null/non-empty) and asynchronously gene
rates a new one. | 324 * Invalidates the old token (if non-null/non-empty) and asynchronously gene
rates a new one. |
| 324 * | 325 * |
| 325 * - Assumes that the account is a valid account. | 326 * - Assumes that the account is a valid account. |
| 326 */ | 327 */ |
| 327 public void getNewAuthToken(Account account, String authToken, String authTo
kenType, | 328 public void getNewAuthToken(Account account, String authToken, String authTo
kenType, |
| 328 GetAuthTokenCallback callback) { | 329 GetAuthTokenCallback callback) { |
| 329 invalidateAuthToken(authToken); | 330 invalidateAuthToken(authToken); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 } catch (AuthException ex) { | 403 } catch (AuthException ex) { |
| 403 Log.w(TAG, "Failed to perform auth task", ex); | 404 Log.w(TAG, "Failed to perform auth task", ex); |
| 404 mIsTransientError.set(ex.isTransientError()); | 405 mIsTransientError.set(ex.isTransientError()); |
| 405 } | 406 } |
| 406 return null; | 407 return null; |
| 407 } | 408 } |
| 408 @Override | 409 @Override |
| 409 public void onPostExecute(T result) { | 410 public void onPostExecute(T result) { |
| 410 if (result != null) { | 411 if (result != null) { |
| 411 mAuthTask.onSuccess(result); | 412 mAuthTask.onSuccess(result); |
| 412 } else if (!mIsTransientError.get() | 413 } else if (!mIsTransientError.get() || mNumTries.incrementAn
dGet() >= MAX_TRIES |
| 413 || mNumTries.incrementAndGet() >= MAX_TRIES | |
| 414 || !NetworkChangeNotifier.isInitialized()) { | 414 || !NetworkChangeNotifier.isInitialized()) { |
| 415 // Permanent error, ran out of tries, or we can't listen
for network | 415 // Permanent error, ran out of tries, or we can't listen
for network |
| 416 // change events; give up. | 416 // change events; give up. |
| 417 mAuthTask.onFailure(mIsTransientError.get()); | 417 mAuthTask.onFailure(mIsTransientError.get()); |
| 418 } else { | 418 } else { |
| 419 // Transient error with tries left; register for another
attempt. | 419 // Transient error with tries left; register for another
attempt. |
| 420 NetworkChangeNotifier.addConnectionTypeObserver(Connecti
onRetry.this); | 420 NetworkChangeNotifier.addConnectionTypeObserver(Connecti
onRetry.this); |
| 421 } | 421 } |
| 422 } | 422 } |
| 423 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | 423 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| 424 } | 424 } |
| 425 | 425 |
| 426 @Override | 426 @Override |
| 427 public void onConnectionTypeChanged(int connectionType) { | 427 public void onConnectionTypeChanged(int connectionType) { |
| 428 assert mNumTries.get() < MAX_TRIES; | 428 assert mNumTries.get() < MAX_TRIES; |
| 429 if (NetworkChangeNotifier.isOnline()) { | 429 if (NetworkChangeNotifier.isOnline()) { |
| 430 // The network is back; stop listening and try again. | 430 // The network is back; stop listening and try again. |
| 431 NetworkChangeNotifier.removeConnectionTypeObserver(this); | 431 NetworkChangeNotifier.removeConnectionTypeObserver(this); |
| 432 attempt(); | 432 attempt(); |
| 433 } | 433 } |
| 434 } | 434 } |
| 435 } | 435 } |
| 436 } | 436 } |
| OLD | NEW |