summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/sync/ProfileSyncService.java23
-rw-r--r--sync/android/java/src/org/chromium/sync/internal_api/pub/PassphraseType.java111
-rw-r--r--sync/android/java/src/org/chromium/sync/internal_api/pub/SyncDecryptionPassphraseType.java9
3 files changed, 130 insertions, 13 deletions
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/sync/ProfileSyncService.java b/chrome/android/java/src/org/chromium/chrome/browser/sync/ProfileSyncService.java
index df8c885..9ee9833 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/sync/ProfileSyncService.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/sync/ProfileSyncService.java
@@ -17,6 +17,7 @@ import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.identity.UniqueIdentificationGenerator;
import org.chromium.chrome.browser.invalidation.InvalidationServiceFactory;
import org.chromium.chrome.browser.profiles.Profile;
+import org.chromium.sync.internal_api.pub.PassphraseType;
import org.chromium.sync.internal_api.pub.SyncDecryptionPassphraseType;
import org.chromium.sync.internal_api.pub.base.ModelType;
@@ -178,14 +179,14 @@ public class ProfileSyncService {
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.");
+ 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.");
+ Log.e(TAG, "Unable to write session sync tag. "
+ + "This may lead to unexpected tab sync behavior.");
}
}
@@ -223,6 +224,20 @@ public class ProfileSyncService {
return SyncDecryptionPassphraseType.fromInternalValue(passphraseType);
}
+ /**
+ * Returns the actual passphrase type being used for encryption.
+ * The sync backend must be running (isSyncInitialized() returns true) before
+ * calling this function.
+ * <p/>
+ * This method should only be used if you want to know the raw value. For checking whether
+ * we should ask the user for a passphrase, use isPassphraseRequiredForDecryption().
+ */
+ public PassphraseType getPassphraseType() {
+ assert isSyncInitialized();
+ int passphraseType = nativeGetPassphraseType(mNativeProfileSyncServiceAndroid);
+ return PassphraseType.fromInternalValue(passphraseType);
+ }
+
public boolean isSyncKeystoreMigrationDone() {
assert isSyncInitialized();
return nativeIsSyncKeystoreMigrationDone(mNativeProfileSyncServiceAndroid);
diff --git a/sync/android/java/src/org/chromium/sync/internal_api/pub/PassphraseType.java b/sync/android/java/src/org/chromium/sync/internal_api/pub/PassphraseType.java
new file mode 100644
index 0000000..4802881
--- /dev/null
+++ b/sync/android/java/src/org/chromium/sync/internal_api/pub/PassphraseType.java
@@ -0,0 +1,111 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.sync.internal_api.pub;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * This enum describes the type of passphrase required, if any, to decrypt synced data.
+ *
+ * It implements the Android {@link Parcelable} interface so it is easy to pass around in intents.
+ *
+ * It maps the native enum syncer::PassphraseType.
+ */
+public enum PassphraseType implements Parcelable {
+ IMPLICIT_PASSPHRASE(0), // GAIA-based passphrase (deprecated).
+ KEYSTORE_PASSPHRASE(1), // Keystore passphrase.
+ FROZEN_IMPLICIT_PASSPHRASE(2), // Frozen GAIA passphrase.
+ CUSTOM_PASSPHRASE(3); // User-provided passphrase.
+
+ public static Parcelable.Creator CREATOR =
+ new Parcelable.Creator<PassphraseType>() {
+ @Override
+ public PassphraseType createFromParcel(Parcel parcel) {
+ return fromInternalValue(parcel.readInt());
+ }
+
+ @Override
+ public PassphraseType[] newArray(int size) {
+ return new PassphraseType[size];
+ }
+ };
+
+ public static PassphraseType fromInternalValue(int value) {
+ for (PassphraseType type : values()) {
+ if (type.internalValue() == value) {
+ return type;
+ }
+ }
+ throw new IllegalArgumentException("No value for " + value + " found.");
+ }
+
+ private final int mNativeValue;
+
+ private PassphraseType(int nativeValue) {
+ mNativeValue = nativeValue;
+ }
+
+ public Set<PassphraseType> getVisibleTypes() {
+ Set<PassphraseType> visibleTypes = new HashSet<>();
+ switch (this) {
+ case IMPLICIT_PASSPHRASE: // Intentional fall through.
+ case KEYSTORE_PASSPHRASE:
+ visibleTypes.add(this);
+ visibleTypes.add(CUSTOM_PASSPHRASE);
+ break;
+ case FROZEN_IMPLICIT_PASSPHRASE:
+ visibleTypes.add(KEYSTORE_PASSPHRASE);
+ visibleTypes.add(FROZEN_IMPLICIT_PASSPHRASE);
+ break;
+ case CUSTOM_PASSPHRASE:
+ visibleTypes.add(KEYSTORE_PASSPHRASE);
+ visibleTypes.add(CUSTOM_PASSPHRASE);
+ break;
+ }
+ return visibleTypes;
+ }
+
+ /**
+ * Get the types that are allowed to be enabled from the current type.
+ *
+ * @param encryptEverythingAllowed Whether encrypting all data is allowed.
+ */
+ public Set<PassphraseType> getAllowedTypes(boolean encryptEverythingAllowed) {
+ Set<PassphraseType> allowedTypes = new HashSet<>();
+ switch (this) {
+ case IMPLICIT_PASSPHRASE: // Intentional fall through.
+ case KEYSTORE_PASSPHRASE:
+ allowedTypes.add(this);
+ if (encryptEverythingAllowed) {
+ allowedTypes.add(CUSTOM_PASSPHRASE);
+ }
+ break;
+ case FROZEN_IMPLICIT_PASSPHRASE: // Intentional fall through.
+ case CUSTOM_PASSPHRASE: // Intentional fall through.
+ default:
+ break;
+ }
+ return allowedTypes;
+ }
+
+ public int internalValue() {
+ // Since the values in this enums are constant and very small, this cast is safe.
+ return mNativeValue;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(mNativeValue);
+ }
+}
diff --git a/sync/android/java/src/org/chromium/sync/internal_api/pub/SyncDecryptionPassphraseType.java b/sync/android/java/src/org/chromium/sync/internal_api/pub/SyncDecryptionPassphraseType.java
index 2437953..3190c77 100644
--- a/sync/android/java/src/org/chromium/sync/internal_api/pub/SyncDecryptionPassphraseType.java
+++ b/sync/android/java/src/org/chromium/sync/internal_api/pub/SyncDecryptionPassphraseType.java
@@ -54,7 +54,6 @@ public enum SyncDecryptionPassphraseType implements Parcelable {
mNativeValue = nativeValue;
}
-
public Set<SyncDecryptionPassphraseType> getVisibleTypes() {
Set<SyncDecryptionPassphraseType> visibleTypes = new HashSet<>();
switch (this) {
@@ -105,14 +104,6 @@ public enum SyncDecryptionPassphraseType implements Parcelable {
return allowedTypes;
}
- /**
- * TODO(maxbogue): Remove when no longer used in Clank; see http://crbug.com/424187.
- */
- @Deprecated
- public Set<SyncDecryptionPassphraseType> getAllowedTypes() {
- return getAllowedTypes(true);
- }
-
public int internalValue() {
// Since the values in this enums are constant and very small, this cast is safe.
return mNativeValue;