OLD | NEW |
| (Empty) |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Enumerate the various item subtypes that are supported by sync. | |
6 // Each sync object is expected to have an immutable object type. | |
7 // An object's type is inferred from the type of data it holds. | |
8 | |
9 #ifndef SYNC_INTERNAL_API_PUBLIC_BASE_MODEL_TYPE_H_ | |
10 #define SYNC_INTERNAL_API_PUBLIC_BASE_MODEL_TYPE_H_ | |
11 | |
12 #include <map> | |
13 #include <memory> | |
14 #include <ostream> | |
15 #include <set> | |
16 #include <string> | |
17 | |
18 #include "base/logging.h" | |
19 #include "sync/base/sync_export.h" | |
20 #include "sync/internal_api/public/base/enum_set.h" | |
21 | |
22 namespace base { | |
23 class ListValue; | |
24 class StringValue; | |
25 class Value; | |
26 } | |
27 | |
28 namespace sync_pb { | |
29 class EntitySpecifics; | |
30 class SyncEntity; | |
31 } | |
32 | |
33 namespace syncer { | |
34 | |
35 // TODO(akalin): Move the non-exported functions in this file to a | |
36 // private header. | |
37 | |
38 // A Java counterpart will be generated for this enum. | |
39 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.sync | |
40 | |
41 // |kModelTypeInfoMap| struct entries are in the same order as their definition | |
42 // in ModelType enum. Don't forget to update the |kModelTypeInfoMap| struct in | |
43 // model_type.cc when you make changes in ModelType enum. | |
44 enum ModelType { | |
45 // Object type unknown. Objects may transition through | |
46 // the unknown state during their initial creation, before | |
47 // their properties are set. After deletion, object types | |
48 // are generally preserved. | |
49 UNSPECIFIED, | |
50 // A permanent folder whose children may be of mixed | |
51 // datatypes (e.g. the "Google Chrome" folder). | |
52 TOP_LEVEL_FOLDER, | |
53 | |
54 // ------------------------------------ Start of "real" model types. | |
55 // The model types declared before here are somewhat special, as they | |
56 // they do not correspond to any browser data model. The remaining types | |
57 // are bona fide model types; all have a related browser data model and | |
58 // can be represented in the protocol using a specific Message type in the | |
59 // EntitySpecifics protocol buffer. | |
60 // | |
61 // A bookmark folder or a bookmark URL object. | |
62 BOOKMARKS, | |
63 FIRST_USER_MODEL_TYPE = BOOKMARKS, // Declared 2nd, for debugger prettiness. | |
64 FIRST_REAL_MODEL_TYPE = FIRST_USER_MODEL_TYPE, | |
65 | |
66 // A preference object. | |
67 PREFERENCES, | |
68 // A password object. | |
69 PASSWORDS, | |
70 // An AutofillProfile Object | |
71 AUTOFILL_PROFILE, | |
72 // An autofill object. | |
73 AUTOFILL, | |
74 // Credit cards and addresses synced from the user's account. These are | |
75 // read-only on the client. | |
76 AUTOFILL_WALLET_DATA, | |
77 // Usage counts and last use dates for Wallet cards and addresses. This data | |
78 // is both readable and writable. | |
79 AUTOFILL_WALLET_METADATA, | |
80 // A themes object. | |
81 THEMES, | |
82 // A typed_url object. | |
83 TYPED_URLS, | |
84 // An extension object. | |
85 EXTENSIONS, | |
86 // An object representing a custom search engine. | |
87 SEARCH_ENGINES, | |
88 // An object representing a browser session. | |
89 SESSIONS, | |
90 // An app object. | |
91 APPS, | |
92 // An app setting from the extension settings API. | |
93 APP_SETTINGS, | |
94 // An extension setting from the extension settings API. | |
95 EXTENSION_SETTINGS, | |
96 // App notifications. | |
97 APP_NOTIFICATIONS, // Deprecated. | |
98 // History delete directives. | |
99 HISTORY_DELETE_DIRECTIVES, | |
100 // Synced push notifications. | |
101 SYNCED_NOTIFICATIONS, // Deprecated. | |
102 // Synced Notification app info. | |
103 SYNCED_NOTIFICATION_APP_INFO, // Deprecated. | |
104 // Custom spelling dictionary. | |
105 DICTIONARY, | |
106 // Favicon images. | |
107 FAVICON_IMAGES, | |
108 // Favicon tracking information. | |
109 FAVICON_TRACKING, | |
110 // Client-specific metadata, synced before other user types. | |
111 DEVICE_INFO, | |
112 // These preferences are synced before other user types and are never | |
113 // encrypted. | |
114 PRIORITY_PREFERENCES, | |
115 // Supervised user settings. | |
116 SUPERVISED_USER_SETTINGS, | |
117 // Supervised users. Every supervised user is a profile that is configured | |
118 // remotely by this user and can have restrictions applied. SUPERVISED_USERS | |
119 // and SUPERVISED_USER_SETTINGS can not be encrypted. | |
120 SUPERVISED_USERS, | |
121 // Supervised user shared settings. Shared settings can be modified both by | |
122 // the manager and the supervised user. | |
123 SUPERVISED_USER_SHARED_SETTINGS, | |
124 // Distilled articles. | |
125 ARTICLES, | |
126 // App List items | |
127 APP_LIST, | |
128 // WiFi credentials. Each item contains the information for connecting to one | |
129 // WiFi network. This includes, e.g., network name and password. | |
130 WIFI_CREDENTIALS, | |
131 // Supervised user whitelists. Each item contains a CRX ID (like an extension | |
132 // ID) and a name. | |
133 SUPERVISED_USER_WHITELISTS, | |
134 // Arc Package items. | |
135 ARC_PACKAGE, | |
136 | |
137 // ---- Proxy types ---- | |
138 // Proxy types are excluded from the sync protocol, but are still considered | |
139 // real user types. By convention, we prefix them with 'PROXY_' to distinguish | |
140 // them from normal protocol types. | |
141 | |
142 // Tab sync. This is a placeholder type, so that Sessions can be implicitly | |
143 // enabled for history sync and tabs sync. | |
144 PROXY_TABS, | |
145 FIRST_PROXY_TYPE = PROXY_TABS, | |
146 LAST_PROXY_TYPE = PROXY_TABS, | |
147 LAST_USER_MODEL_TYPE = PROXY_TABS, | |
148 | |
149 // ---- Control Types ---- | |
150 // An object representing a set of Nigori keys. | |
151 NIGORI, | |
152 FIRST_CONTROL_MODEL_TYPE = NIGORI, | |
153 // Flags to enable experimental features. | |
154 EXPERIMENTS, | |
155 LAST_CONTROL_MODEL_TYPE = EXPERIMENTS, | |
156 LAST_REAL_MODEL_TYPE = LAST_CONTROL_MODEL_TYPE, | |
157 | |
158 // If you are adding a new sync datatype that is exposed to the user via the | |
159 // sync preferences UI, be sure to update the list in | |
160 // components/sync_driver/user_selectable_sync_type.h so that the UMA | |
161 // histograms for sync include your new type. In this case, be sure to also | |
162 // update the UserSelectableTypes() definition in | |
163 // sync/syncable/model_type.cc. | |
164 MODEL_TYPE_COUNT, | |
165 }; | |
166 | |
167 typedef EnumSet<ModelType, FIRST_REAL_MODEL_TYPE, LAST_REAL_MODEL_TYPE> | |
168 ModelTypeSet; | |
169 typedef EnumSet<ModelType, UNSPECIFIED, LAST_REAL_MODEL_TYPE> | |
170 FullModelTypeSet; | |
171 typedef std::map<syncer::ModelType, const char*> ModelTypeNameMap; | |
172 | |
173 inline ModelType ModelTypeFromInt(int i) { | |
174 DCHECK_GE(i, 0); | |
175 DCHECK_LT(i, MODEL_TYPE_COUNT); | |
176 return static_cast<ModelType>(i); | |
177 } | |
178 | |
179 // Used by tests outside of sync/. | |
180 SYNC_EXPORT void AddDefaultFieldValue(ModelType datatype, | |
181 sync_pb::EntitySpecifics* specifics); | |
182 | |
183 // Extract the model type of a SyncEntity protocol buffer. ModelType is a | |
184 // local concept: the enum is not in the protocol. The SyncEntity's ModelType | |
185 // is inferred from the presence of particular datatype field in the | |
186 // entity specifics. | |
187 SYNC_EXPORT ModelType GetModelType(const sync_pb::SyncEntity& sync_entity); | |
188 | |
189 // Extract the model type from an EntitySpecifics field. Note that there | |
190 // are some ModelTypes (like TOP_LEVEL_FOLDER) that can't be inferred this way; | |
191 // prefer using GetModelType where possible. | |
192 SYNC_EXPORT ModelType GetModelTypeFromSpecifics( | |
193 const sync_pb::EntitySpecifics& specifics); | |
194 | |
195 // Protocol types are those types that have actual protocol buffer | |
196 // representations. This distinguishes them from Proxy types, which have no | |
197 // protocol representation and are never sent to the server. | |
198 SYNC_EXPORT ModelTypeSet ProtocolTypes(); | |
199 | |
200 // These are the normal user-controlled types. This is to distinguish from | |
201 // ControlTypes which are always enabled. Note that some of these share a | |
202 // preference flag, so not all of them are individually user-selectable. | |
203 SYNC_EXPORT ModelTypeSet UserTypes(); | |
204 | |
205 // These are the user-selectable data types. | |
206 SYNC_EXPORT ModelTypeSet UserSelectableTypes(); | |
207 SYNC_EXPORT bool IsUserSelectableType(ModelType model_type); | |
208 SYNC_EXPORT ModelTypeNameMap GetUserSelectableTypeNameMap(); | |
209 | |
210 // This is the subset of UserTypes() that can be encrypted. | |
211 SYNC_EXPORT ModelTypeSet EncryptableUserTypes(); | |
212 | |
213 // This is the subset of UserTypes() that have priority over other types. These | |
214 // types are synced before other user types and are never encrypted. | |
215 SYNC_EXPORT ModelTypeSet PriorityUserTypes(); | |
216 | |
217 // Proxy types are placeholder types for handling implicitly enabling real | |
218 // types. They do not exist at the server, and are simply used for | |
219 // UI/Configuration logic. | |
220 SYNC_EXPORT ModelTypeSet ProxyTypes(); | |
221 | |
222 // Returns a list of all control types. | |
223 // | |
224 // The control types are intended to contain metadata nodes that are essential | |
225 // for the normal operation of the syncer. As such, they have the following | |
226 // special properties: | |
227 // - They are downloaded early during SyncBackend initialization. | |
228 // - They are always enabled. Users may not disable these types. | |
229 // - Their contents are not encrypted automatically. | |
230 // - They support custom update application and conflict resolution logic. | |
231 // - All change processing occurs on the sync thread (GROUP_PASSIVE). | |
232 SYNC_EXPORT ModelTypeSet ControlTypes(); | |
233 | |
234 // Returns true if this is a control type. | |
235 // | |
236 // See comment above for more information on what makes these types special. | |
237 SYNC_EXPORT bool IsControlType(ModelType model_type); | |
238 | |
239 // Core types are those data types used by sync's core functionality (i.e. not | |
240 // user data types). These types are always enabled, and include ControlTypes(). | |
241 // | |
242 // The set of all core types. | |
243 SYNC_EXPORT ModelTypeSet CoreTypes(); | |
244 // Those core types that have high priority (includes ControlTypes()). | |
245 SYNC_EXPORT ModelTypeSet PriorityCoreTypes(); | |
246 | |
247 // Determine a model type from the field number of its associated | |
248 // EntitySpecifics field. Returns UNSPECIFIED if the field number is | |
249 // not recognized. | |
250 // | |
251 // If you're putting the result in a ModelTypeSet, you should use the | |
252 // following pattern: | |
253 // | |
254 // ModelTypeSet model_types; | |
255 // // Say we're looping through a list of items, each of which has a | |
256 // // field number. | |
257 // for (...) { | |
258 // int field_number = ...; | |
259 // ModelType model_type = | |
260 // GetModelTypeFromSpecificsFieldNumber(field_number); | |
261 // if (!IsRealDataType(model_type)) { | |
262 // DLOG(WARNING) << "Unknown field number " << field_number; | |
263 // continue; | |
264 // } | |
265 // model_types.Put(model_type); | |
266 // } | |
267 SYNC_EXPORT ModelType GetModelTypeFromSpecificsFieldNumber(int field_number); | |
268 | |
269 // Return the field number of the EntitySpecifics field associated with | |
270 // a model type. | |
271 SYNC_EXPORT int GetSpecificsFieldNumberFromModelType( | |
272 ModelType model_type); | |
273 | |
274 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in); | |
275 | |
276 // TODO(sync): The functions below badly need some cleanup. | |
277 | |
278 // Returns a pointer to a string with application lifetime that represents | |
279 // the name of |model_type|. | |
280 SYNC_EXPORT const char* ModelTypeToString(ModelType model_type); | |
281 | |
282 // Some histograms take an integer parameter that represents a model type. | |
283 // The mapping from ModelType to integer is defined here. It should match | |
284 // the mapping from integer to labels defined in histograms.xml. | |
285 SYNC_EXPORT int ModelTypeToHistogramInt(ModelType model_type); | |
286 | |
287 // Handles all model types, and not just real ones. | |
288 // | |
289 // Caller takes ownership of returned value. | |
290 SYNC_EXPORT base::StringValue* ModelTypeToValue(ModelType model_type); | |
291 | |
292 // Converts a Value into a ModelType - complement to ModelTypeToValue(). | |
293 SYNC_EXPORT ModelType ModelTypeFromValue(const base::Value& value); | |
294 | |
295 // Returns the ModelType corresponding to the name |model_type_string|. | |
296 SYNC_EXPORT ModelType ModelTypeFromString( | |
297 const std::string& model_type_string); | |
298 | |
299 // Returns the comma-separated string representation of |model_types|. | |
300 SYNC_EXPORT std::string ModelTypeSetToString(ModelTypeSet model_types); | |
301 | |
302 // Necessary for compatibility with EXPECT_EQ and the like. | |
303 SYNC_EXPORT std::ostream& operator<<(std::ostream& out, | |
304 ModelTypeSet model_type_set); | |
305 | |
306 // Returns the set of comma-separated model types from |model_type_string|. | |
307 SYNC_EXPORT ModelTypeSet ModelTypeSetFromString( | |
308 const std::string& model_type_string); | |
309 | |
310 SYNC_EXPORT std::unique_ptr<base::ListValue> ModelTypeSetToValue( | |
311 ModelTypeSet model_types); | |
312 | |
313 SYNC_EXPORT ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value); | |
314 | |
315 // Returns a string corresponding to the syncable tag for this datatype. | |
316 SYNC_EXPORT std::string ModelTypeToRootTag(ModelType type); | |
317 | |
318 // Returns root_tag for |model_type| in ModelTypeInfo. | |
319 // Difference with ModelTypeToRootTag(), this just simply return toor_tag in | |
320 // ModelTypeInfo. | |
321 SYNC_EXPORT const char* GetModelTypeRootTag(ModelType model_type); | |
322 | |
323 // Convert a real model type to a notification type (used for | |
324 // subscribing to server-issued notifications). Returns true iff | |
325 // |model_type| was a real model type and |notification_type| was | |
326 // filled in. | |
327 SYNC_EXPORT bool RealModelTypeToNotificationType( | |
328 ModelType model_type, | |
329 std::string* notification_type); | |
330 | |
331 // Converts a notification type to a real model type. Returns true | |
332 // iff |notification_type| was the notification type of a real model | |
333 // type and |model_type| was filled in. | |
334 SYNC_EXPORT bool NotificationTypeToRealModelType( | |
335 const std::string& notification_type, | |
336 ModelType* model_type); | |
337 | |
338 // Returns true if |model_type| is a real datatype | |
339 SYNC_EXPORT bool IsRealDataType(ModelType model_type); | |
340 | |
341 // Returns true if |model_type| is a proxy type | |
342 SYNC_EXPORT bool IsProxyType(ModelType model_type); | |
343 | |
344 // Returns true if |model_type| is an act-once type. Act once types drop | |
345 // entities after applying them. Drops are deletes that are not synced to other | |
346 // clients. | |
347 // TODO(haitaol): Make entries of act-once data types immutable. | |
348 SYNC_EXPORT bool IsActOnceDataType(ModelType model_type); | |
349 | |
350 // Returns true if |model_type| requires its root folder to be explicitly | |
351 // created on the server during initial sync. | |
352 SYNC_EXPORT bool IsTypeWithServerGeneratedRoot(ModelType model_type); | |
353 | |
354 // Returns true if root folder for |model_type| is created on the client when | |
355 // that type is initially synced. | |
356 SYNC_EXPORT bool IsTypeWithClientGeneratedRoot(ModelType model_type); | |
357 | |
358 // Returns true if |model_type| supports parent-child hierarchy or entries. | |
359 SYNC_EXPORT bool TypeSupportsHierarchy(ModelType model_type); | |
360 | |
361 // Returns true if |model_type| supports ordering of sibling entries. | |
362 SYNC_EXPORT bool TypeSupportsOrdering(ModelType model_type); | |
363 | |
364 } // namespace syncer | |
365 | |
366 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_MODEL_TYPE_H_ | |
OLD | NEW |