Commit 3e53a395 authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Android][Signin] Move key used to store email to ChromeBackupAgent

Even though ChromeBackupAgent no longer gets the sign-in account from
ChromeSigninController, it still uses
ChromeSigninController.SIGNED_IN_ACCOUNT_KEY as the key to store the
email of the signed in account. This CL moves this key to
ChromeBackupAgent. The value of the key is preserved for backward
compatibility.

Bug: 1046412
Change-Id: I4c49a406f474348471de2f27c67c6e4ac2c523f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2339457Reviewed-by: default avatarAlice Wang <aliceywang@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797324}
parent f4ca4974
......@@ -29,7 +29,6 @@ import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.IdentityServicesProvider;
import org.chromium.components.signin.AccountManagerFacadeProvider;
import org.chromium.components.signin.AccountUtils;
import org.chromium.components.signin.ChromeSigninController;
import org.chromium.components.signin.base.CoreAccountInfo;
import org.chromium.components.signin.identitymanager.ConsentLevel;
import org.chromium.content_public.browser.UiThreadTaskTraits;
......@@ -99,6 +98,10 @@ public class ChromeBackupAgent extends BackupAgent {
ChromePreferenceKeys.PRIVACY_METRICS_REPORTING,
};
// Key used to store the email of the signed in account. This email is obtained from
// IdentityManager during the backup.
static final String SIGNED_IN_ACCOUNT_KEY = "google.services.username";
// Timeout for running the background tasks, needs to be quite long since they may be doing
// network access, but must be less than the 1 minute restore timeout to be useful.
private static final long BACKGROUND_TASK_TIMEOUT_SECS = 20;
......@@ -245,8 +248,7 @@ public class ChromeBackupAgent extends BackupAgent {
IdentityServicesProvider.get()
.getIdentityManager(Profile.getLastUsedRegularProfile())
.getPrimaryAccountInfo(ConsentLevel.SYNC);
// TODO(https://crbug.com/1046412): Inline SIGNED_IN_ACCOUNT_KEY in this class.
backupNames.add(ANDROID_DEFAULT_PREFIX + ChromeSigninController.SIGNED_IN_ACCOUNT_KEY);
backupNames.add(ANDROID_DEFAULT_PREFIX + SIGNED_IN_ACCOUNT_KEY);
backupValues.add(ApiCompatibilityUtils.getBytesUtf8(
accountInfo == null ? "" : accountInfo.getEmail()));
......@@ -303,7 +305,7 @@ public class ChromeBackupAgent extends BackupAgent {
int dataSize = data.getDataSize();
byte[] buffer = new byte[dataSize];
data.readEntityData(buffer, 0, dataSize);
if (key.equals(ANDROID_DEFAULT_PREFIX + ChromeSigninController.SIGNED_IN_ACCOUNT_KEY)) {
if (key.equals(ANDROID_DEFAULT_PREFIX + SIGNED_IN_ACCOUNT_KEY)) {
restoredUserName = new String(buffer);
} else {
backupNames.add(key);
......
......@@ -50,7 +50,6 @@ import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.IdentityServicesProvider;
import org.chromium.components.signin.ChromeSigninController;
import org.chromium.components.signin.base.CoreAccountId;
import org.chromium.components.signin.base.CoreAccountInfo;
import org.chromium.components.signin.identitymanager.ConsentLevel;
......@@ -185,7 +184,7 @@ public class ChromeBackupAgentTest {
verify(backupData).writeEntityData(new byte[] {0}, 1);
byte[] unameBytes = ApiCompatibilityUtils.getBytesUtf8(mAccountInfo.getEmail());
verify(backupData)
.writeEntityHeader("AndroidDefault." + ChromeSigninController.SIGNED_IN_ACCOUNT_KEY,
.writeEntityHeader("AndroidDefault." + ChromeBackupAgent.SIGNED_IN_ACCOUNT_KEY,
unameBytes.length);
verify(backupData).writeEntityData(unameBytes, unameBytes.length);
......@@ -200,8 +199,7 @@ public class ChromeBackupAgentTest {
names, hasItem("AndroidDefault." + ChromePreferenceKeys.FIRST_RUN_FLOW_COMPLETE));
assertThat(names,
hasItem("AndroidDefault." + ChromePreferenceKeys.FIRST_RUN_FLOW_SIGNIN_SETUP));
assertThat(
names, hasItem("AndroidDefault." + ChromeSigninController.SIGNED_IN_ACCOUNT_KEY));
assertThat(names, hasItem("AndroidDefault." + ChromeBackupAgent.SIGNED_IN_ACCOUNT_KEY));
ArrayList<byte[]> values = (ArrayList<byte[]>) newStateStream.readObject();
assertThat(values.size(), equalTo(4));
assertThat(values, hasItem(unameBytes));
......@@ -385,8 +383,7 @@ public class ChromeBackupAgentTest {
final String[] keys = {"native.pref1", "native.pref2",
"AndroidDefault." + ChromePreferenceKeys.FIRST_RUN_FLOW_COMPLETE,
"AndroidDefault.junk",
"AndroidDefault." + ChromeSigninController.SIGNED_IN_ACCOUNT_KEY};
"AndroidDefault.junk", "AndroidDefault." + ChromeBackupAgent.SIGNED_IN_ACCOUNT_KEY};
byte[] unameBytes = ApiCompatibilityUtils.getBytesUtf8(mAccountInfo.getEmail());
final byte[][] values = {{0}, {1}, {1}, {23, 42}, unameBytes};
when(backupData.getKey()).thenAnswer(new Answer<String>() {
......
......@@ -14,8 +14,7 @@ import org.chromium.base.ContextUtils;
public class ChromeSigninController {
public static final String TAG = "ChromeSigninController";
// Used by ChromeBackupAgent and for testing.
public static final String SIGNED_IN_ACCOUNT_KEY = "google.services.username";
private static final String SIGNED_IN_ACCOUNT_KEY = "google.services.username";
private static final Object LOCK = new Object();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment