OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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 // Enumerate the various item subtypes that are supported by sync. | 5 // Enumerate the various item subtypes that are supported by sync. |
6 // Each sync object is expected to have an immutable object type. | 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. | 7 // An object's type is inferred from the type of data it holds. |
8 | 8 |
9 #ifndef COMPONENTS_SYNC_BASE_MODEL_TYPE_H_ | 9 #ifndef COMPONENTS_SYNC_BASE_MODEL_TYPE_H_ |
10 #define COMPONENTS_SYNC_BASE_MODEL_TYPE_H_ | 10 #define COMPONENTS_SYNC_BASE_MODEL_TYPE_H_ |
11 | 11 |
12 #include <map> | 12 #include <map> |
13 #include <memory> | 13 #include <memory> |
14 #include <ostream> | 14 #include <ostream> |
15 #include <set> | 15 #include <set> |
16 #include <string> | 16 #include <string> |
17 | 17 |
18 #include "base/logging.h" | 18 #include "base/logging.h" |
19 #include "components/sync/base/enum_set.h" | 19 #include "components/sync/base/enum_set.h" |
20 #include "components/sync/base/sync_export.h" | |
21 | 20 |
22 namespace base { | 21 namespace base { |
23 class ListValue; | 22 class ListValue; |
24 class StringValue; | 23 class StringValue; |
25 class Value; | 24 class Value; |
26 } | 25 } |
27 | 26 |
28 namespace sync_pb { | 27 namespace sync_pb { |
29 class EntitySpecifics; | 28 class EntitySpecifics; |
30 class SyncEntity; | 29 class SyncEntity; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 typedef EnumSet<ModelType, UNSPECIFIED, LAST_REAL_MODEL_TYPE> FullModelTypeSet; | 168 typedef EnumSet<ModelType, UNSPECIFIED, LAST_REAL_MODEL_TYPE> FullModelTypeSet; |
170 typedef std::map<syncer::ModelType, const char*> ModelTypeNameMap; | 169 typedef std::map<syncer::ModelType, const char*> ModelTypeNameMap; |
171 | 170 |
172 inline ModelType ModelTypeFromInt(int i) { | 171 inline ModelType ModelTypeFromInt(int i) { |
173 DCHECK_GE(i, 0); | 172 DCHECK_GE(i, 0); |
174 DCHECK_LT(i, MODEL_TYPE_COUNT); | 173 DCHECK_LT(i, MODEL_TYPE_COUNT); |
175 return static_cast<ModelType>(i); | 174 return static_cast<ModelType>(i); |
176 } | 175 } |
177 | 176 |
178 // Used by tests outside of sync/. | 177 // Used by tests outside of sync/. |
179 SYNC_EXPORT void AddDefaultFieldValue(ModelType datatype, | 178 void AddDefaultFieldValue(ModelType datatype, |
180 sync_pb::EntitySpecifics* specifics); | 179 sync_pb::EntitySpecifics* specifics); |
181 | 180 |
182 // Extract the model type of a SyncEntity protocol buffer. ModelType is a | 181 // Extract the model type of a SyncEntity protocol buffer. ModelType is a |
183 // local concept: the enum is not in the protocol. The SyncEntity's ModelType | 182 // local concept: the enum is not in the protocol. The SyncEntity's ModelType |
184 // is inferred from the presence of particular datatype field in the | 183 // is inferred from the presence of particular datatype field in the |
185 // entity specifics. | 184 // entity specifics. |
186 SYNC_EXPORT ModelType GetModelType(const sync_pb::SyncEntity& sync_entity); | 185 ModelType GetModelType(const sync_pb::SyncEntity& sync_entity); |
187 | 186 |
188 // Extract the model type from an EntitySpecifics field. Note that there | 187 // Extract the model type from an EntitySpecifics field. Note that there |
189 // are some ModelTypes (like TOP_LEVEL_FOLDER) that can't be inferred this way; | 188 // are some ModelTypes (like TOP_LEVEL_FOLDER) that can't be inferred this way; |
190 // prefer using GetModelType where possible. | 189 // prefer using GetModelType where possible. |
191 SYNC_EXPORT ModelType | 190 ModelType GetModelTypeFromSpecifics(const sync_pb::EntitySpecifics& specifics); |
192 GetModelTypeFromSpecifics(const sync_pb::EntitySpecifics& specifics); | |
193 | 191 |
194 // Protocol types are those types that have actual protocol buffer | 192 // Protocol types are those types that have actual protocol buffer |
195 // representations. This distinguishes them from Proxy types, which have no | 193 // representations. This distinguishes them from Proxy types, which have no |
196 // protocol representation and are never sent to the server. | 194 // protocol representation and are never sent to the server. |
197 SYNC_EXPORT ModelTypeSet ProtocolTypes(); | 195 ModelTypeSet ProtocolTypes(); |
198 | 196 |
199 // These are the normal user-controlled types. This is to distinguish from | 197 // These are the normal user-controlled types. This is to distinguish from |
200 // ControlTypes which are always enabled. Note that some of these share a | 198 // ControlTypes which are always enabled. Note that some of these share a |
201 // preference flag, so not all of them are individually user-selectable. | 199 // preference flag, so not all of them are individually user-selectable. |
202 SYNC_EXPORT ModelTypeSet UserTypes(); | 200 ModelTypeSet UserTypes(); |
203 | 201 |
204 // These are the user-selectable data types. | 202 // These are the user-selectable data types. |
205 SYNC_EXPORT ModelTypeSet UserSelectableTypes(); | 203 ModelTypeSet UserSelectableTypes(); |
206 SYNC_EXPORT bool IsUserSelectableType(ModelType model_type); | 204 bool IsUserSelectableType(ModelType model_type); |
207 SYNC_EXPORT ModelTypeNameMap GetUserSelectableTypeNameMap(); | 205 ModelTypeNameMap GetUserSelectableTypeNameMap(); |
208 | 206 |
209 // This is the subset of UserTypes() that can be encrypted. | 207 // This is the subset of UserTypes() that can be encrypted. |
210 SYNC_EXPORT ModelTypeSet EncryptableUserTypes(); | 208 ModelTypeSet EncryptableUserTypes(); |
211 | 209 |
212 // This is the subset of UserTypes() that have priority over other types. These | 210 // This is the subset of UserTypes() that have priority over other types. These |
213 // types are synced before other user types and are never encrypted. | 211 // types are synced before other user types and are never encrypted. |
214 SYNC_EXPORT ModelTypeSet PriorityUserTypes(); | 212 ModelTypeSet PriorityUserTypes(); |
215 | 213 |
216 // Proxy types are placeholder types for handling implicitly enabling real | 214 // Proxy types are placeholder types for handling implicitly enabling real |
217 // types. They do not exist at the server, and are simply used for | 215 // types. They do not exist at the server, and are simply used for |
218 // UI/Configuration logic. | 216 // UI/Configuration logic. |
219 SYNC_EXPORT ModelTypeSet ProxyTypes(); | 217 ModelTypeSet ProxyTypes(); |
220 | 218 |
221 // Returns a list of all control types. | 219 // Returns a list of all control types. |
222 // | 220 // |
223 // The control types are intended to contain metadata nodes that are essential | 221 // The control types are intended to contain metadata nodes that are essential |
224 // for the normal operation of the syncer. As such, they have the following | 222 // for the normal operation of the syncer. As such, they have the following |
225 // special properties: | 223 // special properties: |
226 // - They are downloaded early during SyncBackend initialization. | 224 // - They are downloaded early during SyncBackend initialization. |
227 // - They are always enabled. Users may not disable these types. | 225 // - They are always enabled. Users may not disable these types. |
228 // - Their contents are not encrypted automatically. | 226 // - Their contents are not encrypted automatically. |
229 // - They support custom update application and conflict resolution logic. | 227 // - They support custom update application and conflict resolution logic. |
230 // - All change processing occurs on the sync thread (GROUP_PASSIVE). | 228 // - All change processing occurs on the sync thread (GROUP_PASSIVE). |
231 SYNC_EXPORT ModelTypeSet ControlTypes(); | 229 ModelTypeSet ControlTypes(); |
232 | 230 |
233 // Returns true if this is a control type. | 231 // Returns true if this is a control type. |
234 // | 232 // |
235 // See comment above for more information on what makes these types special. | 233 // See comment above for more information on what makes these types special. |
236 SYNC_EXPORT bool IsControlType(ModelType model_type); | 234 bool IsControlType(ModelType model_type); |
237 | 235 |
238 // Core types are those data types used by sync's core functionality (i.e. not | 236 // Core types are those data types used by sync's core functionality (i.e. not |
239 // user data types). These types are always enabled, and include ControlTypes(). | 237 // user data types). These types are always enabled, and include ControlTypes(). |
240 // | 238 // |
241 // The set of all core types. | 239 // The set of all core types. |
242 SYNC_EXPORT ModelTypeSet CoreTypes(); | 240 ModelTypeSet CoreTypes(); |
243 // Those core types that have high priority (includes ControlTypes()). | 241 // Those core types that have high priority (includes ControlTypes()). |
244 SYNC_EXPORT ModelTypeSet PriorityCoreTypes(); | 242 ModelTypeSet PriorityCoreTypes(); |
245 | 243 |
246 // Determine a model type from the field number of its associated | 244 // Determine a model type from the field number of its associated |
247 // EntitySpecifics field. Returns UNSPECIFIED if the field number is | 245 // EntitySpecifics field. Returns UNSPECIFIED if the field number is |
248 // not recognized. | 246 // not recognized. |
249 // | 247 // |
250 // If you're putting the result in a ModelTypeSet, you should use the | 248 // If you're putting the result in a ModelTypeSet, you should use the |
251 // following pattern: | 249 // following pattern: |
252 // | 250 // |
253 // ModelTypeSet model_types; | 251 // ModelTypeSet model_types; |
254 // // Say we're looping through a list of items, each of which has a | 252 // // Say we're looping through a list of items, each of which has a |
255 // // field number. | 253 // // field number. |
256 // for (...) { | 254 // for (...) { |
257 // int field_number = ...; | 255 // int field_number = ...; |
258 // ModelType model_type = | 256 // ModelType model_type = |
259 // GetModelTypeFromSpecificsFieldNumber(field_number); | 257 // GetModelTypeFromSpecificsFieldNumber(field_number); |
260 // if (!IsRealDataType(model_type)) { | 258 // if (!IsRealDataType(model_type)) { |
261 // DLOG(WARNING) << "Unknown field number " << field_number; | 259 // DLOG(WARNING) << "Unknown field number " << field_number; |
262 // continue; | 260 // continue; |
263 // } | 261 // } |
264 // model_types.Put(model_type); | 262 // model_types.Put(model_type); |
265 // } | 263 // } |
266 SYNC_EXPORT ModelType GetModelTypeFromSpecificsFieldNumber(int field_number); | 264 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number); |
267 | 265 |
268 // Return the field number of the EntitySpecifics field associated with | 266 // Return the field number of the EntitySpecifics field associated with |
269 // a model type. | 267 // a model type. |
270 SYNC_EXPORT int GetSpecificsFieldNumberFromModelType(ModelType model_type); | 268 int GetSpecificsFieldNumberFromModelType(ModelType model_type); |
271 | 269 |
272 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in); | 270 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in); |
273 | 271 |
274 // TODO(sync): The functions below badly need some cleanup. | 272 // TODO(sync): The functions below badly need some cleanup. |
275 | 273 |
276 // Returns a pointer to a string with application lifetime that represents | 274 // Returns a pointer to a string with application lifetime that represents |
277 // the name of |model_type|. | 275 // the name of |model_type|. |
278 SYNC_EXPORT const char* ModelTypeToString(ModelType model_type); | 276 const char* ModelTypeToString(ModelType model_type); |
279 | 277 |
280 // Some histograms take an integer parameter that represents a model type. | 278 // Some histograms take an integer parameter that represents a model type. |
281 // The mapping from ModelType to integer is defined here. It should match | 279 // The mapping from ModelType to integer is defined here. It should match |
282 // the mapping from integer to labels defined in histograms.xml. | 280 // the mapping from integer to labels defined in histograms.xml. |
283 SYNC_EXPORT int ModelTypeToHistogramInt(ModelType model_type); | 281 int ModelTypeToHistogramInt(ModelType model_type); |
284 | 282 |
285 // Handles all model types, and not just real ones. | 283 // Handles all model types, and not just real ones. |
286 // | 284 // |
287 // Caller takes ownership of returned value. | 285 // Caller takes ownership of returned value. |
288 SYNC_EXPORT base::StringValue* ModelTypeToValue(ModelType model_type); | 286 base::StringValue* ModelTypeToValue(ModelType model_type); |
289 | 287 |
290 // Converts a Value into a ModelType - complement to ModelTypeToValue(). | 288 // Converts a Value into a ModelType - complement to ModelTypeToValue(). |
291 SYNC_EXPORT ModelType ModelTypeFromValue(const base::Value& value); | 289 ModelType ModelTypeFromValue(const base::Value& value); |
292 | 290 |
293 // Returns the ModelType corresponding to the name |model_type_string|. | 291 // Returns the ModelType corresponding to the name |model_type_string|. |
294 SYNC_EXPORT ModelType ModelTypeFromString(const std::string& model_type_string); | 292 ModelType ModelTypeFromString(const std::string& model_type_string); |
295 | 293 |
296 // Returns the comma-separated string representation of |model_types|. | 294 // Returns the comma-separated string representation of |model_types|. |
297 SYNC_EXPORT std::string ModelTypeSetToString(ModelTypeSet model_types); | 295 std::string ModelTypeSetToString(ModelTypeSet model_types); |
298 | 296 |
299 // Necessary for compatibility with EXPECT_EQ and the like. | 297 // Necessary for compatibility with EXPECT_EQ and the like. |
300 SYNC_EXPORT std::ostream& operator<<(std::ostream& out, | 298 std::ostream& operator<<(std::ostream& out, ModelTypeSet model_type_set); |
301 ModelTypeSet model_type_set); | |
302 | 299 |
303 // Returns the set of comma-separated model types from |model_type_string|. | 300 // Returns the set of comma-separated model types from |model_type_string|. |
304 SYNC_EXPORT ModelTypeSet | 301 ModelTypeSet ModelTypeSetFromString(const std::string& model_type_string); |
305 ModelTypeSetFromString(const std::string& model_type_string); | |
306 | 302 |
307 SYNC_EXPORT std::unique_ptr<base::ListValue> ModelTypeSetToValue( | 303 std::unique_ptr<base::ListValue> ModelTypeSetToValue(ModelTypeSet model_types); |
308 ModelTypeSet model_types); | |
309 | 304 |
310 SYNC_EXPORT ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value); | 305 ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value); |
311 | 306 |
312 // Returns a string corresponding to the syncable tag for this datatype. | 307 // Returns a string corresponding to the syncable tag for this datatype. |
313 SYNC_EXPORT std::string ModelTypeToRootTag(ModelType type); | 308 std::string ModelTypeToRootTag(ModelType type); |
314 | 309 |
315 // Returns root_tag for |model_type| in ModelTypeInfo. | 310 // Returns root_tag for |model_type| in ModelTypeInfo. |
316 // Difference with ModelTypeToRootTag(), this just simply return toor_tag in | 311 // Difference with ModelTypeToRootTag(), this just simply return toor_tag in |
317 // ModelTypeInfo. | 312 // ModelTypeInfo. |
318 SYNC_EXPORT const char* GetModelTypeRootTag(ModelType model_type); | 313 const char* GetModelTypeRootTag(ModelType model_type); |
319 | 314 |
320 // Convert a real model type to a notification type (used for | 315 // Convert a real model type to a notification type (used for |
321 // subscribing to server-issued notifications). Returns true iff | 316 // subscribing to server-issued notifications). Returns true iff |
322 // |model_type| was a real model type and |notification_type| was | 317 // |model_type| was a real model type and |notification_type| was |
323 // filled in. | 318 // filled in. |
324 SYNC_EXPORT bool RealModelTypeToNotificationType( | 319 bool RealModelTypeToNotificationType(ModelType model_type, |
325 ModelType model_type, | 320 std::string* notification_type); |
326 std::string* notification_type); | |
327 | 321 |
328 // Converts a notification type to a real model type. Returns true | 322 // Converts a notification type to a real model type. Returns true |
329 // iff |notification_type| was the notification type of a real model | 323 // iff |notification_type| was the notification type of a real model |
330 // type and |model_type| was filled in. | 324 // type and |model_type| was filled in. |
331 SYNC_EXPORT bool NotificationTypeToRealModelType( | 325 bool NotificationTypeToRealModelType(const std::string& notification_type, |
332 const std::string& notification_type, | 326 ModelType* model_type); |
333 ModelType* model_type); | |
334 | 327 |
335 // Returns true if |model_type| is a real datatype | 328 // Returns true if |model_type| is a real datatype |
336 SYNC_EXPORT bool IsRealDataType(ModelType model_type); | 329 bool IsRealDataType(ModelType model_type); |
337 | 330 |
338 // Returns true if |model_type| is a proxy type | 331 // Returns true if |model_type| is a proxy type |
339 SYNC_EXPORT bool IsProxyType(ModelType model_type); | 332 bool IsProxyType(ModelType model_type); |
340 | 333 |
341 // Returns true if |model_type| is an act-once type. Act once types drop | 334 // Returns true if |model_type| is an act-once type. Act once types drop |
342 // entities after applying them. Drops are deletes that are not synced to other | 335 // entities after applying them. Drops are deletes that are not synced to other |
343 // clients. | 336 // clients. |
344 // TODO(haitaol): Make entries of act-once data types immutable. | 337 // TODO(haitaol): Make entries of act-once data types immutable. |
345 SYNC_EXPORT bool IsActOnceDataType(ModelType model_type); | 338 bool IsActOnceDataType(ModelType model_type); |
346 | 339 |
347 // Returns true if |model_type| requires its root folder to be explicitly | 340 // Returns true if |model_type| requires its root folder to be explicitly |
348 // created on the server during initial sync. | 341 // created on the server during initial sync. |
349 SYNC_EXPORT bool IsTypeWithServerGeneratedRoot(ModelType model_type); | 342 bool IsTypeWithServerGeneratedRoot(ModelType model_type); |
350 | 343 |
351 // Returns true if root folder for |model_type| is created on the client when | 344 // Returns true if root folder for |model_type| is created on the client when |
352 // that type is initially synced. | 345 // that type is initially synced. |
353 SYNC_EXPORT bool IsTypeWithClientGeneratedRoot(ModelType model_type); | 346 bool IsTypeWithClientGeneratedRoot(ModelType model_type); |
354 | 347 |
355 // Returns true if |model_type| supports parent-child hierarchy or entries. | 348 // Returns true if |model_type| supports parent-child hierarchy or entries. |
356 SYNC_EXPORT bool TypeSupportsHierarchy(ModelType model_type); | 349 bool TypeSupportsHierarchy(ModelType model_type); |
357 | 350 |
358 // Returns true if |model_type| supports ordering of sibling entries. | 351 // Returns true if |model_type| supports ordering of sibling entries. |
359 SYNC_EXPORT bool TypeSupportsOrdering(ModelType model_type); | 352 bool TypeSupportsOrdering(ModelType model_type); |
360 | 353 |
361 } // namespace syncer | 354 } // namespace syncer |
362 | 355 |
363 #endif // COMPONENTS_SYNC_BASE_MODEL_TYPE_H_ | 356 #endif // COMPONENTS_SYNC_BASE_MODEL_TYPE_H_ |
OLD | NEW |