Index: chrome/android/java/src/org/chromium/chrome/browser/signin/SigninManager.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/signin/SigninManager.java b/chrome/android/java/src/org/chromium/chrome/browser/signin/SigninManager.java |
index 6f065c7d3e77c9e137247a2c81649414fcd3305f..41b7371f7c8c8bf30428397b993d8640e9806787 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/signin/SigninManager.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/signin/SigninManager.java |
@@ -24,9 +24,12 @@ import org.chromium.base.FieldTrialList; |
import org.chromium.base.ObserverList; |
import org.chromium.base.ThreadUtils; |
import org.chromium.chrome.R; |
+import org.chromium.chrome.browser.child_accounts.ChildAccountService; |
+import org.chromium.chrome.browser.firstrun.FirstRunActivity; |
import org.chromium.chrome.browser.invalidation.InvalidationController; |
import org.chromium.chrome.browser.notifications.GoogleServicesNotificationController; |
import org.chromium.chrome.browser.sync.ProfileSyncService; |
+import org.chromium.chrome.browser.sync.SyncController; |
import org.chromium.sync.AndroidSyncSettings; |
import org.chromium.sync.internal_api.pub.base.ModelType; |
import org.chromium.sync.signin.ChromeSigninController; |
@@ -47,6 +50,24 @@ public class SigninManager { |
public static final String CONFIRM_MANAGED_SIGNIN_DIALOG_TAG = |
"confirm_managed_signin_dialog_tag"; |
+ |
+ // The type of signin flow. |
+ /** Regular (interactive) signin. */ |
+ public static final int SIGNIN_TYPE_INTERACTIVE = 0; |
+ |
+ /** Forced signin for education-enrolled devices. */ |
+ public static final int SIGNIN_TYPE_FORCED_EDU = 1; |
+ |
+ /** Forced signin for child accounts. */ |
+ public static final int SIGNIN_TYPE_FORCED_CHILD_ACCOUNT = 2; |
+ |
+ // The timing of enabling the ProfileSyncService. |
+ /** Postpone sync till the set up is fully complete. */ |
+ public static final int SIGNIN_SYNC_SETUP_IN_PROGRESS = 0; |
+ |
+ /** Enable sync immediately. */ |
+ public static final int SIGNIN_SYNC_IMMEDIATELY = 1; |
+ |
private static final String CLEAR_DATA_PROGRESS_DIALOG_TAG = "clear_data_progress"; |
private static final String TAG = "SigninManager"; |
@@ -470,6 +491,58 @@ public class SigninManager { |
} |
/** |
+ * Signs in to the specified account. |
+ * The operation will be performed in the background. |
+ * |
+ * @param activity The context to use for the operation. |
+ * @param account The account to sign into. |
+ * @param signInType The type of the sign-in (one of SIGNIN_TYPE constants). |
+ * @param signInSync When to enable the ProfileSyncService (one of SIGNIN_SYNC constants). |
+ * @param showSignInNotification Whether the sign-in notification should be shown. |
+ * @param observer The observer to invoke when done, or null. |
+ */ |
+ public void signInToSelectedAccount(final Activity activity, final Account account, |
+ final int signInType, final int signInSync, final boolean showSignInNotification, |
+ final SignInFlowObserver observer) { |
+ // The SigninManager handles most of the sign-in flow, and onSigninComplete handles the |
+ // Chrome-specific details. |
+ final boolean passive = signInType != SIGNIN_TYPE_INTERACTIVE; |
+ |
+ startSignIn(activity, account, passive, new SignInFlowObserver() { |
+ @Override |
+ public void onSigninComplete() { |
+ // TODO(acleung): Maybe GoogleServicesManager should have a |
+ // sync = true but setSetupInProgress(true) state? |
+ ProfileSyncService.get(activity).setSetupInProgress( |
+ signInSync == SIGNIN_SYNC_SETUP_IN_PROGRESS); |
+ SyncController.get(activity).start(); |
+ |
+ if (observer != null) observer.onSigninComplete(); |
+ |
+ if (signInType != SIGNIN_TYPE_INTERACTIVE) { |
+ AccountManagementFragment.setSignOutAllowedPreferenceValue(activity, false); |
+ } |
+ |
+ if (signInType == SIGNIN_TYPE_FORCED_CHILD_ACCOUNT) { |
+ ChildAccountService.getInstance(activity).onChildAccountSigninComplete(); |
+ } |
+ |
+ SigninManager.get(activity).logInSignedInUser(); |
+ // If Chrome was started from an external intent we should show the sync signin |
+ // popup, since the user has not seen the welcome screen where there is easy access |
+ // to turn off sync. |
+ if (showSignInNotification) { |
+ ((FirstRunActivity) activity).showSignInNotification(); |
+ } |
+ } |
+ @Override |
+ public void onSigninCancelled() { |
+ if (observer != null) observer.onSigninCancelled(); |
+ } |
+ }); |
+ } |
+ |
+ /** |
* This class must be public and static. Otherwise an exception will be thrown when Android |
* recreates the fragment (e.g. after a configuration change). |
*/ |