This source file includes following definitions.
- onSignInAllowedChanged
- onSigninComplete
- onSigninCancelled
- get
- onFirstRunCheckDone
- isSignInAllowed
- addSignInAllowedObserver
- removeSignInAllowedObserver
- notifySignInAllowedChanged
- startSignIn
- onPolicyCheckedBeforeSignIn
- onPolicyFetchedBeforeSignIn
- doSignIn
- signOut
- getManagementDomain
- logInSignedInUser
- cancelSignIn
- wipeProfileData
- onProfileDataWiped
- onSignOutDone
- isNewProfileManagementEnabled
- nativeInit
- nativeShouldLoadPolicyForUser
- nativeCheckPolicyBeforeSignIn
- nativeFetchPolicyBeforeSignIn
- nativeOnSignInCompleted
- nativeSignOut
- nativeGetManagementDomain
- nativeWipeProfileData
- nativeLogInSignedInUser
- nativeIsNewProfileManagementEnabled
package org.chromium.chrome.browser.signin;
import android.accounts.Account;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Handler;
import android.util.Log;
import org.chromium.base.CalledByNative;
import org.chromium.base.ObserverList;
import org.chromium.base.ThreadUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.invalidation.InvalidationController;
import org.chromium.chrome.browser.sync.ProfileSyncService;
import org.chromium.sync.internal_api.pub.base.ModelType;
import org.chromium.sync.notifier.SyncStatusHelper;
import org.chromium.sync.signin.ChromeSigninController;
import java.util.HashSet;
public class SigninManager {
private static final String TAG = "SigninManager";
private static SigninManager sSigninManager;
private final Context mContext;
private final long mNativeSigninManagerAndroid;
private boolean mFirstRunCheckIsPending = true;
private final ObserverList<SignInAllowedObserver> mSignInAllowedObservers =
new ObserverList<SignInAllowedObserver>();
private Activity mSignInActivity;
private Account mSignInAccount;
private Observer mSignInObserver;
private boolean mPassive = false;
private ProgressDialog mSignOutProgressDialog;
private Runnable mSignOutCallback;
private AlertDialog mPolicyConfirmationDialog;
public static interface SignInAllowedObserver {
public void onSignInAllowedChanged();
}
public static interface Observer {
public void onSigninComplete();
public void onSigninCancelled();
}
public static SigninManager get(Context context) {
ThreadUtils.assertOnUiThread();
if (sSigninManager == null) {
sSigninManager = new SigninManager(context);
}
return sSigninManager;
}
private SigninManager(Context context) {
ThreadUtils.assertOnUiThread();
mContext = context.getApplicationContext();
mNativeSigninManagerAndroid = nativeInit();
}
public void onFirstRunCheckDone() {
mFirstRunCheckIsPending = false;
if (isSignInAllowed()) {
notifySignInAllowedChanged();
}
}
public boolean isSignInAllowed() {
return !mFirstRunCheckIsPending &&
mSignInAccount == null &&
ChromeSigninController.get(mContext).getSignedInUser() == null;
}
public void addSignInAllowedObserver(SignInAllowedObserver observer) {
mSignInAllowedObservers.addObserver(observer);
}
public void removeSignInAllowedObserver(SignInAllowedObserver observer) {
mSignInAllowedObservers.removeObserver(observer);
}
private void notifySignInAllowedChanged() {
new Handler().post(new Runnable() {
@Override
public void run() {
for (SignInAllowedObserver observer : mSignInAllowedObservers) {
observer.onSignInAllowedChanged();
}
}
});
}
public void startSignIn(
Activity activity, final Account account, boolean passive, final Observer observer) {
assert mSignInActivity == null;
assert mSignInAccount == null;
assert mSignInObserver == null;
if (mFirstRunCheckIsPending) {
Log.w(TAG, "Ignoring sign-in request until the First Run check completes.");
return;
}
mSignInActivity = activity;
mSignInAccount = account;
mSignInObserver = observer;
mPassive = passive;
notifySignInAllowedChanged();
if (!nativeShouldLoadPolicyForUser(account.name)) {
doSignIn();
return;
}
Log.d(TAG, "Checking if account has policy management enabled");
nativeCheckPolicyBeforeSignIn(mNativeSigninManagerAndroid, account.name);
}
@CalledByNative
private void onPolicyCheckedBeforeSignIn(String managementDomain) {
if (managementDomain == null) {
Log.d(TAG, "Account doesn't have policy");
doSignIn();
return;
}
if (mSignInActivity.isDestroyed()) {
cancelSignIn();
return;
}
if (mPassive) {
nativeFetchPolicyBeforeSignIn(mNativeSigninManagerAndroid);
return;
}
Log.d(TAG, "Account has policy management");
AlertDialog.Builder builder = new AlertDialog.Builder(mSignInActivity);
builder.setTitle(R.string.policy_dialog_title);
builder.setMessage(mContext.getResources().getString(R.string.policy_dialog_message,
managementDomain));
builder.setPositiveButton(
R.string.policy_dialog_proceed,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
Log.d(TAG, "Accepted policy management, proceeding with sign-in");
nativeFetchPolicyBeforeSignIn(mNativeSigninManagerAndroid);
mPolicyConfirmationDialog = null;
}
});
builder.setNegativeButton(
R.string.policy_dialog_cancel,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
Log.d(TAG, "Cancelled sign-in");
cancelSignIn();
mPolicyConfirmationDialog = null;
}
});
builder.setOnDismissListener(
new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (mPolicyConfirmationDialog != null) {
Log.d(TAG, "Policy dialog dismissed, cancelling sign-in.");
cancelSignIn();
mPolicyConfirmationDialog = null;
}
}
});
mPolicyConfirmationDialog = builder.create();
mPolicyConfirmationDialog.show();
}
@CalledByNative
private void onPolicyFetchedBeforeSignIn() {
doSignIn();
}
private void doSignIn() {
Log.d(TAG, "Committing the sign-in process now");
assert mSignInAccount != null;
ChromeSigninController.get(mContext).setSignedInAccountName(mSignInAccount.name);
nativeOnSignInCompleted(mNativeSigninManagerAndroid, mSignInAccount.name);
InvalidationController invalidationController = InvalidationController.get(mContext);
invalidationController.setRegisteredTypes(mSignInAccount, true, new HashSet<ModelType>());
ProfileSyncService profileSyncService = ProfileSyncService.get(mContext);
if (SyncStatusHelper.get(mContext).isSyncEnabled(mSignInAccount) &&
!profileSyncService.hasSyncSetupCompleted()) {
profileSyncService.setSetupInProgress(true);
profileSyncService.syncSignIn();
}
if (mSignInObserver != null)
mSignInObserver.onSigninComplete();
Log.d(TAG, "Signin done");
mSignInActivity = null;
mSignInAccount = null;
mSignInObserver = null;
notifySignInAllowedChanged();
}
public void signOut(Activity activity, Runnable callback) {
mSignOutCallback = callback;
boolean wipeData = getManagementDomain() != null;
Log.d(TAG, "Signing out, wipe data? " + wipeData);
ChromeSigninController.get(mContext).clearSignedInUser();
ProfileSyncService.get(mContext).signOut();
nativeSignOut(mNativeSigninManagerAndroid);
if (wipeData) {
wipeProfileData(activity);
} else {
onSignOutDone();
}
}
public String getManagementDomain() {
return nativeGetManagementDomain(mNativeSigninManagerAndroid);
}
public void logInSignedInUser() {
nativeLogInSignedInUser(mNativeSigninManagerAndroid);
}
private void cancelSignIn() {
if (mSignInObserver != null)
mSignInObserver.onSigninCancelled();
mSignInActivity = null;
mSignInObserver = null;
mSignInAccount = null;
notifySignInAllowedChanged();
}
private void wipeProfileData(Activity activity) {
if (activity != null) {
boolean indeterminate = true;
boolean cancelable = false;
mSignOutProgressDialog = ProgressDialog.show(
activity,
activity.getString(R.string.wiping_profile_data_title),
activity.getString(R.string.wiping_profile_data_message),
indeterminate, cancelable);
}
nativeWipeProfileData(mNativeSigninManagerAndroid);
}
@CalledByNative
private void onProfileDataWiped() {
if (mSignOutProgressDialog != null && mSignOutProgressDialog.isShowing())
mSignOutProgressDialog.dismiss();
onSignOutDone();
}
private void onSignOutDone() {
if (mSignOutCallback != null) {
new Handler().post(mSignOutCallback);
mSignOutCallback = null;
}
}
public static boolean isNewProfileManagementEnabled() {
return nativeIsNewProfileManagementEnabled();
}
private native long nativeInit();
private native boolean nativeShouldLoadPolicyForUser(String username);
private native void nativeCheckPolicyBeforeSignIn(
long nativeSigninManagerAndroid, String username);
private native void nativeFetchPolicyBeforeSignIn(long nativeSigninManagerAndroid);
private native void nativeOnSignInCompleted(long nativeSigninManagerAndroid, String username);
private native void nativeSignOut(long nativeSigninManagerAndroid);
private native String nativeGetManagementDomain(long nativeSigninManagerAndroid);
private native void nativeWipeProfileData(long nativeSigninManagerAndroid);
private native void nativeLogInSignedInUser(long nativeSigninManagerAndroid);
private static native boolean nativeIsNewProfileManagementEnabled();
}