| 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 "sync/internal_api/public/base/model_type.h" | 5 #include "sync/internal_api/public/base/model_type.h" |
| 6 | 6 |
| 7 #include "base/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "sync/protocol/app_notification_specifics.pb.h" | 9 #include "sync/protocol/app_notification_specifics.pb.h" |
| 10 #include "sync/protocol/app_setting_specifics.pb.h" | 10 #include "sync/protocol/app_setting_specifics.pb.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 break; | 94 break; |
| 95 case DICTIONARY: | 95 case DICTIONARY: |
| 96 specifics->mutable_dictionary(); | 96 specifics->mutable_dictionary(); |
| 97 break; | 97 break; |
| 98 case FAVICON_IMAGES: | 98 case FAVICON_IMAGES: |
| 99 specifics->mutable_favicon_image(); | 99 specifics->mutable_favicon_image(); |
| 100 break; | 100 break; |
| 101 case FAVICON_TRACKING: | 101 case FAVICON_TRACKING: |
| 102 specifics->mutable_favicon_tracking(); | 102 specifics->mutable_favicon_tracking(); |
| 103 break; | 103 break; |
| 104 case MANAGED_USER_SETTINGS: |
| 105 specifics->mutable_managed_user_setting(); |
| 106 break; |
| 104 default: | 107 default: |
| 105 NOTREACHED() << "No known extension for model type."; | 108 NOTREACHED() << "No known extension for model type."; |
| 106 } | 109 } |
| 107 } | 110 } |
| 108 | 111 |
| 109 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { | 112 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { |
| 110 ModelTypeSet protocol_types = ProtocolTypes(); | 113 ModelTypeSet protocol_types = ProtocolTypes(); |
| 111 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); | 114 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); |
| 112 iter.Inc()) { | 115 iter.Inc()) { |
| 113 if (GetSpecificsFieldNumberFromModelType(iter.Get()) == field_number) | 116 if (GetSpecificsFieldNumberFromModelType(iter.Get()) == field_number) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 case PRIORITY_PREFERENCES: | 183 case PRIORITY_PREFERENCES: |
| 181 return sync_pb::EntitySpecifics::kPriorityPreferenceFieldNumber; | 184 return sync_pb::EntitySpecifics::kPriorityPreferenceFieldNumber; |
| 182 break; | 185 break; |
| 183 case DICTIONARY: | 186 case DICTIONARY: |
| 184 return sync_pb::EntitySpecifics::kDictionaryFieldNumber; | 187 return sync_pb::EntitySpecifics::kDictionaryFieldNumber; |
| 185 break; | 188 break; |
| 186 case FAVICON_IMAGES: | 189 case FAVICON_IMAGES: |
| 187 return sync_pb::EntitySpecifics::kFaviconImageFieldNumber; | 190 return sync_pb::EntitySpecifics::kFaviconImageFieldNumber; |
| 188 case FAVICON_TRACKING: | 191 case FAVICON_TRACKING: |
| 189 return sync_pb::EntitySpecifics::kFaviconTrackingFieldNumber; | 192 return sync_pb::EntitySpecifics::kFaviconTrackingFieldNumber; |
| 193 case MANAGED_USER_SETTINGS: |
| 194 return sync_pb::EntitySpecifics::kManagedUserSettingFieldNumber; |
| 190 default: | 195 default: |
| 191 NOTREACHED() << "No known extension for model type."; | 196 NOTREACHED() << "No known extension for model type."; |
| 192 return 0; | 197 return 0; |
| 193 } | 198 } |
| 194 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of " | 199 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of " |
| 195 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681"; | 200 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681"; |
| 196 return 0; | 201 return 0; |
| 197 } | 202 } |
| 198 | 203 |
| 199 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) { | 204 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 301 |
| 297 if (specifics.has_dictionary()) | 302 if (specifics.has_dictionary()) |
| 298 return DICTIONARY; | 303 return DICTIONARY; |
| 299 | 304 |
| 300 if (specifics.has_favicon_image()) | 305 if (specifics.has_favicon_image()) |
| 301 return FAVICON_IMAGES; | 306 return FAVICON_IMAGES; |
| 302 | 307 |
| 303 if (specifics.has_favicon_tracking()) | 308 if (specifics.has_favicon_tracking()) |
| 304 return FAVICON_TRACKING; | 309 return FAVICON_TRACKING; |
| 305 | 310 |
| 311 if (specifics.has_managed_user_setting()) |
| 312 return MANAGED_USER_SETTINGS; |
| 313 |
| 306 return UNSPECIFIED; | 314 return UNSPECIFIED; |
| 307 } | 315 } |
| 308 | 316 |
| 309 ModelTypeSet ProtocolTypes() { | 317 ModelTypeSet ProtocolTypes() { |
| 310 ModelTypeSet set = ModelTypeSet::All(); | 318 ModelTypeSet set = ModelTypeSet::All(); |
| 311 set.RemoveAll(ProxyTypes()); | 319 set.RemoveAll(ProxyTypes()); |
| 312 return set; | 320 return set; |
| 313 } | 321 } |
| 314 | 322 |
| 315 ModelTypeSet UserTypes() { | 323 ModelTypeSet UserTypes() { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 345 | 353 |
| 346 ModelTypeSet EncryptableUserTypes() { | 354 ModelTypeSet EncryptableUserTypes() { |
| 347 ModelTypeSet encryptable_user_types = UserTypes(); | 355 ModelTypeSet encryptable_user_types = UserTypes(); |
| 348 // We never encrypt history delete directives. | 356 // We never encrypt history delete directives. |
| 349 encryptable_user_types.Remove(HISTORY_DELETE_DIRECTIVES); | 357 encryptable_user_types.Remove(HISTORY_DELETE_DIRECTIVES); |
| 350 // Synced notifications are not encrypted since the server must see changes. | 358 // Synced notifications are not encrypted since the server must see changes. |
| 351 encryptable_user_types.Remove(SYNCED_NOTIFICATIONS); | 359 encryptable_user_types.Remove(SYNCED_NOTIFICATIONS); |
| 352 // Priority preferences are not encrypted because they might be synced before | 360 // Priority preferences are not encrypted because they might be synced before |
| 353 // encryption is ready. | 361 // encryption is ready. |
| 354 encryptable_user_types.RemoveAll(PriorityUserTypes()); | 362 encryptable_user_types.RemoveAll(PriorityUserTypes()); |
| 363 // Managed user settings are not encrypted since they are set server-side. |
| 364 encryptable_user_types.Remove(MANAGED_USER_SETTINGS); |
| 355 // Proxy types have no sync representation and are therefore not encrypted. | 365 // Proxy types have no sync representation and are therefore not encrypted. |
| 356 // Note however that proxy types map to one or more protocol types, which | 366 // Note however that proxy types map to one or more protocol types, which |
| 357 // may or may not be encrypted themselves. | 367 // may or may not be encrypted themselves. |
| 358 encryptable_user_types.RemoveAll(ProxyTypes()); | 368 encryptable_user_types.RemoveAll(ProxyTypes()); |
| 359 return encryptable_user_types; | 369 return encryptable_user_types; |
| 360 } | 370 } |
| 361 | 371 |
| 362 ModelTypeSet PriorityUserTypes() { | 372 ModelTypeSet PriorityUserTypes() { |
| 363 return ModelTypeSet(PRIORITY_PREFERENCES); | 373 return ModelTypeSet(PRIORITY_PREFERENCES); |
| 364 } | 374 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 case EXPERIMENTS: | 443 case EXPERIMENTS: |
| 434 return "Experiments"; | 444 return "Experiments"; |
| 435 case PRIORITY_PREFERENCES: | 445 case PRIORITY_PREFERENCES: |
| 436 return "Priority Preferences"; | 446 return "Priority Preferences"; |
| 437 case DICTIONARY: | 447 case DICTIONARY: |
| 438 return "Dictionary"; | 448 return "Dictionary"; |
| 439 case FAVICON_IMAGES: | 449 case FAVICON_IMAGES: |
| 440 return "Favicon Images"; | 450 return "Favicon Images"; |
| 441 case FAVICON_TRACKING: | 451 case FAVICON_TRACKING: |
| 442 return "Favicon Tracking"; | 452 return "Favicon Tracking"; |
| 453 case MANAGED_USER_SETTINGS: |
| 454 return "Managed User Settings"; |
| 443 case PROXY_TABS: | 455 case PROXY_TABS: |
| 444 return "Tabs"; | 456 return "Tabs"; |
| 445 default: | 457 default: |
| 446 break; | 458 break; |
| 447 } | 459 } |
| 448 NOTREACHED() << "No known extension for model type."; | 460 NOTREACHED() << "No known extension for model type."; |
| 449 return "INVALID"; | 461 return "INVALID"; |
| 450 } | 462 } |
| 451 | 463 |
| 452 // The normal rules about histograms apply here. Always append to the bottom of | 464 // The normal rules about histograms apply here. Always append to the bottom of |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 case PRIORITY_PREFERENCES: | 512 case PRIORITY_PREFERENCES: |
| 501 return 21; | 513 return 21; |
| 502 case DICTIONARY: | 514 case DICTIONARY: |
| 503 return 22; | 515 return 22; |
| 504 case FAVICON_IMAGES: | 516 case FAVICON_IMAGES: |
| 505 return 23; | 517 return 23; |
| 506 case FAVICON_TRACKING: | 518 case FAVICON_TRACKING: |
| 507 return 24; | 519 return 24; |
| 508 case PROXY_TABS: | 520 case PROXY_TABS: |
| 509 return 25; | 521 return 25; |
| 522 case MANAGED_USER_SETTINGS: |
| 523 return 26; |
| 510 // Silence a compiler warning. | 524 // Silence a compiler warning. |
| 511 case MODEL_TYPE_COUNT: | 525 case MODEL_TYPE_COUNT: |
| 512 return 0; | 526 return 0; |
| 513 } | 527 } |
| 514 return 0; | 528 return 0; |
| 515 } | 529 } |
| 516 | 530 |
| 517 base::StringValue* ModelTypeToValue(ModelType model_type) { | 531 base::StringValue* ModelTypeToValue(ModelType model_type) { |
| 518 if (model_type >= FIRST_REAL_MODEL_TYPE) { | 532 if (model_type >= FIRST_REAL_MODEL_TYPE) { |
| 519 return new base::StringValue(ModelTypeToString(model_type)); | 533 return new base::StringValue(ModelTypeToString(model_type)); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 else if (model_type_string == "Experiments") | 595 else if (model_type_string == "Experiments") |
| 582 return EXPERIMENTS; | 596 return EXPERIMENTS; |
| 583 else if (model_type_string == "Priority Preferences") | 597 else if (model_type_string == "Priority Preferences") |
| 584 return PRIORITY_PREFERENCES; | 598 return PRIORITY_PREFERENCES; |
| 585 else if (model_type_string == "Dictionary") | 599 else if (model_type_string == "Dictionary") |
| 586 return DICTIONARY; | 600 return DICTIONARY; |
| 587 else if (model_type_string == "Favicon Images") | 601 else if (model_type_string == "Favicon Images") |
| 588 return FAVICON_IMAGES; | 602 return FAVICON_IMAGES; |
| 589 else if (model_type_string == "Favicon Tracking") | 603 else if (model_type_string == "Favicon Tracking") |
| 590 return FAVICON_TRACKING; | 604 return FAVICON_TRACKING; |
| 605 else if (model_type_string == "Managed User Settings") |
| 606 return MANAGED_USER_SETTINGS; |
| 591 else if (model_type_string == "Tabs") | 607 else if (model_type_string == "Tabs") |
| 592 return PROXY_TABS; | 608 return PROXY_TABS; |
| 593 else | 609 else |
| 594 NOTREACHED() << "No known model type corresponding to " | 610 NOTREACHED() << "No known model type corresponding to " |
| 595 << model_type_string << "."; | 611 << model_type_string << "."; |
| 596 return UNSPECIFIED; | 612 return UNSPECIFIED; |
| 597 } | 613 } |
| 598 | 614 |
| 599 std::string ModelTypeSetToString(ModelTypeSet model_types) { | 615 std::string ModelTypeSetToString(ModelTypeSet model_types) { |
| 600 std::string result; | 616 std::string result; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 case EXPERIMENTS: | 685 case EXPERIMENTS: |
| 670 return "google_chrome_experiments"; | 686 return "google_chrome_experiments"; |
| 671 case PRIORITY_PREFERENCES: | 687 case PRIORITY_PREFERENCES: |
| 672 return "google_chrome_priority_preferences"; | 688 return "google_chrome_priority_preferences"; |
| 673 case DICTIONARY: | 689 case DICTIONARY: |
| 674 return "google_chrome_dictionary"; | 690 return "google_chrome_dictionary"; |
| 675 case FAVICON_IMAGES: | 691 case FAVICON_IMAGES: |
| 676 return "google_chrome_favicon_images"; | 692 return "google_chrome_favicon_images"; |
| 677 case FAVICON_TRACKING: | 693 case FAVICON_TRACKING: |
| 678 return "google_chrome_favicon_tracking"; | 694 return "google_chrome_favicon_tracking"; |
| 695 case MANAGED_USER_SETTINGS: |
| 696 return "google_chrome_managed_user_settings"; |
| 679 case PROXY_TABS: | 697 case PROXY_TABS: |
| 680 return std::string(); | 698 return std::string(); |
| 681 default: | 699 default: |
| 682 break; | 700 break; |
| 683 } | 701 } |
| 684 NOTREACHED() << "No known extension for model type."; | 702 NOTREACHED() << "No known extension for model type."; |
| 685 return "INVALID"; | 703 return "INVALID"; |
| 686 } | 704 } |
| 687 | 705 |
| 688 // TODO(akalin): Figure out a better way to do these mappings. | 706 // TODO(akalin): Figure out a better way to do these mappings. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 706 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; | 724 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; |
| 707 const char kHistoryDeleteDirectiveNotificationType[] = | 725 const char kHistoryDeleteDirectiveNotificationType[] = |
| 708 "HISTORY_DELETE_DIRECTIVE"; | 726 "HISTORY_DELETE_DIRECTIVE"; |
| 709 const char kSyncedNotificationType[] = "SYNCED_NOTIFICATION"; | 727 const char kSyncedNotificationType[] = "SYNCED_NOTIFICATION"; |
| 710 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; | 728 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; |
| 711 const char kExperimentsNotificationType[] = "EXPERIMENTS"; | 729 const char kExperimentsNotificationType[] = "EXPERIMENTS"; |
| 712 const char kPriorityPreferenceNotificationType[] = "PRIORITY_PREFERENCE"; | 730 const char kPriorityPreferenceNotificationType[] = "PRIORITY_PREFERENCE"; |
| 713 const char kDictionaryNotificationType[] = "DICTIONARY"; | 731 const char kDictionaryNotificationType[] = "DICTIONARY"; |
| 714 const char kFaviconImageNotificationType[] = "FAVICON_IMAGE"; | 732 const char kFaviconImageNotificationType[] = "FAVICON_IMAGE"; |
| 715 const char kFaviconTrackingNotificationType[] = "FAVICON_TRACKING"; | 733 const char kFaviconTrackingNotificationType[] = "FAVICON_TRACKING"; |
| 734 const char kManagedUserSettingNotificationType[] = "MANAGED_USER_SETTING"; |
| 716 } // namespace | 735 } // namespace |
| 717 | 736 |
| 718 bool RealModelTypeToNotificationType(ModelType model_type, | 737 bool RealModelTypeToNotificationType(ModelType model_type, |
| 719 std::string* notification_type) { | 738 std::string* notification_type) { |
| 720 switch (model_type) { | 739 switch (model_type) { |
| 721 case BOOKMARKS: | 740 case BOOKMARKS: |
| 722 *notification_type = kBookmarkNotificationType; | 741 *notification_type = kBookmarkNotificationType; |
| 723 return true; | 742 return true; |
| 724 case PREFERENCES: | 743 case PREFERENCES: |
| 725 *notification_type = kPreferenceNotificationType; | 744 *notification_type = kPreferenceNotificationType; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 return true; | 799 return true; |
| 781 case DICTIONARY: | 800 case DICTIONARY: |
| 782 *notification_type = kDictionaryNotificationType; | 801 *notification_type = kDictionaryNotificationType; |
| 783 return true; | 802 return true; |
| 784 case FAVICON_IMAGES: | 803 case FAVICON_IMAGES: |
| 785 *notification_type = kFaviconImageNotificationType; | 804 *notification_type = kFaviconImageNotificationType; |
| 786 return true; | 805 return true; |
| 787 case FAVICON_TRACKING: | 806 case FAVICON_TRACKING: |
| 788 *notification_type = kFaviconTrackingNotificationType; | 807 *notification_type = kFaviconTrackingNotificationType; |
| 789 return true; | 808 return true; |
| 809 case MANAGED_USER_SETTINGS: |
| 810 *notification_type = kManagedUserSettingNotificationType; |
| 811 return true; |
| 790 default: | 812 default: |
| 791 break; | 813 break; |
| 792 } | 814 } |
| 793 notification_type->clear(); | 815 notification_type->clear(); |
| 794 return false; | 816 return false; |
| 795 } | 817 } |
| 796 | 818 |
| 797 bool NotificationTypeToRealModelType(const std::string& notification_type, | 819 bool NotificationTypeToRealModelType(const std::string& notification_type, |
| 798 ModelType* model_type) { | 820 ModelType* model_type) { |
| 799 if (notification_type == kBookmarkNotificationType) { | 821 if (notification_type == kBookmarkNotificationType) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 return true; | 880 return true; |
| 859 } else if (notification_type == kDictionaryNotificationType) { | 881 } else if (notification_type == kDictionaryNotificationType) { |
| 860 *model_type = DICTIONARY; | 882 *model_type = DICTIONARY; |
| 861 return true; | 883 return true; |
| 862 } else if (notification_type == kFaviconImageNotificationType) { | 884 } else if (notification_type == kFaviconImageNotificationType) { |
| 863 *model_type = FAVICON_IMAGES; | 885 *model_type = FAVICON_IMAGES; |
| 864 return true; | 886 return true; |
| 865 } else if (notification_type == kFaviconTrackingNotificationType) { | 887 } else if (notification_type == kFaviconTrackingNotificationType) { |
| 866 *model_type = FAVICON_TRACKING; | 888 *model_type = FAVICON_TRACKING; |
| 867 return true; | 889 return true; |
| 890 } else if (notification_type == kManagedUserSettingNotificationType) { |
| 891 *model_type = MANAGED_USER_SETTINGS; |
| 892 return true; |
| 868 } | 893 } |
| 869 *model_type = UNSPECIFIED; | 894 *model_type = UNSPECIFIED; |
| 870 return false; | 895 return false; |
| 871 } | 896 } |
| 872 | 897 |
| 873 bool IsRealDataType(ModelType model_type) { | 898 bool IsRealDataType(ModelType model_type) { |
| 874 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; | 899 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; |
| 875 } | 900 } |
| 876 | 901 |
| 877 bool IsActOnceDataType(ModelType model_type) { | 902 bool IsActOnceDataType(ModelType model_type) { |
| 878 return model_type == HISTORY_DELETE_DIRECTIVES; | 903 return model_type == HISTORY_DELETE_DIRECTIVES; |
| 879 } | 904 } |
| 880 | 905 |
| 881 } // namespace syncer | 906 } // namespace syncer |
| OLD | NEW |