Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Move passphrase dialog logic to the enum.
Browse files Browse the repository at this point in the history
In preparation for a bug fix.

BUG=419927

Review URL: https://codereview.chromium.org/642623002

Cr-Commit-Position: refs/heads/master@{#298900}
  • Loading branch information
maxbogue authored and Commit bot committed Oct 9, 2014
1 parent 2bcfdba commit cd77acb
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
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.
*
Expand Down Expand Up @@ -51,6 +54,50 @@ private SyncDecryptionPassphraseType(int nativeValue) {
mNativeValue = nativeValue;
}


public Set<SyncDecryptionPassphraseType> getVisibleTypes() {
Set<SyncDecryptionPassphraseType> visibleTypes = new HashSet<>();
switch (this) {
case NONE: // Intentional fall through.
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;
case INVALID: // Intentional fall through.
default:
visibleTypes.add(this);
break;
}
return visibleTypes;
}

public Set<SyncDecryptionPassphraseType> getAllowedTypes() {
Set<SyncDecryptionPassphraseType> allowedTypes = new HashSet<>();
switch (this) {
case NONE: // Intentional fall through.
case IMPLICIT_PASSPHRASE: // Intentional fall through.
case KEYSTORE_PASSPHRASE:
allowedTypes.add(this);
allowedTypes.add(CUSTOM_PASSPHRASE);
break;
case FROZEN_IMPLICIT_PASSPHRASE: // Intentional fall through.
case CUSTOM_PASSPHRASE: // Intentional fall through.
case INVALID: // 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;
Expand Down

0 comments on commit cd77acb

Please sign in to comment.