diff options
-rw-r--r-- | chrome/android/java/src/org/chromium/chrome/browser/ChromeApplication.java | 16 | ||||
-rw-r--r-- | sync/android/java/src/org/chromium/sync/signin/AccountManagerHelper.java | 24 |
2 files changed, 36 insertions, 4 deletions
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromeApplication.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeApplication.java index 3eff68e..194bf1e 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/ChromeApplication.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeApplication.java @@ -93,6 +93,9 @@ import org.chromium.content.browser.ChildProcessLauncher; import org.chromium.content.browser.ContentViewStatics; import org.chromium.content.browser.DownloadController; import org.chromium.printing.PrintingController; +import org.chromium.sync.signin.AccountManagerDelegate; +import org.chromium.sync.signin.AccountManagerHelper; +import org.chromium.sync.signin.SystemAccountManagerDelegate; import org.chromium.ui.UiUtils; import org.chromium.ui.base.ActivityWindowAndroid; import org.chromium.ui.base.ResourceBundle; @@ -206,6 +209,11 @@ public class ChromeApplication extends ContentApplication { } }); + // Set the default AccountManagerDelegate to ensure it is always used when the instance + // of the AccountManagerHelper is created. Must be done before AccountMangerHelper.get(...) + // is called. + AccountManagerHelper.setDefaultAccountManagerDelegate(createAccountManagerDelegate()); + // Set the unique identification generator for invalidations. The // invalidations system can start and attempt to fetch the client ID // very early. We need this generator to be ready before that happens. @@ -784,6 +792,14 @@ public class ChromeApplication extends ContentApplication { } /** + * Creates a new {@link AccountManagerDelegate}. + * @return the created {@link AccountManagerDelegate}. + */ + public AccountManagerDelegate createAccountManagerDelegate() { + return new SystemAccountManagerDelegate(this); + } + + /** * Update the font size after changing the Android accessibility system setting. Doing so kills * the Activities but it doesn't kill the ChromeApplication, so this should be called in * {@link #onStart} instead of {@link #initialize}. diff --git a/sync/android/java/src/org/chromium/sync/signin/AccountManagerHelper.java b/sync/android/java/src/org/chromium/sync/signin/AccountManagerHelper.java index 79e7b5e..7f08ed3 100644 --- a/sync/android/java/src/org/chromium/sync/signin/AccountManagerHelper.java +++ b/sync/android/java/src/org/chromium/sync/signin/AccountManagerHelper.java @@ -63,6 +63,8 @@ public class AccountManagerHelper { private static final int MAX_TRIES = 3; + private static AccountManagerDelegate sDefaultAccountManagerDelegate; + private static AccountManagerHelper sAccountManagerHelper; private final AccountManagerDelegate mAccountManager; @@ -70,6 +72,16 @@ public class AccountManagerHelper { private Context mApplicationContext; /** + * Provides functionality to set the default {@link AccountManagerDelegate} to be used when + * the AccountManagerHelper is created. This may be set during application startup to ensure + * all callers get the correct implementation. + * @param delegate the default AccountManagerDelegate to use when constructing the instance. + */ + public static void setDefaultAccountManagerDelegate(AccountManagerDelegate delegate) { + sDefaultAccountManagerDelegate = delegate; + } + + /** * A simple callback for getAuthToken. */ public interface GetAuthTokenCallback { @@ -85,8 +97,7 @@ public class AccountManagerHelper { * @param context the Android context * @param accountManager the account manager to use as a backend service */ - private AccountManagerHelper(Context context, - AccountManagerDelegate accountManager) { + private AccountManagerHelper(Context context, AccountManagerDelegate accountManager) { mApplicationContext = context.getApplicationContext(); mAccountManager = accountManager; } @@ -104,8 +115,13 @@ public class AccountManagerHelper { public static AccountManagerHelper get(Context context) { synchronized (sLock) { if (sAccountManagerHelper == null) { - sAccountManagerHelper = new AccountManagerHelper(context, - new SystemAccountManagerDelegate(context)); + if (sDefaultAccountManagerDelegate == null) { + sAccountManagerHelper = new AccountManagerHelper(context, + new SystemAccountManagerDelegate(context)); + } else { + sAccountManagerHelper = new AccountManagerHelper(context, + sDefaultAccountManagerDelegate); + } } } return sAccountManagerHelper; |