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/core/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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
196 // Protocol types are those types that have actual protocol buffer | 197 // Protocol types are those types that have actual protocol buffer |
197 // representations. This distinguishes them from Proxy types, which have no | 198 // representations. This distinguishes them from Proxy types, which have no |
198 // protocol representation and are never sent to the server. | 199 // protocol representation and are never sent to the server. |
199 ModelTypeSet ProtocolTypes(); | 200 constexpr ModelTypeSet ProtocolTypes() { |
| 201 return ModelTypeSet(BOOKMARKS, PREFERENCES, PASSWORDS, AUTOFILL_PROFILE, |
| 202 AUTOFILL, AUTOFILL_WALLET_DATA, AUTOFILL_WALLET_METADATA, |
| 203 THEMES, TYPED_URLS, EXTENSIONS, SEARCH_ENGINES, SESSIONS, |
| 204 APPS, APP_SETTINGS, EXTENSION_SETTINGS, APP_NOTIFICATIONS, |
| 205 HISTORY_DELETE_DIRECTIVES, SYNCED_NOTIFICATIONS, |
| 206 SYNCED_NOTIFICATION_APP_INFO, DICTIONARY, FAVICON_IMAGES, |
| 207 FAVICON_TRACKING, DEVICE_INFO, PRIORITY_PREFERENCES, |
| 208 SUPERVISED_USER_SETTINGS, SUPERVISED_USERS, |
| 209 SUPERVISED_USER_SHARED_SETTINGS, ARTICLES, APP_LIST, |
| 210 WIFI_CREDENTIALS, SUPERVISED_USER_WHITELISTS, ARC_PACKAGE, |
| 211 PRINTERS, READING_LIST, USER_EVENTS, NIGORI, EXPERIMENTS); |
| 212 } |
200 | 213 |
201 // These are the normal user-controlled types. This is to distinguish from | 214 // 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 | 215 // ControlTypes which are always enabled. Note that some of these share a |
203 // preference flag, so not all of them are individually user-selectable. | 216 // preference flag, so not all of them are individually user-selectable. |
204 ModelTypeSet UserTypes(); | 217 constexpr ModelTypeSet UserTypes() { |
| 218 return ModelTypeSet::FromRange(FIRST_USER_MODEL_TYPE, LAST_USER_MODEL_TYPE); |
| 219 } |
205 | 220 |
206 // These are the user-selectable data types. | 221 // These are the user-selectable data types. |
207 ModelTypeSet UserSelectableTypes(); | 222 constexpr ModelTypeSet UserSelectableTypes() { |
208 bool IsUserSelectableType(ModelType model_type); | 223 return ModelTypeSet(BOOKMARKS, PREFERENCES, PASSWORDS, AUTOFILL, THEMES, |
209 ModelTypeNameMap GetUserSelectableTypeNameMap(); | 224 TYPED_URLS, EXTENSIONS, APPS, |
| 225 #if BUILDFLAG(ENABLE_READING_LIST) |
| 226 READING_LIST, |
| 227 #endif |
| 228 PROXY_TABS); |
| 229 } |
210 | 230 |
211 // This is the subset of UserTypes() that can be encrypted. | 231 constexpr bool IsUserSelectableType(ModelType model_type) { |
212 ModelTypeSet EncryptableUserTypes(); | 232 return UserSelectableTypes().Has(model_type); |
| 233 } |
213 | 234 |
214 // This is the subset of UserTypes() that have priority over other types. These | 235 // 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. | 236 // types are synced before other user types and are never encrypted. |
216 ModelTypeSet PriorityUserTypes(); | 237 constexpr ModelTypeSet PriorityUserTypes() { |
| 238 return ModelTypeSet(DEVICE_INFO, PRIORITY_PREFERENCES); |
| 239 } |
217 | 240 |
218 // Proxy types are placeholder types for handling implicitly enabling real | 241 // Proxy types are placeholder types for handling implicitly enabling real |
219 // types. They do not exist at the server, and are simply used for | 242 // types. They do not exist at the server, and are simply used for |
220 // UI/Configuration logic. | 243 // UI/Configuration logic. |
221 ModelTypeSet ProxyTypes(); | 244 constexpr ModelTypeSet ProxyTypes() { |
| 245 return ModelTypeSet::FromRange(FIRST_PROXY_TYPE, LAST_PROXY_TYPE); |
| 246 } |
222 | 247 |
223 // Returns a list of all control types. | 248 // Returns a list of all control types. |
224 // | 249 // |
225 // The control types are intended to contain metadata nodes that are essential | 250 // 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 | 251 // for the normal operation of the syncer. As such, they have the following |
227 // special properties: | 252 // special properties: |
228 // - They are downloaded early during SyncBackend initialization. | 253 // - They are downloaded early during SyncBackend initialization. |
229 // - They are always enabled. Users may not disable these types. | 254 // - They are always enabled. Users may not disable these types. |
230 // - Their contents are not encrypted automatically. | 255 // - Their contents are not encrypted automatically. |
231 // - They support custom update application and conflict resolution logic. | 256 // - They support custom update application and conflict resolution logic. |
232 // - All change processing occurs on the sync thread (GROUP_PASSIVE). | 257 // - All change processing occurs on the sync thread (GROUP_PASSIVE). |
233 ModelTypeSet ControlTypes(); | 258 constexpr ModelTypeSet ControlTypes() { |
| 259 return ModelTypeSet::FromRange(FIRST_CONTROL_MODEL_TYPE, |
| 260 LAST_CONTROL_MODEL_TYPE); |
| 261 } |
234 | 262 |
235 // Returns true if this is a control type. | 263 // Returns true if this is a control type. |
236 // | 264 // |
237 // See comment above for more information on what makes these types special. | 265 // See comment above for more information on what makes these types special. |
238 bool IsControlType(ModelType model_type); | 266 constexpr bool IsControlType(ModelType model_type) { |
| 267 return ControlTypes().Has(model_type); |
| 268 } |
239 | 269 |
240 // Core types are those data types used by sync's core functionality (i.e. not | 270 // 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(). | 271 // user data types). These types are always enabled, and include ControlTypes(). |
242 // | 272 // |
243 // The set of all core types. | 273 // The set of all core types. |
244 ModelTypeSet CoreTypes(); | 274 constexpr ModelTypeSet CoreTypes() { |
| 275 return ModelTypeSet( |
| 276 NIGORI, EXPERIMENTS, SUPERVISED_USERS, SUPERVISED_USER_SETTINGS, |
| 277 SYNCED_NOTIFICATIONS, SYNCED_NOTIFICATION_APP_INFO, |
| 278 SUPERVISED_USER_SHARED_SETTINGS, SUPERVISED_USER_WHITELISTS); |
| 279 } |
245 // Those core types that have high priority (includes ControlTypes()). | 280 // Those core types that have high priority (includes ControlTypes()). |
246 ModelTypeSet PriorityCoreTypes(); | 281 constexpr ModelTypeSet PriorityCoreTypes() { |
| 282 return ModelTypeSet(NIGORI, EXPERIMENTS, SUPERVISED_USERS, |
| 283 SUPERVISED_USER_SETTINGS); |
| 284 } |
| 285 |
| 286 ModelTypeNameMap GetUserSelectableTypeNameMap(); |
| 287 |
| 288 // This is the subset of UserTypes() that can be encrypted. |
| 289 ModelTypeSet EncryptableUserTypes(); |
247 | 290 |
248 // Determine a model type from the field number of its associated | 291 // Determine a model type from the field number of its associated |
249 // EntitySpecifics field. Returns UNSPECIFIED if the field number is | 292 // EntitySpecifics field. Returns UNSPECIFIED if the field number is |
250 // not recognized. | 293 // not recognized. |
251 // | 294 // |
252 // If you're putting the result in a ModelTypeSet, you should use the | 295 // If you're putting the result in a ModelTypeSet, you should use the |
253 // following pattern: | 296 // following pattern: |
254 // | 297 // |
255 // ModelTypeSet model_types; | 298 // ModelTypeSet model_types; |
256 // // Say we're looping through a list of items, each of which has a | 299 // // Say we're looping through a list of items, each of which has a |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 | 394 |
352 // Returns true if |model_type| supports parent-child hierarchy or entries. | 395 // Returns true if |model_type| supports parent-child hierarchy or entries. |
353 bool TypeSupportsHierarchy(ModelType model_type); | 396 bool TypeSupportsHierarchy(ModelType model_type); |
354 | 397 |
355 // Returns true if |model_type| supports ordering of sibling entries. | 398 // Returns true if |model_type| supports ordering of sibling entries. |
356 bool TypeSupportsOrdering(ModelType model_type); | 399 bool TypeSupportsOrdering(ModelType model_type); |
357 | 400 |
358 } // namespace syncer | 401 } // namespace syncer |
359 | 402 |
360 #endif // COMPONENTS_SYNC_BASE_MODEL_TYPE_H_ | 403 #endif // COMPONENTS_SYNC_BASE_MODEL_TYPE_H_ |
OLD | NEW |