Java Code Examples for org.chromium.chrome.browser.sync.ProfileSyncService

The following examples show how to use org.chromium.chrome.browser.sync.ProfileSyncService. These examples are extracted from open source projects. 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 Project: delion   Source File: AccountManagementFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    // Prevent sync from starting if it hasn't already to give the user a chance to change
    // their sync settings.
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.setSetupInProgress(true);
    }

    mGaiaServiceType = AccountManagementScreenHelper.GAIA_SERVICE_TYPE_NONE;
    if (getArguments() != null) {
        mGaiaServiceType =
                getArguments().getInt(SHOW_GAIA_SERVICE_TYPE_EXTRA, mGaiaServiceType);
    }

    AccountManagementScreenHelper.logEvent(
            ProfileAccountManagementMetrics.VIEW,
            mGaiaServiceType);

    startFetchingAccountsInformation(getActivity(), Profile.getLastUsedProfile());
}
 
Example 2
Source Project: delion   Source File: AccountManagementFragment.java    License: Apache License 2.0 6 votes vote down vote up
private void configureSyncSettings() {
    final Preferences preferences = (Preferences) getActivity();
    final Account account = ChromeSigninController.get(getActivity()).getSignedInUser();
    findPreference(PREF_SYNC_SETTINGS)
            .setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    if (!isVisible() || !isResumed()) return false;

                    if (ProfileSyncService.get() == null) return true;

                    if (AndroidSyncSettings.isMasterSyncEnabled(preferences)) {
                        Bundle args = new Bundle();
                        args.putString(
                                SyncCustomizationFragment.ARGUMENT_ACCOUNT, account.name);
                        preferences.startFragment(
                                SyncCustomizationFragment.class.getName(), args);
                    } else {
                        openSyncSettingsPage(preferences);
                    }

                    return true;
                }
            });
}
 
Example 3
Source Project: delion   Source File: SyncPreference.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Checks if sync error icon should be shown. Show sync error icon if sync is off because
 * of error, passphrase required or disabled in Android.
 */
static boolean showSyncErrorIcon(Context context) {
    if (!AndroidSyncSettings.isMasterSyncEnabled(context)) {
        return true;
    }

    ProfileSyncService profileSyncService = ProfileSyncService.get();
    if (profileSyncService != null) {
        if (profileSyncService.hasUnrecoverableError()) {
            return true;
        }

        if (profileSyncService.getAuthError() != GoogleServiceAuthError.State.NONE) {
            return true;
        }

        if (profileSyncService.isSyncActive()
                && profileSyncService.isPassphraseRequiredForDecryption()) {
            return true;
        }
    }

    return false;
}
 
Example 4
Source Project: delion   Source File: PassphraseActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    Account account = ChromeSigninController.get(this).getSignedInUser();
    if (account == null) {
        finish();
        return;
    }

    if (!isShowingDialog(FRAGMENT_PASSPHRASE)) {
        if (ProfileSyncService.get().isBackendInitialized()) {
            displayPassphraseDialog();
        } else {
            addSyncStateChangedListener();
            displaySpinnerDialog();
        }
    }
}
 
Example 5
Source Project: delion   Source File: PassphraseDialogFragment.java    License: Apache License 2.0 6 votes vote down vote up
private String getPromptText() {
    ProfileSyncService pss = ProfileSyncService.get();
    String accountName = pss.getCurrentSignedInAccountText() + "\n\n";
    PassphraseType passphraseType = pss.getPassphraseType();
    if (pss.hasExplicitPassphraseTime()) {
        switch (passphraseType) {
            case FROZEN_IMPLICIT_PASSPHRASE:
                return accountName + pss.getSyncEnterGooglePassphraseBodyWithDateText();
            case CUSTOM_PASSPHRASE:
                return accountName + pss.getSyncEnterCustomPassphraseBodyWithDateText();
            case IMPLICIT_PASSPHRASE: // Falling through intentionally.
            case KEYSTORE_PASSPHRASE: // Falling through intentionally.
            default:
                Log.w(TAG, "Found incorrect passphrase type " + passphraseType
                                + ". Falling back to default string.");
                return accountName + pss.getSyncEnterCustomPassphraseBodyText();
        }
    }
    return accountName + pss.getSyncEnterCustomPassphraseBodyText();
}
 
Example 6
Source Project: delion   Source File: ChromeActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onStopWithNative() {
    Tab tab = getActivityTab();
    if (tab != null && !hasWindowFocus()) tab.onActivityHidden();
    if (mAppMenuHandler != null) mAppMenuHandler.hideAppMenu();
    if (mGSAServiceClient != null) {
        mGSAServiceClient.disconnect();
        mGSAServiceClient = null;
        if (mSyncStateChangedListener != null) {
            ProfileSyncService syncService = ProfileSyncService.get();
            if (syncService != null) {
                syncService.removeSyncStateChangedListener(mSyncStateChangedListener);
            }
            mSyncStateChangedListener = null;
        }
    }
    super.onStopWithNative();
}
 
Example 7
Source Project: AndroidChromium   Source File: AccountManagementFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    // Prevent sync from starting if it hasn't already to give the user a chance to change
    // their sync settings.
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.setSetupInProgress(true);
    }

    mGaiaServiceType = AccountManagementScreenHelper.GAIA_SERVICE_TYPE_NONE;
    if (getArguments() != null) {
        mGaiaServiceType =
                getArguments().getInt(SHOW_GAIA_SERVICE_TYPE_EXTRA, mGaiaServiceType);
    }

    AccountManagementScreenHelper.logEvent(
            ProfileAccountManagementMetrics.VIEW,
            mGaiaServiceType);

    startFetchingAccountsInformation(getActivity(), Profile.getLastUsedProfile());
}
 
Example 8
Source Project: AndroidChromium   Source File: AccountManagementFragment.java    License: Apache License 2.0 6 votes vote down vote up
private void configureSyncSettings() {
    final Preferences preferences = (Preferences) getActivity();
    final Account account = ChromeSigninController.get(getActivity()).getSignedInUser();
    findPreference(PREF_SYNC_SETTINGS)
            .setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    if (!isVisible() || !isResumed()) return false;

                    if (ProfileSyncService.get() == null) return true;

                    Bundle args = new Bundle();
                    args.putString(SyncCustomizationFragment.ARGUMENT_ACCOUNT, account.name);
                    preferences.startFragment(SyncCustomizationFragment.class.getName(), args);

                    return true;
                }
            });
}
 
Example 9
Source Project: AndroidChromium   Source File: SyncPreference.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Checks if sync error icon should be shown. Show sync error icon if sync is off because
 * of error, passphrase required or disabled in Android.
 */
static boolean showSyncErrorIcon(Context context) {
    if (!AndroidSyncSettings.isMasterSyncEnabled(context)) {
        return true;
    }

    ProfileSyncService profileSyncService = ProfileSyncService.get();
    if (profileSyncService != null) {
        if (profileSyncService.hasUnrecoverableError()) {
            return true;
        }

        if (profileSyncService.getAuthError() != GoogleServiceAuthError.State.NONE) {
            return true;
        }

        if (profileSyncService.isSyncActive()
                && profileSyncService.isPassphraseRequiredForDecryption()) {
            return true;
        }
    }

    return false;
}
 
Example 10
Source Project: AndroidChromium   Source File: PassphraseActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    Account account = ChromeSigninController.get(this).getSignedInUser();
    if (account == null) {
        finish();
        return;
    }

    if (!isShowingDialog(FRAGMENT_PASSPHRASE)) {
        if (ProfileSyncService.get().isBackendInitialized()) {
            displayPassphraseDialog();
        } else {
            addSyncStateChangedListener();
            displaySpinnerDialog();
        }
    }
}
 
Example 11
Source Project: AndroidChromium   Source File: PassphraseDialogFragment.java    License: Apache License 2.0 6 votes vote down vote up
private String getPromptText() {
    ProfileSyncService pss = ProfileSyncService.get();
    String accountName = pss.getCurrentSignedInAccountText() + "\n\n";
    PassphraseType passphraseType = pss.getPassphraseType();
    if (pss.hasExplicitPassphraseTime()) {
        switch (passphraseType) {
            case FROZEN_IMPLICIT_PASSPHRASE:
                return accountName + pss.getSyncEnterGooglePassphraseBodyWithDateText();
            case CUSTOM_PASSPHRASE:
                return accountName + pss.getSyncEnterCustomPassphraseBodyWithDateText();
            case IMPLICIT_PASSPHRASE: // Falling through intentionally.
            case KEYSTORE_PASSPHRASE: // Falling through intentionally.
            default:
                Log.w(TAG, "Found incorrect passphrase type " + passphraseType
                                + ". Falling back to default string.");
                return accountName + pss.getSyncEnterCustomPassphraseBodyText();
        }
    }
    return accountName + pss.getSyncEnterCustomPassphraseBodyText();
}
 
Example 12
Source Project: AndroidChromium   Source File: ChromeActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onStopWithNative() {
    Tab tab = getActivityTab();
    if (tab != null && !hasWindowFocus()) tab.onActivityHidden();
    if (mAppMenuHandler != null) mAppMenuHandler.hideAppMenu();

    if (GSAState.getInstance(this).isGsaAvailable()) {
        GSAAccountChangeListener.getInstance().disconnect();
        if (mSyncStateChangedListener != null) {
            ProfileSyncService syncService = ProfileSyncService.get();
            if (syncService != null) {
                syncService.removeSyncStateChangedListener(mSyncStateChangedListener);
            }
            mSyncStateChangedListener = null;
        }
    }
    super.onStopWithNative();
}
 
Example 13
Source Project: 365browser   Source File: AccountManagementFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    // Prevent sync from starting if it hasn't already to give the user a chance to change
    // their sync settings.
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.setSetupInProgress(true);
    }

    mGaiaServiceType = AccountManagementScreenHelper.GAIA_SERVICE_TYPE_NONE;
    if (getArguments() != null) {
        mGaiaServiceType =
                getArguments().getInt(SHOW_GAIA_SERVICE_TYPE_EXTRA, mGaiaServiceType);
    }

    mProfile = Profile.getLastUsedProfile();

    AccountManagementScreenHelper.logEvent(
            ProfileAccountManagementMetrics.VIEW,
            mGaiaServiceType);

    startFetchingAccountsInformation(getActivity(), mProfile);
}
 
Example 14
Source Project: 365browser   Source File: AccountManagementFragment.java    License: Apache License 2.0 6 votes vote down vote up
private void configureSyncSettings() {
    final Preferences preferences = (Preferences) getActivity();
    findPreference(PREF_SYNC_SETTINGS)
            .setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    if (!isVisible() || !isResumed()) return false;

                    if (ProfileSyncService.get() == null) return true;

                    Bundle args = new Bundle();
                    args.putString(
                            SyncCustomizationFragment.ARGUMENT_ACCOUNT, mSignedInAccountName);
                    preferences.startFragment(SyncCustomizationFragment.class.getName(), args);

                    return true;
                }
            });
}
 
Example 15
Source Project: 365browser   Source File: SyncPreference.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Checks if sync error icon should be shown. Show sync error icon if sync is off because
 * of error, passphrase required or disabled in Android.
 */
static boolean showSyncErrorIcon(Context context) {
    if (!AndroidSyncSettings.isMasterSyncEnabled(context)) {
        return true;
    }

    ProfileSyncService profileSyncService = ProfileSyncService.get();
    if (profileSyncService != null) {
        if (profileSyncService.hasUnrecoverableError()) {
            return true;
        }

        if (profileSyncService.getAuthError() != GoogleServiceAuthError.State.NONE) {
            return true;
        }

        if (profileSyncService.isSyncActive()
                && profileSyncService.isPassphraseRequiredForDecryption()) {
            return true;
        }
    }

    return false;
}
 
Example 16
Source Project: 365browser   Source File: PassphraseActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    Account account = ChromeSigninController.get().getSignedInUser();
    if (account == null) {
        finish();
        return;
    }

    if (!isShowingDialog(FRAGMENT_PASSPHRASE)) {
        if (ProfileSyncService.get().isEngineInitialized()) {
            displayPassphraseDialog();
        } else {
            addSyncStateChangedListener();
            displaySpinnerDialog();
        }
    }
}
 
Example 17
Source Project: 365browser   Source File: PassphraseDialogFragment.java    License: Apache License 2.0 6 votes vote down vote up
private String getPromptText() {
    ProfileSyncService pss = ProfileSyncService.get();
    String accountName = pss.getCurrentSignedInAccountText() + "\n\n";
    PassphraseType passphraseType = pss.getPassphraseType();
    if (pss.hasExplicitPassphraseTime()) {
        switch (passphraseType) {
            case FROZEN_IMPLICIT_PASSPHRASE:
                return accountName + pss.getSyncEnterGooglePassphraseBodyWithDateText();
            case CUSTOM_PASSPHRASE:
                return accountName + pss.getSyncEnterCustomPassphraseBodyWithDateText();
            case IMPLICIT_PASSPHRASE: // Falling through intentionally.
            case KEYSTORE_PASSPHRASE: // Falling through intentionally.
            default:
                Log.w(TAG, "Found incorrect passphrase type " + passphraseType
                                + ". Falling back to default string.");
                return accountName + pss.getSyncEnterCustomPassphraseBodyText();
        }
    }
    return accountName + pss.getSyncEnterCustomPassphraseBodyText();
}
 
Example 18
Source Project: 365browser   Source File: ChromeActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onStopWithNative() {
    Tab tab = getActivityTab();
    if (tab != null && !hasWindowFocus()) tab.onActivityHidden();
    if (mAppMenuHandler != null) mAppMenuHandler.hideAppMenu();

    if (GSAState.getInstance(this).isGsaAvailable()) {
        GSAAccountChangeListener.getInstance().disconnect();
        if (mSyncStateChangedListener != null) {
            ProfileSyncService syncService = ProfileSyncService.get();
            if (syncService != null) {
                syncService.removeSyncStateChangedListener(mSyncStateChangedListener);
            }
            mSyncStateChangedListener = null;
        }
    }
    super.onStopWithNative();
}
 
Example 19
/**
 * Signs out of Chrome.
 * <p/>
 * This method clears the signed-in username, stops sync and sends out a
 * sign-out notification on the native side.
 *
 * @param activity If not null then a progress dialog is shown over the activity until signout
 * completes, in case the account had management enabled. The activity must be valid until the
 * callback is invoked.
 * @param callback Will be invoked after signout completes, if not null.
 */
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();
    }
}
 
Example 20
/**
 * Signs out of Chrome.
 * <p/>
 * This method clears the signed-in username, stops sync and sends out a
 * sign-out notification on the native side.
 *
 * @param activity If not null then a progress dialog is shown over the activity until signout
 * completes, in case the account had management enabled. The activity must be valid until the
 * callback is invoked.
 * @param callback Will be invoked after signout completes, if not null.
 */
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();
    }
}
 
Example 21
Source Project: delion   Source File: PrecacheLauncher.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * If precaching is enabled, then allow the PrecacheController to be launched and signal Chrome
 * when conditions are right to start precaching. If precaching is disabled, prevent the
 * PrecacheController from ever starting.
 *
 * @param context any context within the application
 */
@VisibleForTesting
void updateEnabled(final Context context) {
    Log.v(TAG, "updateEnabled starting");
    ThreadUtils.postOnUiThread(new Runnable() {
        @Override
        public void run() {
            mCalled = true;
            final ProfileSyncService sync = ProfileSyncService.get();

            if (mListener == null && sync != null) {
                mListener = new ProfileSyncService.SyncStateChangedListener() {
                    public void syncStateChanged() {
                        if (sync.isBackendInitialized()) {
                            mSyncInitialized = true;
                            updateEnabledSync(context);
                        }
                    }
                };
                sync.addSyncStateChangedListener(mListener);
            }

            if (mListener != null) {
                // Call the listener once, in case the sync backend is already initialized.
                mListener.syncStateChanged();
            }
            Log.v(TAG, "updateEnabled complete");
        }
    });
}
 
Example 22
Source Project: delion   Source File: AccountManagementFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    SigninManager.get(getActivity()).addSignInStateObserver(this);
    ProfileDownloader.addObserver(this);
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.addSyncStateChangedListener(this);
    }

    update();
}
 
Example 23
Source Project: delion   Source File: AccountManagementFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onPause() {
    super.onPause();
    SigninManager.get(getActivity()).removeSignInStateObserver(this);
    ProfileDownloader.removeObserver(this);
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.removeSyncStateChangedListener(this);
    }
}
 
Example 24
Source Project: delion   Source File: AccountManagementFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();

    // Allow sync to begin syncing if it hasn't yet.
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService != null) {
        syncService.setSetupInProgress(false);
    }
}
 
Example 25
Source Project: delion   Source File: SigninHelper.java    License: Apache License 2.0 5 votes vote down vote up
private SigninHelper(Context context) {
    mContext = context;
    mProfileSyncService = ProfileSyncService.get();
    mSigninManager = SigninManager.get(mContext);
    mAccountTrackerService = AccountTrackerService.get(mContext);
    mOAuth2TokenService = OAuth2TokenService.getForProfile(Profile.getLastUsedProfile());
    mChromeSigninController = ChromeSigninController.get(mContext);
}
 
Example 26
Source Project: delion   Source File: ContextReporter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Records an appropriate status via UMA given the current sync status.
 */
public static void reportSyncStatus(@Nullable ProfileSyncService syncService) {
    if (syncService == null || !syncService.isBackendInitialized()) {
        reportStatus(STATUS_SYNC_NOT_INITIALIZED);
    } else if (!syncService.getActiveDataTypes().contains(ModelType.TYPED_URLS)) {
        reportStatus(STATUS_SYNC_NOT_SYNCING_URLS);
    } else if (!syncService.getPassphraseType().equals(PassphraseType.KEYSTORE_PASSPHRASE)) {
        reportStatus(STATUS_SYNC_NOT_KEYSTORE_PASSPHRASE);
    } else {
        reportStatus(STATUS_SYNC_OTHER);
    }
}
 
Example 27
Source Project: delion   Source File: SignInPreference.java    License: 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 28
Source Project: delion   Source File: SignInPreference.java    License: 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 29
Source Project: delion   Source File: PassphraseActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void addSyncStateChangedListener() {
    if (mSyncStateChangedListener != null) {
        return;
    }
    mSyncStateChangedListener = new ProfileSyncService.SyncStateChangedListener() {
        @Override
        public void syncStateChanged() {
            if (ProfileSyncService.get().isBackendInitialized()) {
                removeSyncStateChangedListener();
                displayPassphraseDialog();
            }
        }
    };
    ProfileSyncService.get().addSyncStateChangedListener(mSyncStateChangedListener);
}
 
Example 30
Source Project: delion   Source File: PassphraseActivity.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Callback for PassphraseDialogFragment.Listener
 */
@Override
public boolean onPassphraseEntered(String passphrase) {
    if (!passphrase.isEmpty() && ProfileSyncService.get().setDecryptionPassphrase(passphrase)) {
        // The passphrase was correct - close this activity.
        finish();
        return true;
    }
    return false;
}