diff options
author | maxbogue <maxbogue@chromium.org> | 2014-12-08 11:12:46 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-08 19:13:18 +0000 |
commit | 3acb676b7eb268393332bbc4d5c963f82d39d37c (patch) | |
tree | e7cc8d0d036554daf99fe6520e59610d01dc8ce5 /sync | |
parent | b85d3edc109c1844404f7538fbcff5d3984a3433 (diff) | |
download | chromium_src-3acb676b7eb268393332bbc4d5c963f82d39d37c.zip chromium_src-3acb676b7eb268393332bbc4d5c963f82d39d37c.tar.gz chromium_src-3acb676b7eb268393332bbc4d5c963f82d39d37c.tar.bz2 |
Add PassphraseType to replace SyncDecryptionPassphraseType.
PassphraseType does not have the extra INVALID and NONE values that
SyncDecryptionPassphraseType does; it matches the C++ side.
Review URL: https://codereview.chromium.org/779333003
Cr-Commit-Position: refs/heads/master@{#307299}
Diffstat (limited to 'sync')
-rw-r--r-- | sync/android/java/src/org/chromium/sync/internal_api/pub/PassphraseType.java | 111 | ||||
-rw-r--r-- | sync/android/java/src/org/chromium/sync/internal_api/pub/SyncDecryptionPassphraseType.java | 9 |
2 files changed, 111 insertions, 9 deletions
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; |