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

Side by Side Diff: components/sync/android/java/src/org/chromium/components/sync/signin/SystemAccountManagerDelegate.java

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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 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.components.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;
(...skipping 12 matching lines...) Expand all
28 28
29 import java.io.IOException; 29 import java.io.IOException;
30 import java.util.concurrent.TimeUnit; 30 import java.util.concurrent.TimeUnit;
31 31
32 /** 32 /**
33 * Default implementation of {@link AccountManagerDelegate} which delegates all calls to the 33 * Default implementation of {@link AccountManagerDelegate} which delegates all calls to the
34 * Android account manager. 34 * Android account manager.
35 */ 35 */
36 @MainDex 36 @MainDex
37 public class SystemAccountManagerDelegate implements AccountManagerDelegate { 37 public class SystemAccountManagerDelegate implements AccountManagerDelegate {
38
39 private final AccountManager mAccountManager; 38 private final AccountManager mAccountManager;
40 private final Context mApplicationContext; 39 private final Context mApplicationContext;
41 private static final String TAG = "Auth"; 40 private static final String TAG = "Auth";
42 41
43 public SystemAccountManagerDelegate(Context context) { 42 public SystemAccountManagerDelegate(Context context) {
44 mApplicationContext = context.getApplicationContext(); 43 mApplicationContext = context.getApplicationContext();
45 mAccountManager = AccountManager.get(context.getApplicationContext()); 44 mAccountManager = AccountManager.get(context.getApplicationContext());
46 } 45 }
47 46
48 @Override 47 @Override
49 public Account[] getAccountsByType(String type) { 48 public Account[] getAccountsByType(String type) {
50 if (!AccountManagerHelper.get(mApplicationContext).hasGetAccountsPermiss ion()) { 49 if (!AccountManagerHelper.get(mApplicationContext).hasGetAccountsPermiss ion()) {
51 return new Account[]{}; 50 return new Account[] {};
52 } 51 }
53 long now = SystemClock.elapsedRealtime(); 52 long now = SystemClock.elapsedRealtime();
54 Account[] accounts = mAccountManager.getAccountsByType(type); 53 Account[] accounts = mAccountManager.getAccountsByType(type);
55 long elapsed = SystemClock.elapsedRealtime() - now; 54 long elapsed = SystemClock.elapsedRealtime() - now;
56 recordElapsedTimeHistogram("Signin.AndroidGetAccountsTime_AccountManager ", elapsed); 55 recordElapsedTimeHistogram("Signin.AndroidGetAccountsTime_AccountManager ", elapsed);
57 return accounts; 56 return accounts;
58 } 57 }
59 58
60 @Override 59 @Override
61 public void getAccountsByType(final String type, final Callback<Account[]> c allback) { 60 public void getAccountsByType(final String type, final Callback<Account[]> c allback) {
62 new AsyncTask<Void, Void, Account[]>() { 61 new AsyncTask<Void, Void, Account[]>() {
63 @Override 62 @Override
64 protected Account[] doInBackground(Void... params) { 63 protected Account[] doInBackground(Void... params) {
65 return getAccountsByType(type); 64 return getAccountsByType(type);
66 } 65 }
67 66
68 @Override 67 @Override
69 protected void onPostExecute(Account[] accounts) { 68 protected void onPostExecute(Account[] accounts) {
70 callback.onResult(accounts); 69 callback.onResult(accounts);
71 } 70 }
72 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); 71 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
73 } 72 }
74 73
75 @Override 74 @Override
76 public String getAuthToken(Account account, String authTokenScope) throws Au thException { 75 public String getAuthToken(Account account, String authTokenScope) throws Au thException {
77 assert !ThreadUtils.runningOnUiThread(); 76 assert !ThreadUtils.runningOnUiThread();
78 assert AccountManagerHelper.GOOGLE_ACCOUNT_TYPE.equals(account.type); 77 assert AccountManagerHelper.GOOGLE_ACCOUNT_TYPE.equals(account.type);
79 try { 78 try {
80 return GoogleAuthUtil.getTokenWithNotification(mApplicationContext, account, 79 return GoogleAuthUtil.getTokenWithNotification(
81 authTokenScope, null); 80 mApplicationContext, account, authTokenScope, null);
82 } catch (GoogleAuthException ex) { 81 } catch (GoogleAuthException ex) {
83 // This case includes a UserRecoverableNotifiedException, but most c lients will have 82 // This case includes a UserRecoverableNotifiedException, but most c lients will have
84 // their own retry mechanism anyway. 83 // their own retry mechanism anyway.
85 // TODO(bauerb): Investigate integrating the callback with Connectio nRetry. 84 // TODO(bauerb): Investigate integrating the callback with Connectio nRetry.
86 throw new AuthException(false /* isTransientError */, ex); 85 throw new AuthException(false /* isTransientError */, ex);
87 } catch (IOException ex) { 86 } catch (IOException ex) {
88 throw new AuthException(true /* isTransientError */, ex); 87 throw new AuthException(true /* isTransientError */, ex);
89 } 88 }
90 } 89 }
91 90
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 * process has been initialized. 140 * process has been initialized.
142 * 141 *
143 * @param histogramName the name of the histogram. 142 * @param histogramName the name of the histogram.
144 * @param elapsedMs the elapsed time in milliseconds. 143 * @param elapsedMs the elapsed time in milliseconds.
145 */ 144 */
146 protected static void recordElapsedTimeHistogram(String histogramName, long elapsedMs) { 145 protected static void recordElapsedTimeHistogram(String histogramName, long elapsedMs) {
147 if (!LibraryLoader.isInitialized()) return; 146 if (!LibraryLoader.isInitialized()) return;
148 RecordHistogram.recordTimesHistogram(histogramName, elapsedMs, TimeUnit. MILLISECONDS); 147 RecordHistogram.recordTimesHistogram(histogramName, elapsedMs, TimeUnit. MILLISECONDS);
149 } 148 }
150 } 149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698