From 707d212b01c53966e9a8401764c8c668ac870171 Mon Sep 17 00:00:00 2001 From: Alice Wang Date: Wed, 10 Mar 2021 14:34:35 +0000 Subject: [PATCH] [Android] Use native account info source in FRE and record fetch time This CL replaces the GmsProfileDataSource usage in FRE |Turn on Sync?| screen with the native account info source and records the account info fetch time. Bug: 1181226 Change-Id: I743f39cb58016389537d148e6e10e86086efb6e3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2734654 Reviewed-by: Alex Ilin Reviewed-by: Boris Sazonov Commit-Queue: Alice Wang Cr-Commit-Position: refs/heads/master@{#861561} --- .../browser/signin/SigninFragmentBase.java | 7 +++++++ .../signin/identitymanager/IdentityManager.java | 17 +++++++++++++++++ .../histograms_xml/signin/histograms.xml | 11 +++++++++++ 3 files changed, 35 insertions(+) diff --git a/chrome/android/java/src/org/chromium/chrome/browser/signin/SigninFragmentBase.java b/chrome/android/java/src/org/chromium/chrome/browser/signin/SigninFragmentBase.java index f0910660587eb5..b71f6af6ab9310 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/signin/SigninFragmentBase.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/signin/SigninFragmentBase.java @@ -31,6 +31,7 @@ import org.chromium.base.task.AsyncTask; import org.chromium.chrome.R; import org.chromium.chrome.browser.consent_auditor.ConsentAuditorFeature; +import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.preferences.Pref; import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.signin.services.DisplayableProfileData; @@ -242,6 +243,12 @@ public void onCreate(@Nullable Bundle savedInstanceState) { ? ProfileDataCache.createWithDefaultImageSize( requireContext(), R.drawable.ic_account_child_20dp) : ProfileDataCache.createWithDefaultImageSizeAndNoBadge(requireContext()); + + if (ChromeFeatureList.isEnabled(ChromeFeatureList.DEPRECATE_MENAGERIE_API) + && mSigninAccessPoint == SigninAccessPoint.START_PAGE) { + mProfileDataCache.disableGmsProfileDataSource(); + } + // By default this is set to true so that when system back button is pressed user action // is recorded in onDestroy(). mRecordUndoSignin = true; diff --git a/components/signin/public/android/java/src/org/chromium/components/signin/identitymanager/IdentityManager.java b/components/signin/public/android/java/src/org/chromium/components/signin/identitymanager/IdentityManager.java index 058488e0872000..7d0386c38b2491 100644 --- a/components/signin/public/android/java/src/org/chromium/components/signin/identitymanager/IdentityManager.java +++ b/components/signin/public/android/java/src/org/chromium/components/signin/identitymanager/IdentityManager.java @@ -5,6 +5,7 @@ package org.chromium.components.signin.identitymanager; import android.accounts.Account; +import android.os.SystemClock; import androidx.annotation.MainThread; import androidx.annotation.Nullable; @@ -13,10 +14,14 @@ import org.chromium.base.ObserverList; import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.NativeMethods; +import org.chromium.base.metrics.RecordHistogram; import org.chromium.components.signin.base.AccountInfo; import org.chromium.components.signin.base.CoreAccountId; import org.chromium.components.signin.base.CoreAccountInfo; +import java.util.HashMap; +import java.util.Map; + /** * IdentityManager provides access to native IdentityManager's public API to java components. */ @@ -56,6 +61,9 @@ public interface GetAccessTokenCallback private ProfileOAuth2TokenServiceDelegate mProfileOAuth2TokenServiceDelegate; private final ObserverList mObservers = new ObserverList<>(); + // Account id and the corresponding fetch start time, this is only used to record the + // account information fetch duration. + private final Map mAccountAndFetchStartTimes = new HashMap<>(); /** * Called by native to create an instance of IdentityManager. @@ -122,6 +130,14 @@ public void onAccountsCookieDeletedByUserAction() { @CalledByNative @VisibleForTesting public void onExtendedAccountInfoUpdated(AccountInfo accountInfo) { + final CoreAccountId accountId = accountInfo.getId(); + if (accountInfo.getAccountImage() != null + && mAccountAndFetchStartTimes.containsKey(accountId)) { + long startTime = mAccountAndFetchStartTimes.get(accountId); + RecordHistogram.recordTimesHistogram("Signin.AndroidAccountInfoFetchTime", + SystemClock.elapsedRealtime() - startTime); + mAccountAndFetchStartTimes.remove(accountId); + } for (Observer observer : mObservers) { observer.onExtendedAccountInfoUpdated(accountInfo); } @@ -174,6 +190,7 @@ public CoreAccountInfo[] getAccountsWithRefreshTokens() { */ public void forceRefreshOfExtendedAccountInfo(CoreAccountId coreAccountId) { assert coreAccountId != null : "coreAccountId shouldn't be null!"; + mAccountAndFetchStartTimes.put(coreAccountId, SystemClock.elapsedRealtime()); IdentityManagerJni.get().forceRefreshOfExtendedAccountInfo( mNativeIdentityManager, coreAccountId); } diff --git a/tools/metrics/histograms/histograms_xml/signin/histograms.xml b/tools/metrics/histograms/histograms_xml/signin/histograms.xml index 4bdc7b273f6df9..fe679aa9774da0 100644 --- a/tools/metrics/histograms/histograms_xml/signin/histograms.xml +++ b/tools/metrics/histograms/histograms_xml/signin/histograms.xml @@ -126,6 +126,17 @@ prefs when the profile is loaded. --> + + aliceywang@chromium.org + chrome-signin-team@google.com + + The time it takes to fetch the account information (user names, avatar) for + one account on Android. This is recorded when account information is + downloaded in FRE or when there is an accounts change event. + + + bsazonov@chromium.org