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 #ifndef COMPONENTS_SYNC_BASE_MODEL_TYPE_H_ | 5 #ifndef COMPONENTS_SYNC_BASE_MODEL_TYPE_H_ |
6 #define COMPONENTS_SYNC_BASE_MODEL_TYPE_H_ | 6 #define COMPONENTS_SYNC_BASE_MODEL_TYPE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <ostream> | 10 #include <ostream> |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "components/reading_list/features/reading_list_enable_flags.h" |
15 #include "components/sync/base/enum_set.h" | 16 #include "components/sync/base/enum_set.h" |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 class ListValue; | 19 class ListValue; |
19 class Value; | 20 class Value; |
20 } | 21 } |
21 | 22 |
22 namespace sync_pb { | 23 namespace sync_pb { |
23 class EntitySpecifics; | 24 class EntitySpecifics; |
24 class SyncEntity; | 25 class SyncEntity; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 // local concept: the enum is not in the protocol. The SyncEntity's ModelType | 187 // local concept: the enum is not in the protocol. The SyncEntity's ModelType |
187 // is inferred from the presence of particular datatype field in the | 188 // is inferred from the presence of particular datatype field in the |
188 // entity specifics. | 189 // entity specifics. |
189 ModelType GetModelType(const sync_pb::SyncEntity& sync_entity); | 190 ModelType GetModelType(const sync_pb::SyncEntity& sync_entity); |
190 | 191 |
191 // Extract the model type from an EntitySpecifics field. Note that there | 192 // Extract the model type from an EntitySpecifics field. Note that there |
192 // are some ModelTypes (like TOP_LEVEL_FOLDER) that can't be inferred this way; | 193 // are some ModelTypes (like TOP_LEVEL_FOLDER) that can't be inferred this way; |
193 // prefer using GetModelType where possible. | 194 // prefer using GetModelType where possible. |
194 ModelType GetModelTypeFromSpecifics(const sync_pb::EntitySpecifics& specifics); | 195 ModelType GetModelTypeFromSpecifics(const sync_pb::EntitySpecifics& specifics); |
195 | 196 |
| 197 // Notes: |
| 198 // 1) This list must contain exactly the same elements as the set returned by |
| 199 // UserSelectableTypes(). |
| 200 // 2) This list must be in the same order as the respective values in the |
| 201 // ModelType enum. |
| 202 constexpr const char* kUserSelectableDataTypeNames[] = { |
| 203 "bookmarks", "preferences", "passwords", "autofill", |
| 204 "themes", "typedUrls", "extensions", "apps", |
| 205 #if BUILDFLAG(ENABLE_READING_LIST) |
| 206 "readingList", |
| 207 #endif |
| 208 "tabs", |
| 209 }; |
| 210 |
196 // Protocol types are those types that have actual protocol buffer | 211 // Protocol types are those types that have actual protocol buffer |
197 // representations. This distinguishes them from Proxy types, which have no | 212 // representations. This distinguishes them from Proxy types, which have no |
198 // protocol representation and are never sent to the server. | 213 // protocol representation and are never sent to the server. |
199 ModelTypeSet ProtocolTypes(); | 214 constexpr ModelTypeSet ProtocolTypes() { |
| 215 return ModelTypeSet(BOOKMARKS, PREFERENCES, PASSWORDS, AUTOFILL_PROFILE, |
| 216 AUTOFILL, AUTOFILL_WALLET_DATA, AUTOFILL_WALLET_METADATA, |
| 217 THEMES, TYPED_URLS, EXTENSIONS, SEARCH_ENGINES, SESSIONS, |
| 218 APPS, APP_SETTINGS, EXTENSION_SETTINGS, APP_NOTIFICATIONS, |
| 219 HISTORY_DELETE_DIRECTIVES, SYNCED_NOTIFICATIONS, |
| 220 SYNCED_NOTIFICATION_APP_INFO, DICTIONARY, FAVICON_IMAGES, |
| 221 FAVICON_TRACKING, DEVICE_INFO, PRIORITY_PREFERENCES, |
| 222 SUPERVISED_USER_SETTINGS, SUPERVISED_USERS, |
| 223 SUPERVISED_USER_SHARED_SETTINGS, ARTICLES, APP_LIST, |
| 224 WIFI_CREDENTIALS, SUPERVISED_USER_WHITELISTS, ARC_PACKAGE, |
| 225 PRINTERS, READING_LIST, USER_EVENTS, NIGORI, EXPERIMENTS); |
| 226 } |
200 | 227 |
201 // These are the normal user-controlled types. This is to distinguish from | 228 // These are the normal user-controlled types. This is to distinguish from |
202 // ControlTypes which are always enabled. Note that some of these share a | 229 // ControlTypes which are always enabled. Note that some of these share a |
203 // preference flag, so not all of them are individually user-selectable. | 230 // preference flag, so not all of them are individually user-selectable. |
204 ModelTypeSet UserTypes(); | 231 constexpr ModelTypeSet UserTypes() { |
| 232 return ModelTypeSet::FromRange(FIRST_USER_MODEL_TYPE, LAST_USER_MODEL_TYPE); |
| 233 } |
205 | 234 |
206 // These are the user-selectable data types. | 235 // These are the user-selectable data types. |
207 ModelTypeSet UserSelectableTypes(); | 236 constexpr ModelTypeSet UserSelectableTypes() { |
208 bool IsUserSelectableType(ModelType model_type); | 237 return ModelTypeSet(BOOKMARKS, PREFERENCES, PASSWORDS, AUTOFILL, THEMES, |
209 ModelTypeNameMap GetUserSelectableTypeNameMap(); | 238 TYPED_URLS, EXTENSIONS, APPS, |
| 239 #if BUILDFLAG(ENABLE_READING_LIST) |
| 240 READING_LIST, |
| 241 #endif |
| 242 PROXY_TABS); |
| 243 } |
210 | 244 |
211 // This is the subset of UserTypes() that can be encrypted. | 245 constexpr bool IsUserSelectableType(ModelType model_type) { |
212 ModelTypeSet EncryptableUserTypes(); | 246 return UserSelectableTypes().Has(model_type); |
| 247 } |
213 | 248 |
214 // This is the subset of UserTypes() that have priority over other types. These | 249 // This is the subset of UserTypes() that have priority over other types. These |
215 // types are synced before other user types and are never encrypted. | 250 // types are synced before other user types and are never encrypted. |
216 ModelTypeSet PriorityUserTypes(); | 251 constexpr ModelTypeSet PriorityUserTypes() { |
| 252 return ModelTypeSet(DEVICE_INFO, PRIORITY_PREFERENCES); |
| 253 } |
217 | 254 |
218 // Proxy types are placeholder types for handling implicitly enabling real | 255 // Proxy types are placeholder types for handling implicitly enabling real |
219 // types. They do not exist at the server, and are simply used for | 256 // types. They do not exist at the server, and are simply used for |
220 // UI/Configuration logic. | 257 // UI/Configuration logic. |
221 ModelTypeSet ProxyTypes(); | 258 constexpr ModelTypeSet ProxyTypes() { |
| 259 return ModelTypeSet::FromRange(FIRST_PROXY_TYPE, LAST_PROXY_TYPE); |
| 260 } |
222 | 261 |
223 // Returns a list of all control types. | 262 // Returns a list of all control types. |
224 // | 263 // |
225 // The control types are intended to contain metadata nodes that are essential | 264 // The control types are intended to contain metadata nodes that are essential |
226 // for the normal operation of the syncer. As such, they have the following | 265 // for the normal operation of the syncer. As such, they have the following |
227 // special properties: | 266 // special properties: |
228 // - They are downloaded early during SyncBackend initialization. | 267 // - They are downloaded early during SyncBackend initialization. |
229 // - They are always enabled. Users may not disable these types. | 268 // - They are always enabled. Users may not disable these types. |
230 // - Their contents are not encrypted automatically. | 269 // - Their contents are not encrypted automatically. |
231 // - They support custom update application and conflict resolution logic. | 270 // - They support custom update application and conflict resolution logic. |
232 // - All change processing occurs on the sync thread (GROUP_PASSIVE). | 271 // - All change processing occurs on the sync thread (GROUP_PASSIVE). |
233 ModelTypeSet ControlTypes(); | 272 constexpr ModelTypeSet ControlTypes() { |
| 273 return ModelTypeSet::FromRange(FIRST_CONTROL_MODEL_TYPE, |
| 274 LAST_CONTROL_MODEL_TYPE); |
| 275 } |
234 | 276 |
235 // Returns true if this is a control type. | 277 // Returns true if this is a control type. |
236 // | 278 // |
237 // See comment above for more information on what makes these types special. | 279 // See comment above for more information on what makes these types special. |
238 bool IsControlType(ModelType model_type); | 280 constexpr bool IsControlType(ModelType model_type) { |
| 281 return ControlTypes().Has(model_type); |
| 282 } |
239 | 283 |
240 // Core types are those data types used by sync's core functionality (i.e. not | 284 // Core types are those data types used by sync's core functionality (i.e. not |
241 // user data types). These types are always enabled, and include ControlTypes(). | 285 // user data types). These types are always enabled, and include ControlTypes(). |
242 // | 286 // |
243 // The set of all core types. | 287 // The set of all core types. |
244 ModelTypeSet CoreTypes(); | 288 constexpr ModelTypeSet CoreTypes() { |
| 289 return ModelTypeSet( |
| 290 NIGORI, EXPERIMENTS, SUPERVISED_USERS, SUPERVISED_USER_SETTINGS, |
| 291 SYNCED_NOTIFICATIONS, SYNCED_NOTIFICATION_APP_INFO, |
| 292 SUPERVISED_USER_SHARED_SETTINGS, SUPERVISED_USER_WHITELISTS); |
| 293 } |
245 // Those core types that have high priority (includes ControlTypes()). | 294 // Those core types that have high priority (includes ControlTypes()). |
246 ModelTypeSet PriorityCoreTypes(); | 295 constexpr ModelTypeSet PriorityCoreTypes() { |
| 296 return ModelTypeSet(NIGORI, EXPERIMENTS, SUPERVISED_USERS, |
| 297 SUPERVISED_USER_SETTINGS); |
| 298 } |
247 | 299 |
248 // Types that may commit data, but should never be included in a GetUpdates. | 300 // Types that may commit data, but should never be included in a GetUpdates. |
249 ModelTypeSet CommitOnlyTypes(); | 301 constexpr ModelTypeSet CommitOnlyTypes() { |
| 302 return ModelTypeSet(USER_EVENTS); |
| 303 } |
| 304 |
| 305 ModelTypeNameMap GetUserSelectableTypeNameMap(); |
| 306 |
| 307 // This is the subset of UserTypes() that can be encrypted. |
| 308 ModelTypeSet EncryptableUserTypes(); |
250 | 309 |
251 // Determine a model type from the field number of its associated | 310 // Determine a model type from the field number of its associated |
252 // EntitySpecifics field. Returns UNSPECIFIED if the field number is | 311 // EntitySpecifics field. Returns UNSPECIFIED if the field number is |
253 // not recognized. | 312 // not recognized. |
254 // | 313 // |
255 // If you're putting the result in a ModelTypeSet, you should use the | 314 // If you're putting the result in a ModelTypeSet, you should use the |
256 // following pattern: | 315 // following pattern: |
257 // | 316 // |
258 // ModelTypeSet model_types; | 317 // ModelTypeSet model_types; |
259 // // Say we're looping through a list of items, each of which has a | 318 // // Say we're looping through a list of items, each of which has a |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 | 411 |
353 // Returns true if |model_type| supports parent-child hierarchy or entries. | 412 // Returns true if |model_type| supports parent-child hierarchy or entries. |
354 bool TypeSupportsHierarchy(ModelType model_type); | 413 bool TypeSupportsHierarchy(ModelType model_type); |
355 | 414 |
356 // Returns true if |model_type| supports ordering of sibling entries. | 415 // Returns true if |model_type| supports ordering of sibling entries. |
357 bool TypeSupportsOrdering(ModelType model_type); | 416 bool TypeSupportsOrdering(ModelType model_type); |
358 | 417 |
359 } // namespace syncer | 418 } // namespace syncer |
360 | 419 |
361 #endif // COMPONENTS_SYNC_BASE_MODEL_TYPE_H_ | 420 #endif // COMPONENTS_SYNC_BASE_MODEL_TYPE_H_ |
OLD | NEW |