This source file includes following definitions.
- syncStateChanged
- get
- getProfileSyncServiceAndroid
- finishSyncFirstSetupIfNeeded
- signOut
- syncSignIn
- syncSignIn
- syncSignInWithAuthToken
- requestSyncFromNativeChrome
- requestSyncFromNativeChromeForAllTypes
- requestSyncCycleForTest
- querySyncStatus
- setSessionsId
- getSyncDecryptionPassphraseTypeIfRequired
- getSyncDecryptionPassphraseType
- isSyncKeystoreMigrationDone
- hasExplicitPassphraseTime
- getSyncEnterGooglePassphraseBodyWithDateText
- getSyncEnterCustomPassphraseBodyWithDateText
- getCurrentSignedInAccountText
- getSyncEnterCustomPassphraseBodyText
- isUsingSecondaryPassphrase
- isPassphraseRequiredForDecryption
- isPassphraseRequiredForExternalType
- isSyncInitialized
- isFirstSetupInProgress
- isEncryptEverythingEnabled
- enableEncryptEverything
- setEncryptionPassphrase
- isCryptographerReady
- setDecryptionPassphrase
- getAuthError
- getPreferredDataTypes
- hasKeepEverythingSynced
- setPreferredDataTypes
- setSyncSetupCompleted
- hasSyncSetupCompleted
- isStartSuppressed
- setSetupInProgress
- addSyncStateChangedListener
- removeSyncStateChangedListener
- hasUnrecoverableError
- syncStateChanged
- getSyncInternalsInfoForTest
- enableSync
- disableSync
- getLastSyncedTimeForTest
- nativeNudgeSyncer
- nativeNudgeSyncerForAllTypes
- nativeInit
- nativeEnableSync
- nativeDisableSync
- nativeSignInSync
- nativeSignOutSync
- nativeSetSyncSessionsId
- nativeQuerySyncStatusSummary
- nativeGetAuthError
- nativeIsSyncInitialized
- nativeIsFirstSetupInProgress
- nativeIsEncryptEverythingEnabled
- nativeEnableEncryptEverything
- nativeIsPassphraseRequiredForDecryption
- nativeIsPassphraseRequiredForExternalType
- nativeIsUsingSecondaryPassphrase
- nativeSetDecryptionPassphrase
- nativeSetEncryptionPassphrase
- nativeIsCryptographerReady
- nativeGetPassphraseType
- nativeHasExplicitPassphraseTime
- nativeGetSyncEnterGooglePassphraseBodyWithDateText
- nativeGetSyncEnterCustomPassphraseBodyWithDateText
- nativeGetCurrentSignedInAccountText
- nativeGetSyncEnterCustomPassphraseBodyText
- nativeIsSyncKeystoreMigrationDone
- nativeGetEnabledDataTypes
- nativeSetPreferredDataTypes
- nativeSetSetupInProgress
- nativeSetSyncSetupCompleted
- nativeHasSyncSetupCompleted
- nativeIsStartSuppressed
- nativeHasKeepEverythingSynced
- nativeHasUnrecoverableError
- nativeGetAboutInfoForTest
- nativeGetLastSyncedTimeForTest
package org.chromium.chrome.browser.sync;
import android.content.Context;
import android.util.Log;
import com.google.common.annotations.VisibleForTesting;
import org.chromium.base.CalledByNative;
import org.chromium.base.ThreadUtils;
import org.chromium.chrome.browser.identity.UniqueIdentificationGenerator;
import org.chromium.sync.internal_api.pub.SyncDecryptionPassphraseType;
import org.chromium.sync.internal_api.pub.base.ModelType;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
public class ProfileSyncService {
public interface SyncStateChangedListener {
public void syncStateChanged();
}
private static final String TAG = "ProfileSyncService";
@VisibleForTesting
public static final String SESSION_TAG_PREFIX = "session_sync";
private static ProfileSyncService sSyncSetupManager;
@VisibleForTesting
protected final Context mContext;
private final List<SyncStateChangedListener> mListeners =
new CopyOnWriteArrayList<SyncStateChangedListener>();
private final long mNativeProfileSyncServiceAndroid;
public static ProfileSyncService get(Context context) {
ThreadUtils.assertOnUiThread();
if (sSyncSetupManager == null) {
sSyncSetupManager = new ProfileSyncService(context);
}
return sSyncSetupManager;
}
private ProfileSyncService(Context context) {
ThreadUtils.assertOnUiThread();
mContext = context.getApplicationContext();
mNativeProfileSyncServiceAndroid = nativeInit();
}
@CalledByNative
private static long getProfileSyncServiceAndroid(Context context) {
return get(context).mNativeProfileSyncServiceAndroid;
}
@VisibleForTesting
public void finishSyncFirstSetupIfNeeded() {
if (isFirstSetupInProgress()) {
setSyncSetupCompleted();
setSetupInProgress(false);
}
}
public void signOut() {
nativeSignOutSync(mNativeProfileSyncServiceAndroid);
}
public void syncSignIn() {
nativeSignInSync(mNativeProfileSyncServiceAndroid);
syncStateChanged();
}
@Deprecated
public void syncSignIn(String account) {
syncSignIn();
}
@Deprecated
public void syncSignInWithAuthToken(String account, String authToken) {
syncSignIn(account);
}
public void requestSyncFromNativeChrome(
int objectSource, String objectId, long version, String payload) {
ThreadUtils.assertOnUiThread();
nativeNudgeSyncer(
mNativeProfileSyncServiceAndroid, objectSource, objectId, version, payload);
}
public void requestSyncFromNativeChromeForAllTypes() {
ThreadUtils.assertOnUiThread();
nativeNudgeSyncerForAllTypes(mNativeProfileSyncServiceAndroid);
}
@VisibleForTesting
public void requestSyncCycleForTest() {
ThreadUtils.assertOnUiThread();
requestSyncFromNativeChromeForAllTypes();
}
public String querySyncStatus() {
ThreadUtils.assertOnUiThread();
return nativeQuerySyncStatusSummary(mNativeProfileSyncServiceAndroid);
}
public void setSessionsId(UniqueIdentificationGenerator generator) {
ThreadUtils.assertOnUiThread();
String uniqueTag = generator.getUniqueId(null);
if (uniqueTag.isEmpty()) {
Log.e(TAG, "Unable to get unique tag for sync. " +
"This may lead to unexpected tab sync behavior.");
return;
}
String sessionTag = SESSION_TAG_PREFIX + uniqueTag;
if (!nativeSetSyncSessionsId(mNativeProfileSyncServiceAndroid, sessionTag)) {
Log.e(TAG, "Unable to write session sync tag. " +
"This may lead to unexpected tab sync behavior.");
}
}
public SyncDecryptionPassphraseType getSyncDecryptionPassphraseTypeIfRequired() {
if (isSyncInitialized() && isPassphraseRequiredForDecryption()) {
return getSyncDecryptionPassphraseType();
}
return SyncDecryptionPassphraseType.NONE;
}
public SyncDecryptionPassphraseType getSyncDecryptionPassphraseType() {
assert isSyncInitialized();
int passphraseType = nativeGetPassphraseType(mNativeProfileSyncServiceAndroid);
return SyncDecryptionPassphraseType.fromInternalValue(passphraseType);
}
public boolean isSyncKeystoreMigrationDone() {
assert isSyncInitialized();
return nativeIsSyncKeystoreMigrationDone(mNativeProfileSyncServiceAndroid);
}
public boolean hasExplicitPassphraseTime() {
assert isSyncInitialized();
return nativeHasExplicitPassphraseTime(mNativeProfileSyncServiceAndroid);
}
public String getSyncEnterGooglePassphraseBodyWithDateText() {
assert isSyncInitialized();
return nativeGetSyncEnterGooglePassphraseBodyWithDateText(mNativeProfileSyncServiceAndroid);
}
public String getSyncEnterCustomPassphraseBodyWithDateText() {
assert isSyncInitialized();
return nativeGetSyncEnterCustomPassphraseBodyWithDateText(mNativeProfileSyncServiceAndroid);
}
public String getCurrentSignedInAccountText() {
assert isSyncInitialized();
return nativeGetCurrentSignedInAccountText(mNativeProfileSyncServiceAndroid);
}
public String getSyncEnterCustomPassphraseBodyText() {
return nativeGetSyncEnterCustomPassphraseBodyText(mNativeProfileSyncServiceAndroid);
}
public boolean isUsingSecondaryPassphrase() {
assert isSyncInitialized();
return nativeIsUsingSecondaryPassphrase(mNativeProfileSyncServiceAndroid);
}
public boolean isPassphraseRequiredForDecryption() {
assert isSyncInitialized();
return nativeIsPassphraseRequiredForDecryption(mNativeProfileSyncServiceAndroid);
}
public boolean isPassphraseRequiredForExternalType() {
assert isSyncInitialized();
return nativeIsPassphraseRequiredForExternalType(mNativeProfileSyncServiceAndroid);
}
public boolean isSyncInitialized() {
return nativeIsSyncInitialized(mNativeProfileSyncServiceAndroid);
}
public boolean isFirstSetupInProgress() {
return nativeIsFirstSetupInProgress(mNativeProfileSyncServiceAndroid);
}
public boolean isEncryptEverythingEnabled() {
assert isSyncInitialized();
return nativeIsEncryptEverythingEnabled(mNativeProfileSyncServiceAndroid);
}
public void enableEncryptEverything() {
assert isSyncInitialized();
nativeEnableEncryptEverything(mNativeProfileSyncServiceAndroid);
}
public void setEncryptionPassphrase(String passphrase, boolean isGaia) {
assert isSyncInitialized();
nativeSetEncryptionPassphrase(mNativeProfileSyncServiceAndroid, passphrase, isGaia);
}
public boolean isCryptographerReady() {
assert isSyncInitialized();
return nativeIsCryptographerReady(mNativeProfileSyncServiceAndroid);
}
public boolean setDecryptionPassphrase(String passphrase) {
assert isSyncInitialized();
return nativeSetDecryptionPassphrase(mNativeProfileSyncServiceAndroid, passphrase);
}
public GoogleServiceAuthError.State getAuthError() {
int authErrorCode = nativeGetAuthError(mNativeProfileSyncServiceAndroid);
return GoogleServiceAuthError.State.fromCode(authErrorCode);
}
public Set<ModelType> getPreferredDataTypes() {
long modelTypeSelection =
nativeGetEnabledDataTypes(mNativeProfileSyncServiceAndroid);
Set<ModelType> syncTypes = new HashSet<ModelType>();
if ((modelTypeSelection & ModelTypeSelection.AUTOFILL) != 0) {
syncTypes.add(ModelType.AUTOFILL);
}
if ((modelTypeSelection & ModelTypeSelection.AUTOFILL_PROFILE) != 0) {
syncTypes.add(ModelType.AUTOFILL_PROFILE);
}
if ((modelTypeSelection & ModelTypeSelection.BOOKMARK) != 0) {
syncTypes.add(ModelType.BOOKMARK);
}
if ((modelTypeSelection & ModelTypeSelection.EXPERIMENTS) != 0) {
syncTypes.add(ModelType.EXPERIMENTS);
}
if ((modelTypeSelection & ModelTypeSelection.NIGORI) != 0) {
syncTypes.add(ModelType.NIGORI);
}
if ((modelTypeSelection & ModelTypeSelection.PASSWORD) != 0) {
syncTypes.add(ModelType.PASSWORD);
}
if ((modelTypeSelection & ModelTypeSelection.SESSION) != 0) {
syncTypes.add(ModelType.SESSION);
}
if ((modelTypeSelection & ModelTypeSelection.TYPED_URL) != 0) {
syncTypes.add(ModelType.TYPED_URL);
}
if ((modelTypeSelection & ModelTypeSelection.HISTORY_DELETE_DIRECTIVE) != 0) {
syncTypes.add(ModelType.HISTORY_DELETE_DIRECTIVE);
}
if ((modelTypeSelection & ModelTypeSelection.DEVICE_INFO) != 0) {
syncTypes.add(ModelType.DEVICE_INFO);
}
if ((modelTypeSelection & ModelTypeSelection.PROXY_TABS) != 0) {
syncTypes.add(ModelType.PROXY_TABS);
}
if ((modelTypeSelection & ModelTypeSelection.FAVICON_IMAGE) != 0) {
syncTypes.add(ModelType.FAVICON_IMAGE);
}
if ((modelTypeSelection & ModelTypeSelection.FAVICON_TRACKING) != 0) {
syncTypes.add(ModelType.FAVICON_TRACKING);
}
return syncTypes;
}
public boolean hasKeepEverythingSynced() {
return nativeHasKeepEverythingSynced(mNativeProfileSyncServiceAndroid);
}
public void setPreferredDataTypes(boolean syncEverything, Set<ModelType> enabledTypes) {
long modelTypeSelection = 0;
if (syncEverything || enabledTypes.contains(ModelType.AUTOFILL)) {
modelTypeSelection |= ModelTypeSelection.AUTOFILL;
}
if (syncEverything || enabledTypes.contains(ModelType.BOOKMARK)) {
modelTypeSelection |= ModelTypeSelection.BOOKMARK;
}
if (syncEverything || enabledTypes.contains(ModelType.PASSWORD)) {
modelTypeSelection |= ModelTypeSelection.PASSWORD;
}
if (syncEverything || enabledTypes.contains(ModelType.PROXY_TABS)) {
modelTypeSelection |= ModelTypeSelection.PROXY_TABS;
}
if (syncEverything || enabledTypes.contains(ModelType.TYPED_URL)) {
modelTypeSelection |= ModelTypeSelection.TYPED_URL;
}
nativeSetPreferredDataTypes(
mNativeProfileSyncServiceAndroid, syncEverything, modelTypeSelection);
}
public void setSyncSetupCompleted() {
nativeSetSyncSetupCompleted(mNativeProfileSyncServiceAndroid);
}
public boolean hasSyncSetupCompleted() {
return nativeHasSyncSetupCompleted(mNativeProfileSyncServiceAndroid);
}
public boolean isStartSuppressed() {
return nativeIsStartSuppressed(mNativeProfileSyncServiceAndroid);
}
public void setSetupInProgress(boolean inProgress) {
nativeSetSetupInProgress(mNativeProfileSyncServiceAndroid, inProgress);
}
public void addSyncStateChangedListener(SyncStateChangedListener listener) {
ThreadUtils.assertOnUiThread();
mListeners.add(listener);
}
public void removeSyncStateChangedListener(SyncStateChangedListener listener) {
ThreadUtils.assertOnUiThread();
mListeners.remove(listener);
}
public boolean hasUnrecoverableError() {
return nativeHasUnrecoverableError(mNativeProfileSyncServiceAndroid);
}
@CalledByNative
public void syncStateChanged() {
if (!mListeners.isEmpty()) {
for (SyncStateChangedListener listener : mListeners) {
listener.syncStateChanged();
}
}
}
@VisibleForTesting
public String getSyncInternalsInfoForTest() {
ThreadUtils.assertOnUiThread();
return nativeGetAboutInfoForTest(mNativeProfileSyncServiceAndroid);
}
public void enableSync() {
nativeEnableSync(mNativeProfileSyncServiceAndroid);
}
public void disableSync() {
nativeDisableSync(mNativeProfileSyncServiceAndroid);
}
public long getLastSyncedTimeForTest() {
return nativeGetLastSyncedTimeForTest(mNativeProfileSyncServiceAndroid);
}
private native void nativeNudgeSyncer(
long nativeProfileSyncServiceAndroid, int objectSource, String objectId, long version,
String payload);
private native void nativeNudgeSyncerForAllTypes(long nativeProfileSyncServiceAndroid);
private native long nativeInit();
private native void nativeEnableSync(long nativeProfileSyncServiceAndroid);
private native void nativeDisableSync(long nativeProfileSyncServiceAndroid);
private native void nativeSignInSync(long nativeProfileSyncServiceAndroid);
private native void nativeSignOutSync(long nativeProfileSyncServiceAndroid);
private native boolean nativeSetSyncSessionsId(
long nativeProfileSyncServiceAndroid, String tag);
private native String nativeQuerySyncStatusSummary(long nativeProfileSyncServiceAndroid);
private native int nativeGetAuthError(long nativeProfileSyncServiceAndroid);
private native boolean nativeIsSyncInitialized(long nativeProfileSyncServiceAndroid);
private native boolean nativeIsFirstSetupInProgress(long nativeProfileSyncServiceAndroid);
private native boolean nativeIsEncryptEverythingEnabled(long nativeProfileSyncServiceAndroid);
private native void nativeEnableEncryptEverything(long nativeProfileSyncServiceAndroid);
private native boolean nativeIsPassphraseRequiredForDecryption(
long nativeProfileSyncServiceAndroid);
private native boolean nativeIsPassphraseRequiredForExternalType(
long nativeProfileSyncServiceAndroid);
private native boolean nativeIsUsingSecondaryPassphrase(long nativeProfileSyncServiceAndroid);
private native boolean nativeSetDecryptionPassphrase(
long nativeProfileSyncServiceAndroid, String passphrase);
private native void nativeSetEncryptionPassphrase(
long nativeProfileSyncServiceAndroid, String passphrase, boolean isGaia);
private native boolean nativeIsCryptographerReady(long nativeProfileSyncServiceAndroid);
private native int nativeGetPassphraseType(long nativeProfileSyncServiceAndroid);
private native boolean nativeHasExplicitPassphraseTime(long nativeProfileSyncServiceAndroid);
private native String nativeGetSyncEnterGooglePassphraseBodyWithDateText(
long nativeProfileSyncServiceAndroid);
private native String nativeGetSyncEnterCustomPassphraseBodyWithDateText(
long nativeProfileSyncServiceAndroid);
private native String nativeGetCurrentSignedInAccountText(long nativeProfileSyncServiceAndroid);
private native String nativeGetSyncEnterCustomPassphraseBodyText(
long nativeProfileSyncServiceAndroid);
private native boolean nativeIsSyncKeystoreMigrationDone(long nativeProfileSyncServiceAndroid);
private native long nativeGetEnabledDataTypes(
long nativeProfileSyncServiceAndroid);
private native void nativeSetPreferredDataTypes(
long nativeProfileSyncServiceAndroid, boolean syncEverything, long modelTypeSelection);
private native void nativeSetSetupInProgress(
long nativeProfileSyncServiceAndroid, boolean inProgress);
private native void nativeSetSyncSetupCompleted(long nativeProfileSyncServiceAndroid);
private native boolean nativeHasSyncSetupCompleted(long nativeProfileSyncServiceAndroid);
private native boolean nativeIsStartSuppressed(long nativeProfileSyncServiceAndroid);
private native boolean nativeHasKeepEverythingSynced(long nativeProfileSyncServiceAndroid);
private native boolean nativeHasUnrecoverableError(long nativeProfileSyncServiceAndroid);
private native String nativeGetAboutInfoForTest(long nativeProfileSyncServiceAndroid);
private native long nativeGetLastSyncedTimeForTest(long nativeProfileSyncServiceAndroid);
}