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
3 // found in the LICENSE file.
5 #include "sync/internal_api/public/base/model_type.h"
7 #include "base/strings/string_split.h"
8 #include "base/values.h"
9 #include "sync/protocol/app_notification_specifics.pb.h"
10 #include "sync/protocol/app_setting_specifics.pb.h"
11 #include "sync/protocol/app_specifics.pb.h"
12 #include "sync/protocol/autofill_specifics.pb.h"
13 #include "sync/protocol/bookmark_specifics.pb.h"
14 #include "sync/protocol/extension_setting_specifics.pb.h"
15 #include "sync/protocol/extension_specifics.pb.h"
16 #include "sync/protocol/nigori_specifics.pb.h"
17 #include "sync/protocol/password_specifics.pb.h"
18 #include "sync/protocol/preference_specifics.pb.h"
19 #include "sync/protocol/search_engine_specifics.pb.h"
20 #include "sync/protocol/session_specifics.pb.h"
21 #include "sync/protocol/sync.pb.h"
22 #include "sync/protocol/theme_specifics.pb.h"
23 #include "sync/protocol/typed_url_specifics.pb.h"
24 #include "sync/syncable/syncable_proto_util.h"
28 void AddDefaultFieldValue(ModelType datatype,
29 sync_pb::EntitySpecifics* specifics) {
30 if (!ProtocolTypes().Has(datatype)) {
31 NOTREACHED() << "Only protocol types have field values.";
36 specifics->mutable_bookmark();
39 specifics->mutable_password();
42 specifics->mutable_preference();
45 specifics->mutable_autofill();
47 case AUTOFILL_PROFILE:
48 specifics->mutable_autofill_profile();
51 specifics->mutable_theme();
54 specifics->mutable_typed_url();
57 specifics->mutable_extension();
60 specifics->mutable_nigori();
63 specifics->mutable_search_engine();
66 specifics->mutable_session();
69 specifics->mutable_app();
72 specifics->mutable_app_list();
75 specifics->mutable_app_setting();
77 case EXTENSION_SETTINGS:
78 specifics->mutable_extension_setting();
80 case APP_NOTIFICATIONS:
81 specifics->mutable_app_notification();
83 case HISTORY_DELETE_DIRECTIVES:
84 specifics->mutable_history_delete_directive();
86 case SYNCED_NOTIFICATIONS:
87 specifics->mutable_synced_notification();
89 case SYNCED_NOTIFICATION_APP_INFO:
90 specifics->mutable_synced_notification_app_info();
93 specifics->mutable_device_info();
96 specifics->mutable_experiments();
98 case PRIORITY_PREFERENCES:
99 specifics->mutable_priority_preference();
102 specifics->mutable_dictionary();
105 specifics->mutable_favicon_image();
107 case FAVICON_TRACKING:
108 specifics->mutable_favicon_tracking();
110 case SUPERVISED_USER_SETTINGS:
111 specifics->mutable_managed_user_setting();
113 case SUPERVISED_USERS:
114 specifics->mutable_managed_user();
116 case SUPERVISED_USER_SHARED_SETTINGS:
117 specifics->mutable_managed_user_shared_setting();
120 specifics->mutable_article();
123 NOTREACHED() << "No known extension for model type.";
127 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) {
128 ModelTypeSet protocol_types = ProtocolTypes();
129 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good();
131 if (GetSpecificsFieldNumberFromModelType(iter.Get()) == field_number)
137 int GetSpecificsFieldNumberFromModelType(ModelType model_type) {
138 DCHECK(ProtocolTypes().Has(model_type))
139 << "Only protocol types have field values.";
140 switch (model_type) {
142 return sync_pb::EntitySpecifics::kBookmarkFieldNumber;
144 return sync_pb::EntitySpecifics::kPasswordFieldNumber;
146 return sync_pb::EntitySpecifics::kPreferenceFieldNumber;
148 return sync_pb::EntitySpecifics::kAutofillFieldNumber;
149 case AUTOFILL_PROFILE:
150 return sync_pb::EntitySpecifics::kAutofillProfileFieldNumber;
152 return sync_pb::EntitySpecifics::kThemeFieldNumber;
154 return sync_pb::EntitySpecifics::kTypedUrlFieldNumber;
156 return sync_pb::EntitySpecifics::kExtensionFieldNumber;
158 return sync_pb::EntitySpecifics::kNigoriFieldNumber;
160 return sync_pb::EntitySpecifics::kSearchEngineFieldNumber;
162 return sync_pb::EntitySpecifics::kSessionFieldNumber;
164 return sync_pb::EntitySpecifics::kAppFieldNumber;
166 return sync_pb::EntitySpecifics::kAppListFieldNumber;
168 return sync_pb::EntitySpecifics::kAppSettingFieldNumber;
169 case EXTENSION_SETTINGS:
170 return sync_pb::EntitySpecifics::kExtensionSettingFieldNumber;
171 case APP_NOTIFICATIONS:
172 return sync_pb::EntitySpecifics::kAppNotificationFieldNumber;
173 case HISTORY_DELETE_DIRECTIVES:
174 return sync_pb::EntitySpecifics::kHistoryDeleteDirectiveFieldNumber;
175 case SYNCED_NOTIFICATIONS:
176 return sync_pb::EntitySpecifics::kSyncedNotificationFieldNumber;
177 case SYNCED_NOTIFICATION_APP_INFO:
178 return sync_pb::EntitySpecifics::kSyncedNotificationAppInfoFieldNumber;
180 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber;
182 return sync_pb::EntitySpecifics::kExperimentsFieldNumber;
183 case PRIORITY_PREFERENCES:
184 return sync_pb::EntitySpecifics::kPriorityPreferenceFieldNumber;
186 return sync_pb::EntitySpecifics::kDictionaryFieldNumber;
188 return sync_pb::EntitySpecifics::kFaviconImageFieldNumber;
189 case FAVICON_TRACKING:
190 return sync_pb::EntitySpecifics::kFaviconTrackingFieldNumber;
191 case SUPERVISED_USER_SETTINGS:
192 return sync_pb::EntitySpecifics::kManagedUserSettingFieldNumber;
193 case SUPERVISED_USERS:
194 return sync_pb::EntitySpecifics::kManagedUserFieldNumber;
195 case SUPERVISED_USER_SHARED_SETTINGS:
196 return sync_pb::EntitySpecifics::kManagedUserSharedSettingFieldNumber;
198 return sync_pb::EntitySpecifics::kArticleFieldNumber;
200 NOTREACHED() << "No known extension for model type.";
205 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) {
206 FullModelTypeSet out;
207 for (ModelTypeSet::Iterator i = in.First(); i.Good(); i.Inc()) {
213 // Note: keep this consistent with GetModelType in entry.cc!
214 ModelType GetModelType(const sync_pb::SyncEntity& sync_entity) {
215 DCHECK(!IsRoot(sync_entity)); // Root shouldn't ever go over the wire.
217 // Backwards compatibility with old (pre-specifics) protocol.
218 if (sync_entity.has_bookmarkdata())
221 ModelType specifics_type = GetModelTypeFromSpecifics(sync_entity.specifics());
222 if (specifics_type != UNSPECIFIED)
223 return specifics_type;
225 // Loose check for server-created top-level folders that aren't
226 // bound to a particular model type.
227 if (!sync_entity.server_defined_unique_tag().empty() &&
228 IsFolder(sync_entity)) {
229 return TOP_LEVEL_FOLDER;
232 // This is an item of a datatype we can't understand. Maybe it's
233 // from the future? Either we mis-encoded the object, or the
234 // server sent us entries it shouldn't have.
235 NOTREACHED() << "Unknown datatype in sync proto.";
239 ModelType GetModelTypeFromSpecifics(const sync_pb::EntitySpecifics& specifics) {
240 if (specifics.has_bookmark())
243 if (specifics.has_password())
246 if (specifics.has_preference())
249 if (specifics.has_autofill())
252 if (specifics.has_autofill_profile())
253 return AUTOFILL_PROFILE;
255 if (specifics.has_theme())
258 if (specifics.has_typed_url())
261 if (specifics.has_extension())
264 if (specifics.has_nigori())
267 if (specifics.has_app())
270 if (specifics.has_app_list())
273 if (specifics.has_search_engine())
274 return SEARCH_ENGINES;
276 if (specifics.has_session())
279 if (specifics.has_app_setting())
282 if (specifics.has_extension_setting())
283 return EXTENSION_SETTINGS;
285 if (specifics.has_app_notification())
286 return APP_NOTIFICATIONS;
288 if (specifics.has_history_delete_directive())
289 return HISTORY_DELETE_DIRECTIVES;
291 if (specifics.has_synced_notification())
292 return SYNCED_NOTIFICATIONS;
294 if (specifics.has_synced_notification_app_info())
295 return SYNCED_NOTIFICATION_APP_INFO;
297 if (specifics.has_device_info())
300 if (specifics.has_experiments())
303 if (specifics.has_priority_preference())
304 return PRIORITY_PREFERENCES;
306 if (specifics.has_dictionary())
309 if (specifics.has_favicon_image())
310 return FAVICON_IMAGES;
312 if (specifics.has_favicon_tracking())
313 return FAVICON_TRACKING;
315 if (specifics.has_managed_user_setting())
316 return SUPERVISED_USER_SETTINGS;
318 if (specifics.has_managed_user())
319 return SUPERVISED_USERS;
321 if (specifics.has_managed_user_shared_setting())
322 return SUPERVISED_USER_SHARED_SETTINGS;
324 if (specifics.has_article())
330 ModelTypeSet ProtocolTypes() {
331 ModelTypeSet set = ModelTypeSet::All();
332 set.RemoveAll(ProxyTypes());
336 ModelTypeSet UserTypes() {
338 // TODO(sync): We should be able to build the actual enumset's internal
339 // bitset value here at compile time, rather than performing an iteration
341 for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) {
342 set.Put(ModelTypeFromInt(i));
347 ModelTypeSet UserSelectableTypes() {
349 // Although the order doesn't technically matter here, it's clearer to keep
350 // these in the same order as their definition in the ModelType enum.
352 set.Put(PREFERENCES);
363 bool IsUserSelectableType(ModelType model_type) {
364 return UserSelectableTypes().Has(model_type);
367 ModelTypeSet EncryptableUserTypes() {
368 ModelTypeSet encryptable_user_types = UserTypes();
369 // We never encrypt history delete directives.
370 encryptable_user_types.Remove(HISTORY_DELETE_DIRECTIVES);
371 // Synced notifications are not encrypted since the server must see changes.
372 encryptable_user_types.Remove(SYNCED_NOTIFICATIONS);
373 // Synced Notification App Info does not have private data, so it is not
375 encryptable_user_types.Remove(SYNCED_NOTIFICATION_APP_INFO);
376 // Device info data is not encrypted because it might be synced before
377 // encryption is ready.
378 encryptable_user_types.Remove(DEVICE_INFO);
379 // Priority preferences are not encrypted because they might be synced before
380 // encryption is ready.
381 encryptable_user_types.Remove(PRIORITY_PREFERENCES);
382 // Supervised user settings are not encrypted since they are set server-side.
383 encryptable_user_types.Remove(SUPERVISED_USER_SETTINGS);
384 // Supervised users are not encrypted since they are managed server-side.
385 encryptable_user_types.Remove(SUPERVISED_USERS);
386 // Supervised user shared settings are not encrypted since they are managed
387 // server-side and shared between manager and supervised user.
388 encryptable_user_types.Remove(SUPERVISED_USER_SHARED_SETTINGS);
389 // Proxy types have no sync representation and are therefore not encrypted.
390 // Note however that proxy types map to one or more protocol types, which
391 // may or may not be encrypted themselves.
392 encryptable_user_types.RemoveAll(ProxyTypes());
393 return encryptable_user_types;
396 ModelTypeSet PriorityUserTypes() {
397 return ModelTypeSet(DEVICE_INFO, PRIORITY_PREFERENCES);
400 ModelTypeSet ControlTypes() {
402 // TODO(sync): We should be able to build the actual enumset's internal
403 // bitset value here at compile time, rather than performing an iteration
405 for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) {
406 set.Put(ModelTypeFromInt(i));
412 ModelTypeSet ProxyTypes() {
418 bool IsControlType(ModelType model_type) {
419 return ControlTypes().Has(model_type);
422 ModelTypeSet CoreTypes() {
423 syncer::ModelTypeSet result;
424 result.PutAll(PriorityCoreTypes());
426 // The following are low priority core types.
427 result.Put(SYNCED_NOTIFICATIONS);
428 result.Put(SYNCED_NOTIFICATION_APP_INFO);
429 result.Put(SUPERVISED_USER_SHARED_SETTINGS);
434 ModelTypeSet PriorityCoreTypes() {
435 syncer::ModelTypeSet result;
436 result.PutAll(ControlTypes());
438 // The following are non-control core types.
439 result.Put(SUPERVISED_USERS);
440 result.Put(SUPERVISED_USER_SETTINGS);
445 ModelTypeSet BackupTypes() {
447 result.Put(BOOKMARKS);
448 result.Put(PREFERENCES);
450 result.Put(EXTENSIONS);
451 result.Put(SEARCH_ENGINES);
453 result.Put(APP_LIST);
454 result.Put(APP_SETTINGS);
455 result.Put(EXTENSION_SETTINGS);
456 result.Put(PRIORITY_PREFERENCES);
460 const char* ModelTypeToString(ModelType model_type) {
461 // This is used in serialization routines as well as for displaying debug
462 // information. Do not attempt to change these string values unless you know
463 // what you're doing.
464 switch (model_type) {
465 case TOP_LEVEL_FOLDER:
466 return "Top Level Folder";
468 return "Unspecified";
472 return "Preferences";
484 return "Encryption keys";
486 return "Search Engines";
493 case AUTOFILL_PROFILE:
494 return "Autofill Profiles";
496 return "App settings";
497 case EXTENSION_SETTINGS:
498 return "Extension settings";
499 case APP_NOTIFICATIONS:
500 return "App Notifications";
501 case HISTORY_DELETE_DIRECTIVES:
502 return "History Delete Directives";
503 case SYNCED_NOTIFICATIONS:
504 return "Synced Notifications";
505 case SYNCED_NOTIFICATION_APP_INFO:
506 return "Synced Notification App Info";
508 return "Device Info";
510 return "Experiments";
511 case PRIORITY_PREFERENCES:
512 return "Priority Preferences";
516 return "Favicon Images";
517 case FAVICON_TRACKING:
518 return "Favicon Tracking";
519 case SUPERVISED_USER_SETTINGS:
520 return "Managed User Settings";
521 case SUPERVISED_USERS:
522 return "Managed Users";
523 case SUPERVISED_USER_SHARED_SETTINGS:
524 return "Managed User Shared Settings";
532 NOTREACHED() << "No known extension for model type.";
536 // The normal rules about histograms apply here. Always append to the bottom of
537 // the list, and be careful to not reuse integer values that have already been
538 // assigned. Don't forget to update histograms.xml when you make changes to
540 int ModelTypeToHistogramInt(ModelType model_type) {
541 switch (model_type) {
544 case TOP_LEVEL_FOLDER:
552 case AUTOFILL_PROFILE:
570 case EXTENSION_SETTINGS:
572 case APP_NOTIFICATIONS:
574 case HISTORY_DELETE_DIRECTIVES:
582 case SYNCED_NOTIFICATIONS:
584 case PRIORITY_PREFERENCES:
590 case FAVICON_TRACKING:
594 case SUPERVISED_USER_SETTINGS:
596 case SUPERVISED_USERS:
602 case SUPERVISED_USER_SHARED_SETTINGS:
604 case SYNCED_NOTIFICATION_APP_INFO:
606 // Silence a compiler warning.
607 case MODEL_TYPE_COUNT:
613 base::StringValue* ModelTypeToValue(ModelType model_type) {
614 if (model_type >= FIRST_REAL_MODEL_TYPE) {
615 return new base::StringValue(ModelTypeToString(model_type));
616 } else if (model_type == TOP_LEVEL_FOLDER) {
617 return new base::StringValue("Top-level folder");
618 } else if (model_type == UNSPECIFIED) {
619 return new base::StringValue("Unspecified");
622 return new base::StringValue(std::string());
625 ModelType ModelTypeFromValue(const base::Value& value) {
626 if (value.IsType(base::Value::TYPE_STRING)) {
628 CHECK(value.GetAsString(&result));
629 return ModelTypeFromString(result);
630 } else if (value.IsType(base::Value::TYPE_INTEGER)) {
632 CHECK(value.GetAsInteger(&result));
633 return ModelTypeFromInt(result);
635 NOTREACHED() << "Unsupported value type: " << value.GetType();
640 ModelType ModelTypeFromString(const std::string& model_type_string) {
641 if (model_type_string == "Bookmarks")
643 else if (model_type_string == "Preferences")
645 else if (model_type_string == "Passwords")
647 else if (model_type_string == "Autofill")
649 else if (model_type_string == "Autofill Profiles")
650 return AUTOFILL_PROFILE;
651 else if (model_type_string == "Themes")
653 else if (model_type_string == "Typed URLs")
655 else if (model_type_string == "Extensions")
657 else if (model_type_string == "Encryption keys")
659 else if (model_type_string == "Search Engines")
660 return SEARCH_ENGINES;
661 else if (model_type_string == "Sessions")
663 else if (model_type_string == "Apps")
665 else if (model_type_string == "App List")
667 else if (model_type_string == "App settings")
669 else if (model_type_string == "Extension settings")
670 return EXTENSION_SETTINGS;
671 else if (model_type_string == "App Notifications")
672 return APP_NOTIFICATIONS;
673 else if (model_type_string == "History Delete Directives")
674 return HISTORY_DELETE_DIRECTIVES;
675 else if (model_type_string == "Synced Notifications")
676 return SYNCED_NOTIFICATIONS;
677 else if (model_type_string == "Synced Notification App Info")
678 return SYNCED_NOTIFICATION_APP_INFO;
679 else if (model_type_string == "Device Info")
681 else if (model_type_string == "Experiments")
683 else if (model_type_string == "Priority Preferences")
684 return PRIORITY_PREFERENCES;
685 else if (model_type_string == "Dictionary")
687 else if (model_type_string == "Favicon Images")
688 return FAVICON_IMAGES;
689 else if (model_type_string == "Favicon Tracking")
690 return FAVICON_TRACKING;
691 else if (model_type_string == "Managed User Settings")
692 return SUPERVISED_USER_SETTINGS;
693 else if (model_type_string == "Managed Users")
694 return SUPERVISED_USERS;
695 else if (model_type_string == "Managed User Shared Settings")
696 return SUPERVISED_USER_SHARED_SETTINGS;
697 else if (model_type_string == "Articles")
699 else if (model_type_string == "Tabs")
702 NOTREACHED() << "No known model type corresponding to "
703 << model_type_string << ".";
707 std::string ModelTypeSetToString(ModelTypeSet model_types) {
709 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) {
710 if (!result.empty()) {
713 result += ModelTypeToString(it.Get());
718 ModelTypeSet ModelTypeSetFromString(const std::string& model_types_string) {
719 std::string working_copy = model_types_string;
720 ModelTypeSet model_types;
721 while (!working_copy.empty()) {
722 // Remove any leading spaces.
723 working_copy = working_copy.substr(working_copy.find_first_not_of(' '));
724 if (working_copy.empty())
726 std::string type_str;
727 size_t end = working_copy.find(',');
728 if (end == std::string::npos) {
729 end = working_copy.length() - 1;
730 type_str = working_copy;
732 type_str = working_copy.substr(0, end);
734 syncer::ModelType type = ModelTypeFromString(type_str);
735 if (IsRealDataType(type))
736 model_types.Put(type);
737 working_copy = working_copy.substr(end + 1);
742 base::ListValue* ModelTypeSetToValue(ModelTypeSet model_types) {
743 base::ListValue* value = new base::ListValue();
744 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) {
745 value->Append(new base::StringValue(ModelTypeToString(it.Get())));
750 ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value) {
752 for (base::ListValue::const_iterator i = value.begin();
753 i != value.end(); ++i) {
754 result.Put(ModelTypeFromValue(**i));
759 // TODO(zea): remove all hardcoded tags in model associators and have them use
761 // NOTE: Proxy types should return empty strings (so that we don't NOTREACHED
762 // in tests when we verify they have no root node).
763 std::string ModelTypeToRootTag(ModelType type) {
766 return "google_chrome_bookmarks";
768 return "google_chrome_preferences";
770 return "google_chrome_passwords";
772 return "google_chrome_autofill";
774 return "google_chrome_themes";
776 return "google_chrome_typed_urls";
778 return "google_chrome_extensions";
780 return "google_chrome_nigori";
782 return "google_chrome_search_engines";
784 return "google_chrome_sessions";
786 return "google_chrome_apps";
788 return "google_chrome_app_list";
789 case AUTOFILL_PROFILE:
790 return "google_chrome_autofill_profiles";
792 return "google_chrome_app_settings";
793 case EXTENSION_SETTINGS:
794 return "google_chrome_extension_settings";
795 case APP_NOTIFICATIONS:
796 return "google_chrome_app_notifications";
797 case HISTORY_DELETE_DIRECTIVES:
798 return "google_chrome_history_delete_directives";
799 case SYNCED_NOTIFICATIONS:
800 return "google_chrome_synced_notifications";
801 case SYNCED_NOTIFICATION_APP_INFO:
802 return "google_chrome_synced_notification_app_info";
804 return "google_chrome_device_info";
806 return "google_chrome_experiments";
807 case PRIORITY_PREFERENCES:
808 return "google_chrome_priority_preferences";
810 return "google_chrome_dictionary";
812 return "google_chrome_favicon_images";
813 case FAVICON_TRACKING:
814 return "google_chrome_favicon_tracking";
815 case SUPERVISED_USER_SETTINGS:
816 return "google_chrome_managed_user_settings";
817 case SUPERVISED_USERS:
818 return "google_chrome_managed_users";
819 case SUPERVISED_USER_SHARED_SETTINGS:
820 return "google_chrome_managed_user_shared_settings";
822 return "google_chrome_articles";
824 return std::string();
828 NOTREACHED() << "No known extension for model type.";
832 // TODO(akalin): Figure out a better way to do these mappings.
833 // Note: Do not include proxy types in this list. They should never receive
834 // or trigger notifications.
836 const char kBookmarkNotificationType[] = "BOOKMARK";
837 const char kPreferenceNotificationType[] = "PREFERENCE";
838 const char kPasswordNotificationType[] = "PASSWORD";
839 const char kAutofillNotificationType[] = "AUTOFILL";
840 const char kThemeNotificationType[] = "THEME";
841 const char kTypedUrlNotificationType[] = "TYPED_URL";
842 const char kExtensionNotificationType[] = "EXTENSION";
843 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING";
844 const char kNigoriNotificationType[] = "NIGORI";
845 const char kAppSettingNotificationType[] = "APP_SETTING";
846 const char kAppNotificationType[] = "APP";
847 const char kAppListNotificationType[] = "APP_LIST";
848 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE";
849 const char kSessionNotificationType[] = "SESSION";
850 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE";
851 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION";
852 const char kHistoryDeleteDirectiveNotificationType[] =
853 "HISTORY_DELETE_DIRECTIVE";
854 const char kSyncedNotificationType[] = "SYNCED_NOTIFICATION";
855 const char kSyncedNotificationAppInfoType[] = "SYNCED_NOTIFICATION_APP_INFO";
856 const char kDeviceInfoNotificationType[] = "DEVICE_INFO";
857 const char kExperimentsNotificationType[] = "EXPERIMENTS";
858 const char kPriorityPreferenceNotificationType[] = "PRIORITY_PREFERENCE";
859 const char kDictionaryNotificationType[] = "DICTIONARY";
860 const char kFaviconImageNotificationType[] = "FAVICON_IMAGE";
861 const char kFaviconTrackingNotificationType[] = "FAVICON_TRACKING";
862 const char kSupervisedUserSettingNotificationType[] = "MANAGED_USER_SETTING";
863 const char kSupervisedUserNotificationType[] = "MANAGED_USER";
864 const char kSupervisedUserSharedSettingNotificationType[] =
865 "MANAGED_USER_SHARED_SETTING";
866 const char kArticleNotificationType[] = "ARTICLE";
869 bool RealModelTypeToNotificationType(ModelType model_type,
870 std::string* notification_type) {
871 switch (model_type) {
873 *notification_type = kBookmarkNotificationType;
876 *notification_type = kPreferenceNotificationType;
879 *notification_type = kPasswordNotificationType;
882 *notification_type = kAutofillNotificationType;
885 *notification_type = kThemeNotificationType;
888 *notification_type = kTypedUrlNotificationType;
891 *notification_type = kExtensionNotificationType;
894 *notification_type = kNigoriNotificationType;
897 *notification_type = kAppSettingNotificationType;
900 *notification_type = kAppNotificationType;
903 *notification_type = kAppListNotificationType;
906 *notification_type = kSearchEngineNotificationType;
909 *notification_type = kSessionNotificationType;
911 case AUTOFILL_PROFILE:
912 *notification_type = kAutofillProfileNotificationType;
914 case EXTENSION_SETTINGS:
915 *notification_type = kExtensionSettingNotificationType;
917 case APP_NOTIFICATIONS:
918 *notification_type = kAppNotificationNotificationType;
920 case HISTORY_DELETE_DIRECTIVES:
921 *notification_type = kHistoryDeleteDirectiveNotificationType;
923 case SYNCED_NOTIFICATIONS:
924 *notification_type = kSyncedNotificationType;
926 case SYNCED_NOTIFICATION_APP_INFO:
927 *notification_type = kSyncedNotificationAppInfoType;
930 *notification_type = kDeviceInfoNotificationType;
933 *notification_type = kExperimentsNotificationType;
935 case PRIORITY_PREFERENCES:
936 *notification_type = kPriorityPreferenceNotificationType;
939 *notification_type = kDictionaryNotificationType;
942 *notification_type = kFaviconImageNotificationType;
944 case FAVICON_TRACKING:
945 *notification_type = kFaviconTrackingNotificationType;
947 case SUPERVISED_USER_SETTINGS:
948 *notification_type = kSupervisedUserSettingNotificationType;
950 case SUPERVISED_USERS:
951 *notification_type = kSupervisedUserNotificationType;
953 case SUPERVISED_USER_SHARED_SETTINGS:
954 *notification_type = kSupervisedUserSharedSettingNotificationType;
957 *notification_type = kArticleNotificationType;
962 notification_type->clear();
966 bool NotificationTypeToRealModelType(const std::string& notification_type,
967 ModelType* model_type) {
968 if (notification_type == kBookmarkNotificationType) {
969 *model_type = BOOKMARKS;
971 } else if (notification_type == kPreferenceNotificationType) {
972 *model_type = PREFERENCES;
974 } else if (notification_type == kPasswordNotificationType) {
975 *model_type = PASSWORDS;
977 } else if (notification_type == kAutofillNotificationType) {
978 *model_type = AUTOFILL;
980 } else if (notification_type == kThemeNotificationType) {
981 *model_type = THEMES;
983 } else if (notification_type == kTypedUrlNotificationType) {
984 *model_type = TYPED_URLS;
986 } else if (notification_type == kExtensionNotificationType) {
987 *model_type = EXTENSIONS;
989 } else if (notification_type == kNigoriNotificationType) {
990 *model_type = NIGORI;
992 } else if (notification_type == kAppNotificationType) {
995 } else if (notification_type == kAppListNotificationType) {
996 *model_type = APP_LIST;
998 } else if (notification_type == kSearchEngineNotificationType) {
999 *model_type = SEARCH_ENGINES;
1001 } else if (notification_type == kSessionNotificationType) {
1002 *model_type = SESSIONS;
1004 } else if (notification_type == kAutofillProfileNotificationType) {
1005 *model_type = AUTOFILL_PROFILE;
1007 } else if (notification_type == kAppSettingNotificationType) {
1008 *model_type = APP_SETTINGS;
1010 } else if (notification_type == kExtensionSettingNotificationType) {
1011 *model_type = EXTENSION_SETTINGS;
1013 } else if (notification_type == kAppNotificationNotificationType) {
1014 *model_type = APP_NOTIFICATIONS;
1016 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) {
1017 *model_type = HISTORY_DELETE_DIRECTIVES;
1019 } else if (notification_type == kSyncedNotificationType) {
1020 *model_type = SYNCED_NOTIFICATIONS;
1022 } else if (notification_type == kSyncedNotificationAppInfoType) {
1023 *model_type = SYNCED_NOTIFICATION_APP_INFO;
1025 } else if (notification_type == kDeviceInfoNotificationType) {
1026 *model_type = DEVICE_INFO;
1028 } else if (notification_type == kExperimentsNotificationType) {
1029 *model_type = EXPERIMENTS;
1031 } else if (notification_type == kPriorityPreferenceNotificationType) {
1032 *model_type = PRIORITY_PREFERENCES;
1034 } else if (notification_type == kDictionaryNotificationType) {
1035 *model_type = DICTIONARY;
1037 } else if (notification_type == kFaviconImageNotificationType) {
1038 *model_type = FAVICON_IMAGES;
1040 } else if (notification_type == kFaviconTrackingNotificationType) {
1041 *model_type = FAVICON_TRACKING;
1043 } else if (notification_type == kSupervisedUserSettingNotificationType) {
1044 *model_type = SUPERVISED_USER_SETTINGS;
1046 } else if (notification_type == kSupervisedUserNotificationType) {
1047 *model_type = SUPERVISED_USERS;
1049 } else if (notification_type ==
1050 kSupervisedUserSharedSettingNotificationType) {
1051 *model_type = SUPERVISED_USER_SHARED_SETTINGS;
1053 } else if (notification_type == kArticleNotificationType) {
1054 *model_type = ARTICLES;
1057 *model_type = UNSPECIFIED;
1061 bool IsRealDataType(ModelType model_type) {
1062 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT;
1065 bool IsProxyType(ModelType model_type) {
1066 return model_type >= FIRST_PROXY_TYPE && model_type <= LAST_PROXY_TYPE;
1069 bool IsActOnceDataType(ModelType model_type) {
1070 return model_type == HISTORY_DELETE_DIRECTIVES;
1073 } // namespace syncer