Java Code Examples for org.chromium.chrome.browser.sync.ProfileSyncService#get()

The following examples show how to use org.chromium.chrome.browser.sync.ProfileSyncService#get() . 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: AccountManagementFragment.java    From delion with 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 File: SyncPreference.java    From AndroidChromium with 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 3
Source File: AccountManagementFragment.java    From 365browser with 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 4
Source File: AccountManagementFragment.java    From AndroidChromium with 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 5
Source File: ChromeActivity.java    From delion with 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 6
Source File: PassphraseDialogFragment.java    From AndroidChromium with 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 7
Source File: SyncPreference.java    From 365browser with 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 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: SigninHelper.java    From AndroidChromium with 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 10
Source File: InvalidationController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the sync invalidation types that the client is registered for based on the preferred
 * sync types.  Starts the client if needed.
 */
public void ensureStartedAndUpdateRegisteredTypes() {
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService == null) return;

    mStarted = true;

    // Ensure GCM has been initialized.
    ensureGcmIsInitialized();

    // Do not apply changes to {@link #mSessionInvalidationsEnabled} yet because the timer task
    // may be scheduled far into the future.
    mEnableSessionInvalidationsTimer.resume();

    HashSet<Integer> typesToRegister = new HashSet<Integer>();
    typesToRegister.addAll(syncService.getPreferredDataTypes());
    if (!mSessionInvalidationsEnabled) {
        typesToRegister.remove(ModelType.SESSIONS);
        typesToRegister.remove(ModelType.FAVICON_TRACKING);
        typesToRegister.remove(ModelType.FAVICON_IMAGES);
    }

    Intent registerIntent = InvalidationIntentProtocol.createRegisterIntent(
            ChromeSigninController.get().getSignedInUser(), typesToRegister);
    registerIntent.setClass(
            mContext, InvalidationClientService.getRegisteredClass());
    startServiceIfPossible(registerIntent);
}
 
Example 11
Source File: AccountManagementFragment.java    From 365browser with 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 12
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);
    }
}
 
Example 13
Source File: SigninHelper.java    From 365browser with 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();
    mOAuth2TokenService = OAuth2TokenService.getForProfile(Profile.getLastUsedProfile());
    mChromeSigninController = ChromeSigninController.get();
}
 
Example 14
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 15
Source File: InvalidationController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the sync invalidation types that the client is registered for based on the preferred
 * sync types.  Starts the client if needed.
 */
public void ensureStartedAndUpdateRegisteredTypes() {
    ProfileSyncService syncService = ProfileSyncService.get();
    if (syncService == null) return;

    mStarted = true;

    // Ensure GCM has been initialized.
    ensureGcmIsInitialized();

    // Do not apply changes to {@link #mSessionInvalidationsEnabled} yet because the timer task
    // may be scheduled far into the future.
    mEnableSessionInvalidationsTimer.resume();

    HashSet<Integer> typesToRegister = new HashSet<Integer>();
    typesToRegister.addAll(syncService.getPreferredDataTypes());
    if (!mSessionInvalidationsEnabled) {
        typesToRegister.remove(ModelType.SESSIONS);
        typesToRegister.remove(ModelType.FAVICON_TRACKING);
        typesToRegister.remove(ModelType.FAVICON_IMAGES);
    }

    Intent registerIntent = InvalidationIntentProtocol.createRegisterIntent(
            ChromeSigninController.get(mContext).getSignedInUser(),
            typesToRegister);
    registerIntent.setClass(
            mContext, InvalidationClientService.getRegisteredClass());
    mContext.startService(registerIntent);
}
 
Example 16
Source File: SigninHelper.java    From delion with 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 17
Source File: AccountManagementFragment.java    From delion with 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 18
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 19
Source File: ClearBrowsingDataPreferencesBasic.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private boolean isHistorySyncEnabled() {
    boolean syncEnabled = AndroidSyncSettings.isSyncEnabled(getActivity());
    ProfileSyncService syncService = ProfileSyncService.get();
    return syncEnabled && syncService != null
            && syncService.getActiveDataTypes().contains(ModelType.HISTORY_DELETE_DIRECTIVES);
}
 
Example 20
Source File: SyncPreference.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Return a short summary of the current sync status.
 */
static String getSyncStatusSummary(Context context) {
    if (!ChromeSigninController.get(context).isSignedIn()) return "";

    ProfileSyncService profileSyncService = ProfileSyncService.get();
    Resources res = context.getResources();

    if (ChildAccountService.isChildAccount()) {
        return res.getString(R.string.kids_account);
    }

    if (!AndroidSyncSettings.isMasterSyncEnabled(context)) {
        return res.getString(R.string.sync_android_master_sync_disabled);
    }

    if (profileSyncService == null) {
        return res.getString(R.string.sync_is_disabled);
    }

    if (profileSyncService.getAuthError() != GoogleServiceAuthError.State.NONE) {
        return res.getString(profileSyncService.getAuthError().getMessage());
    }

    if (profileSyncService.getProtocolErrorClientAction()
            == ProtocolErrorClientAction.UPGRADE_CLIENT) {
        return res.getString(
                R.string.sync_error_upgrade_client, BuildInfo.getPackageLabel(context));
    }

    if (profileSyncService.hasUnrecoverableError()) {
        return res.getString(R.string.sync_error_generic);
    }

    boolean syncEnabled = AndroidSyncSettings.isSyncEnabled(context);

    if (syncEnabled) {
        if (!profileSyncService.isSyncActive()) {
            return res.getString(R.string.sync_setup_progress);
        }

        if (profileSyncService.isPassphraseRequiredForDecryption()) {
            return res.getString(R.string.sync_need_passphrase);
        }

        Account account = ChromeSigninController.get(context).getSignedInUser();
        return String.format(
                context.getString(R.string.account_management_sync_summary), account.name);
    }

    return context.getString(R.string.sync_is_disabled);
}