OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.sync.notifier; | 5 package org.chromium.components.sync.notifier; |
6 | 6 |
7 import android.accounts.Account; | 7 import android.accounts.Account; |
8 import android.content.Intent; | 8 import android.content.Intent; |
9 | 9 |
10 import com.google.ipc.invalidation.external.client.types.ObjectId; | 10 import com.google.ipc.invalidation.external.client.types.ObjectId; |
11 import com.google.protos.ipc.invalidation.Types; | 11 import com.google.protos.ipc.invalidation.Types; |
12 | 12 |
13 import org.chromium.base.CollectionUtil; | 13 import org.chromium.base.CollectionUtil; |
14 import org.chromium.sync.ModelTypeHelper; | 14 import org.chromium.components.sync.ModelTypeHelper; |
15 | 15 |
16 import java.util.ArrayList; | 16 import java.util.ArrayList; |
17 import java.util.HashSet; | 17 import java.util.HashSet; |
18 import java.util.Set; | 18 import java.util.Set; |
19 | 19 |
20 /** | 20 /** |
21 * Constants and utility methods to create the intents used to communicate betwe
en the | 21 * Constants and utility methods to create the intents used to communicate betwe
en the |
22 * controller and the invalidation client library. | 22 * controller and the invalidation client library. |
23 */ | 23 */ |
24 public class InvalidationIntentProtocol { | 24 public class InvalidationIntentProtocol { |
25 /** | 25 /** |
26 * Action set on register intents. | 26 * Action set on register intents. |
27 */ | 27 */ |
28 public static final String ACTION_REGISTER = | 28 public static final String ACTION_REGISTER = |
29 "org.chromium.sync.notifier.ACTION_REGISTER_TYPES"; | 29 "org.chromium.components.sync.notifier.ACTION_REGISTER_TYPES"; |
30 | 30 |
31 /** | 31 /** |
32 * Parcelable-valued intent extra containing the account of the user. | 32 * Parcelable-valued intent extra containing the account of the user. |
33 */ | 33 */ |
34 public static final String EXTRA_ACCOUNT = "account"; | 34 public static final String EXTRA_ACCOUNT = "account"; |
35 | 35 |
36 /** | 36 /** |
37 * String-list-valued intent extra of the syncable types to sync. | 37 * String-list-valued intent extra of the syncable types to sync. |
38 */ | 38 */ |
39 public static final String EXTRA_REGISTERED_TYPES = "registered_types"; | 39 public static final String EXTRA_REGISTERED_TYPES = "registered_types"; |
(...skipping 19 matching lines...) Expand all Loading... |
59 * Create an Intent that will start the invalidation listener service and | 59 * Create an Intent that will start the invalidation listener service and |
60 * register for the specified types. | 60 * register for the specified types. |
61 */ | 61 */ |
62 public static Intent createRegisterIntent(Account account, Set<Integer> type
s) { | 62 public static Intent createRegisterIntent(Account account, Set<Integer> type
s) { |
63 Intent registerIntent = new Intent(ACTION_REGISTER); | 63 Intent registerIntent = new Intent(ACTION_REGISTER); |
64 String[] selectedTypesArray = new String[types.size()]; | 64 String[] selectedTypesArray = new String[types.size()]; |
65 int pos = 0; | 65 int pos = 0; |
66 for (Integer type : types) { | 66 for (Integer type : types) { |
67 selectedTypesArray[pos++] = ModelTypeHelper.toNotificationType(type)
; | 67 selectedTypesArray[pos++] = ModelTypeHelper.toNotificationType(type)
; |
68 } | 68 } |
69 registerIntent.putStringArrayListExtra(EXTRA_REGISTERED_TYPES, | 69 registerIntent.putStringArrayListExtra( |
70 CollectionUtil.newArrayList(selectedTypesArray)); | 70 EXTRA_REGISTERED_TYPES, CollectionUtil.newArrayList(selectedType
sArray)); |
71 registerIntent.putExtra(EXTRA_ACCOUNT, account); | 71 registerIntent.putExtra(EXTRA_ACCOUNT, account); |
72 return registerIntent; | 72 return registerIntent; |
73 } | 73 } |
74 | 74 |
75 /** | 75 /** |
76 * Create an Intent that will start the invalidation listener service and | 76 * Create an Intent that will start the invalidation listener service and |
77 * register for the object ids with the specified sources and names. | 77 * register for the object ids with the specified sources and names. |
78 * Sync-specific objects are filtered out of the request since Sync types | 78 * Sync-specific objects are filtered out of the request since Sync types |
79 * are registered using the other version of createRegisterIntent. | 79 * are registered using the other version of createRegisterIntent. |
80 */ | 80 */ |
81 public static Intent createRegisterIntent(Account account, int[] objectSourc
es, | 81 public static Intent createRegisterIntent( |
82 String[] objectNames) { | 82 Account account, int[] objectSources, String[] objectNames) { |
83 if (objectSources.length != objectNames.length) { | 83 if (objectSources.length != objectNames.length) { |
84 throw new IllegalArgumentException( | 84 throw new IllegalArgumentException( |
85 "objectSources and objectNames must have the same length"); | 85 "objectSources and objectNames must have the same length"); |
86 } | 86 } |
87 | 87 |
88 // Add all non-Sync objects to new lists. | 88 // Add all non-Sync objects to new lists. |
89 ArrayList<Integer> sources = new ArrayList<Integer>(); | 89 ArrayList<Integer> sources = new ArrayList<Integer>(); |
90 ArrayList<String> names = new ArrayList<String>(); | 90 ArrayList<String> names = new ArrayList<String>(); |
91 for (int i = 0; i < objectSources.length; i++) { | 91 for (int i = 0; i < objectSources.length; i++) { |
92 if (objectSources[i] != Types.ObjectSource.CHROME_SYNC) { | 92 if (objectSources[i] != Types.ObjectSource.CHROME_SYNC) { |
(...skipping 25 matching lines...) Expand all Loading... |
118 ArrayList<Integer> objectSources = | 118 ArrayList<Integer> objectSources = |
119 intent.getIntegerArrayListExtra(EXTRA_REGISTERED_OBJECT_SOURCES)
; | 119 intent.getIntegerArrayListExtra(EXTRA_REGISTERED_OBJECT_SOURCES)
; |
120 ArrayList<String> objectNames = | 120 ArrayList<String> objectNames = |
121 intent.getStringArrayListExtra(EXTRA_REGISTERED_OBJECT_NAMES); | 121 intent.getStringArrayListExtra(EXTRA_REGISTERED_OBJECT_NAMES); |
122 if (objectSources == null || objectNames == null | 122 if (objectSources == null || objectNames == null |
123 || objectSources.size() != objectNames.size()) { | 123 || objectSources.size() != objectNames.size()) { |
124 return null; | 124 return null; |
125 } | 125 } |
126 Set<ObjectId> objectIds = new HashSet<ObjectId>(objectSources.size()); | 126 Set<ObjectId> objectIds = new HashSet<ObjectId>(objectSources.size()); |
127 for (int i = 0; i < objectSources.size(); i++) { | 127 for (int i = 0; i < objectSources.size(); i++) { |
128 objectIds.add(ObjectId.newInstance( | 128 objectIds.add( |
129 objectSources.get(i), objectNames.get(i).getBytes())); | 129 ObjectId.newInstance(objectSources.get(i), objectNames.get(i
).getBytes())); |
130 } | 130 } |
131 return objectIds; | 131 return objectIds; |
132 } | 132 } |
133 | 133 |
134 private InvalidationIntentProtocol() { | 134 private InvalidationIntentProtocol() { |
135 // Disallow instantiation. | 135 // Disallow instantiation. |
136 } | 136 } |
137 } | 137 } |
OLD | NEW |