| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "components/sync/base/model_type.h" | 5 #include "components/sync/base/model_type.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 if (specifics.has_experiments()) | 422 if (specifics.has_experiments()) |
| 423 return EXPERIMENTS; | 423 return EXPERIMENTS; |
| 424 | 424 |
| 425 return UNSPECIFIED; | 425 return UNSPECIFIED; |
| 426 } | 426 } |
| 427 | 427 |
| 428 ModelTypeSet ProtocolTypes() { | 428 ModelTypeSet ProtocolTypes() { |
| 429 return Difference(ModelTypeSet::All(), ProxyTypes()); | 429 return Difference(ModelTypeSet::All(), ProxyTypes()); |
| 430 } | 430 } |
| 431 | 431 |
| 432 ModelTypeSet UserTypes() { | |
| 433 // TODO(sync): We should be able to build the actual enumset's internal | |
| 434 // bitset value here at compile time, instead of makes a new one each time. | |
| 435 return ModelTypeSet::FromRange(FIRST_USER_MODEL_TYPE, LAST_USER_MODEL_TYPE); | |
| 436 } | |
| 437 | |
| 438 ModelTypeSet UserSelectableTypes() { | |
| 439 return ModelTypeSet(BOOKMARKS, PREFERENCES, PASSWORDS, AUTOFILL, THEMES, | |
| 440 TYPED_URLS, EXTENSIONS, APPS, | |
| 441 #if BUILDFLAG(ENABLE_READING_LIST) | |
| 442 READING_LIST, | |
| 443 #endif | |
| 444 PROXY_TABS); | |
| 445 } | |
| 446 | |
| 447 bool IsUserSelectableType(ModelType model_type) { | |
| 448 return UserSelectableTypes().Has(model_type); | |
| 449 } | |
| 450 | |
| 451 ModelTypeNameMap GetUserSelectableTypeNameMap() { | 432 ModelTypeNameMap GetUserSelectableTypeNameMap() { |
| 452 ModelTypeNameMap type_names; | 433 ModelTypeNameMap type_names; |
| 453 ModelTypeSet type_set = UserSelectableTypes(); | 434 ModelTypeSet type_set = UserSelectableTypes(); |
| 454 ModelTypeSet::Iterator it = type_set.First(); | 435 ModelTypeSet::Iterator it = type_set.First(); |
| 455 DCHECK_EQ(arraysize(kUserSelectableDataTypeNames), type_set.Size()); | 436 DCHECK_EQ(arraysize(kUserSelectableDataTypeNames), type_set.Size()); |
| 456 for (size_t i = 0; i < arraysize(kUserSelectableDataTypeNames) && it.Good(); | 437 for (size_t i = 0; i < arraysize(kUserSelectableDataTypeNames) && it.Good(); |
| 457 ++i, it.Inc()) { | 438 ++i, it.Inc()) { |
| 458 type_names[it.Get()] = kUserSelectableDataTypeNames[i]; | 439 type_names[it.Get()] = kUserSelectableDataTypeNames[i]; |
| 459 } | 440 } |
| 460 return type_names; | 441 return type_names; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 encryptable_user_types.Remove(SUPERVISED_USER_WHITELISTS); | 473 encryptable_user_types.Remove(SUPERVISED_USER_WHITELISTS); |
| 493 // User events are not encrypted since they are consumed server-side. | 474 // User events are not encrypted since they are consumed server-side. |
| 494 encryptable_user_types.Remove(USER_EVENTS); | 475 encryptable_user_types.Remove(USER_EVENTS); |
| 495 // Proxy types have no sync representation and are therefore not encrypted. | 476 // Proxy types have no sync representation and are therefore not encrypted. |
| 496 // Note however that proxy types map to one or more protocol types, which | 477 // Note however that proxy types map to one or more protocol types, which |
| 497 // may or may not be encrypted themselves. | 478 // may or may not be encrypted themselves. |
| 498 encryptable_user_types.RemoveAll(ProxyTypes()); | 479 encryptable_user_types.RemoveAll(ProxyTypes()); |
| 499 return encryptable_user_types; | 480 return encryptable_user_types; |
| 500 } | 481 } |
| 501 | 482 |
| 502 ModelTypeSet PriorityUserTypes() { | |
| 503 return ModelTypeSet(DEVICE_INFO, PRIORITY_PREFERENCES); | |
| 504 } | |
| 505 | |
| 506 ModelTypeSet ControlTypes() { | |
| 507 // TODO(sync): We should be able to build the actual enumset's internal | |
| 508 // bitset value here at compile time, instead of makes a new one each time. | |
| 509 return ModelTypeSet::FromRange(FIRST_CONTROL_MODEL_TYPE, | |
| 510 LAST_CONTROL_MODEL_TYPE); | |
| 511 } | |
| 512 | |
| 513 ModelTypeSet ProxyTypes() { | |
| 514 return ModelTypeSet::FromRange(FIRST_PROXY_TYPE, LAST_PROXY_TYPE); | |
| 515 } | |
| 516 | |
| 517 bool IsControlType(ModelType model_type) { | |
| 518 return ControlTypes().Has(model_type); | |
| 519 } | |
| 520 | |
| 521 ModelTypeSet CoreTypes() { | 483 ModelTypeSet CoreTypes() { |
| 522 ModelTypeSet result = PriorityCoreTypes(); | 484 ModelTypeSet result = PriorityCoreTypes(); |
| 523 | 485 |
| 524 // The following are low priority core types. | 486 // The following are low priority core types. |
| 525 result.Put(SYNCED_NOTIFICATIONS); | 487 result.PutAll({SYNCED_NOTIFICATIONS, SYNCED_NOTIFICATION_APP_INFO, |
| 526 result.Put(SYNCED_NOTIFICATION_APP_INFO); | 488 SUPERVISED_USER_SHARED_SETTINGS, SUPERVISED_USER_WHITELISTS}); |
| 527 result.Put(SUPERVISED_USER_SHARED_SETTINGS); | |
| 528 result.Put(SUPERVISED_USER_WHITELISTS); | |
| 529 | 489 |
| 530 return result; | 490 return result; |
| 531 } | 491 } |
| 532 | 492 |
| 533 ModelTypeSet PriorityCoreTypes() { | 493 ModelTypeSet PriorityCoreTypes() { |
| 534 ModelTypeSet result = ControlTypes(); | 494 ModelTypeSet result = ControlTypes(); |
| 535 | 495 |
| 536 // The following are non-control core types. | 496 // The following are non-control core types. |
| 537 result.Put(SUPERVISED_USERS); | 497 result.PutAll({SUPERVISED_USERS, SUPERVISED_USER_SETTINGS}); |
| 538 result.Put(SUPERVISED_USER_SETTINGS); | |
| 539 | 498 |
| 540 return result; | 499 return result; |
| 541 } | 500 } |
| 542 | 501 |
| 543 const char* ModelTypeToString(ModelType model_type) { | 502 const char* ModelTypeToString(ModelType model_type) { |
| 544 // This is used in serialization routines as well as for displaying debug | 503 // This is used in serialization routines as well as for displaying debug |
| 545 // information. Do not attempt to change these string values unless you know | 504 // information. Do not attempt to change these string values unless you know |
| 546 // what you're doing. | 505 // what you're doing. |
| 547 if (model_type >= UNSPECIFIED && model_type < MODEL_TYPE_COUNT) | 506 if (model_type >= UNSPECIFIED && model_type < MODEL_TYPE_COUNT) |
| 548 return kModelTypeInfoMap[model_type].model_type_string; | 507 return kModelTypeInfoMap[model_type].model_type_string; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 bool TypeSupportsHierarchy(ModelType model_type) { | 684 bool TypeSupportsHierarchy(ModelType model_type) { |
| 726 // TODO(stanisc): crbug/438313: Should this also include TOP_LEVEL_FOLDER? | 685 // TODO(stanisc): crbug/438313: Should this also include TOP_LEVEL_FOLDER? |
| 727 return model_type == BOOKMARKS; | 686 return model_type == BOOKMARKS; |
| 728 } | 687 } |
| 729 | 688 |
| 730 bool TypeSupportsOrdering(ModelType model_type) { | 689 bool TypeSupportsOrdering(ModelType model_type) { |
| 731 return model_type == BOOKMARKS; | 690 return model_type == BOOKMARKS; |
| 732 } | 691 } |
| 733 | 692 |
| 734 } // namespace syncer | 693 } // namespace syncer |
| OLD | NEW |