| 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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 if (specifics.has_user_event()) | 418 if (specifics.has_user_event()) |
| 419 return USER_EVENTS; | 419 return USER_EVENTS; |
| 420 if (specifics.has_nigori()) | 420 if (specifics.has_nigori()) |
| 421 return NIGORI; | 421 return NIGORI; |
| 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() { | |
| 429 return Difference(ModelTypeSet::All(), ProxyTypes()); | |
| 430 } | |
| 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() { | 428 ModelTypeNameMap GetUserSelectableTypeNameMap() { |
| 452 ModelTypeNameMap type_names; | 429 ModelTypeNameMap type_names; |
| 453 ModelTypeSet type_set = UserSelectableTypes(); | 430 ModelTypeSet type_set = UserSelectableTypes(); |
| 454 ModelTypeSet::Iterator it = type_set.First(); | 431 ModelTypeSet::Iterator it = type_set.First(); |
| 455 DCHECK_EQ(arraysize(kUserSelectableDataTypeNames), type_set.Size()); | 432 DCHECK_EQ(arraysize(kUserSelectableDataTypeNames), type_set.Size()); |
| 456 for (size_t i = 0; i < arraysize(kUserSelectableDataTypeNames) && it.Good(); | 433 for (size_t i = 0; i < arraysize(kUserSelectableDataTypeNames) && it.Good(); |
| 457 ++i, it.Inc()) { | 434 ++i, it.Inc()) { |
| 458 type_names[it.Get()] = kUserSelectableDataTypeNames[i]; | 435 type_names[it.Get()] = kUserSelectableDataTypeNames[i]; |
| 459 } | 436 } |
| 460 return type_names; | 437 return type_names; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 encryptable_user_types.Remove(SUPERVISED_USER_WHITELISTS); | 469 encryptable_user_types.Remove(SUPERVISED_USER_WHITELISTS); |
| 493 // User events are not encrypted since they are consumed server-side. | 470 // User events are not encrypted since they are consumed server-side. |
| 494 encryptable_user_types.Remove(USER_EVENTS); | 471 encryptable_user_types.Remove(USER_EVENTS); |
| 495 // Proxy types have no sync representation and are therefore not encrypted. | 472 // 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 | 473 // Note however that proxy types map to one or more protocol types, which |
| 497 // may or may not be encrypted themselves. | 474 // may or may not be encrypted themselves. |
| 498 encryptable_user_types.RemoveAll(ProxyTypes()); | 475 encryptable_user_types.RemoveAll(ProxyTypes()); |
| 499 return encryptable_user_types; | 476 return encryptable_user_types; |
| 500 } | 477 } |
| 501 | 478 |
| 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() { | |
| 522 ModelTypeSet result = PriorityCoreTypes(); | |
| 523 | |
| 524 // The following are low priority core types. | |
| 525 result.Put(SYNCED_NOTIFICATIONS); | |
| 526 result.Put(SYNCED_NOTIFICATION_APP_INFO); | |
| 527 result.Put(SUPERVISED_USER_SHARED_SETTINGS); | |
| 528 result.Put(SUPERVISED_USER_WHITELISTS); | |
| 529 | |
| 530 return result; | |
| 531 } | |
| 532 | |
| 533 ModelTypeSet PriorityCoreTypes() { | |
| 534 ModelTypeSet result = ControlTypes(); | |
| 535 | |
| 536 // The following are non-control core types. | |
| 537 result.Put(SUPERVISED_USERS); | |
| 538 result.Put(SUPERVISED_USER_SETTINGS); | |
| 539 | |
| 540 return result; | |
| 541 } | |
| 542 | |
| 543 const char* ModelTypeToString(ModelType model_type) { | 479 const char* ModelTypeToString(ModelType model_type) { |
| 544 // This is used in serialization routines as well as for displaying debug | 480 // 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 | 481 // information. Do not attempt to change these string values unless you know |
| 546 // what you're doing. | 482 // what you're doing. |
| 547 if (model_type >= UNSPECIFIED && model_type < MODEL_TYPE_COUNT) | 483 if (model_type >= UNSPECIFIED && model_type < MODEL_TYPE_COUNT) |
| 548 return kModelTypeInfoMap[model_type].model_type_string; | 484 return kModelTypeInfoMap[model_type].model_type_string; |
| 549 NOTREACHED() << "No known extension for model type."; | 485 NOTREACHED() << "No known extension for model type."; |
| 550 return "Invalid"; | 486 return "Invalid"; |
| 551 } | 487 } |
| 552 | 488 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 bool TypeSupportsHierarchy(ModelType model_type) { | 661 bool TypeSupportsHierarchy(ModelType model_type) { |
| 726 // TODO(stanisc): crbug/438313: Should this also include TOP_LEVEL_FOLDER? | 662 // TODO(stanisc): crbug/438313: Should this also include TOP_LEVEL_FOLDER? |
| 727 return model_type == BOOKMARKS; | 663 return model_type == BOOKMARKS; |
| 728 } | 664 } |
| 729 | 665 |
| 730 bool TypeSupportsOrdering(ModelType model_type) { | 666 bool TypeSupportsOrdering(ModelType model_type) { |
| 731 return model_type == BOOKMARKS; | 667 return model_type == BOOKMARKS; |
| 732 } | 668 } |
| 733 | 669 |
| 734 } // namespace syncer | 670 } // namespace syncer |
| OLD | NEW |