This source file includes following definitions.
- AUTOFILL
- AUTOFILL_PROFILE
- BOOKMARK
- EXPERIMENTS
- NIGORI
- PASSWORD
- SESSION
- TYPED_URL
- HISTORY_DELETE_DIRECTIVE
- DEVICE_INFO
- PROXY_TABS
- FAVICON_IMAGE
- FAVICON_TRACKING
- toObjectId
- fromObjectId
- syncTypesToModelTypes
- syncTypesToObjectIds
- modelTypesToObjectIds
- modelTypesToSyncTypes
package org.chromium.sync.internal_api.pub.base;
import android.util.Log;
import com.google.common.annotations.VisibleForTesting;
import com.google.ipc.invalidation.external.client.types.ObjectId;
import com.google.protos.ipc.invalidation.Types;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
public enum ModelType {
AUTOFILL("AUTOFILL"),
AUTOFILL_PROFILE("AUTOFILL_PROFILE"),
BOOKMARK("BOOKMARK"),
EXPERIMENTS("EXPERIMENTS"),
NIGORI("NIGORI"),
PASSWORD("PASSWORD"),
SESSION("SESSION"),
TYPED_URL("TYPED_URL"),
HISTORY_DELETE_DIRECTIVE("HISTORY_DELETE_DIRECTIVE"),
DEVICE_INFO("DEVICE_INFO"),
PROXY_TABS("NULL", true),
FAVICON_IMAGE("FAVICON_IMAGE"),
FAVICON_TRACKING("FAVICON_TRACKING");
public static final String ALL_TYPES_TYPE = "ALL_TYPES";
private static final String TAG = "ModelType";
private final String mModelType;
private final boolean mNonInvalidationType;
ModelType(String modelType, boolean nonInvalidationType) {
mModelType = modelType;
mNonInvalidationType = nonInvalidationType;
}
ModelType(String modelType) {
this(modelType, false);
}
@VisibleForTesting
public ObjectId toObjectId() {
return ObjectId.newInstance(Types.ObjectSource.Type.CHROME_SYNC.getNumber(),
mModelType.getBytes());
}
public static ModelType fromObjectId(ObjectId objectId) {
try {
return valueOf(new String(objectId.getName()));
} catch (IllegalArgumentException e) {
return null;
}
}
public static Set<ModelType> syncTypesToModelTypes(Collection<String> syncTypes) {
if (syncTypes.contains(ALL_TYPES_TYPE)) {
return EnumSet.allOf(ModelType.class);
} else {
Set<ModelType> modelTypes = new HashSet<ModelType>(syncTypes.size());
for (String syncType : syncTypes) {
try {
modelTypes.add(valueOf(syncType));
} catch (IllegalArgumentException exception) {
Log.w(TAG, "Could not translate sync type to model type: " + syncType);
}
}
return modelTypes;
}
}
public static Set<ObjectId> syncTypesToObjectIds(Collection<String> syncTypes) {
return modelTypesToObjectIds(syncTypesToModelTypes(syncTypes));
}
public static Set<ObjectId> modelTypesToObjectIds(Set<ModelType> modelTypes) {
Set<ObjectId> objectIds = new HashSet<ObjectId>(modelTypes.size());
for (ModelType modelType : modelTypes) {
if (!modelType.mNonInvalidationType) {
objectIds.add(modelType.toObjectId());
}
}
return objectIds;
}
public static Set<String> modelTypesToSyncTypes(Set<ModelType> modelTypes) {
Set<String> objectIds = new HashSet<String>(modelTypes.size());
for (ModelType modelType : modelTypes) {
objectIds.add(modelType.toString());
}
return objectIds;
}
}