summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-27 21:18:18 +0000
committerzea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-27 21:18:18 +0000
commit6805b60643ae360b5350f97209a420ee46161fee (patch)
tree414704d0e4ea9d8767cdcffd115ec53f56a5cd94
parentd06bcaca1a000d55e80d9cbf0865eb32f7668ba1 (diff)
downloadchromium_src-6805b60643ae360b5350f97209a420ee46161fee.zip
chromium_src-6805b60643ae360b5350f97209a420ee46161fee.tar.gz
chromium_src-6805b60643ae360b5350f97209a420ee46161fee.tar.bz2
[Sync] Move Android enabled types logic into native
This adds a JNI method to get the set of enabled types, which is then used in registering for invalidations. BUG=224144 Review URL: https://chromiumcodereview.appspot.com/13109002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191025 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/sync/ProfileSyncService.java54
-rw-r--r--chrome/browser/sync/profile_sync_service_android.cc84
-rw-r--r--chrome/browser/sync/profile_sync_service_android.h21
-rw-r--r--chrome/browser/sync/profile_sync_service_model_type_selection_android.h30
-rw-r--r--sync/android/java/src/org/chromium/sync/internal_api/pub/base/ModelType.java59
-rw-r--r--sync/android/java/src/org/chromium/sync/notifier/InvalidationController.java26
-rw-r--r--sync/android/java/src/org/chromium/sync/notifier/ModelTypeResolver.java17
-rw-r--r--sync/android/java/src/org/chromium/sync/notifier/ModelTypeResolverImpl.java37
-rw-r--r--sync/android/javatests/src/org/chromium/sync/notifier/InvalidationControllerTest.java23
-rw-r--r--sync/android/javatests/src/org/chromium/sync/notifier/ModelTypeResolverTest.java72
10 files changed, 165 insertions, 258 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 3b28021..b7d3c2a 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
@@ -420,22 +420,47 @@ public class ProfileSyncService {
* @return Set of enabled types.
*/
public Set<ModelType> getPreferredDataTypes() {
+ long modelTypeSelection =
+ nativeGetEnabledDataTypes(mNativeProfileSyncServiceAndroid);
Set<ModelType> syncTypes = new HashSet<ModelType>();
-
- if (nativeIsAutofillSyncEnabled(mNativeProfileSyncServiceAndroid)) {
- syncTypes.add(ModelType.AUTOFILL);
+ if ((modelTypeSelection & ModelTypeSelection.AUTOFILL) != 0) {
+ syncTypes.add(ModelType.AUTOFILL);
+ }
+ if ((modelTypeSelection & ModelTypeSelection.AUTOFILL_PROFILE) != 0) {
+ syncTypes.add(ModelType.AUTOFILL_PROFILE);
+ }
+ if ((modelTypeSelection & ModelTypeSelection.BOOKMARK) != 0) {
+ syncTypes.add(ModelType.BOOKMARK);
+ }
+ if ((modelTypeSelection & ModelTypeSelection.EXPERIMENTS) != 0) {
+ syncTypes.add(ModelType.EXPERIMENTS);
+ }
+ if ((modelTypeSelection & ModelTypeSelection.NIGORI) != 0) {
+ syncTypes.add(ModelType.NIGORI);
+ }
+ if ((modelTypeSelection & ModelTypeSelection.PASSWORD) != 0) {
+ syncTypes.add(ModelType.PASSWORD);
+ }
+ if ((modelTypeSelection & ModelTypeSelection.SESSION) != 0) {
+ syncTypes.add(ModelType.SESSION);
+ }
+ if ((modelTypeSelection & ModelTypeSelection.TYPED_URL) != 0) {
+ syncTypes.add(ModelType.TYPED_URL);
+ }
+ if ((modelTypeSelection & ModelTypeSelection.HISTORY_DELETE_DIRECTIVE) != 0) {
+ syncTypes.add(ModelType.HISTORY_DELETE_DIRECTIVE);
}
- if (nativeIsBookmarkSyncEnabled(mNativeProfileSyncServiceAndroid)) {
- syncTypes.add(ModelType.BOOKMARK);
+ if ((modelTypeSelection & ModelTypeSelection.DEVICE_INFO) != 0) {
+ syncTypes.add(ModelType.DEVICE_INFO);
}
- if (nativeIsPasswordSyncEnabled(mNativeProfileSyncServiceAndroid)) {
- syncTypes.add(ModelType.PASSWORD);
+ if ((modelTypeSelection & ModelTypeSelection.PROXY_TABS) != 0) {
+ syncTypes.add(ModelType.PROXY_TABS);
}
- if (nativeIsTypedUrlSyncEnabled(mNativeProfileSyncServiceAndroid)) {
- syncTypes.add(ModelType.TYPED_URL);
+ if ((modelTypeSelection & ModelTypeSelection.FAVICON_IMAGE) != 0) {
+ syncTypes.add(ModelType.FAVICON_IMAGE);
}
- if (nativeIsSessionSyncEnabled(mNativeProfileSyncServiceAndroid)) {
- syncTypes.add(ModelType.SESSION);
+ if ((modelTypeSelection & ModelTypeSelection.FAVICON_TRACKING) != 0) {
+ syncTypes.add(ModelType.FAVICON_TRACKING);
}
return syncTypes;
}
@@ -577,6 +602,8 @@ public class ProfileSyncService {
private native String nativeGetSyncEnterCustomPassphraseBodyText(
int nativeProfileSyncServiceAndroid);
private native boolean nativeIsSyncKeystoreMigrationDone(int nativeProfileSyncServiceAndroid);
+ private native long nativeGetEnabledDataTypes(
+ int nativeProfileSyncServiceAndroid);
private native void nativeSetPreferredDataTypes(
int nativeProfileSyncServiceAndroid, boolean syncEverything, long modelTypeSelection);
private native void nativeSetSetupInProgress(
@@ -584,11 +611,6 @@ public class ProfileSyncService {
private native void nativeSetSyncSetupCompleted(int nativeProfileSyncServiceAndroid);
private native boolean nativeHasSyncSetupCompleted(int nativeProfileSyncServiceAndroid);
private native boolean nativeHasKeepEverythingSynced(int nativeProfileSyncServiceAndroid);
- private native boolean nativeIsAutofillSyncEnabled(int nativeProfileSyncServiceAndroid);
- private native boolean nativeIsBookmarkSyncEnabled(int nativeProfileSyncServiceAndroid);
- private native boolean nativeIsPasswordSyncEnabled(int nativeProfileSyncServiceAndroid);
- private native boolean nativeIsTypedUrlSyncEnabled(int nativeProfileSyncServiceAndroid);
- private native boolean nativeIsSessionSyncEnabled(int nativeProfileSyncServiceAndroid);
private native boolean nativeHasUnrecoverableError(int nativeProfileSyncServiceAndroid);
private native String nativeGetAboutInfoForTest(int nativeProfileSyncServiceAndroid);
private native void nativeOAuth2TokenFetched(
diff --git a/chrome/browser/sync/profile_sync_service_android.cc b/chrome/browser/sync/profile_sync_service_android.cc
index c2cf934..b20e7d8 100644
--- a/chrome/browser/sync/profile_sync_service_android.cc
+++ b/chrome/browser/sync/profile_sync_service_android.cc
@@ -461,12 +461,60 @@ jboolean ProfileSyncServiceAndroid::IsSyncKeystoreMigrationDone(
return is_status_valid && !status.keystore_migration_time.is_null();
}
+jlong ProfileSyncServiceAndroid::GetEnabledDataTypes(JNIEnv* env,
+ jobject obj) {
+ jlong model_type_selection = 0;
+ syncer::ModelTypeSet types = sync_service_->GetPreferredDataTypes();
+ types.PutAll(syncer::ControlTypes());
+ if (types.Has(syncer::BOOKMARKS)) {
+ model_type_selection |= BOOKMARK;
+ }
+ if (types.Has(syncer::AUTOFILL)) {
+ model_type_selection |= AUTOFILL;
+ }
+ if (types.Has(syncer::AUTOFILL_PROFILE)) {
+ model_type_selection |= AUTOFILL_PROFILE;
+ }
+ if (types.Has(syncer::PASSWORDS)) {
+ model_type_selection |= PASSWORD;
+ }
+ if (types.Has(syncer::TYPED_URLS)) {
+ model_type_selection |= TYPED_URL;
+ }
+ if (types.Has(syncer::SESSIONS)) {
+ model_type_selection |= SESSION;
+ }
+ if (types.Has(syncer::HISTORY_DELETE_DIRECTIVES)) {
+ model_type_selection |= HISTORY_DELETE_DIRECTIVE;
+ }
+ if (types.Has(syncer::PROXY_TABS)) {
+ model_type_selection |= PROXY_TABS;
+ }
+ if (types.Has(syncer::FAVICON_IMAGES)) {
+ model_type_selection |= FAVICON_IMAGE;
+ }
+ if (types.Has(syncer::FAVICON_TRACKING)) {
+ model_type_selection |= FAVICON_TRACKING;
+ }
+ if (types.Has(syncer::DEVICE_INFO)) {
+ model_type_selection |= DEVICE_INFO;
+ }
+ if (types.Has(syncer::NIGORI)) {
+ model_type_selection |= NIGORI;
+ }
+ if (types.Has(syncer::EXPERIMENTS)) {
+ model_type_selection |= EXPERIMENTS;
+ }
+ return model_type_selection;
+}
+
void ProfileSyncServiceAndroid::SetPreferredDataTypes(
JNIEnv* env, jobject obj,
jboolean sync_everything,
jlong model_type_selection) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
syncer::ModelTypeSet types;
+ // Note: only user selectable types should be included here.
if (model_type_selection & AUTOFILL)
types.Put(syncer::AUTOFILL);
if (model_type_selection & BOOKMARK)
@@ -477,6 +525,7 @@ void ProfileSyncServiceAndroid::SetPreferredDataTypes(
types.Put(syncer::SESSIONS);
if (model_type_selection & TYPED_URL)
types.Put(syncer::TYPED_URLS);
+ DCHECK(syncer::UserSelectableTypes().HasAll(types));
sync_service_->OnUserChoseDatatypes(sync_everything, types);
}
@@ -511,41 +560,6 @@ jboolean ProfileSyncServiceAndroid::HasKeepEverythingSynced(
return prefs.HasKeepEverythingSynced();
}
-jboolean ProfileSyncServiceAndroid::IsAutofillSyncEnabled(
- JNIEnv* env, jobject obj) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- return HasKeepEverythingSynced(env, obj) ||
- sync_service_->GetPreferredDataTypes().Has(syncer::AUTOFILL);
-}
-
-jboolean ProfileSyncServiceAndroid::IsBookmarkSyncEnabled(
- JNIEnv* env, jobject obj) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- return HasKeepEverythingSynced(env, obj) ||
- sync_service_->GetPreferredDataTypes().Has(syncer::BOOKMARKS);
-}
-
-jboolean ProfileSyncServiceAndroid::IsPasswordSyncEnabled(
- JNIEnv* env, jobject obj) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- return HasKeepEverythingSynced(env, obj) ||
- sync_service_->GetPreferredDataTypes().Has(syncer::PASSWORDS);
-}
-
-jboolean ProfileSyncServiceAndroid::IsTypedUrlSyncEnabled(
- JNIEnv* env, jobject obj) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- return HasKeepEverythingSynced(env, obj) ||
- sync_service_->GetPreferredDataTypes().Has(syncer::TYPED_URLS);
-}
-
-jboolean ProfileSyncServiceAndroid::IsSessionSyncEnabled(
- JNIEnv* env, jobject obj) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- return HasKeepEverythingSynced(env, obj) ||
- sync_service_->GetPreferredDataTypes().Has(syncer::SESSIONS);
-}
-
jboolean ProfileSyncServiceAndroid::HasUnrecoverableError(
JNIEnv* env, jobject) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
diff --git a/chrome/browser/sync/profile_sync_service_android.h b/chrome/browser/sync/profile_sync_service_android.h
index 0495a04..a43c7d4 100644
--- a/chrome/browser/sync/profile_sync_service_android.h
+++ b/chrome/browser/sync/profile_sync_service_android.h
@@ -149,6 +149,12 @@ class ProfileSyncServiceAndroid : public ProfileSyncServiceObserver {
// Returns true if sync has been migrated.
jboolean IsSyncKeystoreMigrationDone(JNIEnv* env, jobject obj);
+ // Get the set of enabled data types. These are the types currently both
+ // registered and preferred. Note that control types are always included here.
+ // Returns a bit map of the values from
+ // profile_sync_service_model_type_selection_android.h.
+ jlong GetEnabledDataTypes(JNIEnv* env, jobject obj);
+
// Enables the passed data types.
// If |sync_everything| is true, then all data types are enabled and the
// contents of |model_type_selection| is
@@ -173,21 +179,6 @@ class ProfileSyncServiceAndroid : public ProfileSyncServiceObserver {
// Returns true if sync is configured to "sync everything".
jboolean HasKeepEverythingSynced(JNIEnv* env, jobject obj);
- // Returns true if the user has autofill sync enabled.
- jboolean IsAutofillSyncEnabled(JNIEnv* env, jobject obj);
-
- // Returns true if the user has bookmark sync enabled.
- jboolean IsBookmarkSyncEnabled(JNIEnv* env, jobject obj);
-
- // Returns true if the user has password sync enabled.
- jboolean IsPasswordSyncEnabled(JNIEnv* env, jobject obj);
-
- // Returns true if the user has typed URL sync enabled.
- jboolean IsTypedUrlSyncEnabled(JNIEnv* env, jobject obj);
-
- // Returns true if the user has session sync enabled.
- jboolean IsSessionSyncEnabled(JNIEnv* env, jobject obj);
-
// Turns on encryption for all data types. This is an asynchronous operation
// which happens after the current configuration pass is done, so a call to
// this routine must be followed by a call to SetEnabledDataTypes().
diff --git a/chrome/browser/sync/profile_sync_service_model_type_selection_android.h b/chrome/browser/sync/profile_sync_service_model_type_selection_android.h
index 3628596..822814d 100644
--- a/chrome/browser/sync/profile_sync_service_model_type_selection_android.h
+++ b/chrome/browser/sync/profile_sync_service_model_type_selection_android.h
@@ -5,15 +5,31 @@
// This file intentionally does not have header guards, it's included
// inside a macro to generate enum.
-// This file contains the list of sync ModelTypes that Android can select as
-// preferred types.
+// This file contains the list of sync ModelTypes that Android can register for
+// invalidations for.
-DEFINE_MODEL_TYPE_SELECTION(AUTOFILL, 1)
+DEFINE_MODEL_TYPE_SELECTION(AUTOFILL, 1<<0)
-DEFINE_MODEL_TYPE_SELECTION(BOOKMARK, 2)
+DEFINE_MODEL_TYPE_SELECTION(BOOKMARK, 1<<1)
-DEFINE_MODEL_TYPE_SELECTION(PASSWORD, 4)
+DEFINE_MODEL_TYPE_SELECTION(PASSWORD, 1<<2)
-DEFINE_MODEL_TYPE_SELECTION(SESSION, 8)
+DEFINE_MODEL_TYPE_SELECTION(SESSION, 1<<3)
-DEFINE_MODEL_TYPE_SELECTION(TYPED_URL, 16)
+DEFINE_MODEL_TYPE_SELECTION(TYPED_URL, 1<<4)
+
+DEFINE_MODEL_TYPE_SELECTION(AUTOFILL_PROFILE, 1<<5)
+
+DEFINE_MODEL_TYPE_SELECTION(HISTORY_DELETE_DIRECTIVE, 1<<6)
+
+DEFINE_MODEL_TYPE_SELECTION(PROXY_TABS, 1<<7)
+
+DEFINE_MODEL_TYPE_SELECTION(FAVICON_IMAGE, 1<<8)
+
+DEFINE_MODEL_TYPE_SELECTION(FAVICON_TRACKING, 1<<9)
+
+DEFINE_MODEL_TYPE_SELECTION(NIGORI, 1<<10)
+
+DEFINE_MODEL_TYPE_SELECTION(DEVICE_INFO, 1<<11)
+
+DEFINE_MODEL_TYPE_SELECTION(EXPERIMENTS, 1<<12)
diff --git a/sync/android/java/src/org/chromium/sync/internal_api/pub/base/ModelType.java b/sync/android/java/src/org/chromium/sync/internal_api/pub/base/ModelType.java
index 4ada2fe..2b0ad85 100644
--- a/sync/android/java/src/org/chromium/sync/internal_api/pub/base/ModelType.java
+++ b/sync/android/java/src/org/chromium/sync/internal_api/pub/base/ModelType.java
@@ -35,11 +35,11 @@ public enum ModelType {
/**
* Flags to enable experimental features.
*/
- EXPERIMENTS("EXPERIMENTS", true),
+ EXPERIMENTS("EXPERIMENTS"),
/**
* An object representing a set of Nigori keys.
*/
- NIGORI("NIGORI", true),
+ NIGORI("NIGORI"),
/**
* A password entry.
*/
@@ -51,7 +51,27 @@ public enum ModelType {
/**
* A typed_url folder or a typed_url object.
*/
- TYPED_URL("TYPED_URL");
+ TYPED_URL("TYPED_URL"),
+ /**
+ * A history delete directive object.
+ */
+ HISTORY_DELETE_DIRECTIVE("HISTORY_DELETE_DIRECTIVE"),
+ /**
+ * A device info object.
+ */
+ DEVICE_INFO("DEVICE_INFO"),
+ /**
+ * A proxy tabs object (placeholder for sessions).
+ */
+ PROXY_TABS("NULL"),
+ /**
+ * A favicon image object.
+ */
+ FAVICON_IMAGE("FAVICON_IMAGE"),
+ /**
+ * A favicon tracking object.
+ */
+ FAVICON_TRACKING("FAVICON_TRACKING");
/** Special type representing all possible types. */
public static final String ALL_TYPES_TYPE = "ALL_TYPES";
@@ -60,18 +80,8 @@ public enum ModelType {
private final String mModelType;
- /**
- * True if this is a control type.
- */
- private final boolean mControl;
-
ModelType(String modelType) {
- this(modelType, false);
- }
-
- ModelType(String modelType, boolean control) {
mModelType = modelType;
- mControl = control;
}
public ObjectId toObjectId() {
@@ -131,27 +141,4 @@ public enum ModelType {
}
return objectIds;
}
-
- /**
- * Returns a set of all the control {@link ModelType}s.
- */
- public static Set<ModelType> controlTypes() {
- Set<ModelType> controlTypes = new HashSet<ModelType>();
- for (ModelType modelType : values()) {
- if (modelType.mControl) {
- controlTypes.add(modelType);
- }
- }
- return controlTypes;
- }
-
- /**
- * Returns a Multimap of all the {@link ModelType} groups. The key is the main
- * {@link ModelType}, and the value is a collection of {@link ModelType}s in the same group.
- */
- public static Multimap<ModelType, ModelType> modelTypeGroups() {
- Multimap<ModelType, ModelType> modelTypeGroups = HashMultimap.create();
- modelTypeGroups.put(AUTOFILL, AUTOFILL_PROFILE);
- return modelTypeGroups;
- }
}
diff --git a/sync/android/java/src/org/chromium/sync/notifier/InvalidationController.java b/sync/android/java/src/org/chromium/sync/notifier/InvalidationController.java
index cd98293..aa6b3d3 100644
--- a/sync/android/java/src/org/chromium/sync/notifier/InvalidationController.java
+++ b/sync/android/java/src/org/chromium/sync/notifier/InvalidationController.java
@@ -119,7 +119,9 @@ public class InvalidationController implements ActivityStatus.StateListener {
* @param types Set of types for which to register. Ignored if {@code allTypes == true}.
*/
public void setRegisteredTypes(Account account, boolean allTypes, Set<ModelType> types) {
- Set<ModelType> typesToRegister = getModelTypeResolver().resolveModelTypes(types);
+ Set<ModelType> typesToRegister = types;
+ // Proxy types should never receive notifications.
+ typesToRegister.remove(ModelType.PROXY_TABS);
Intent registerIntent = IntentProtocol.createRegisterIntent(account, allTypes,
typesToRegister);
setDestinationClassName(registerIntent);
@@ -132,6 +134,7 @@ public class InvalidationController implements ActivityStatus.StateListener {
* values. It can be used on startup of Chrome to ensure we always have a consistent set of
* registrations.
*/
+ @Deprecated
public void refreshRegisteredTypes() {
InvalidationPreferences invalidationPreferences = new InvalidationPreferences(mContext);
Set<String> savedSyncedTypes = invalidationPreferences.getSavedSyncedTypes();
@@ -144,6 +147,22 @@ public class InvalidationController implements ActivityStatus.StateListener {
}
/**
+ * Reads all stored preferences and calls
+ * {@link #setRegisteredTypes(android.accounts.Account, boolean, java.util.Set)} with the stored
+ * values, refreshing the set of types with {@code types}. It can be used on startup of Chrome
+ * to ensure we always have a set of registrations consistent with the native code.
+ * @param types Set of types for which to register.
+ */
+ public void refreshRegisteredTypes(Set<ModelType> types) {
+ InvalidationPreferences invalidationPreferences = new InvalidationPreferences(mContext);
+ Set<String> savedSyncedTypes = invalidationPreferences.getSavedSyncedTypes();
+ Account account = invalidationPreferences.getSavedSyncedAccount();
+ boolean allTypes = savedSyncedTypes != null &&
+ savedSyncedTypes.contains(ModelType.ALL_TYPES_TYPE);
+ setRegisteredTypes(account, allTypes, types);
+ }
+
+ /**
* Starts the invalidation client.
*/
public void start() {
@@ -240,11 +259,6 @@ public class InvalidationController implements ActivityStatus.StateListener {
return null;
}
- @VisibleForTesting
- ModelTypeResolver getModelTypeResolver() {
- return new ModelTypeResolverImpl();
- }
-
@Override
public void onActivityStateChange(int newState) {
if (SyncStatusHelper.get(mContext).isSyncEnabled()) {
diff --git a/sync/android/java/src/org/chromium/sync/notifier/ModelTypeResolver.java b/sync/android/java/src/org/chromium/sync/notifier/ModelTypeResolver.java
deleted file mode 100644
index 7a30e2f..0000000
--- a/sync/android/java/src/org/chromium/sync/notifier/ModelTypeResolver.java
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright (c) 2013 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.notifier;
-
-import org.chromium.sync.internal_api.pub.base.ModelType;
-
-import java.util.Set;
-
-/**
- * A utility class that supports groups of {@link ModelType}s and also supports adding the default
- * set of {@link ModelType}s.
- */
-interface ModelTypeResolver {
- Set<ModelType> resolveModelTypes(Set<ModelType> modelTypes);
-}
diff --git a/sync/android/java/src/org/chromium/sync/notifier/ModelTypeResolverImpl.java b/sync/android/java/src/org/chromium/sync/notifier/ModelTypeResolverImpl.java
deleted file mode 100644
index 27a8e6d..0000000
--- a/sync/android/java/src/org/chromium/sync/notifier/ModelTypeResolverImpl.java
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright (c) 2013 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.notifier;
-
-import com.google.common.collect.Multimap;
-
-import org.chromium.sync.internal_api.pub.base.ModelType;
-
-import java.util.HashSet;
-import java.util.Set;
-
-class ModelTypeResolverImpl implements ModelTypeResolver {
- @Override
- public Set<ModelType> resolveModelTypes(Set<ModelType> modelTypes) {
- // Create a new set that we will return as a result, and add all original ModelTypes.
- Set<ModelType> typesWithGroups = new HashSet<ModelType>();
- Set<ModelType> modelTypesNonNull =
- modelTypes == null ? new HashSet<ModelType>() : modelTypes;
- typesWithGroups.addAll(modelTypesNonNull);
-
- Multimap<ModelType, ModelType> modelTypeGroups = ModelType.modelTypeGroups();
- // Remove ModelTypes that are specified, that does not have their group ModelType specified.
- for (ModelType modelType : modelTypeGroups.keySet()) {
- if (modelTypesNonNull.contains(modelType)) {
- typesWithGroups.addAll(modelTypeGroups.get(modelType));
- } else {
- typesWithGroups.removeAll(modelTypeGroups.get(modelType));
- }
- }
-
- // Add all control types.
- typesWithGroups.addAll(ModelType.controlTypes());
- return typesWithGroups;
- }
-}
diff --git a/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationControllerTest.java b/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationControllerTest.java
index bd5398a..90d4db9 100644
--- a/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationControllerTest.java
+++ b/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationControllerTest.java
@@ -152,20 +152,7 @@ public class InvalidationControllerTest extends InstrumentationTestCase {
@SmallTest
@Feature({"Sync"})
public void testRegisterForSpecificTypes() {
- final String controllerFlag = "resolveModelTypes";
- final ModelTypeResolver resolver = new ModelTypeResolver() {
- @Override
- public Set<ModelType> resolveModelTypes(Set<ModelType> modelTypes) {
- mContext.setFlag(controllerFlag);
- return modelTypes;
- }
- };
- InvalidationController controller = new InvalidationController(mContext) {
- @Override
- ModelTypeResolver getModelTypeResolver() {
- return resolver;
- }
- };
+ InvalidationController controller = new InvalidationController(mContext);
Account account = new Account("test@example.com", "bogus");
controller.setRegisteredTypes(account, false,
Sets.newHashSet(ModelType.BOOKMARK, ModelType.SESSION));
@@ -186,7 +173,6 @@ public class InvalidationControllerTest extends InstrumentationTestCase {
Set<String> actualTypes = Sets.newHashSet();
actualTypes.addAll(intent.getStringArrayListExtra(IntentProtocol.EXTRA_REGISTERED_TYPES));
assertEquals(expectedTypes, actualTypes);
- assertTrue(mContext.isFlagSet(controllerFlag));
}
@SmallTest
@@ -223,6 +209,9 @@ public class InvalidationControllerTest extends InstrumentationTestCase {
Set<String> storedModelTypes = new HashSet<String>();
storedModelTypes.add(ModelType.BOOKMARK.name());
storedModelTypes.add(ModelType.TYPED_URL.name());
+ Set<ModelType> refreshedTypes = new HashSet<ModelType>();
+ refreshedTypes.add(ModelType.BOOKMARK);
+ refreshedTypes.add(ModelType.TYPED_URL);
invalidationPreferences.setSyncTypes(edit, storedModelTypes);
Account storedAccount = AccountManagerHelper.createAccountFromName("test@gmail.com");
invalidationPreferences.setAccount(edit, storedAccount);
@@ -244,7 +233,7 @@ public class InvalidationControllerTest extends InstrumentationTestCase {
};
// Execute the test.
- controller.refreshRegisteredTypes();
+ controller.refreshRegisteredTypes(refreshedTypes);
// Validate the values.
assertEquals(storedAccount, resultAccount.get());
@@ -283,7 +272,7 @@ public class InvalidationControllerTest extends InstrumentationTestCase {
};
// Execute the test.
- controller.refreshRegisteredTypes();
+ controller.refreshRegisteredTypes(new HashSet<ModelType>());
// Validate the values.
assertEquals(storedAccount, resultAccount.get());
diff --git a/sync/android/javatests/src/org/chromium/sync/notifier/ModelTypeResolverTest.java b/sync/android/javatests/src/org/chromium/sync/notifier/ModelTypeResolverTest.java
deleted file mode 100644
index aa53eb8..0000000
--- a/sync/android/javatests/src/org/chromium/sync/notifier/ModelTypeResolverTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright (c) 2013 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.notifier;
-
-import android.test.InstrumentationTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-
-import org.chromium.base.test.util.Feature;
-import org.chromium.sync.internal_api.pub.base.ModelType;
-
-import java.util.HashSet;
-import java.util.Set;
-
-public class ModelTypeResolverTest extends InstrumentationTestCase {
- @SmallTest
- @Feature({"Sync"})
- public void testControlTypesShouldAlwaysBeAddedEvenForNullModelTypes() throws Exception {
- ModelTypeResolverImpl resolver = new ModelTypeResolverImpl();
- Set<ModelType> result = resolver.resolveModelTypes(null);
- assertNotNull(result);
- assertEquals("Size should be the same as number of control types",
- ModelType.controlTypes().size(), result.size());
- assertTrue("Should contain all control ModelTypes",
- result.containsAll(ModelType.controlTypes()));
- }
-
- @SmallTest
- @Feature({"Sync"})
- public void testControlTypesShouldAlwaysBeAdded() throws Exception {
- ModelTypeResolverImpl resolver = new ModelTypeResolverImpl();
- Set<ModelType> result = resolver.resolveModelTypes(new HashSet<ModelType>());
- assertNotNull(result);
- assertEquals("Size should be the same as number of control types",
- ModelType.controlTypes().size(), result.size());
- assertTrue("Should contain all control ModelTypes",
- result.containsAll(ModelType.controlTypes()));
- }
-
- @SmallTest
- @Feature({"Sync"})
- public void testAddingAutofillShouldAddAutofillProfile() throws Exception {
- Set<ModelType> modelTypes = new HashSet<ModelType>();
- modelTypes.add(ModelType.AUTOFILL);
- ModelTypeResolverImpl resolver = new ModelTypeResolverImpl();
- Set<ModelType> result = resolver.resolveModelTypes(modelTypes);
- assertNotNull(result);
- assertEquals("Size should be 2 plus the number of control types",
- 2 + ModelType.controlTypes().size(), result.size());
- assertTrue("Should have AUTOFILL ModelType", result.contains(ModelType.AUTOFILL));
- assertTrue("Should have AUTOFILL_PROFILE ModelType",
- result.contains(ModelType.AUTOFILL_PROFILE));
- }
-
- @SmallTest
- @Feature({"Sync"})
- public void testModelTypesThatArePartOfGroupsShouldStillWork() throws Exception {
- Set<ModelType> modelTypes = new HashSet<ModelType>();
- modelTypes.add(ModelType.BOOKMARK);
- modelTypes.add(ModelType.SESSION);
- modelTypes.add(ModelType.TYPED_URL);
- ModelTypeResolverImpl resolver = new ModelTypeResolverImpl();
- Set<ModelType> result = resolver.resolveModelTypes(modelTypes);
- assertNotNull(result);
- assertEquals("Size should be " + modelTypes.size() + " plus the number of control types",
- modelTypes.size() + ModelType.controlTypes().size(), result.size());
- assertTrue("Should have BOOKMARK ModelType", result.contains(ModelType.BOOKMARK));
- assertTrue("Should have SESSION ModelType", result.contains(ModelType.SESSION));
- assertTrue("Should have TYPED_URL ModelType", result.contains(ModelType.TYPED_URL));
- }
-}