1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.chrome.testshell.signin;
7 import android.accounts.Account;
8 import android.accounts.AccountManager;
9 import android.content.BroadcastReceiver;
10 import android.content.Context;
11 import android.content.Intent;
12 import android.util.Log;
14 import org.chromium.base.ThreadUtils;
15 import org.chromium.chrome.browser.profiles.Profile;
16 import org.chromium.chrome.browser.signin.OAuth2TokenService;
17 import org.chromium.content.browser.BrowserStartupController;
18 import org.chromium.sync.signin.ChromeSigninController;
21 * A BroadcastReceiver for acting on changes to Android accounts.
23 public class AccountsChangedReceiver extends BroadcastReceiver {
24 private static final String TAG = "AccountsChangedReceiver";
27 public void onReceive(final Context context, Intent intent) {
28 if (AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION.equals(intent.getAction())) {
29 final Account signedInUser =
30 ChromeSigninController.get(context).getSignedInUser();
31 if (signedInUser != null) {
32 BrowserStartupController.StartupCallback callback =
33 new BrowserStartupController.StartupCallback() {
35 public void onSuccess(boolean alreadyStarted) {
36 OAuth2TokenService.getForProfile(Profile.getLastUsedProfile())
37 .validateAccounts(context);
41 public void onFailure() {
42 Log.w(TAG, "Failed to start browser process.");
45 startBrowserProcessOnUiThread(context, callback);
50 private static void startBrowserProcessOnUiThread(final Context context,
51 final BrowserStartupController.StartupCallback callback) {
52 ThreadUtils.runOnUiThread(new Runnable() {
55 BrowserStartupController.get(context).startBrowserProcessesAsync(callback);