diff options
author | yfriedman@chromium.org <yfriedman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-20 23:57:15 +0000 |
---|---|---|
committer | yfriedman@chromium.org <yfriedman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-20 23:57:15 +0000 |
commit | b594f92e3ef37df1193afc06e58e2d02385b9531 (patch) | |
tree | 8dd1d39b75c2fd3530cdcc5590e0f96396ee2537 /sync/android | |
parent | f811c1a26ce0468799e688663392e062b7cc91b8 (diff) | |
download | chromium_src-b594f92e3ef37df1193afc06e58e2d02385b9531.zip chromium_src-b594f92e3ef37df1193afc06e58e2d02385b9531.tar.gz chromium_src-b594f92e3ef37df1193afc06e58e2d02385b9531.tar.bz2 |
[Android] Remove all usage of com.google.common.collect
To minimize apk size, minimize dependencies on guava. This removes 7k method definitions from the dex file.
BUG=272790
NOTRY=true
Review URL: https://chromiumcodereview.appspot.com/22978010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@218579 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/android')
7 files changed, 104 insertions, 96 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 afec46c..6388588 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 @@ -7,11 +7,12 @@ package org.chromium.sync.internal_api.pub.base; import android.util.Log; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Sets; 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; /** @@ -122,9 +123,9 @@ public enum ModelType { */ public static Set<ModelType> syncTypesToModelTypes(Collection<String> syncTypes) { if (syncTypes.contains(ALL_TYPES_TYPE)) { - return Sets.newHashSet(ModelType.values()); + return EnumSet.allOf(ModelType.class); } else { - Set<ModelType> modelTypes = Sets.newHashSetWithExpectedSize(syncTypes.size()); + Set<ModelType> modelTypes = new HashSet<ModelType>(syncTypes.size()); for (String syncType : syncTypes) { try { modelTypes.add(valueOf(syncType)); @@ -152,7 +153,7 @@ public enum ModelType { * This strips out any {@link ModelType} that is not an invalidation type. */ public static Set<ObjectId> modelTypesToObjectIds(Set<ModelType> modelTypes) { - Set<ObjectId> objectIds = Sets.newHashSetWithExpectedSize(modelTypes.size()); + Set<ObjectId> objectIds = new HashSet<ObjectId>(modelTypes.size()); for (ModelType modelType : modelTypes) { if (!modelType.mNonInvalidationType) { objectIds.add(modelType.toObjectId()); @@ -163,7 +164,7 @@ public enum ModelType { /** Converts a set of {@link ModelType} to a set of string names. */ public static Set<String> modelTypesToSyncTypes(Set<ModelType> modelTypes) { - Set<String> objectIds = Sets.newHashSetWithExpectedSize(modelTypes.size()); + Set<String> objectIds = new HashSet<String>(modelTypes.size()); for (ModelType modelType : modelTypes) { objectIds.add(modelType.toString()); } 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 5503e8e..943785d 100644 --- a/sync/android/java/src/org/chromium/sync/notifier/InvalidationController.java +++ b/sync/android/java/src/org/chromium/sync/notifier/InvalidationController.java @@ -10,9 +10,9 @@ import android.content.Intent; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; import org.chromium.base.ActivityStatus; +import org.chromium.base.CollectionUtil; import org.chromium.sync.internal_api.pub.base.ModelType; import java.util.Set; @@ -66,7 +66,7 @@ public class InvalidationController implements ActivityStatus.StateListener { } } registerIntent.putStringArrayListExtra(EXTRA_REGISTERED_TYPES, - Lists.newArrayList(selectedTypesArray)); + CollectionUtil.newArrayList(selectedTypesArray)); registerIntent.putExtra(EXTRA_ACCOUNT, account); return registerIntent; } diff --git a/sync/android/java/src/org/chromium/sync/notifier/InvalidationService.java b/sync/android/java/src/org/chromium/sync/notifier/InvalidationService.java index b0a239d..7b0abd9 100644 --- a/sync/android/java/src/org/chromium/sync/notifier/InvalidationService.java +++ b/sync/android/java/src/org/chromium/sync/notifier/InvalidationService.java @@ -12,8 +12,6 @@ import android.os.Bundle; import android.util.Log; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import com.google.ipc.invalidation.external.client.InvalidationListener.RegistrationState; import com.google.ipc.invalidation.external.client.contrib.AndroidListener; import com.google.ipc.invalidation.external.client.types.ErrorInfo; @@ -22,14 +20,15 @@ import com.google.ipc.invalidation.external.client.types.ObjectId; import com.google.protos.ipc.invalidation.Types.ClientType; import org.chromium.base.ActivityStatus; +import org.chromium.base.CollectionUtil; import org.chromium.sync.internal_api.pub.base.ModelType; import org.chromium.sync.notifier.InvalidationController.IntentProtocol; import org.chromium.sync.notifier.InvalidationPreferences.EditContext; import org.chromium.sync.signin.AccountManagerHelper; import org.chromium.sync.signin.ChromeSigninController; -import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Random; import java.util.Set; @@ -96,7 +95,7 @@ public class InvalidationService extends AndroidListener { // If the intent requests a change in registrations, change them. List<String> regTypes = intent.getStringArrayListExtra(IntentProtocol.EXTRA_REGISTERED_TYPES); - setRegisteredTypes(Sets.newHashSet(regTypes)); + setRegisteredTypes(new HashSet<String>(regTypes)); } else { // Otherwise, we don't recognize the intent. Pass it to the notification client service. super.onHandleIntent(intent); @@ -131,7 +130,7 @@ public class InvalidationService extends AndroidListener { if (isTransient) { // Retry immediately on transient failures. The base AndroidListener will handle // exponential backoff if there are repeated failures. - List<ObjectId> objectIdAsList = Lists.newArrayList(objectId); + List<ObjectId> objectIdAsList = CollectionUtil.newArrayList(objectId); if (readRegistrationsFromPrefs().contains(objectId)) { register(clientId, objectIdAsList); } else { @@ -144,7 +143,7 @@ public class InvalidationService extends AndroidListener { public void informRegistrationStatus( byte[] clientId, ObjectId objectId, RegistrationState regState) { Log.d(TAG, "Registration status for " + objectId + ": " + regState); - List<ObjectId> objectIdAsList = Lists.newArrayList(objectId); + List<ObjectId> objectIdAsList = CollectionUtil.newArrayList(objectId); boolean registrationisDesired = readRegistrationsFromPrefs().contains(objectId); if (regState == RegistrationState.REGISTERED) { if (!registrationisDesired) { @@ -329,8 +328,8 @@ public class InvalidationService extends AndroidListener { // expansion of the ALL_TYPES_TYPE wildcard. // NOTE: syncTypes MUST NOT be used below this line, since it contains an unexpanded // wildcard. - List<ObjectId> unregistrations = Lists.newArrayList(); - List<ObjectId> registrations = Lists.newArrayList(); + Set<ObjectId> unregistrations = new HashSet<ObjectId>(); + Set<ObjectId> registrations = new HashSet<ObjectId>(); computeRegistrationOps(existingRegistrations, ModelType.syncTypesToObjectIds(syncTypes), registrations, unregistrations); @@ -347,12 +346,15 @@ public class InvalidationService extends AndroidListener { */ @VisibleForTesting static void computeRegistrationOps(Set<ObjectId> existingRegs, Set<ObjectId> desiredRegs, - Collection<ObjectId> regAccumulator, Collection<ObjectId> unregAccumulator) { + Set<ObjectId> regAccumulator, Set<ObjectId> unregAccumulator) { + // Registrations to do are elements in the new set but not the old set. - regAccumulator.addAll(Sets.difference(desiredRegs, existingRegs)); + regAccumulator.addAll(desiredRegs); + regAccumulator.removeAll(existingRegs); // Unregistrations to do are elements in the old set but not the new set. - unregAccumulator.addAll(Sets.difference(existingRegs, desiredRegs)); + unregAccumulator.addAll(existingRegs); + unregAccumulator.removeAll(desiredRegs); } /** 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 44f9eb4..8cc270d 100644 --- a/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationControllerTest.java +++ b/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationControllerTest.java @@ -13,10 +13,8 @@ import android.content.pm.PackageManager; import android.test.InstrumentationTestCase; import android.test.suitebuilder.annotation.SmallTest; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; - import org.chromium.base.ActivityStatus; +import org.chromium.base.CollectionUtil; import org.chromium.base.test.util.AdvancedMockContext; import org.chromium.base.test.util.Feature; import org.chromium.sync.internal_api.pub.base.ModelType; @@ -155,7 +153,7 @@ public class InvalidationControllerTest extends InstrumentationTestCase { InvalidationController controller = new InvalidationController(mContext); Account account = new Account("test@example.com", "bogus"); controller.setRegisteredTypes(account, false, - Sets.newHashSet(ModelType.BOOKMARK, ModelType.SESSION)); + CollectionUtil.newHashSet(ModelType.BOOKMARK, ModelType.SESSION)); assertEquals(1, mContext.getNumStartedIntents()); // Validate destination. @@ -168,9 +166,9 @@ public class InvalidationControllerTest extends InstrumentationTestCase { assertEquals(account, intentAccount); // Validate registered types. - Set<String> expectedTypes = - Sets.newHashSet(ModelType.BOOKMARK.name(), ModelType.SESSION.name()); - Set<String> actualTypes = Sets.newHashSet(); + Set<String> expectedTypes = CollectionUtil.newHashSet(ModelType.BOOKMARK.name(), + ModelType.SESSION.name()); + Set<String> actualTypes = new HashSet<String>(); actualTypes.addAll(intent.getStringArrayListExtra(IntentProtocol.EXTRA_REGISTERED_TYPES)); assertEquals(expectedTypes, actualTypes); } @@ -180,7 +178,7 @@ public class InvalidationControllerTest extends InstrumentationTestCase { public void testRegisterForAllTypes() { Account account = new Account("test@example.com", "bogus"); mController.setRegisteredTypes(account, true, - Sets.newHashSet(ModelType.BOOKMARK, ModelType.SESSION)); + CollectionUtil.newHashSet(ModelType.BOOKMARK, ModelType.SESSION)); assertEquals(1, mContext.getNumStartedIntents()); // Validate destination. @@ -193,8 +191,8 @@ public class InvalidationControllerTest extends InstrumentationTestCase { assertEquals(account, intentAccount); // Validate registered types. - Set<String> expectedTypes = Sets.newHashSet(ModelType.ALL_TYPES_TYPE); - Set<String> actualTypes = Sets.newHashSet(); + Set<String> expectedTypes = CollectionUtil.newHashSet(ModelType.ALL_TYPES_TYPE); + Set<String> actualTypes = new HashSet<String>(); actualTypes.addAll(intent.getStringArrayListExtra(IntentProtocol.EXTRA_REGISTERED_TYPES)); assertEquals(expectedTypes, actualTypes); } @@ -298,7 +296,7 @@ public class InvalidationControllerTest extends InstrumentationTestCase { * Mock context that saves all intents given to {@code startService}. */ private static class IntentSavingContext extends AdvancedMockContext { - private final List<Intent> startedIntents = Lists.newArrayList(); + private final List<Intent> startedIntents = new ArrayList<Intent>(); IntentSavingContext(Context targetContext) { super(targetContext); diff --git a/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationPreferencesTest.java b/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationPreferencesTest.java index 4586513..2c5e841 100644 --- a/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationPreferencesTest.java +++ b/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationPreferencesTest.java @@ -9,14 +9,13 @@ import android.content.Context; import android.test.InstrumentationTestCase; import android.test.suitebuilder.annotation.SmallTest; -import com.google.common.collect.Sets; - +import org.chromium.base.CollectionUtil; import org.chromium.base.test.util.AdvancedMockContext; import org.chromium.base.test.util.Feature; import org.chromium.sync.internal_api.pub.base.ModelType; -import org.chromium.sync.notifier.InvalidationPreferences; import java.util.Arrays; +import java.util.EnumSet; import java.util.HashSet; import java.util.Set; @@ -41,9 +40,10 @@ public class InvalidationPreferencesTest extends InstrumentationTestCase { * Test plan: convert three strings to model types, one of which is invalid. Verify that * the two valid strings are properly converted and that the invalid string is dropped. */ - HashSet<ModelType> expectedTypes = Sets.newHashSet(ModelType.BOOKMARK, ModelType.SESSION); + HashSet<ModelType> expectedTypes = CollectionUtil.newHashSet( + ModelType.BOOKMARK,ModelType.SESSION); Set<ModelType> actualTypes = ModelType.syncTypesToModelTypes( - Sets.newHashSet("BOOKMARK", "SESSION", "0!!!INVALID")); + CollectionUtil.newHashSet("BOOKMARK", "SESSION", "0!!!INVALID")); assertEquals(expectedTypes, actualTypes); } @@ -54,9 +54,9 @@ public class InvalidationPreferencesTest extends InstrumentationTestCase { * Test plan: convert the special all-types type to model types. Verify that it is * properly expanded. */ - HashSet<ModelType> expectedTypes = Sets.newHashSet(ModelType.values()); + Set<ModelType> expectedTypes = EnumSet.allOf(ModelType.class); Set<ModelType> actualTypes = ModelType.syncTypesToModelTypes( - Sets.newHashSet(ModelType.ALL_TYPES_TYPE)); + CollectionUtil.newHashSet(ModelType.ALL_TYPES_TYPE)); assertEquals(expectedTypes, actualTypes); } @@ -84,7 +84,7 @@ public class InvalidationPreferencesTest extends InstrumentationTestCase { // We should never write both a real type and the all-types type in practice, but we test // with them here to ensure that preferences are not interpreting the written data. - Set<String> syncTypes = Sets.newHashSet("BOOKMARK", ModelType.ALL_TYPES_TYPE); + Set<String> syncTypes = CollectionUtil.newHashSet("BOOKMARK", ModelType.ALL_TYPES_TYPE); Account account = new Account("test@example.com", "bogus"); byte[] internalClientState = new byte[]{100,101,102}; invPreferences.setSyncTypes(editContext, syncTypes); @@ -102,4 +102,4 @@ public class InvalidationPreferencesTest extends InstrumentationTestCase { assertTrue(Arrays.equals( internalClientState, invPreferences.getInternalNotificationClientState())); } -} +}
\ No newline at end of file diff --git a/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationServiceTest.java b/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationServiceTest.java index db27879..18d6507 100644 --- a/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationServiceTest.java +++ b/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationServiceTest.java @@ -11,15 +11,13 @@ import android.os.Bundle; import android.test.ServiceTestCase; import android.test.suitebuilder.annotation.SmallTest; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import com.google.ipc.invalidation.external.client.InvalidationListener.RegistrationState; import com.google.ipc.invalidation.external.client.contrib.AndroidListener; import com.google.ipc.invalidation.external.client.types.ErrorInfo; import com.google.ipc.invalidation.external.client.types.Invalidation; import com.google.ipc.invalidation.external.client.types.ObjectId; +import org.chromium.base.CollectionUtil; import org.chromium.base.test.util.AdvancedMockContext; import org.chromium.base.test.util.Feature; import org.chromium.sync.internal_api.pub.base.ModelType; @@ -27,7 +25,10 @@ import org.chromium.sync.notifier.InvalidationController.IntentProtocol; import org.chromium.sync.notifier.InvalidationPreferences.EditContext; import org.chromium.sync.signin.AccountManagerHelper; +import java.util.ArrayList; import java.util.Arrays; +import java.util.EnumSet; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -50,7 +51,7 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio @Override public void setUp() throws Exception { super.setUp(); - mStartServiceIntents = Lists.newArrayList(); + mStartServiceIntents = new ArrayList<Intent>(); setContext(new AdvancedMockContext(getContext()) { @Override public ComponentName startService(Intent intent) { @@ -78,49 +79,52 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio * Test plan: compute the set of registration operations resulting from various combinations * of existing and desired registrations. Verifying that they are correct. */ - List<ObjectId> regAccumulator = Lists.newArrayList(); - List<ObjectId> unregAccumulator = Lists.newArrayList(); + Set<ObjectId> regAccumulator = new HashSet<ObjectId>(); + Set<ObjectId> unregAccumulator = new HashSet<ObjectId>(); // Empty existing and desired registrations should yield empty operation sets. InvalidationService.computeRegistrationOps( ModelType.modelTypesToObjectIds( - Sets.newHashSet(ModelType.BOOKMARK, ModelType.SESSION)), + CollectionUtil.newHashSet(ModelType.BOOKMARK, ModelType.SESSION)), ModelType.modelTypesToObjectIds( - Sets.newHashSet(ModelType.BOOKMARK, ModelType.SESSION)), + CollectionUtil.newHashSet(ModelType.BOOKMARK, ModelType.SESSION)), regAccumulator, unregAccumulator); assertEquals(0, regAccumulator.size()); assertEquals(0, unregAccumulator.size()); // Equal existing and desired registrations should yield empty operation sets. - InvalidationService.computeRegistrationOps(Sets.<ObjectId>newHashSet(), - Sets.<ObjectId>newHashSet(), regAccumulator, unregAccumulator); + InvalidationService.computeRegistrationOps(new HashSet<ObjectId>(), + new HashSet<ObjectId>(), regAccumulator, unregAccumulator); assertEquals(0, regAccumulator.size()); assertEquals(0, unregAccumulator.size()); // Empty existing and non-empty desired registrations should yield desired registrations // as the registration operations to do and no unregistrations. Set<ObjectId> desiredTypes = - Sets.newHashSet(ModelType.BOOKMARK.toObjectId(), ModelType.SESSION.toObjectId()); + CollectionUtil.newHashSet( + ModelType.BOOKMARK.toObjectId(), ModelType.SESSION.toObjectId()); InvalidationService.computeRegistrationOps( - Sets.<ObjectId>newHashSet(), + new HashSet<ObjectId>(), desiredTypes, regAccumulator, unregAccumulator); assertEquals( - Sets.newHashSet(ModelType.BOOKMARK.toObjectId(), ModelType.SESSION.toObjectId()), - Sets.newHashSet(regAccumulator)); + CollectionUtil.newHashSet( + ModelType.BOOKMARK.toObjectId(), ModelType.SESSION.toObjectId()), + new HashSet<ObjectId>(regAccumulator)); assertEquals(0, unregAccumulator.size()); regAccumulator.clear(); // Unequal existing and desired registrations should yield both registrations and // unregistrations. We should unregister TYPED_URL and register BOOKMARK, keeping SESSION. InvalidationService.computeRegistrationOps( - Sets.<ObjectId>newHashSet( + CollectionUtil.newHashSet( ModelType.SESSION.toObjectId(), ModelType.TYPED_URL.toObjectId()), - Sets.<ObjectId>newHashSet( + CollectionUtil.newHashSet( ModelType.BOOKMARK.toObjectId(), ModelType.SESSION.toObjectId()), regAccumulator, unregAccumulator); - assertEquals(Lists.newArrayList(ModelType.BOOKMARK.toObjectId()), regAccumulator); - assertEquals(Lists.newArrayList(ModelType.TYPED_URL.toObjectId()), unregAccumulator); + assertEquals(CollectionUtil.newHashSet(ModelType.BOOKMARK.toObjectId()), regAccumulator); + assertEquals(CollectionUtil.newHashSet(ModelType.TYPED_URL.toObjectId()), + unregAccumulator); regAccumulator.clear(); unregAccumulator.clear(); } @@ -136,7 +140,7 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio // Persist some registrations. InvalidationPreferences invPrefs = new InvalidationPreferences(getContext()); EditContext editContext = invPrefs.edit(); - invPrefs.setSyncTypes(editContext, Lists.newArrayList("BOOKMARK", "SESSION")); + invPrefs.setSyncTypes(editContext, CollectionUtil.newArrayList("BOOKMARK", "SESSION")); assertTrue(invPrefs.commit(editContext)); // Issue ready. @@ -147,9 +151,9 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio assertTrue(Arrays.equals(otherCid, InvalidationService.getClientIdForTest())); // Verify registrations issued. - assertEquals( - Sets.newHashSet(ModelType.BOOKMARK.toObjectId(), ModelType.SESSION.toObjectId()), - Sets.newHashSet(getService().mRegistrations.get(0))); + assertEquals(CollectionUtil.newHashSet( + ModelType.BOOKMARK.toObjectId(), ModelType.SESSION.toObjectId()), + new HashSet<ObjectId>(getService().mRegistrations.get(0))); } @SmallTest @@ -169,15 +173,15 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio // Persist some registrations. InvalidationPreferences invPrefs = new InvalidationPreferences(getContext()); EditContext editContext = invPrefs.edit(); - invPrefs.setSyncTypes(editContext, Lists.newArrayList("BOOKMARK", "SESSION")); + invPrefs.setSyncTypes(editContext, CollectionUtil.newArrayList("BOOKMARK", "SESSION")); assertTrue(invPrefs.commit(editContext)); // Reissue registrations and verify that the appropriate registrations are issued. getService().reissueRegistrations(CLIENT_ID); assertEquals(1, getService().mRegistrations.size()); - assertEquals( - Sets.newHashSet(ModelType.BOOKMARK.toObjectId(), ModelType.SESSION.toObjectId()), - Sets.newHashSet(getService().mRegistrations.get(0))); + assertEquals(CollectionUtil.newHashSet( + ModelType.BOOKMARK.toObjectId(), ModelType.SESSION.toObjectId()), + new HashSet<ObjectId>(getService().mRegistrations.get(0))); } @SmallTest @@ -195,7 +199,7 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio // Initial test setup: persist a single registration into preferences. InvalidationPreferences invPrefs = new InvalidationPreferences(getContext()); EditContext editContext = invPrefs.edit(); - invPrefs.setSyncTypes(editContext, Lists.newArrayList("SESSION")); + invPrefs.setSyncTypes(editContext, CollectionUtil.newArrayList("SESSION")); assertTrue(invPrefs.commit(editContext)); // Cases 1 and 2: calls matching desired state cause no actions. @@ -211,7 +215,7 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio RegistrationState.REGISTERED); assertEquals(1, getService().mUnregistrations.size()); assertEquals(0, getService().mRegistrations.size()); - assertEquals(Lists.newArrayList(ModelType.BOOKMARK.toObjectId()), + assertEquals(CollectionUtil.newArrayList(ModelType.BOOKMARK.toObjectId()), getService().mUnregistrations.get(0)); // Case 4: unregistration of a desired object triggers a registration. @@ -219,7 +223,7 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio RegistrationState.UNREGISTERED); assertEquals(1, getService().mUnregistrations.size()); assertEquals(1, getService().mRegistrations.size()); - assertEquals(Lists.newArrayList(ModelType.SESSION.toObjectId()), + assertEquals(CollectionUtil.newArrayList(ModelType.SESSION.toObjectId()), getService().mRegistrations.get(0)); } @@ -241,7 +245,7 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio // Initial test setup: persist a single registration into preferences. InvalidationPreferences invPrefs = new InvalidationPreferences(getContext()); EditContext editContext = invPrefs.edit(); - invPrefs.setSyncTypes(editContext, Lists.newArrayList("SESSION")); + invPrefs.setSyncTypes(editContext, CollectionUtil.newArrayList("SESSION")); assertTrue(invPrefs.commit(editContext)); // Cases 2 and 4: permanent registration failures never cause calls to be made. @@ -256,7 +260,7 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio getService().informRegistrationFailure(CLIENT_ID, ModelType.SESSION.toObjectId(), true, ""); assertEquals(1, getService().mRegistrations.size()); assertTrue(getService().mUnregistrations.isEmpty()); - assertEquals(Lists.newArrayList(ModelType.SESSION.toObjectId()), + assertEquals(CollectionUtil.newArrayList(ModelType.SESSION.toObjectId()), getService().mRegistrations.get(0)); // Case 3: transient failure of an undesired registration results in unregistration. @@ -264,7 +268,7 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio ""); assertEquals(1, getService().mRegistrations.size()); assertEquals(1, getService().mUnregistrations.size()); - assertEquals(Lists.newArrayList(ModelType.BOOKMARK.toObjectId()), + assertEquals(CollectionUtil.newArrayList(ModelType.BOOKMARK.toObjectId()), getService().mUnregistrations.get(0)); } @@ -484,8 +488,8 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio getService().onCreate(); // Send register Intent. - ImmutableSet<ModelType> desiredRegistrations = - ImmutableSet.of(ModelType.BOOKMARK, ModelType.SESSION); + Set<ModelType> desiredRegistrations = CollectionUtil.newHashSet( + ModelType.BOOKMARK, ModelType.SESSION); Account account = AccountManagerHelper.createAccountFromName("test@example.com"); Intent registrationIntent = IntentProtocol.createRegisterIntent(account, false, desiredRegistrations); @@ -504,7 +508,8 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio // verify that the on-disk state is updated and that no addition Intents are issued. getService().onHandleIntent(IntentProtocol.createRegisterIntent(account, true, null)); assertEquals(account, invPrefs.getSavedSyncedAccount()); - assertEquals(ImmutableSet.of(ModelType.ALL_TYPES_TYPE), invPrefs.getSavedSyncedTypes()); + assertEquals(CollectionUtil.newHashSet(ModelType.ALL_TYPES_TYPE), + invPrefs.getSavedSyncedTypes()); assertEquals(1, mStartServiceIntents.size()); // Finally, send one more registration-change intent, this time with a different account, @@ -534,7 +539,8 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio assertTrue(InvalidationService.getIsClientStartedForTest()); InvalidationPreferences invPrefs = new InvalidationPreferences(getContext()); assertEquals(account, invPrefs.getSavedSyncedAccount()); - assertEquals(ImmutableSet.of(ModelType.ALL_TYPES_TYPE), invPrefs.getSavedSyncedTypes()); + assertEquals(CollectionUtil.newHashSet(ModelType.ALL_TYPES_TYPE), + invPrefs.getSavedSyncedTypes()); assertEquals(1, mStartServiceIntents.size()); assertTrue(isAndroidListenerStartIntent(mStartServiceIntents.get(0))); @@ -544,8 +550,8 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio // Ensure registrations are correct. Set<ObjectId> expectedTypes = - ModelType.modelTypesToObjectIds(Sets.newHashSet(ModelType.values())); - assertEquals(expectedTypes, Sets.newHashSet(getService().mRegistrations.get(0))); + ModelType.modelTypesToObjectIds(EnumSet.allOf(ModelType.class)); + assertEquals(expectedTypes, new HashSet<ObjectId>(getService().mRegistrations.get(0))); } @SmallTest @@ -557,14 +563,14 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio // Send register Intent with no desired types. Account account = AccountManagerHelper.createAccountFromName("test@example.com"); Intent registrationIntent = - IntentProtocol.createRegisterIntent(account, false, Sets.<ModelType>newHashSet()); + IntentProtocol.createRegisterIntent(account, false, new HashSet<ModelType>()); getService().onHandleIntent(registrationIntent); // Verify client started and state written. assertTrue(InvalidationService.getIsClientStartedForTest()); InvalidationPreferences invPrefs = new InvalidationPreferences(getContext()); assertEquals(account, invPrefs.getSavedSyncedAccount()); - assertEquals(Sets.<String>newHashSet(), invPrefs.getSavedSyncedTypes()); + assertEquals(new HashSet<String>(), invPrefs.getSavedSyncedTypes()); assertEquals(1, mStartServiceIntents.size()); assertTrue(isAndroidListenerStartIntent(mStartServiceIntents.get(0))); @@ -579,8 +585,8 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio // Ensure registrations are correct. assertEquals(1, getService().mRegistrations.size()); Set<ObjectId> expectedTypes = - ModelType.modelTypesToObjectIds(Sets.newHashSet(ModelType.values())); - assertEquals(expectedTypes, Sets.newHashSet(getService().mRegistrations.get(0))); + ModelType.modelTypesToObjectIds(EnumSet.allOf(ModelType.class)); + assertEquals(expectedTypes, new HashSet<ObjectId>(getService().mRegistrations.get(0))); } @SmallTest @@ -594,8 +600,8 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio // Send register Intent. Account account = AccountManagerHelper.createAccountFromName("test@example.com"); - ImmutableSet<ModelType> desiredRegistrations = - ImmutableSet.of(ModelType.BOOKMARK, ModelType.SESSION); + Set<ModelType> desiredRegistrations = CollectionUtil.newHashSet( + ModelType.BOOKMARK, ModelType.SESSION); Intent registrationIntent = IntentProtocol.createRegisterIntent(account, false, desiredRegistrations); getService().onHandleIntent(registrationIntent); @@ -622,8 +628,8 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio // Send register Intent. Verify client started but no registrations issued. Account account = AccountManagerHelper.createAccountFromName("test@example.com"); - ImmutableSet<ModelType> desiredRegistrations = - ImmutableSet.of(ModelType.BOOKMARK, ModelType.SESSION); + Set<ModelType> desiredRegistrations = CollectionUtil.newHashSet( + ModelType.BOOKMARK, ModelType.SESSION); Set<ObjectId> desiredObjectIds = ModelType.modelTypesToObjectIds(desiredRegistrations); Intent registrationIntent = IntentProtocol.createRegisterIntent(account, false, @@ -650,7 +656,7 @@ public class InvalidationServiceTest extends ServiceTestCase<TestableInvalidatio actualRegisterIntent.getExtras().keySet()); assertEquals( desiredObjectIds, - Sets.newHashSet(getService().mRegistrations.get(0))); + new HashSet<ObjectId>(getService().mRegistrations.get(0))); } @SmallTest diff --git a/sync/android/javatests/src/org/chromium/sync/notifier/TestableInvalidationService.java b/sync/android/javatests/src/org/chromium/sync/notifier/TestableInvalidationService.java index 9614a10..04eb6ba 100644 --- a/sync/android/javatests/src/org/chromium/sync/notifier/TestableInvalidationService.java +++ b/sync/android/javatests/src/org/chromium/sync/notifier/TestableInvalidationService.java @@ -4,15 +4,16 @@ package org.chromium.sync.notifier; -import com.google.common.collect.Lists; -import com.google.ipc.invalidation.external.client.types.AckHandle; -import com.google.ipc.invalidation.external.client.types.ObjectId; - import android.accounts.Account; import android.content.ComponentName; import android.content.Intent; import android.os.Bundle; +import com.google.ipc.invalidation.external.client.types.ObjectId; + +import org.chromium.base.CollectionUtil; + +import java.util.ArrayList; import java.util.List; /** @@ -23,18 +24,18 @@ import java.util.List; */ public class TestableInvalidationService extends InvalidationService { /** Object ids given to {@link #register}, one list element per call. */ - final List<List<ObjectId>> mRegistrations = Lists.newArrayList(); + final List<List<ObjectId>> mRegistrations = new ArrayList<List<ObjectId>>(); /** Object ids given to {@link #unregister}, one list element per call. */ - final List<List<ObjectId>> mUnregistrations = Lists.newArrayList(); + final List<List<ObjectId>> mUnregistrations = new ArrayList<List<ObjectId>>(); /** Intents given to {@link #startService}. */ - final List<Intent> mStartedServices = Lists.newArrayList(); + final List<Intent> mStartedServices = new ArrayList<Intent>(); /** Bundles given to {@link #requestSyncFromContentResolver}. */ - final List<Bundle> mRequestedSyncs = Lists.newArrayList(); + final List<Bundle> mRequestedSyncs = new ArrayList<Bundle>(); - final List<byte[]> mAcknowledgements = Lists.newArrayList(); + final List<byte[]> mAcknowledgements = new ArrayList<byte[]>(); /** Whether Chrome is in the foreground. */ private boolean mIsChromeInForeground = false; @@ -52,13 +53,13 @@ public class TestableInvalidationService extends InvalidationService { @Override public void register(byte[] clientId, Iterable<ObjectId> objectIds) { - mRegistrations.add(Lists.newArrayList(objectIds)); + mRegistrations.add(CollectionUtil.newArrayList(objectIds)); super.register(clientId, objectIds); } @Override public void unregister(byte[] clientId, Iterable<ObjectId> objectIds) { - mUnregistrations.add(Lists.newArrayList(objectIds)); + mUnregistrations.add(CollectionUtil.newArrayList(objectIds)); super.unregister(clientId, objectIds); } |