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 26 matching lines...) Expand all Loading... |
37 "autofill", | 37 "autofill", |
38 "themes", | 38 "themes", |
39 "typedUrls", | 39 "typedUrls", |
40 "extensions", | 40 "extensions", |
41 "apps", | 41 "apps", |
42 "wifiCredentials", | 42 "wifiCredentials", |
43 "tabs", | 43 "tabs", |
44 }; | 44 }; |
45 | 45 |
46 static_assert( | 46 static_assert( |
47 35 == MODEL_TYPE_COUNT, | 47 36 == MODEL_TYPE_COUNT, |
48 "update kUserSelectableDataTypeName to match UserSelectableTypes"); | 48 "update kUserSelectableDataTypeName to match UserSelectableTypes"); |
49 | 49 |
50 void AddDefaultFieldValue(ModelType datatype, | 50 void AddDefaultFieldValue(ModelType datatype, |
51 sync_pb::EntitySpecifics* specifics) { | 51 sync_pb::EntitySpecifics* specifics) { |
52 if (!ProtocolTypes().Has(datatype)) { | 52 if (!ProtocolTypes().Has(datatype)) { |
53 NOTREACHED() << "Only protocol types have field values."; | 53 NOTREACHED() << "Only protocol types have field values."; |
54 return; | 54 return; |
55 } | 55 } |
56 switch (datatype) { | 56 switch (datatype) { |
57 case BOOKMARKS: | 57 case BOOKMARKS: |
58 specifics->mutable_bookmark(); | 58 specifics->mutable_bookmark(); |
59 break; | 59 break; |
60 case PASSWORDS: | 60 case PASSWORDS: |
61 specifics->mutable_password(); | 61 specifics->mutable_password(); |
62 break; | 62 break; |
63 case PREFERENCES: | 63 case PREFERENCES: |
64 specifics->mutable_preference(); | 64 specifics->mutable_preference(); |
65 break; | 65 break; |
66 case AUTOFILL: | 66 case AUTOFILL: |
67 specifics->mutable_autofill(); | 67 specifics->mutable_autofill(); |
68 break; | 68 break; |
69 case AUTOFILL_PROFILE: | 69 case AUTOFILL_PROFILE: |
70 specifics->mutable_autofill_profile(); | 70 specifics->mutable_autofill_profile(); |
71 break; | 71 break; |
72 case AUTOFILL_WALLET_DATA: | 72 case AUTOFILL_WALLET_DATA: |
73 specifics->mutable_autofill_wallet(); | 73 specifics->mutable_autofill_wallet(); |
74 break; | 74 break; |
| 75 case AUTOFILL_WALLET_METADATA: |
| 76 specifics->mutable_wallet_metadata(); |
| 77 break; |
75 case THEMES: | 78 case THEMES: |
76 specifics->mutable_theme(); | 79 specifics->mutable_theme(); |
77 break; | 80 break; |
78 case TYPED_URLS: | 81 case TYPED_URLS: |
79 specifics->mutable_typed_url(); | 82 specifics->mutable_typed_url(); |
80 break; | 83 break; |
81 case EXTENSIONS: | 84 case EXTENSIONS: |
82 specifics->mutable_extension(); | 85 specifics->mutable_extension(); |
83 break; | 86 break; |
84 case NIGORI: | 87 case NIGORI: |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 case PASSWORDS: | 177 case PASSWORDS: |
175 return sync_pb::EntitySpecifics::kPasswordFieldNumber; | 178 return sync_pb::EntitySpecifics::kPasswordFieldNumber; |
176 case PREFERENCES: | 179 case PREFERENCES: |
177 return sync_pb::EntitySpecifics::kPreferenceFieldNumber; | 180 return sync_pb::EntitySpecifics::kPreferenceFieldNumber; |
178 case AUTOFILL: | 181 case AUTOFILL: |
179 return sync_pb::EntitySpecifics::kAutofillFieldNumber; | 182 return sync_pb::EntitySpecifics::kAutofillFieldNumber; |
180 case AUTOFILL_PROFILE: | 183 case AUTOFILL_PROFILE: |
181 return sync_pb::EntitySpecifics::kAutofillProfileFieldNumber; | 184 return sync_pb::EntitySpecifics::kAutofillProfileFieldNumber; |
182 case AUTOFILL_WALLET_DATA: | 185 case AUTOFILL_WALLET_DATA: |
183 return sync_pb::EntitySpecifics::kAutofillWalletFieldNumber; | 186 return sync_pb::EntitySpecifics::kAutofillWalletFieldNumber; |
| 187 case AUTOFILL_WALLET_METADATA: |
| 188 return sync_pb::EntitySpecifics::kWalletMetadataFieldNumber; |
184 case THEMES: | 189 case THEMES: |
185 return sync_pb::EntitySpecifics::kThemeFieldNumber; | 190 return sync_pb::EntitySpecifics::kThemeFieldNumber; |
186 case TYPED_URLS: | 191 case TYPED_URLS: |
187 return sync_pb::EntitySpecifics::kTypedUrlFieldNumber; | 192 return sync_pb::EntitySpecifics::kTypedUrlFieldNumber; |
188 case EXTENSIONS: | 193 case EXTENSIONS: |
189 return sync_pb::EntitySpecifics::kExtensionFieldNumber; | 194 return sync_pb::EntitySpecifics::kExtensionFieldNumber; |
190 case NIGORI: | 195 case NIGORI: |
191 return sync_pb::EntitySpecifics::kNigoriFieldNumber; | 196 return sync_pb::EntitySpecifics::kNigoriFieldNumber; |
192 case SEARCH_ENGINES: | 197 case SEARCH_ENGINES: |
193 return sync_pb::EntitySpecifics::kSearchEngineFieldNumber; | 198 return sync_pb::EntitySpecifics::kSearchEngineFieldNumber; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 290 |
286 if (specifics.has_autofill()) | 291 if (specifics.has_autofill()) |
287 return AUTOFILL; | 292 return AUTOFILL; |
288 | 293 |
289 if (specifics.has_autofill_profile()) | 294 if (specifics.has_autofill_profile()) |
290 return AUTOFILL_PROFILE; | 295 return AUTOFILL_PROFILE; |
291 | 296 |
292 if (specifics.has_autofill_wallet()) | 297 if (specifics.has_autofill_wallet()) |
293 return AUTOFILL_WALLET_DATA; | 298 return AUTOFILL_WALLET_DATA; |
294 | 299 |
| 300 if (specifics.has_wallet_metadata()) |
| 301 return AUTOFILL_WALLET_METADATA; |
| 302 |
295 if (specifics.has_theme()) | 303 if (specifics.has_theme()) |
296 return THEMES; | 304 return THEMES; |
297 | 305 |
298 if (specifics.has_typed_url()) | 306 if (specifics.has_typed_url()) |
299 return TYPED_URLS; | 307 return TYPED_URLS; |
300 | 308 |
301 if (specifics.has_extension()) | 309 if (specifics.has_extension()) |
302 return EXTENSIONS; | 310 return EXTENSIONS; |
303 | 311 |
304 if (specifics.has_nigori()) | 312 if (specifics.has_nigori()) |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 case SUPERVISED_USER_WHITELISTS: | 598 case SUPERVISED_USER_WHITELISTS: |
591 return "Managed User Whitelists"; | 599 return "Managed User Whitelists"; |
592 case ARTICLES: | 600 case ARTICLES: |
593 return "Articles"; | 601 return "Articles"; |
594 case WIFI_CREDENTIALS: | 602 case WIFI_CREDENTIALS: |
595 return "WiFi Credentials"; | 603 return "WiFi Credentials"; |
596 case PROXY_TABS: | 604 case PROXY_TABS: |
597 return "Tabs"; | 605 return "Tabs"; |
598 case AUTOFILL_WALLET_DATA: | 606 case AUTOFILL_WALLET_DATA: |
599 return "Autofill Wallet"; | 607 return "Autofill Wallet"; |
| 608 case AUTOFILL_WALLET_METADATA: |
| 609 return "Autofill Wallet Metadata"; |
600 default: | 610 default: |
601 break; | 611 break; |
602 } | 612 } |
603 NOTREACHED() << "No known extension for model type."; | 613 NOTREACHED() << "No known extension for model type."; |
604 return "INVALID"; | 614 return "INVALID"; |
605 } | 615 } |
606 | 616 |
607 // The normal rules about histograms apply here. Always append to the bottom of | 617 // The normal rules about histograms apply here. Always append to the bottom of |
608 // the list, and be careful to not reuse integer values that have already been | 618 // the list, and be careful to not reuse integer values that have already been |
609 // assigned. | 619 // assigned. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 case SUPERVISED_USER_SHARED_SETTINGS: | 685 case SUPERVISED_USER_SHARED_SETTINGS: |
676 return 30; | 686 return 30; |
677 case SYNCED_NOTIFICATION_APP_INFO: | 687 case SYNCED_NOTIFICATION_APP_INFO: |
678 return 31; | 688 return 31; |
679 case WIFI_CREDENTIALS: | 689 case WIFI_CREDENTIALS: |
680 return 32; | 690 return 32; |
681 case SUPERVISED_USER_WHITELISTS: | 691 case SUPERVISED_USER_WHITELISTS: |
682 return 33; | 692 return 33; |
683 case AUTOFILL_WALLET_DATA: | 693 case AUTOFILL_WALLET_DATA: |
684 return 34; | 694 return 34; |
| 695 case AUTOFILL_WALLET_METADATA: |
| 696 return 35; |
685 // Silence a compiler warning. | 697 // Silence a compiler warning. |
686 case MODEL_TYPE_COUNT: | 698 case MODEL_TYPE_COUNT: |
687 return 0; | 699 return 0; |
688 } | 700 } |
689 return 0; | 701 return 0; |
690 } | 702 } |
691 | 703 |
692 base::StringValue* ModelTypeToValue(ModelType model_type) { | 704 base::StringValue* ModelTypeToValue(ModelType model_type) { |
693 if (model_type >= FIRST_REAL_MODEL_TYPE) { | 705 if (model_type >= FIRST_REAL_MODEL_TYPE) { |
694 return new base::StringValue(ModelTypeToString(model_type)); | 706 return new base::StringValue(ModelTypeToString(model_type)); |
(...skipping 27 matching lines...) Expand all Loading... |
722 else if (model_type_string == "Preferences") | 734 else if (model_type_string == "Preferences") |
723 return PREFERENCES; | 735 return PREFERENCES; |
724 else if (model_type_string == "Passwords") | 736 else if (model_type_string == "Passwords") |
725 return PASSWORDS; | 737 return PASSWORDS; |
726 else if (model_type_string == "Autofill") | 738 else if (model_type_string == "Autofill") |
727 return AUTOFILL; | 739 return AUTOFILL; |
728 else if (model_type_string == "Autofill Profiles") | 740 else if (model_type_string == "Autofill Profiles") |
729 return AUTOFILL_PROFILE; | 741 return AUTOFILL_PROFILE; |
730 else if (model_type_string == "Autofill Wallet") | 742 else if (model_type_string == "Autofill Wallet") |
731 return AUTOFILL_WALLET_DATA; | 743 return AUTOFILL_WALLET_DATA; |
| 744 else if (model_type_string == "Autofill Wallet Metadata") |
| 745 return AUTOFILL_WALLET_METADATA; |
732 else if (model_type_string == "Themes") | 746 else if (model_type_string == "Themes") |
733 return THEMES; | 747 return THEMES; |
734 else if (model_type_string == "Typed URLs") | 748 else if (model_type_string == "Typed URLs") |
735 return TYPED_URLS; | 749 return TYPED_URLS; |
736 else if (model_type_string == "Extensions") | 750 else if (model_type_string == "Extensions") |
737 return EXTENSIONS; | 751 return EXTENSIONS; |
738 else if (model_type_string == "Encryption keys") | 752 else if (model_type_string == "Encryption keys") |
739 return NIGORI; | 753 return NIGORI; |
740 else if (model_type_string == "Search Engines") | 754 else if (model_type_string == "Search Engines") |
741 return SEARCH_ENGINES; | 755 return SEARCH_ENGINES; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 case SESSIONS: | 882 case SESSIONS: |
869 return "google_chrome_sessions"; | 883 return "google_chrome_sessions"; |
870 case APPS: | 884 case APPS: |
871 return "google_chrome_apps"; | 885 return "google_chrome_apps"; |
872 case APP_LIST: | 886 case APP_LIST: |
873 return "google_chrome_app_list"; | 887 return "google_chrome_app_list"; |
874 case AUTOFILL_PROFILE: | 888 case AUTOFILL_PROFILE: |
875 return "google_chrome_autofill_profiles"; | 889 return "google_chrome_autofill_profiles"; |
876 case AUTOFILL_WALLET_DATA: | 890 case AUTOFILL_WALLET_DATA: |
877 return "google_chrome_autofill_wallet"; | 891 return "google_chrome_autofill_wallet"; |
| 892 case AUTOFILL_WALLET_METADATA: |
| 893 return "google_chrome_autofill_wallet_metadata"; |
878 case APP_SETTINGS: | 894 case APP_SETTINGS: |
879 return "google_chrome_app_settings"; | 895 return "google_chrome_app_settings"; |
880 case EXTENSION_SETTINGS: | 896 case EXTENSION_SETTINGS: |
881 return "google_chrome_extension_settings"; | 897 return "google_chrome_extension_settings"; |
882 case APP_NOTIFICATIONS: | 898 case APP_NOTIFICATIONS: |
883 return "google_chrome_app_notifications"; | 899 return "google_chrome_app_notifications"; |
884 case HISTORY_DELETE_DIRECTIVES: | 900 case HISTORY_DELETE_DIRECTIVES: |
885 return "google_chrome_history_delete_directives"; | 901 return "google_chrome_history_delete_directives"; |
886 case SYNCED_NOTIFICATIONS: | 902 case SYNCED_NOTIFICATIONS: |
887 return "google_chrome_synced_notifications"; | 903 return "google_chrome_synced_notifications"; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 const char kTypedUrlNotificationType[] = "TYPED_URL"; | 948 const char kTypedUrlNotificationType[] = "TYPED_URL"; |
933 const char kExtensionNotificationType[] = "EXTENSION"; | 949 const char kExtensionNotificationType[] = "EXTENSION"; |
934 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; | 950 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; |
935 const char kNigoriNotificationType[] = "NIGORI"; | 951 const char kNigoriNotificationType[] = "NIGORI"; |
936 const char kAppSettingNotificationType[] = "APP_SETTING"; | 952 const char kAppSettingNotificationType[] = "APP_SETTING"; |
937 const char kAppNotificationType[] = "APP"; | 953 const char kAppNotificationType[] = "APP"; |
938 const char kAppListNotificationType[] = "APP_LIST"; | 954 const char kAppListNotificationType[] = "APP_LIST"; |
939 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; | 955 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; |
940 const char kSessionNotificationType[] = "SESSION"; | 956 const char kSessionNotificationType[] = "SESSION"; |
941 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; | 957 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; |
| 958 const char kAutofillWalletMetadataNotificationType[] = |
| 959 "AUTOFILL_WALLET_METADATA"; |
942 const char kAutofillWalletNotificationType[] = "AUTOFILL_WALLET"; | 960 const char kAutofillWalletNotificationType[] = "AUTOFILL_WALLET"; |
943 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; | 961 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; |
944 const char kHistoryDeleteDirectiveNotificationType[] = | 962 const char kHistoryDeleteDirectiveNotificationType[] = |
945 "HISTORY_DELETE_DIRECTIVE"; | 963 "HISTORY_DELETE_DIRECTIVE"; |
946 const char kSyncedNotificationType[] = "SYNCED_NOTIFICATION"; | 964 const char kSyncedNotificationType[] = "SYNCED_NOTIFICATION"; |
947 const char kSyncedNotificationAppInfoType[] = "SYNCED_NOTIFICATION_APP_INFO"; | 965 const char kSyncedNotificationAppInfoType[] = "SYNCED_NOTIFICATION_APP_INFO"; |
948 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; | 966 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; |
949 const char kExperimentsNotificationType[] = "EXPERIMENTS"; | 967 const char kExperimentsNotificationType[] = "EXPERIMENTS"; |
950 const char kPriorityPreferenceNotificationType[] = "PRIORITY_PREFERENCE"; | 968 const char kPriorityPreferenceNotificationType[] = "PRIORITY_PREFERENCE"; |
951 const char kDictionaryNotificationType[] = "DICTIONARY"; | 969 const char kDictionaryNotificationType[] = "DICTIONARY"; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 return true; | 1020 return true; |
1003 case SESSIONS: | 1021 case SESSIONS: |
1004 *notification_type = kSessionNotificationType; | 1022 *notification_type = kSessionNotificationType; |
1005 return true; | 1023 return true; |
1006 case AUTOFILL_PROFILE: | 1024 case AUTOFILL_PROFILE: |
1007 *notification_type = kAutofillProfileNotificationType; | 1025 *notification_type = kAutofillProfileNotificationType; |
1008 return true; | 1026 return true; |
1009 case AUTOFILL_WALLET_DATA: | 1027 case AUTOFILL_WALLET_DATA: |
1010 *notification_type = kAutofillWalletNotificationType; | 1028 *notification_type = kAutofillWalletNotificationType; |
1011 return true; | 1029 return true; |
| 1030 case AUTOFILL_WALLET_METADATA: |
| 1031 *notification_type = kAutofillWalletMetadataNotificationType; |
| 1032 return true; |
1012 case EXTENSION_SETTINGS: | 1033 case EXTENSION_SETTINGS: |
1013 *notification_type = kExtensionSettingNotificationType; | 1034 *notification_type = kExtensionSettingNotificationType; |
1014 return true; | 1035 return true; |
1015 case APP_NOTIFICATIONS: | 1036 case APP_NOTIFICATIONS: |
1016 *notification_type = kAppNotificationNotificationType; | 1037 *notification_type = kAppNotificationNotificationType; |
1017 return true; | 1038 return true; |
1018 case HISTORY_DELETE_DIRECTIVES: | 1039 case HISTORY_DELETE_DIRECTIVES: |
1019 *notification_type = kHistoryDeleteDirectiveNotificationType; | 1040 *notification_type = kHistoryDeleteDirectiveNotificationType; |
1020 return true; | 1041 return true; |
1021 case SYNCED_NOTIFICATIONS: | 1042 case SYNCED_NOTIFICATIONS: |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 return true; | 1125 return true; |
1105 } else if (notification_type == kSessionNotificationType) { | 1126 } else if (notification_type == kSessionNotificationType) { |
1106 *model_type = SESSIONS; | 1127 *model_type = SESSIONS; |
1107 return true; | 1128 return true; |
1108 } else if (notification_type == kAutofillProfileNotificationType) { | 1129 } else if (notification_type == kAutofillProfileNotificationType) { |
1109 *model_type = AUTOFILL_PROFILE; | 1130 *model_type = AUTOFILL_PROFILE; |
1110 return true; | 1131 return true; |
1111 } else if (notification_type == kAutofillWalletNotificationType) { | 1132 } else if (notification_type == kAutofillWalletNotificationType) { |
1112 *model_type = AUTOFILL_WALLET_DATA; | 1133 *model_type = AUTOFILL_WALLET_DATA; |
1113 return true; | 1134 return true; |
| 1135 } else if (notification_type == kAutofillWalletMetadataNotificationType) { |
| 1136 *model_type = AUTOFILL_WALLET_METADATA; |
| 1137 return true; |
1114 } else if (notification_type == kAppSettingNotificationType) { | 1138 } else if (notification_type == kAppSettingNotificationType) { |
1115 *model_type = APP_SETTINGS; | 1139 *model_type = APP_SETTINGS; |
1116 return true; | 1140 return true; |
1117 } else if (notification_type == kExtensionSettingNotificationType) { | 1141 } else if (notification_type == kExtensionSettingNotificationType) { |
1118 *model_type = EXTENSION_SETTINGS; | 1142 *model_type = EXTENSION_SETTINGS; |
1119 return true; | 1143 return true; |
1120 } else if (notification_type == kAppNotificationNotificationType) { | 1144 } else if (notification_type == kAppNotificationNotificationType) { |
1121 *model_type = APP_NOTIFICATIONS; | 1145 *model_type = APP_NOTIFICATIONS; |
1122 return true; | 1146 return true; |
1123 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) { | 1147 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 bool IsTypeWithServerGeneratedRoot(ModelType model_type) { | 1210 bool IsTypeWithServerGeneratedRoot(ModelType model_type) { |
1187 return model_type == BOOKMARKS || model_type == NIGORI; | 1211 return model_type == BOOKMARKS || model_type == NIGORI; |
1188 } | 1212 } |
1189 | 1213 |
1190 bool IsTypeWithClientGeneratedRoot(ModelType model_type) { | 1214 bool IsTypeWithClientGeneratedRoot(ModelType model_type) { |
1191 return IsRealDataType(model_type) && | 1215 return IsRealDataType(model_type) && |
1192 !IsTypeWithServerGeneratedRoot(model_type); | 1216 !IsTypeWithServerGeneratedRoot(model_type); |
1193 } | 1217 } |
1194 | 1218 |
1195 } // namespace syncer | 1219 } // namespace syncer |
OLD | NEW |