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 ModelTypeSet ProtocolTypes(); |
skym
2017/05/05 23:15:42
Why isn't this one constexpr?
| |
200 | 201 |
201 // These are the normal user-controlled types. This is to distinguish from | 202 // 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 | 203 // ControlTypes which are always enabled. Note that some of these share a |
203 // preference flag, so not all of them are individually user-selectable. | 204 // preference flag, so not all of them are individually user-selectable. |
204 ModelTypeSet UserTypes(); | 205 constexpr ModelTypeSet UserTypes() { |
206 return ModelTypeSet::FromRange(FIRST_USER_MODEL_TYPE, LAST_USER_MODEL_TYPE); | |
207 } | |
205 | 208 |
206 // These are the user-selectable data types. | 209 // These are the user-selectable data types. |
207 ModelTypeSet UserSelectableTypes(); | 210 constexpr ModelTypeSet UserSelectableTypes() { |
208 bool IsUserSelectableType(ModelType model_type); | 211 return ModelTypeSet(BOOKMARKS, PREFERENCES, PASSWORDS, AUTOFILL, THEMES, |
212 TYPED_URLS, EXTENSIONS, APPS, | |
213 #if BUILDFLAG(ENABLE_READING_LIST) | |
214 READING_LIST, | |
215 #endif | |
216 PROXY_TABS); | |
217 } | |
218 | |
219 constexpr bool IsUserSelectableType(ModelType model_type) { | |
skym
2017/05/05 23:15:42
Can you re-order these functions so all the conste
Patrick Noland
2017/05/08 20:29:19
Done.
| |
220 return UserSelectableTypes().Has(model_type); | |
221 } | |
222 | |
209 ModelTypeNameMap GetUserSelectableTypeNameMap(); | 223 ModelTypeNameMap GetUserSelectableTypeNameMap(); |
210 | 224 |
211 // This is the subset of UserTypes() that can be encrypted. | 225 // This is the subset of UserTypes() that can be encrypted. |
212 ModelTypeSet EncryptableUserTypes(); | 226 ModelTypeSet EncryptableUserTypes(); |
213 | 227 |
214 // This is the subset of UserTypes() that have priority over other types. These | 228 // 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. | 229 // types are synced before other user types and are never encrypted. |
216 ModelTypeSet PriorityUserTypes(); | 230 constexpr ModelTypeSet PriorityUserTypes() { |
231 return ModelTypeSet(DEVICE_INFO, PRIORITY_PREFERENCES); | |
232 } | |
217 | 233 |
218 // Proxy types are placeholder types for handling implicitly enabling real | 234 // Proxy types are placeholder types for handling implicitly enabling real |
219 // types. They do not exist at the server, and are simply used for | 235 // types. They do not exist at the server, and are simply used for |
220 // UI/Configuration logic. | 236 // UI/Configuration logic. |
221 ModelTypeSet ProxyTypes(); | 237 constexpr ModelTypeSet ProxyTypes() { |
238 return ModelTypeSet::FromRange(FIRST_PROXY_TYPE, LAST_PROXY_TYPE); | |
239 } | |
222 | 240 |
223 // Returns a list of all control types. | 241 // Returns a list of all control types. |
224 // | 242 // |
225 // The control types are intended to contain metadata nodes that are essential | 243 // 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 | 244 // for the normal operation of the syncer. As such, they have the following |
227 // special properties: | 245 // special properties: |
228 // - They are downloaded early during SyncBackend initialization. | 246 // - They are downloaded early during SyncBackend initialization. |
229 // - They are always enabled. Users may not disable these types. | 247 // - They are always enabled. Users may not disable these types. |
230 // - Their contents are not encrypted automatically. | 248 // - Their contents are not encrypted automatically. |
231 // - They support custom update application and conflict resolution logic. | 249 // - They support custom update application and conflict resolution logic. |
232 // - All change processing occurs on the sync thread (GROUP_PASSIVE). | 250 // - All change processing occurs on the sync thread (GROUP_PASSIVE). |
233 ModelTypeSet ControlTypes(); | 251 constexpr ModelTypeSet ControlTypes() { |
252 return ModelTypeSet::FromRange(FIRST_CONTROL_MODEL_TYPE, | |
253 LAST_CONTROL_MODEL_TYPE); | |
254 } | |
234 | 255 |
235 // Returns true if this is a control type. | 256 // Returns true if this is a control type. |
236 // | 257 // |
237 // See comment above for more information on what makes these types special. | 258 // See comment above for more information on what makes these types special. |
238 bool IsControlType(ModelType model_type); | 259 constexpr bool IsControlType(ModelType model_type) { |
260 return ControlTypes().Has(model_type); | |
261 } | |
239 | 262 |
240 // Core types are those data types used by sync's core functionality (i.e. not | 263 // 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(). | 264 // user data types). These types are always enabled, and include ControlTypes(). |
242 // | 265 // |
243 // The set of all core types. | 266 // The set of all core types. |
244 ModelTypeSet CoreTypes(); | 267 ModelTypeSet CoreTypes(); |
skym
2017/05/05 23:15:41
Why isn't this one constexpr?
Patrick Noland
2017/05/08 20:29:19
Done.
| |
245 // Those core types that have high priority (includes ControlTypes()). | 268 // Those core types that have high priority (includes ControlTypes()). |
246 ModelTypeSet PriorityCoreTypes(); | 269 ModelTypeSet PriorityCoreTypes(); |
skym
2017/05/05 23:15:42
Why isn't this one constexpr?
Patrick Noland
2017/05/08 20:29:19
Done.
| |
247 | 270 |
248 // Determine a model type from the field number of its associated | 271 // Determine a model type from the field number of its associated |
249 // EntitySpecifics field. Returns UNSPECIFIED if the field number is | 272 // EntitySpecifics field. Returns UNSPECIFIED if the field number is |
250 // not recognized. | 273 // not recognized. |
251 // | 274 // |
252 // If you're putting the result in a ModelTypeSet, you should use the | 275 // If you're putting the result in a ModelTypeSet, you should use the |
253 // following pattern: | 276 // following pattern: |
254 // | 277 // |
255 // ModelTypeSet model_types; | 278 // ModelTypeSet model_types; |
256 // // Say we're looping through a list of items, each of which has a | 279 // // Say we're looping through a list of items, each of which has a |
257 // // field number. | 280 // // field number. |
258 // for (...) { | 281 // for (...) { |
259 // int field_number = ...; | 282 // int field_number = ...; |
260 // ModelType model_type = | 283 // ModelType model_type = |
261 // GetModelTypeFromSpecificsFieldNumber(field_number); | 284 // GetModelTypeFromSpecificsFieldNumber(field_number); |
262 // if (!IsRealDataType(model_type)) { | 285 // if (!IsRealDataType(model_type)) { |
263 // DLOG(WARNING) << "Unknown field number " << field_number; | 286 // DLOG(WARNING) << "Unknown field number " << field_number; |
264 // continue; | 287 // continue; |
265 // } | 288 // } |
266 // model_types.Put(model_type); | 289 // model_types.Put(model_type); |
267 // } | 290 // } |
268 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number); | 291 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number); |
269 | 292 |
270 // Return the field number of the EntitySpecifics field associated with | 293 // Return the field number of the EntitySpecifics field associated with |
271 // a model type. | 294 // a model type. |
272 int GetSpecificsFieldNumberFromModelType(ModelType model_type); | 295 int GetSpecificsFieldNumberFromModelType(ModelType model_type); |
273 | 296 |
274 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in); | 297 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in); |
skym
2017/05/05 23:15:41
Why isn't this one constexpr?
Patrick Noland
2017/05/08 20:29:19
There's not a clean way to constexpr copy an EnumS
| |
275 | 298 |
276 // TODO(sync): The functions below badly need some cleanup. | 299 // TODO(sync): The functions below badly need some cleanup. |
277 | 300 |
278 // Returns a pointer to a string with application lifetime that represents | 301 // Returns a pointer to a string with application lifetime that represents |
279 // the name of |model_type|. | 302 // the name of |model_type|. |
280 const char* ModelTypeToString(ModelType model_type); | 303 const char* ModelTypeToString(ModelType model_type); |
281 | 304 |
282 // Some histograms take an integer parameter that represents a model type. | 305 // Some histograms take an integer parameter that represents a model type. |
283 // The mapping from ModelType to integer is defined here. It should match | 306 // The mapping from ModelType to integer is defined here. It should match |
284 // the mapping from integer to labels defined in histograms.xml. | 307 // the mapping from integer to labels defined in histograms.xml. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 | 374 |
352 // Returns true if |model_type| supports parent-child hierarchy or entries. | 375 // Returns true if |model_type| supports parent-child hierarchy or entries. |
353 bool TypeSupportsHierarchy(ModelType model_type); | 376 bool TypeSupportsHierarchy(ModelType model_type); |
354 | 377 |
355 // Returns true if |model_type| supports ordering of sibling entries. | 378 // Returns true if |model_type| supports ordering of sibling entries. |
356 bool TypeSupportsOrdering(ModelType model_type); | 379 bool TypeSupportsOrdering(ModelType model_type); |
357 | 380 |
358 } // namespace syncer | 381 } // namespace syncer |
359 | 382 |
360 #endif // COMPONENTS_SYNC_BASE_MODEL_TYPE_H_ | 383 #endif // COMPONENTS_SYNC_BASE_MODEL_TYPE_H_ |
OLD | NEW |