Commit aae3a263 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

Sync: Delete ModelTypeHelper.java

It was part of the old invalidations implementation, and not used
anymore.
This was the last reference from sync to third_party/cacheinvalidation,
so all references to that are also removed from BUILD.gn and DEPS
files.

Bug: 1099672
Change-Id: I3491fa1cea04d0deebe68988cd3af5a5a4da1afb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2270182
Commit-Queue: Mikel Astiz <mastiz@chromium.org>
Auto-Submit: Marc Treib <treib@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#783025}
parent 380d7656
...@@ -405,17 +405,11 @@ jumbo_static_library("rest_of_sync") { ...@@ -405,17 +405,11 @@ jumbo_static_library("rest_of_sync") {
"//components/variations/net", "//components/variations/net",
"//services/network/public/cpp", "//services/network/public/cpp",
"//sql", "//sql",
"//third_party/cacheinvalidation",
"//third_party/crc32c", "//third_party/crc32c",
"//third_party/zlib/google:compression_utils", "//third_party/zlib/google:compression_utils",
"//ui/base", "//ui/base",
] ]
if (is_android) {
deps += [ "//components/sync/android:jni_headers" ]
sources += [ "android/model_type_helper.cc" ]
}
configs += [ "//build/config/compiler:wexit_time_destructors" ] configs += [ "//build/config/compiler:wexit_time_destructors" ]
} }
......
...@@ -14,13 +14,10 @@ android_library("sync_java") { ...@@ -14,13 +14,10 @@ android_library("sync_java") {
"//third_party/android_deps:androidx_annotation_annotation_java", "//third_party/android_deps:androidx_annotation_annotation_java",
"//third_party/android_deps:com_google_code_findbugs_jsr305_java", "//third_party/android_deps:com_google_code_findbugs_jsr305_java",
"//third_party/android_sdk:android_gcm_java", "//third_party/android_sdk:android_gcm_java",
"//third_party/cacheinvalidation:cacheinvalidation_javalib",
"//third_party/cacheinvalidation:cacheinvalidation_proto_java",
] ]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ] annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
srcjar_deps = [ ":java_enums" ] srcjar_deps = [ ":java_enums" ]
sources = [ sources = [
"java/src/org/chromium/components/sync/ModelTypeHelper.java",
"java/src/org/chromium/components/sync/Passphrase.java", "java/src/org/chromium/components/sync/Passphrase.java",
"java/src/org/chromium/components/sync/SyncConstants.java", "java/src/org/chromium/components/sync/SyncConstants.java",
"java/src/org/chromium/components/sync/SyncContentResolverDelegate.java", "java/src/org/chromium/components/sync/SyncContentResolverDelegate.java",
...@@ -36,7 +33,3 @@ java_cpp_enum("java_enums") { ...@@ -36,7 +33,3 @@ java_cpp_enum("java_enums") {
"//components/sync/driver/sync_service_utils.h", "//components/sync/driver/sync_service_utils.h",
] ]
} }
generate_jni("jni_headers") {
sources = [ "java/src/org/chromium/components/sync/ModelTypeHelper.java" ]
}
...@@ -2,5 +2,4 @@ include_rules = [ ...@@ -2,5 +2,4 @@ include_rules = [
"+components/signin/core/browser/android", "+components/signin/core/browser/android",
"+components/sync/base", "+components/sync/base",
"+components/sync/test/android", # For sync test tools "+components/sync/test/android", # For sync test tools
"+third_party/cacheinvalidation", # For imports in sync/notifier.
] ]
// Copyright 2015 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.components.sync;
import androidx.annotation.VisibleForTesting;
import com.google.ipc.invalidation.external.client.types.ObjectId;
import com.google.protos.ipc.invalidation.Types;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
/**
* Helper methods for dealing with ModelTypes.
*
* This class deals primarily with converting ModelTypes into notification types (string
* representations that are used to register for invalidations) and converting notification
* types into the actual ObjectIds used for invalidations.
*
*/
@JNINamespace("syncer")
public class ModelTypeHelper {
/**
* Implement this class to override the behavior of
* {@link ModelTypeHelper#toNotificationType()} for tests.
*/
public interface TestDelegate { public String toNotificationType(int modelType); }
private static final String TAG = "ModelTypeHelper";
private static final Object sLock = new Object();
private static final int[] NON_INVALIDATION_TYPES_ARRAY = new int[] {ModelType.PROXY_TABS};
private static TestDelegate sDelegate;
// Convenience sets for checking whether a type can have invalidations. Some ModelTypes
// such as PROXY_TABS are not real types and can't be registered. Initializing these
// once reduces toNotificationType() calls in the isInvalidationType() method.
private static Set<String> sNonInvalidationTypes;
/**
* Initializes the non-invalidation sets. Called lazily the first time they're needed.
*/
private static void initNonInvalidationTypes() {
synchronized (sLock) {
if (sNonInvalidationTypes != null) return;
sNonInvalidationTypes = new HashSet<String>();
for (int i = 0; i < NON_INVALIDATION_TYPES_ARRAY.length; i++) {
sNonInvalidationTypes.add(toNotificationType(NON_INVALIDATION_TYPES_ARRAY[i]));
}
}
}
/**
* Checks whether a type is allowed to register for invalidations.
*/
private static boolean isInvalidationType(String notificationType) {
initNonInvalidationTypes();
return !sNonInvalidationTypes.contains(notificationType);
}
/**
* Converts a notification type into an ObjectId.
*
* If the model type is not an invalidation type, this function uses the string "NULL".
*/
private static ObjectId toObjectId(String notificationType) {
String objectIdString = isInvalidationType(notificationType) ? notificationType : "NULL";
return ObjectId.newInstance(
Types.ObjectSource.CHROME_SYNC, ApiCompatibilityUtils.getBytesUtf8(objectIdString));
}
@VisibleForTesting
public static ObjectId toObjectId(int modelType) {
return toObjectId(toNotificationType(modelType));
}
/**
* Converts a model type to its notification type representation using JNI.
*
* This is the value that is stored in the invalidation preferences and used to
* register for invalidations.
*
* @param modelType the model type to convert to a string.
* @return the string representation of the model type constant.
*/
public static String toNotificationType(int modelType) {
if (sDelegate != null) return sDelegate.toNotificationType(modelType);
// Because PROXY_TABS isn't an invalidation type, it doesn't have a string from native,
// but for backwards compatibility we need to keep its pref value the same as the old
// ModelType enum name value.
if (modelType == ModelType.PROXY_TABS) {
return "PROXY_TABS";
}
return ModelTypeHelperJni.get().modelTypeToNotificationType(modelType);
}
/**
* Converts a set of {@link String} notification types to a set of {@link ObjectId}.
*
* This function assumes that all the strings passed in were generated with
* ModelTypeHelper.toNotificationType. Any notification types that are nonInvalidationTypes
* are filtered out.
*/
public static Set<ObjectId> notificationTypesToObjectIds(Collection<String> notificationTypes) {
Set<ObjectId> objectIds = new HashSet<ObjectId>();
for (String notificationType : notificationTypes) {
if (isInvalidationType(notificationType)) {
objectIds.add(toObjectId(notificationType));
}
}
return objectIds;
}
@VisibleForTesting
public static void setTestDelegate(TestDelegate delegate) {
sDelegate = delegate;
}
@NativeMethods
interface Natives {
String modelTypeToNotificationType(int modelType);
}
}
// Copyright 2015 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.
#include <string>
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/notreached.h"
#include "components/sync/android/jni_headers/ModelTypeHelper_jni.h"
#include "components/sync/base/model_type.h"
using base::android::JavaParamRef;
using base::android::ScopedJavaLocalRef;
namespace syncer {
static ScopedJavaLocalRef<jstring>
JNI_ModelTypeHelper_ModelTypeToNotificationType(
JNIEnv* env,
jint model_type_int) {
std::string model_type_string;
ModelType model_type = static_cast<ModelType>(model_type_int);
if (!RealModelTypeToNotificationType(model_type, &model_type_string)) {
NOTREACHED() << "No string representation of model type " << model_type;
}
return base::android::ConvertUTF8ToJavaString(env, model_type_string);
}
} // namespace syncer
...@@ -7,7 +7,6 @@ include_rules = [ ...@@ -7,7 +7,6 @@ include_rules = [
"+components/reading_list/features", "+components/reading_list/features",
"+components/sync/protocol", "+components/sync/protocol",
"+components/sync_preferences", "+components/sync_preferences",
"+google/cacheinvalidation",
"+third_party/metrics_proto", "+third_party/metrics_proto",
"+third_party/zlib", # For UniquePosition compression "+third_party/zlib", # For UniquePosition compression
"+net", "+net",
......
...@@ -18,7 +18,6 @@ include_rules = [ ...@@ -18,7 +18,6 @@ include_rules = [
"+components/sync/protocol", "+components/sync/protocol",
"+components/sync/test", "+components/sync/test",
"+components/sync_preferences", "+components/sync_preferences",
"+google/cacheinvalidation",
"+net", "+net",
"+policy", "+policy",
"+services/network/public/cpp", "+services/network/public/cpp",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment