| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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.sync.signin; |
| 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; |
| 11 import android.accounts.AuthenticatorDescription; | 11 import android.accounts.AuthenticatorDescription; |
| 12 import android.accounts.AuthenticatorException; | 12 import android.accounts.AuthenticatorException; |
| 13 import android.accounts.OperationCanceledException; | 13 import android.accounts.OperationCanceledException; |
| 14 import android.content.Context; | 14 import android.content.Context; |
| 15 import android.os.AsyncTask; | 15 import android.os.AsyncTask; |
| 16 import android.os.StrictMode; | |
| 17 import android.os.SystemClock; | 16 import android.os.SystemClock; |
| 18 | 17 |
| 19 import com.google.android.gms.auth.GoogleAuthException; | 18 import com.google.android.gms.auth.GoogleAuthException; |
| 20 import com.google.android.gms.auth.GoogleAuthUtil; | 19 import com.google.android.gms.auth.GoogleAuthUtil; |
| 20 import com.google.android.gms.auth.GooglePlayServicesAvailabilityException; |
| 21 import com.google.android.gms.auth.UserRecoverableAuthException; | 21 import com.google.android.gms.auth.UserRecoverableAuthException; |
| 22 | 22 |
| 23 import org.chromium.base.Callback; | 23 import org.chromium.base.Callback; |
| 24 import org.chromium.base.Log; | 24 import org.chromium.base.Log; |
| 25 import org.chromium.base.ThreadUtils; | 25 import org.chromium.base.ThreadUtils; |
| 26 import org.chromium.base.annotations.MainDex; | 26 import org.chromium.base.annotations.MainDex; |
| 27 import org.chromium.base.library_loader.LibraryLoader; | 27 import org.chromium.base.library_loader.LibraryLoader; |
| 28 import org.chromium.base.metrics.RecordHistogram; | 28 import org.chromium.base.metrics.RecordHistogram; |
| 29 | 29 |
| 30 import java.io.IOException; | 30 import java.io.IOException; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 } catch (UserRecoverableAuthException ex) { | 82 } catch (UserRecoverableAuthException ex) { |
| 83 throw new AuthException(false /* isTransientError */, ex.getIntent()
, ex); | 83 throw new AuthException(false /* isTransientError */, ex.getIntent()
, ex); |
| 84 } catch (GoogleAuthException ex) { | 84 } catch (GoogleAuthException ex) { |
| 85 throw new AuthException(false /* isTransientError */, null, ex); | 85 throw new AuthException(false /* isTransientError */, null, ex); |
| 86 } catch (IOException ex) { | 86 } catch (IOException ex) { |
| 87 throw new AuthException(true /* isTransientError */, null, ex); | 87 throw new AuthException(true /* isTransientError */, null, ex); |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 | 90 |
| 91 @Override | 91 @Override |
| 92 public void invalidateAuthToken(String accountType, String authToken) { | 92 public void invalidateAuthToken(String authToken) throws AuthException { |
| 93 // Temporarily allowing disk access while fixing. TODO: http://crbug.com
/535320 | |
| 94 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); | |
| 95 StrictMode.allowThreadDiskReads(); | |
| 96 try { | 93 try { |
| 97 mAccountManager.invalidateAuthToken(accountType, authToken); | 94 GoogleAuthUtil.clearToken(mApplicationContext, authToken); |
| 98 } finally { | 95 } catch (GooglePlayServicesAvailabilityException ex) { |
| 99 StrictMode.setThreadPolicy(oldPolicy); | 96 throw new AuthException(false /* isTransientError */, null, ex); |
| 97 } catch (GoogleAuthException ex) { |
| 98 throw new AuthException(false /* isTransientError */, null, ex); |
| 99 } catch (IOException ex) { |
| 100 throw new AuthException(true /* isTransientError */, null, ex); |
| 100 } | 101 } |
| 101 } | 102 } |
| 102 | 103 |
| 103 @Override | 104 @Override |
| 104 public AuthenticatorDescription[] getAuthenticatorTypes() { | 105 public AuthenticatorDescription[] getAuthenticatorTypes() { |
| 105 return mAccountManager.getAuthenticatorTypes(); | 106 return mAccountManager.getAuthenticatorTypes(); |
| 106 } | 107 } |
| 107 | 108 |
| 108 @Override | 109 @Override |
| 109 public void hasFeatures(Account account, String[] features, final Callback<B
oolean> callback) { | 110 public void hasFeatures(Account account, String[] features, final Callback<B
oolean> callback) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 139 * process has been initialized. | 140 * process has been initialized. |
| 140 * | 141 * |
| 141 * @param histogramName the name of the histogram. | 142 * @param histogramName the name of the histogram. |
| 142 * @param elapsedMs the elapsed time in milliseconds. | 143 * @param elapsedMs the elapsed time in milliseconds. |
| 143 */ | 144 */ |
| 144 protected static void recordElapsedTimeHistogram(String histogramName, long
elapsedMs) { | 145 protected static void recordElapsedTimeHistogram(String histogramName, long
elapsedMs) { |
| 145 if (!LibraryLoader.isInitialized()) return; | 146 if (!LibraryLoader.isInitialized()) return; |
| 146 RecordHistogram.recordTimesHistogram(histogramName, elapsedMs, TimeUnit.
MILLISECONDS); | 147 RecordHistogram.recordTimesHistogram(histogramName, elapsedMs, TimeUnit.
MILLISECONDS); |
| 147 } | 148 } |
| 148 } | 149 } |
| OLD | NEW |