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.
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.
9 #ifndef SYNC_INTERNAL_API_PUBLIC_BASE_MODEL_TYPE_H_
10 #define SYNC_INTERNAL_API_PUBLIC_BASE_MODEL_TYPE_H_
15 #include "base/logging.h"
16 #include "sync/base/sync_export.h"
17 #include "sync/internal_api/public/base/enum_set.h"
26 class EntitySpecifics;
32 // TODO(akalin): Move the non-exported functions in this file to a
36 // Object type unknown. Objects may transition through
37 // the unknown state during their initial creation, before
38 // their properties are set. After deletion, object types
39 // are generally preserved.
41 // A permanent folder whose children may be of mixed
42 // datatypes (e.g. the "Google Chrome" folder).
45 // ------------------------------------ Start of "real" model types.
46 // The model types declared before here are somewhat special, as they
47 // they do not correspond to any browser data model. The remaining types
48 // are bona fide model types; all have a related browser data model and
49 // can be represented in the protocol using a specific Message type in the
50 // EntitySpecifics protocol buffer.
52 // A bookmark folder or a bookmark URL object.
54 FIRST_USER_MODEL_TYPE = BOOKMARKS, // Declared 2nd, for debugger prettiness.
55 FIRST_REAL_MODEL_TYPE = FIRST_USER_MODEL_TYPE,
57 // A preference object.
61 // An AutofillProfile Object
63 // An autofill object.
67 // A typed_url object.
69 // An extension object.
71 // An object representing a custom search engine.
73 // An object representing a browser session.
77 // An app setting from the extension settings API.
79 // An extension setting from the extension settings API.
83 // History delete directives.
84 HISTORY_DELETE_DIRECTIVES,
85 // Synced push notifications.
87 // Synced Notification app info.
88 SYNCED_NOTIFICATION_APP_INFO,
89 // Custom spelling dictionary.
93 // Favicon tracking information.
95 // These preferences are synced before other user types and are never
98 // Managed user settings.
99 MANAGED_USER_SETTINGS,
100 // Managed users. Every managed user is a profile that is configured remotely
101 // by this user and can have restrictions applied. MANAGED_USERS and
102 // MANAGED_USER_SETTINGS can not be encrypted.
104 // Managed user shared settings. Shared settings can be modified both by the
105 // manager and the supervised user.
106 MANAGED_USER_SHARED_SETTINGS,
107 // Distilled articles.
112 // ---- Proxy types ----
113 // Proxy types are excluded from the sync protocol, but are still considered
114 // real user types. By convention, we prefix them with 'PROXY_' to distinguish
115 // them from normal protocol types.
117 // Tab sync. This is a placeholder type, so that Sessions can be implicitly
118 // enabled for history sync and tabs sync.
121 FIRST_PROXY_TYPE = PROXY_TABS,
122 LAST_PROXY_TYPE = PROXY_TABS,
124 LAST_USER_MODEL_TYPE = PROXY_TABS,
126 // ---- Control Types ----
127 // An object representing a set of Nigori keys.
129 FIRST_CONTROL_MODEL_TYPE = NIGORI,
130 // Client-specific metadata.
132 // Flags to enable experimental features.
134 LAST_CONTROL_MODEL_TYPE = EXPERIMENTS,
136 LAST_REAL_MODEL_TYPE = LAST_CONTROL_MODEL_TYPE,
138 // If you are adding a new sync datatype that is exposed to the user via the
139 // sync preferences UI, be sure to update the list in
140 // components/sync_driver/user_selectable_sync_type.h so that the UMA
141 // histograms for sync include your new type. In this case, be sure to also
142 // update the UserSelectableTypes() definition in
143 // sync/syncable/model_type.cc.
148 typedef EnumSet<ModelType, FIRST_REAL_MODEL_TYPE, LAST_REAL_MODEL_TYPE>
150 typedef EnumSet<ModelType, UNSPECIFIED, LAST_REAL_MODEL_TYPE>
153 inline ModelType ModelTypeFromInt(int i) {
155 DCHECK_LT(i, MODEL_TYPE_COUNT);
156 return static_cast<ModelType>(i);
159 // Used by tests outside of sync/.
160 SYNC_EXPORT void AddDefaultFieldValue(ModelType datatype,
161 sync_pb::EntitySpecifics* specifics);
163 // Extract the model type of a SyncEntity protocol buffer. ModelType is a
164 // local concept: the enum is not in the protocol. The SyncEntity's ModelType
165 // is inferred from the presence of particular datatype field in the
167 SYNC_EXPORT_PRIVATE ModelType GetModelType(
168 const sync_pb::SyncEntity& sync_entity);
170 // Extract the model type from an EntitySpecifics field. Note that there
171 // are some ModelTypes (like TOP_LEVEL_FOLDER) that can't be inferred this way;
172 // prefer using GetModelType where possible.
173 SYNC_EXPORT ModelType GetModelTypeFromSpecifics(
174 const sync_pb::EntitySpecifics& specifics);
176 // Protocol types are those types that have actual protocol buffer
177 // representations. This distinguishes them from Proxy types, which have no
178 // protocol representation and are never sent to the server.
179 SYNC_EXPORT ModelTypeSet ProtocolTypes();
181 // These are the normal user-controlled types. This is to distinguish from
182 // ControlTypes which are always enabled. Note that some of these share a
183 // preference flag, so not all of them are individually user-selectable.
184 SYNC_EXPORT ModelTypeSet UserTypes();
186 // These are the user-selectable data types.
187 SYNC_EXPORT ModelTypeSet UserSelectableTypes();
188 SYNC_EXPORT bool IsUserSelectableType(ModelType model_type);
190 // This is the subset of UserTypes() that can be encrypted.
191 SYNC_EXPORT_PRIVATE ModelTypeSet EncryptableUserTypes();
193 // This is the subset of UserTypes() that have priority over other types. These
194 // types are synced before other user types and are never encrypted.
195 SYNC_EXPORT ModelTypeSet PriorityUserTypes();
197 // Proxy types are placeholder types for handling implicitly enabling real
198 // types. They do not exist at the server, and are simply used for
199 // UI/Configuration logic.
200 SYNC_EXPORT ModelTypeSet ProxyTypes();
202 // Returns a list of all control types.
204 // The control types are intended to contain metadata nodes that are essential
205 // for the normal operation of the syncer. As such, they have the following
206 // special properties:
207 // - They are downloaded early during SyncBackend initialization.
208 // - They are always enabled. Users may not disable these types.
209 // - Their contents are not encrypted automatically.
210 // - They support custom update application and conflict resolution logic.
211 // - All change processing occurs on the sync thread (GROUP_PASSIVE).
212 SYNC_EXPORT ModelTypeSet ControlTypes();
214 // Returns true if this is a control type.
216 // See comment above for more information on what makes these types special.
217 SYNC_EXPORT bool IsControlType(ModelType model_type);
219 // Core types are those data types used by sync's core functionality (i.e. not
220 // user data types). These types are always enabled, and include ControlTypes().
222 // The set of all core types.
223 SYNC_EXPORT ModelTypeSet CoreTypes();
224 // Those core types that have high priority (includes ControlTypes()).
225 SYNC_EXPORT ModelTypeSet PriorityCoreTypes();
227 // Determine a model type from the field number of its associated
228 // EntitySpecifics field. Returns UNSPECIFIED if the field number is
231 // If you're putting the result in a ModelTypeSet, you should use the
232 // following pattern:
234 // ModelTypeSet model_types;
235 // // Say we're looping through a list of items, each of which has a
238 // int field_number = ...;
239 // ModelType model_type =
240 // GetModelTypeFromSpecificsFieldNumber(field_number);
241 // if (!IsRealDataType(model_type)) {
242 // DLOG(WARNING) << "Unknown field number " << field_number;
245 // model_types.Put(model_type);
247 SYNC_EXPORT_PRIVATE ModelType GetModelTypeFromSpecificsFieldNumber(
250 // Return the field number of the EntitySpecifics field associated with
253 // Used by tests outside of sync.
254 SYNC_EXPORT int GetSpecificsFieldNumberFromModelType(
255 ModelType model_type);
257 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in);
259 // TODO(sync): The functions below badly need some cleanup.
261 // Returns a pointer to a string with application lifetime that represents
262 // the name of |model_type|.
263 SYNC_EXPORT const char* ModelTypeToString(ModelType model_type);
265 // Some histograms take an integer parameter that represents a model type.
266 // The mapping from ModelType to integer is defined here. It should match
267 // the mapping from integer to labels defined in histograms.xml.
268 SYNC_EXPORT int ModelTypeToHistogramInt(ModelType model_type);
270 // Handles all model types, and not just real ones.
272 // Caller takes ownership of returned value.
273 SYNC_EXPORT_PRIVATE base::StringValue* ModelTypeToValue(ModelType model_type);
275 // Converts a Value into a ModelType - complement to ModelTypeToValue().
276 SYNC_EXPORT_PRIVATE ModelType ModelTypeFromValue(const base::Value& value);
278 // Returns the ModelType corresponding to the name |model_type_string|.
279 SYNC_EXPORT ModelType ModelTypeFromString(
280 const std::string& model_type_string);
282 SYNC_EXPORT std::string ModelTypeSetToString(ModelTypeSet model_types);
284 // Caller takes ownership of returned list.
285 SYNC_EXPORT base::ListValue* ModelTypeSetToValue(ModelTypeSet model_types);
287 SYNC_EXPORT ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value);
289 // Returns a string corresponding to the syncable tag for this datatype.
290 SYNC_EXPORT std::string ModelTypeToRootTag(ModelType type);
292 // Convert a real model type to a notification type (used for
293 // subscribing to server-issued notifications). Returns true iff
294 // |model_type| was a real model type and |notification_type| was
296 bool RealModelTypeToNotificationType(ModelType model_type,
297 std::string* notification_type);
299 // Converts a notification type to a real model type. Returns true
300 // iff |notification_type| was the notification type of a real model
301 // type and |model_type| was filled in.
302 SYNC_EXPORT bool NotificationTypeToRealModelType(
303 const std::string& notification_type,
304 ModelType* model_type);
306 // Returns true if |model_type| is a real datatype
307 SYNC_EXPORT bool IsRealDataType(ModelType model_type);
309 // Returns true if |model_type| is an act-once type. Act once types drop
310 // entities after applying them. Drops are deletes that are not synced to other
312 // TODO(haitaol): Make entries of act-once data types immutable.
313 SYNC_EXPORT bool IsActOnceDataType(ModelType model_type);
315 } // namespace syncer
317 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_MODEL_TYPE_H_