Commit d9c8c6df authored by Alice Wang's avatar Alice Wang Committed by Commit Bot

[Android][Signin] Fix threading bug for ChromeBackupAgent

This CL fixes the threading bug for ChromeBackupAgent.

Bug: 1121344
Change-Id: I1fb2e1935ac602db70a660dc468bf89016f0873f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2391142
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804871}
parent d61316b3
...@@ -45,6 +45,7 @@ import java.util.ArrayList; ...@@ -45,6 +45,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
/** /**
* Backup agent for Chrome, using Android key/value backup. * Backup agent for Chrome, using Android key/value backup.
...@@ -184,6 +185,7 @@ public class ChromeBackupAgent extends BackupAgent { ...@@ -184,6 +185,7 @@ public class ChromeBackupAgent extends BackupAgent {
ParcelFileDescriptor newState) throws IOException { ParcelFileDescriptor newState) throws IOException {
final ArrayList<String> backupNames = new ArrayList<>(); final ArrayList<String> backupNames = new ArrayList<>();
final ArrayList<byte[]> backupValues = new ArrayList<>(); final ArrayList<byte[]> backupValues = new ArrayList<>();
final AtomicReference<CoreAccountInfo> syncAccount = new AtomicReference<>();
// The native preferences can only be read on the UI thread. // The native preferences can only be read on the UI thread.
Boolean nativePrefsRead = PostTask.runSynchronously(UiThreadTaskTraits.DEFAULT, () -> { Boolean nativePrefsRead = PostTask.runSynchronously(UiThreadTaskTraits.DEFAULT, () -> {
...@@ -192,6 +194,10 @@ public class ChromeBackupAgent extends BackupAgent { ...@@ -192,6 +194,10 @@ public class ChromeBackupAgent extends BackupAgent {
// immediately, so by the time it does Chrome may not be running. // immediately, so by the time it does Chrome may not be running.
if (!initializeBrowser()) return false; if (!initializeBrowser()) return false;
syncAccount.set(IdentityServicesProvider.get()
.getIdentityManager(Profile.getLastUsedRegularProfile())
.getPrimaryAccountInfo(ConsentLevel.SYNC));
String[] nativeBackupNames = ChromeBackupAgentJni.get().getBoolBackupNames(this); String[] nativeBackupNames = ChromeBackupAgentJni.get().getBoolBackupNames(this);
boolean[] nativeBackupValues = ChromeBackupAgentJni.get().getBoolBackupValues(this); boolean[] nativeBackupValues = ChromeBackupAgentJni.get().getBoolBackupValues(this);
assert nativeBackupNames.length == nativeBackupValues.length; assert nativeBackupNames.length == nativeBackupValues.length;
...@@ -244,13 +250,9 @@ public class ChromeBackupAgent extends BackupAgent { ...@@ -244,13 +250,9 @@ public class ChromeBackupAgent extends BackupAgent {
} }
// Finally add the user id. // Finally add the user id.
CoreAccountInfo accountInfo =
IdentityServicesProvider.get()
.getIdentityManager(Profile.getLastUsedRegularProfile())
.getPrimaryAccountInfo(ConsentLevel.SYNC);
backupNames.add(ANDROID_DEFAULT_PREFIX + SIGNED_IN_ACCOUNT_KEY); backupNames.add(ANDROID_DEFAULT_PREFIX + SIGNED_IN_ACCOUNT_KEY);
backupValues.add(ApiCompatibilityUtils.getBytesUtf8( backupValues.add(ApiCompatibilityUtils.getBytesUtf8(
accountInfo == null ? "" : accountInfo.getEmail())); syncAccount.get() == null ? "" : syncAccount.get().getEmail()));
BackupState newBackupState = new BackupState(backupNames, backupValues); BackupState newBackupState = new BackupState(backupNames, backupValues);
......
...@@ -47,7 +47,7 @@ public class Profile implements BrowserContextHandle { ...@@ -47,7 +47,7 @@ public class Profile implements BrowserContextHandle {
if (sLastUsedProfileForTesting != null) { if (sLastUsedProfileForTesting != null) {
return sLastUsedProfileForTesting; return sLastUsedProfileForTesting;
} }
assert ThreadUtils.runningOnUiThread(); ThreadUtils.assertOnUiThread();
// TODO(crbug.com/704025): turn this into an assert once the bug is fixed // TODO(crbug.com/704025): turn this into an assert once the bug is fixed
if (!ProfileManager.isInitialized()) { if (!ProfileManager.isInitialized()) {
throw new IllegalStateException("Browser hasn't finished initialization yet!"); throw new IllegalStateException("Browser hasn't finished initialization yet!");
......
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