org.chromium.chrome.browser.signin.SigninManager Java Examples

The following examples show how to use org.chromium.chrome.browser.signin.SigninManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BookmarkPromoHeader.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the class. Note that this will start listening to signin related events and
 * update itself if needed.
 */
BookmarkPromoHeader(Context context,
        PromoHeaderShowingChangeListener showingChangeListener) {
    mContext = context;
    mShowingChangeListener = showingChangeListener;

    AndroidSyncSettings.registerObserver(mContext, this);

    mSignInManager = SigninManager.get(mContext);
    mSignInManager.addSignInStateObserver(this);

    updateShouldShow(false);
    if (shouldShow()) {
        int promoShowCount = ContextUtils.getAppSharedPreferences()
                .getInt(PREF_SIGNIN_PROMO_SHOW_COUNT, 0) + 1;
        ContextUtils.getAppSharedPreferences().edit()
                .putInt(PREF_SIGNIN_PROMO_SHOW_COUNT, promoShowCount).apply();
        RecordUserAction.record("Signin_Impression_FromBookmarkManager");
    }
}
 
Example #2
Source File: RecentTabsManager.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Create an RecentTabsManager to be used with RecentTabsPage and RecentTabsRowAdapter.
 *
 * @param tab The Tab that is showing this recent tabs page.
 * @param profile Profile that is associated with the current session.
 * @param context the Android context this manager will work in.
 */
public RecentTabsManager(Tab tab, Profile profile, Context context) {
    mProfile = profile;
    mTab = tab;
    mForeignSessionHelper = buildForeignSessionHelper(mProfile);
    mNewTabPagePrefs = buildNewTabPagePrefs(mProfile);
    mFaviconHelper = buildFaviconHelper();
    mRecentlyClosedBridge = buildRecentlyClosedBridge(mProfile);
    mSignInManager = SigninManager.get(context);
    mContext = context;

    updateRecentlyClosedTabs();
    registerForForeignSessionUpdates();
    updateForeignSessions();
    mForeignSessionHelper.triggerSessionSync();
    registerForSignInAndSyncNotifications();

    InvalidationController.get(mContext).onRecentTabsPageOpened();
}
 
Example #3
Source File: SyncController.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Trigger Chromium sign in of the given account.
 *
 * This also ensure that sync setup is not in progress anymore, so sync will start after
 * sync initialization has happened.
 *
 * @param activity the current activity.
 * @param accountName the full account name.
 */
public void signIn(Activity activity, String accountName) {
    final Account account = AccountManagerHelper.createAccountFromName(accountName);

    // The SigninManager handles most of the sign-in flow, and doFinishSignIn handles the
    // Chromium testshell specific details.
    SigninManager signinManager = SigninManager.get(mContext);
    signinManager.onFirstRunCheckDone();
    final boolean passive = false;
    signinManager.startSignIn(activity, account, passive, new SigninManager.Observer() {
        @Override
        public void onSigninComplete() {
            SigninManager.get(mContext).logInSignedInUser();
            mProfileSyncService.setSetupInProgress(false);
            mProfileSyncService.syncSignIn();
            start();
        }

        @Override
        public void onSigninCancelled() {
            stop();
        }
    });
}
 
Example #4
Source File: SyncController.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Trigger Chromium sign in of the given account.
 *
 * This also ensure that sync setup is not in progress anymore, so sync will start after
 * sync initialization has happened.
 *
 * @param activity the current activity.
 * @param accountName the full account name.
 */
public void signIn(Activity activity, String accountName) {
    final Account account = AccountManagerHelper.createAccountFromName(accountName);

    // The SigninManager handles most of the sign-in flow, and doFinishSignIn handles the
    // Chromium testshell specific details.
    SigninManager signinManager = SigninManager.get(mContext);
    signinManager.onFirstRunCheckDone();
    final boolean passive = false;
    signinManager.startSignIn(activity, account, passive, new SigninManager.Observer() {
        @Override
        public void onSigninComplete() {
            SigninManager.get(mContext).logInSignedInUser();
            mProfileSyncService.setSetupInProgress(false);
            mProfileSyncService.syncSignIn();
            start();
        }

        @Override
        public void onSigninCancelled() {
            stop();
        }
    });
}
 
Example #5
Source File: BookmarkPromoHeader.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the class. Note that this will start listening to signin related events and
 * update itself if needed.
 */
BookmarkPromoHeader(Context context,
        PromoHeaderShowingChangeListener showingChangeListener) {
    mContext = context;
    mShowingChangeListener = showingChangeListener;

    AndroidSyncSettings.registerObserver(mContext, this);

    mSignInManager = SigninManager.get(mContext);
    mSignInManager.addSignInStateObserver(this);

    updateShouldShow(false);
    if (shouldShow()) {
        int promoShowCount = ContextUtils.getAppSharedPreferences()
                .getInt(PREF_SIGNIN_PROMO_SHOW_COUNT, 0) + 1;
        ContextUtils.getAppSharedPreferences().edit()
                .putInt(PREF_SIGNIN_PROMO_SHOW_COUNT, promoShowCount).apply();
        RecordUserAction.record("Signin_Impression_FromBookmarkManager");
    }
}
 
Example #6
Source File: RecentTabsManager.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Create an RecentTabsManager to be used with RecentTabsPage and RecentTabsRowAdapter.
 *
 * @param tab The Tab that is showing this recent tabs page.
 * @param profile Profile that is associated with the current session.
 * @param context the Android context this manager will work in.
 */
public RecentTabsManager(Tab tab, Profile profile, Context context) {
    mProfile = profile;
    mTab = tab;
    mForeignSessionHelper = buildForeignSessionHelper(mProfile);
    mNewTabPagePrefs = buildNewTabPagePrefs(mProfile);
    mFaviconHelper = buildFaviconHelper();
    mRecentlyClosedBridge = buildRecentlyClosedBridge(mProfile);
    mSignInManager = SigninManager.get(context);
    mContext = context;

    updateRecentlyClosedTabs();
    registerForForeignSessionUpdates();
    updateForeignSessions();
    mForeignSessionHelper.triggerSessionSync();
    registerForSignInAndSyncNotifications();

    InvalidationController.get(mContext).onRecentTabsPageOpened();
}
 
Example #7
Source File: BookmarkPromoHeader.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the class. Note that this will start listening to signin related events and
 * update itself if needed.
 */
BookmarkPromoHeader(Context context,
        PromoHeaderShowingChangeListener showingChangeListener) {
    mContext = context;
    mShowingChangeListener = showingChangeListener;

    AndroidSyncSettings.registerObserver(mContext, this);

    mSignInManager = SigninManager.get(mContext);
    mSignInManager.addSignInStateObserver(this);

    updateShouldShow(false);
    if (shouldShow()) {
        int promoShowCount = ContextUtils.getAppSharedPreferences()
                .getInt(PREF_SIGNIN_PROMO_SHOW_COUNT, 0) + 1;
        ContextUtils.getAppSharedPreferences().edit()
                .putInt(PREF_SIGNIN_PROMO_SHOW_COUNT, promoShowCount).apply();
        RecordUserAction.record("Signin_Impression_FromBookmarkManager");
    }
}
 
Example #8
Source File: SignInPreference.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Starts listening for updates to the sign-in and sync state.
 */
public void registerForUpdates() {
    SigninManager manager = SigninManager.get(getContext());
    manager.addSignInAllowedObserver(this);
    ProfileDownloader.addObserver(this);
    FirstRunSignInProcessor.updateSigninManagerFirstRunCheckDone(getContext());
    AndroidSyncSettings.registerObserver(getContext(), this);
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.addSyncStateChangedListener(this);
    }
}
 
Example #9
Source File: ForcedSigninProcessor.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Processes the fully automatic non-FRE-related forced sign-in.
 * This is used to enforce the environment for Android EDU and child accounts.
 */
private static void processForcedSignIn(final Context appContext) {
    final SigninManager signinManager = SigninManager.get(appContext);
    // By definition we have finished all the checks for first run.
    signinManager.onFirstRunCheckDone();
    if (!FeatureUtilities.canAllowSync(appContext) || !signinManager.isSignInAllowed()) {
        Log.d(TAG, "Sign in disallowed");
        return;
    }
    AccountManagerHelper.get(appContext).getGoogleAccounts(new Callback<Account[]>() {
        @Override
        public void onResult(Account[] accounts) {
            if (accounts.length != 1) {
                Log.d(TAG, "Incorrect number of accounts (%d)", accounts.length);
                return;
            }
            signinManager.signIn(accounts[0], null, new SigninManager.SignInCallback() {
                @Override
                public void onSignInComplete() {
                    // Since this is a forced signin, signout is not allowed.
                    AccountManagementFragment.setSignOutAllowedPreferenceValue(
                            appContext, false);
                }

                @Override
                public void onSignInAborted() {}
            });
        }
    });
}
 
Example #10
Source File: GoogleServicesManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private GoogleServicesManager(Context context) {
    try {
        TraceEvent.begin("GoogleServicesManager.GoogleServicesManager");
        ThreadUtils.assertOnUiThread();
        // We should store the application context, as we outlive any activity which may create
        // us.
        mContext = context.getApplicationContext();

        mChromeSigninController = ChromeSigninController.get();
        mSigninHelper = SigninHelper.get(mContext);

        // The sign out flow starts by clearing the signed in user in the ChromeSigninController
        // on the Java side, and then performs a sign out on the native side. If there is a
        // crash on the native side then the signin state may get out of sync. Make sure that
        // the native side is signed out if the Java side doesn't have a currently signed in
        // user.
        SigninManager signinManager = SigninManager.get(mContext);
        if (!mChromeSigninController.isSignedIn() && signinManager.isSignedInOnNative()) {
            Log.w(TAG, "Signed in state got out of sync, forcing native sign out");
            signinManager.signOut();
        }

        // Initialize sync.
        SyncController.get(context);

        ApplicationStatus.registerApplicationStateListener(this);
    } finally {
        TraceEvent.end("GoogleServicesManager.GoogleServicesManager");
    }
}
 
Example #11
Source File: RecentTabsManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Create an RecentTabsManager to be used with RecentTabsPage and RecentTabsRowAdapter.
 *
 * @param tab The Tab that is showing this recent tabs page.
 * @param profile Profile that is associated with the current session.
 * @param context the Android context this manager will work in.
 */
public RecentTabsManager(Tab tab, Profile profile, Context context) {
    mProfile = profile;
    mTab = tab;
    mForeignSessionHelper = new ForeignSessionHelper(profile);
    mPrefs = new RecentTabsPagePrefs(profile);
    mFaviconHelper = new FaviconHelper();
    mRecentlyClosedTabManager = sRecentlyClosedTabManagerForTests != null
            ? sRecentlyClosedTabManagerForTests
            : new RecentlyClosedBridge(profile);
    mSignInManager = SigninManager.get(context);
    mContext = context;

    mRecentlyClosedTabManager.setTabsUpdatedRunnable(new Runnable() {
        @Override
        public void run() {
            updateRecentlyClosedTabs();
            postUpdate();
        }
    });

    updateRecentlyClosedTabs();
    registerForForeignSessionUpdates();
    updateForeignSessions();
    mForeignSessionHelper.triggerSessionSync();
    registerForSignInAndSyncNotifications();

    InvalidationController.get(mContext).onRecentTabsPageOpened();
}
 
Example #12
Source File: RecentTabsManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Determine whether the sync promo needs to be displayed.
 *
 * @return Whether sync promo should be displayed.
 */
public boolean shouldDisplaySyncPromo() {
    SigninManager signinManager = SigninManager.get(mContext);
    if (signinManager.isSigninDisabledByPolicy() || !signinManager.isSigninSupported()) {
        return false;
    }

    if (ContextUtils.getAppSharedPreferences().getBoolean(
            PREF_SIGNIN_PROMO_DECLINED, false)) {
        return false;
    }

    return !AndroidSyncSettings.isSyncEnabled(mContext) || mForeignSessions.isEmpty();
}
 
Example #13
Source File: SignInPromo.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public SignInPromo(SuggestionsUiDelegate uiDelegate) {
    mDismissed = ChromePreferenceManager.getInstance().getNewTabPageSigninPromoDismissed();

    SigninManager signinManager = SigninManager.get(ContextUtils.getApplicationContext());
    if (mDismissed) {
        mObserver = null;
    } else {
        mObserver = new SigninObserver(signinManager);
        uiDelegate.addDestructionObserver(mObserver);
    }

    setVisible(signinManager.isSignInAllowed() && !signinManager.isSignedInOnNative());
}
 
Example #14
Source File: MainPreferences.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    // updatePreferences() must be called before setupSignInPref as updatePreferences loads
    // the SignInPreference.
    updatePreferences();

    if (SigninManager.get(getActivity()).isSigninSupported()) {
        SigninManager.get(getActivity()).addSignInStateObserver(this);
        setupSignInPref();
    }
}
 
Example #15
Source File: MainPreferences.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onPause() {
    super.onPause();
    if (SigninManager.get(getActivity()).isSigninSupported()) {
        SigninManager.get(getActivity()).removeSignInStateObserver(this);
        clearSignInPref();
    }
}
 
Example #16
Source File: FirstRunSignInProcessor.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Allows the user to sign-in if there are no pending FRE sign-in requests.
 * @param context A context
 */
public static void updateSigninManagerFirstRunCheckDone(Context context) {
    SigninManager manager = SigninManager.get(context);
    if (manager.isSignInAllowed()) return;
    if (!FirstRunStatus.getFirstRunFlowComplete()) return;
    if (!getFirstRunFlowSignInComplete(context)) return;
    manager.onFirstRunCheckDone();
}
 
Example #17
Source File: SignInPreference.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Stops listening for updates to the sign-in and sync state. Every call to registerForUpdates()
 * must be matched with a call to this method.
 */
public void unregisterForUpdates() {
    SigninManager manager = SigninManager.get(getContext());
    manager.removeSignInAllowedObserver(this);
    ProfileDownloader.removeObserver(this);
    AndroidSyncSettings.unregisterObserver(getContext(), this);
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.removeSyncStateChangedListener(this);
    }
}
 
Example #18
Source File: SignInPreference.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the title, summary, and image based on the current sign-in state.
 */
private void update() {
    String accountName = ChromeSigninController.get().getSignedInAccountName();
    if (SigninManager.get(getContext()).isSigninDisabledByPolicy()) {
        setupSigninDisabled();
        mShowingPromo = false;
    } else if (accountName == null) {
        setupNotSignedIn();

        if (!mShowingPromo) {
            // This user action should be recorded when message with sign-in prompt is shown
            RecordUserAction.record("Signin_Impression_FromSettings");
        }
        mShowingPromo = true;
    } else {
        setupSignedIn(accountName);
        mShowingPromo = false;
    }

    setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            return AccountSigninActivity.startIfAllowed(
                    getContext(), SigninAccessPoint.SETTINGS);
        }
    });
}
 
Example #19
Source File: FirstRunSignInProcessor.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Allows the user to sign-in if there are no pending FRE sign-in requests.
 * @param context A context
 */
public static void updateSigninManagerFirstRunCheckDone(Context context) {
    SigninManager manager = SigninManager.get(context);
    if (manager.isSignInAllowed()) return;
    if (!FirstRunStatus.getFirstRunFlowComplete()) return;
    if (!getFirstRunFlowSignInComplete(context)) return;
    manager.onFirstRunCheckDone();
}
 
Example #20
Source File: ForcedSigninProcessor.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Processes the fully automatic non-FRE-related forced sign-in.
 * This is used to enforce the environment for Android EDU and child accounts.
 */
private static void processForcedSignIn(
        final Context appContext, @Nullable final Runnable onComplete) {
    final SigninManager signinManager = SigninManager.get(appContext);
    // By definition we have finished all the checks for first run.
    signinManager.onFirstRunCheckDone();
    if (!FeatureUtilities.canAllowSync(appContext) || !signinManager.isSignInAllowed()) {
        Log.d(TAG, "Sign in disallowed");
        return;
    }
    AccountManagerHelper.get().getGoogleAccounts(new Callback<Account[]>() {
        @Override
        public void onResult(Account[] accounts) {
            if (accounts.length != 1) {
                Log.d(TAG, "Incorrect number of accounts (%d)", accounts.length);
                return;
            }
            signinManager.signIn(accounts[0], null, new SigninManager.SignInCallback() {
                @Override
                public void onSignInComplete() {
                    // Since this is a forced signin, signout is not allowed.
                    AccountManagementFragment.setSignOutAllowedPreferenceValue(false);
                    if (onComplete != null) {
                        onComplete.run();
                    }
                }

                @Override
                public void onSignInAborted() {
                    if (onComplete != null) {
                        onComplete.run();
                    }
                }
            });
        }
    });
}
 
Example #21
Source File: ForcedSigninProcessor.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * If forced signin is required by policy, check that Google Play Services is available, and
 * show a non-cancelable dialog otherwise.
 * @param activity The activity for which to show the dialog.
 */
// TODO(bauerb): Once external dependencies reliably use policy to force sign-in,
// consider removing the child account / EDU checks.
public static void checkCanSignIn(final ChromeActivity activity) {
    final Context appContext = activity.getApplicationContext();
    if (SigninManager.get(appContext).isForceSigninEnabled()) {
        ExternalAuthUtils.getInstance().canUseGooglePlayServices(appContext,
                new UserRecoverableErrorHandler.ModalDialog(activity, false));
    }
}
 
Example #22
Source File: HistoryManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Called when the activity/native page is destroyed.
 */
public void onDestroyed() {
    mSelectableListLayout.onDestroyed();
    mHistoryAdapter.onDestroyed();
    mLargeIconBridge.destroy();
    mLargeIconBridge = null;
    SigninManager.get(mActivity).removeSignInStateObserver(this);
}
 
Example #23
Source File: SignoutFragment.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
    switch (which) {
        case DialogInterface.BUTTON_POSITIVE: {
            SigninManager.get(getActivity()).signOut(getActivity(), null);
            break;
        }
        case DialogInterface.BUTTON_NEGATIVE: {
            dismiss();
            break;
        }
        default:
            break;
    }
}
 
Example #24
Source File: SignoutFragment.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
    switch (which) {
        case DialogInterface.BUTTON_POSITIVE: {
            SigninManager.get(getActivity()).signOut(getActivity(), null);
            break;
        }
        case DialogInterface.BUTTON_NEGATIVE: {
            dismiss();
            break;
        }
        default:
            break;
    }
}
 
Example #25
Source File: GoogleServicesManager.java    From delion with Apache License 2.0 5 votes vote down vote up
private GoogleServicesManager(Context context) {
    try {
        TraceEvent.begin("GoogleServicesManager.GoogleServicesManager");
        ThreadUtils.assertOnUiThread();
        // We should store the application context, as we outlive any activity which may create
        // us.
        mContext = context.getApplicationContext();

        mChromeSigninController = ChromeSigninController.get(mContext);
        mSigninHelper = SigninHelper.get(mContext);

        // The sign out flow starts by clearing the signed in user in the ChromeSigninController
        // on the Java side, and then performs a sign out on the native side. If there is a
        // crash on the native side then the signin state may get out of sync. Make sure that
        // the native side is signed out if the Java side doesn't have a currently signed in
        // user.
        SigninManager signinManager = SigninManager.get(mContext);
        if (!mChromeSigninController.isSignedIn() && signinManager.isSignedInOnNative()) {
            Log.w(TAG, "Signed in state got out of sync, forcing native sign out");
            signinManager.signOut();
        }

        // Initialize sync.
        SyncController.get(context);

        ApplicationStatus.registerApplicationStateListener(this);
    } finally {
        TraceEvent.end("GoogleServicesManager.GoogleServicesManager");
    }
}
 
Example #26
Source File: FirstRunSignInProcessor.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Allows the user to sign-in if there are no pending FRE sign-in requests.
 * @param context A context
 */
public static void updateSigninManagerFirstRunCheckDone(Context context) {
    SigninManager manager = SigninManager.get(context);
    if (manager.isSignInAllowed()) return;
    if (!FirstRunStatus.getFirstRunFlowComplete(context)) return;
    if (!getFirstRunFlowSignInComplete(context)) return;
    manager.onFirstRunCheckDone();
}
 
Example #27
Source File: SignInPreference.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Stops listening for updates to the sign-in and sync state. Every call to registerForUpdates()
 * must be matched with a call to this method.
 */
public void unregisterForUpdates() {
    SigninManager manager = SigninManager.get(getContext());
    manager.removeSignInAllowedObserver(this);
    ProfileDownloader.removeObserver(this);
    AndroidSyncSettings.unregisterObserver(getContext(), this);
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.removeSyncStateChangedListener(this);
    }
}
 
Example #28
Source File: ForcedSigninProcessor.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Processes the fully automatic non-FRE-related forced sign-in.
 * This is used to enforce the environment for Android EDU and child accounts.
 */
private static void processForcedSignIn(final Context appContext) {
    final SigninManager signinManager = SigninManager.get(appContext);
    // By definition we have finished all the checks for first run.
    signinManager.onFirstRunCheckDone();
    if (!FeatureUtilities.canAllowSync(appContext) || !signinManager.isSignInAllowed()) {
        Log.d(TAG, "Sign in disallowed");
        return;
    }
    AccountManagerHelper.get(appContext).getGoogleAccounts(new Callback<Account[]>() {
        @Override
        public void onResult(Account[] accounts) {
            if (accounts.length != 1) {
                Log.d(TAG, "Incorrect number of accounts (%d)", accounts.length);
                return;
            }
            signinManager.signIn(accounts[0], null, new SigninManager.SignInCallback() {
                @Override
                public void onSignInComplete() {
                    // Since this is a forced signin, signout is not allowed.
                    AccountManagementFragment.setSignOutAllowedPreferenceValue(
                            appContext, false);
                }

                @Override
                public void onSignInAborted() {}
            });
        }
    });
}
 
Example #29
Source File: GoogleServicesManager.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private GoogleServicesManager(Context context) {
    try {
        TraceEvent.begin("GoogleServicesManager.GoogleServicesManager");
        ThreadUtils.assertOnUiThread();
        // We should store the application context, as we outlive any activity which may create
        // us.
        mContext = context.getApplicationContext();

        mChromeSigninController = ChromeSigninController.get(mContext);
        mSigninHelper = SigninHelper.get(mContext);

        // The sign out flow starts by clearing the signed in user in the ChromeSigninController
        // on the Java side, and then performs a sign out on the native side. If there is a
        // crash on the native side then the signin state may get out of sync. Make sure that
        // the native side is signed out if the Java side doesn't have a currently signed in
        // user.
        SigninManager signinManager = SigninManager.get(mContext);
        if (!mChromeSigninController.isSignedIn() && signinManager.isSignedInOnNative()) {
            Log.w(TAG, "Signed in state got out of sync, forcing native sign out");
            signinManager.signOut();
        }

        // Initialize sync.
        SyncController.get(context);

        ApplicationStatus.registerApplicationStateListener(this);
    } finally {
        TraceEvent.end("GoogleServicesManager.GoogleServicesManager");
    }
}
 
Example #30
Source File: SignInPreference.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Stops listening for updates to the sign-in and sync state. Every call to registerForUpdates()
 * must be matched with a call to this method.
 */
public void unregisterForUpdates() {
    SigninManager manager = SigninManager.get(getContext());
    manager.removeSignInAllowedObserver(this);
    ProfileDownloader.removeObserver(this);
    AndroidSyncSettings.unregisterObserver(getContext(), this);
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.removeSyncStateChangedListener(this);
    }
}