diff options
author | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-27 21:18:18 +0000 |
---|---|---|
committer | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-27 21:18:18 +0000 |
commit | 6805b60643ae360b5350f97209a420ee46161fee (patch) | |
tree | 414704d0e4ea9d8767cdcffd115ec53f56a5cd94 /sync/android | |
parent | d06bcaca1a000d55e80d9cbf0865eb32f7668ba1 (diff) | |
download | chromium_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
Diffstat (limited to 'sync/android')
6 files changed, 49 insertions, 185 deletions
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)); - } -} |