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 // Priority preferences are not encrypted because they might be synced before
377 // encryption is ready.
378 encryptable_user_types.Remove(PRIORITY_PREFERENCES);
379 // Supervised user settings are not encrypted since they are set server-side.
380 encryptable_user_types.Remove(SUPERVISED_USER_SETTINGS);
381 // Supervised users are not encrypted since they are managed server-side.
382 encryptable_user_types.Remove(SUPERVISED_USERS);
383 // Supervised user shared settings are not encrypted since they are managed
384 // server-side and shared between manager and supervised user.
385 encryptable_user_types.Remove(SUPERVISED_USER_SHARED_SETTINGS);
386 // Proxy types have no sync representation and are therefore not encrypted.
387 // Note however that proxy types map to one or more protocol types, which
388 // may or may not be encrypted themselves.
389 encryptable_user_types.RemoveAll(ProxyTypes());
390 return encryptable_user_types;
393 ModelTypeSet PriorityUserTypes() {
394 return ModelTypeSet(PRIORITY_PREFERENCES);
397 ModelTypeSet ControlTypes() {
399 // TODO(sync): We should be able to build the actual enumset's internal
400 // bitset value here at compile time, rather than performing an iteration
402 for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) {
403 set.Put(ModelTypeFromInt(i));
409 ModelTypeSet ProxyTypes() {
415 bool IsControlType(ModelType model_type) {
416 return ControlTypes().Has(model_type);
419 ModelTypeSet CoreTypes() {
420 syncer::ModelTypeSet result;
421 result.PutAll(PriorityCoreTypes());
423 // The following are low priority core types.
424 result.Put(SYNCED_NOTIFICATIONS);
425 result.Put(SYNCED_NOTIFICATION_APP_INFO);
426 result.Put(SUPERVISED_USER_SHARED_SETTINGS);
431 ModelTypeSet PriorityCoreTypes() {
432 syncer::ModelTypeSet result;
433 result.PutAll(ControlTypes());
435 // The following are non-control core types.
436 result.Put(SUPERVISED_USERS);
437 result.Put(SUPERVISED_USER_SETTINGS);
442 ModelTypeSet BackupTypes() {
444 result.Put(BOOKMARKS);
445 result.Put(PREFERENCES);
447 result.Put(EXTENSIONS);
448 result.Put(SEARCH_ENGINES);
450 result.Put(APP_LIST);
451 result.Put(APP_SETTINGS);
452 result.Put(EXTENSION_SETTINGS);
453 result.Put(PRIORITY_PREFERENCES);
457 const char* ModelTypeToString(ModelType model_type) {
458 // This is used in serialization routines as well as for displaying debug
459 // information. Do not attempt to change these string values unless you know
460 // what you're doing.
461 switch (model_type) {
462 case TOP_LEVEL_FOLDER:
463 return "Top Level Folder";
465 return "Unspecified";
469 return "Preferences";
481 return "Encryption keys";
483 return "Search Engines";
490 case AUTOFILL_PROFILE:
491 return "Autofill Profiles";
493 return "App settings";
494 case EXTENSION_SETTINGS:
495 return "Extension settings";
496 case APP_NOTIFICATIONS:
497 return "App Notifications";
498 case HISTORY_DELETE_DIRECTIVES:
499 return "History Delete Directives";
500 case SYNCED_NOTIFICATIONS:
501 return "Synced Notifications";
502 case SYNCED_NOTIFICATION_APP_INFO:
503 return "Synced Notification App Info";
505 return "Device Info";
507 return "Experiments";
508 case PRIORITY_PREFERENCES:
509 return "Priority Preferences";
513 return "Favicon Images";
514 case FAVICON_TRACKING:
515 return "Favicon Tracking";
516 case SUPERVISED_USER_SETTINGS:
517 return "Managed User Settings";
518 case SUPERVISED_USERS:
519 return "Managed Users";
520 case SUPERVISED_USER_SHARED_SETTINGS:
521 return "Managed User Shared Settings";
529 NOTREACHED() << "No known extension for model type.";
533 // The normal rules about histograms apply here. Always append to the bottom of
534 // the list, and be careful to not reuse integer values that have already been
535 // assigned. Don't forget to update histograms.xml when you make changes to
537 int ModelTypeToHistogramInt(ModelType model_type) {
538 switch (model_type) {
541 case TOP_LEVEL_FOLDER:
549 case AUTOFILL_PROFILE:
567 case EXTENSION_SETTINGS:
569 case APP_NOTIFICATIONS:
571 case HISTORY_DELETE_DIRECTIVES:
579 case SYNCED_NOTIFICATIONS:
581 case PRIORITY_PREFERENCES:
587 case FAVICON_TRACKING:
591 case SUPERVISED_USER_SETTINGS:
593 case SUPERVISED_USERS:
599 case SUPERVISED_USER_SHARED_SETTINGS:
601 case SYNCED_NOTIFICATION_APP_INFO:
603 // Silence a compiler warning.
604 case MODEL_TYPE_COUNT:
610 base::StringValue* ModelTypeToValue(ModelType model_type) {
611 if (model_type >= FIRST_REAL_MODEL_TYPE) {
612 return new base::StringValue(ModelTypeToString(model_type));
613 } else if (model_type == TOP_LEVEL_FOLDER) {
614 return new base::StringValue("Top-level folder");
615 } else if (model_type == UNSPECIFIED) {
616 return new base::StringValue("Unspecified");
619 return new base::StringValue(std::string());
622 ModelType ModelTypeFromValue(const base::Value& value) {
623 if (value.IsType(base::Value::TYPE_STRING)) {
625 CHECK(value.GetAsString(&result));
626 return ModelTypeFromString(result);
627 } else if (value.IsType(base::Value::TYPE_INTEGER)) {
629 CHECK(value.GetAsInteger(&result));
630 return ModelTypeFromInt(result);
632 NOTREACHED() << "Unsupported value type: " << value.GetType();
637 ModelType ModelTypeFromString(const std::string& model_type_string) {
638 if (model_type_string == "Bookmarks")
640 else if (model_type_string == "Preferences")
642 else if (model_type_string == "Passwords")
644 else if (model_type_string == "Autofill")
646 else if (model_type_string == "Autofill Profiles")
647 return AUTOFILL_PROFILE;
648 else if (model_type_string == "Themes")
650 else if (model_type_string == "Typed URLs")
652 else if (model_type_string == "Extensions")
654 else if (model_type_string == "Encryption keys")
656 else if (model_type_string == "Search Engines")
657 return SEARCH_ENGINES;
658 else if (model_type_string == "Sessions")
660 else if (model_type_string == "Apps")
662 else if (model_type_string == "App List")
664 else if (model_type_string == "App settings")
666 else if (model_type_string == "Extension settings")
667 return EXTENSION_SETTINGS;
668 else if (model_type_string == "App Notifications")
669 return APP_NOTIFICATIONS;
670 else if (model_type_string == "History Delete Directives")
671 return HISTORY_DELETE_DIRECTIVES;
672 else if (model_type_string == "Synced Notifications")
673 return SYNCED_NOTIFICATIONS;
674 else if (model_type_string == "Synced Notification App Info")
675 return SYNCED_NOTIFICATION_APP_INFO;
676 else if (model_type_string == "Device Info")
678 else if (model_type_string == "Experiments")
680 else if (model_type_string == "Priority Preferences")
681 return PRIORITY_PREFERENCES;
682 else if (model_type_string == "Dictionary")
684 else if (model_type_string == "Favicon Images")
685 return FAVICON_IMAGES;
686 else if (model_type_string == "Favicon Tracking")
687 return FAVICON_TRACKING;
688 else if (model_type_string == "Managed User Settings")
689 return SUPERVISED_USER_SETTINGS;
690 else if (model_type_string == "Managed Users")
691 return SUPERVISED_USERS;
692 else if (model_type_string == "Managed User Shared Settings")
693 return SUPERVISED_USER_SHARED_SETTINGS;
694 else if (model_type_string == "Articles")
696 else if (model_type_string == "Tabs")
699 NOTREACHED() << "No known model type corresponding to "
700 << model_type_string << ".";
704 std::string ModelTypeSetToString(ModelTypeSet model_types) {
706 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) {
707 if (!result.empty()) {
710 result += ModelTypeToString(it.Get());
715 ModelTypeSet ModelTypeSetFromString(const std::string& model_types_string) {
716 std::string working_copy = model_types_string;
717 ModelTypeSet model_types;
718 while (!working_copy.empty()) {
719 // Remove any leading spaces.
720 working_copy = working_copy.substr(working_copy.find_first_not_of(' '));
721 if (working_copy.empty())
723 std::string type_str;
724 size_t end = working_copy.find(',');
725 if (end == std::string::npos) {
726 end = working_copy.length() - 1;
727 type_str = working_copy;
729 type_str = working_copy.substr(0, end);
731 syncer::ModelType type = ModelTypeFromString(type_str);
732 if (IsRealDataType(type))
733 model_types.Put(type);
734 working_copy = working_copy.substr(end + 1);
739 base::ListValue* ModelTypeSetToValue(ModelTypeSet model_types) {
740 base::ListValue* value = new base::ListValue();
741 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) {
742 value->Append(new base::StringValue(ModelTypeToString(it.Get())));
747 ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value) {
749 for (base::ListValue::const_iterator i = value.begin();
750 i != value.end(); ++i) {
751 result.Put(ModelTypeFromValue(**i));
756 // TODO(zea): remove all hardcoded tags in model associators and have them use
758 // NOTE: Proxy types should return empty strings (so that we don't NOTREACHED
759 // in tests when we verify they have no root node).
760 std::string ModelTypeToRootTag(ModelType type) {
763 return "google_chrome_bookmarks";
765 return "google_chrome_preferences";
767 return "google_chrome_passwords";
769 return "google_chrome_autofill";
771 return "google_chrome_themes";
773 return "google_chrome_typed_urls";
775 return "google_chrome_extensions";
777 return "google_chrome_nigori";
779 return "google_chrome_search_engines";
781 return "google_chrome_sessions";
783 return "google_chrome_apps";
785 return "google_chrome_app_list";
786 case AUTOFILL_PROFILE:
787 return "google_chrome_autofill_profiles";
789 return "google_chrome_app_settings";
790 case EXTENSION_SETTINGS:
791 return "google_chrome_extension_settings";
792 case APP_NOTIFICATIONS:
793 return "google_chrome_app_notifications";
794 case HISTORY_DELETE_DIRECTIVES:
795 return "google_chrome_history_delete_directives";
796 case SYNCED_NOTIFICATIONS:
797 return "google_chrome_synced_notifications";
798 case SYNCED_NOTIFICATION_APP_INFO:
799 return "google_chrome_synced_notification_app_info";
801 return "google_chrome_device_info";
803 return "google_chrome_experiments";
804 case PRIORITY_PREFERENCES:
805 return "google_chrome_priority_preferences";
807 return "google_chrome_dictionary";
809 return "google_chrome_favicon_images";
810 case FAVICON_TRACKING:
811 return "google_chrome_favicon_tracking";
812 case SUPERVISED_USER_SETTINGS:
813 return "google_chrome_managed_user_settings";
814 case SUPERVISED_USERS:
815 return "google_chrome_managed_users";
816 case SUPERVISED_USER_SHARED_SETTINGS:
817 return "google_chrome_managed_user_shared_settings";
819 return "google_chrome_articles";
821 return std::string();
825 NOTREACHED() << "No known extension for model type.";
829 // TODO(akalin): Figure out a better way to do these mappings.
830 // Note: Do not include proxy types in this list. They should never receive
831 // or trigger notifications.
833 const char kBookmarkNotificationType[] = "BOOKMARK";
834 const char kPreferenceNotificationType[] = "PREFERENCE";
835 const char kPasswordNotificationType[] = "PASSWORD";
836 const char kAutofillNotificationType[] = "AUTOFILL";
837 const char kThemeNotificationType[] = "THEME";
838 const char kTypedUrlNotificationType[] = "TYPED_URL";
839 const char kExtensionNotificationType[] = "EXTENSION";
840 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING";
841 const char kNigoriNotificationType[] = "NIGORI";
842 const char kAppSettingNotificationType[] = "APP_SETTING";
843 const char kAppNotificationType[] = "APP";
844 const char kAppListNotificationType[] = "APP_LIST";
845 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE";
846 const char kSessionNotificationType[] = "SESSION";
847 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE";
848 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION";
849 const char kHistoryDeleteDirectiveNotificationType[] =
850 "HISTORY_DELETE_DIRECTIVE";
851 const char kSyncedNotificationType[] = "SYNCED_NOTIFICATION";
852 const char kSyncedNotificationAppInfoType[] = "SYNCED_NOTIFICATION_APP_INFO";
853 const char kDeviceInfoNotificationType[] = "DEVICE_INFO";
854 const char kExperimentsNotificationType[] = "EXPERIMENTS";
855 const char kPriorityPreferenceNotificationType[] = "PRIORITY_PREFERENCE";
856 const char kDictionaryNotificationType[] = "DICTIONARY";
857 const char kFaviconImageNotificationType[] = "FAVICON_IMAGE";
858 const char kFaviconTrackingNotificationType[] = "FAVICON_TRACKING";
859 const char kSupervisedUserSettingNotificationType[] = "MANAGED_USER_SETTING";
860 const char kSupervisedUserNotificationType[] = "MANAGED_USER";
861 const char kSupervisedUserSharedSettingNotificationType[] =
862 "MANAGED_USER_SHARED_SETTING";
863 const char kArticleNotificationType[] = "ARTICLE";
866 bool RealModelTypeToNotificationType(ModelType model_type,
867 std::string* notification_type) {
868 switch (model_type) {
870 *notification_type = kBookmarkNotificationType;
873 *notification_type = kPreferenceNotificationType;
876 *notification_type = kPasswordNotificationType;
879 *notification_type = kAutofillNotificationType;
882 *notification_type = kThemeNotificationType;
885 *notification_type = kTypedUrlNotificationType;
888 *notification_type = kExtensionNotificationType;
891 *notification_type = kNigoriNotificationType;
894 *notification_type = kAppSettingNotificationType;
897 *notification_type = kAppNotificationType;
900 *notification_type = kAppListNotificationType;
903 *notification_type = kSearchEngineNotificationType;
906 *notification_type = kSessionNotificationType;
908 case AUTOFILL_PROFILE:
909 *notification_type = kAutofillProfileNotificationType;
911 case EXTENSION_SETTINGS:
912 *notification_type = kExtensionSettingNotificationType;
914 case APP_NOTIFICATIONS:
915 *notification_type = kAppNotificationNotificationType;
917 case HISTORY_DELETE_DIRECTIVES:
918 *notification_type = kHistoryDeleteDirectiveNotificationType;
920 case SYNCED_NOTIFICATIONS:
921 *notification_type = kSyncedNotificationType;
923 case SYNCED_NOTIFICATION_APP_INFO:
924 *notification_type = kSyncedNotificationAppInfoType;
927 *notification_type = kDeviceInfoNotificationType;
930 *notification_type = kExperimentsNotificationType;
932 case PRIORITY_PREFERENCES:
933 *notification_type = kPriorityPreferenceNotificationType;
936 *notification_type = kDictionaryNotificationType;
939 *notification_type = kFaviconImageNotificationType;
941 case FAVICON_TRACKING:
942 *notification_type = kFaviconTrackingNotificationType;
944 case SUPERVISED_USER_SETTINGS:
945 *notification_type = kSupervisedUserSettingNotificationType;
947 case SUPERVISED_USERS:
948 *notification_type = kSupervisedUserNotificationType;
950 case SUPERVISED_USER_SHARED_SETTINGS:
951 *notification_type = kSupervisedUserSharedSettingNotificationType;
954 *notification_type = kArticleNotificationType;
959 notification_type->clear();
963 bool NotificationTypeToRealModelType(const std::string& notification_type,
964 ModelType* model_type) {
965 if (notification_type == kBookmarkNotificationType) {
966 *model_type = BOOKMARKS;
968 } else if (notification_type == kPreferenceNotificationType) {
969 *model_type = PREFERENCES;
971 } else if (notification_type == kPasswordNotificationType) {
972 *model_type = PASSWORDS;
974 } else if (notification_type == kAutofillNotificationType) {
975 *model_type = AUTOFILL;
977 } else if (notification_type == kThemeNotificationType) {
978 *model_type = THEMES;
980 } else if (notification_type == kTypedUrlNotificationType) {
981 *model_type = TYPED_URLS;
983 } else if (notification_type == kExtensionNotificationType) {
984 *model_type = EXTENSIONS;
986 } else if (notification_type == kNigoriNotificationType) {
987 *model_type = NIGORI;
989 } else if (notification_type == kAppNotificationType) {
992 } else if (notification_type == kAppListNotificationType) {
993 *model_type = APP_LIST;
995 } else if (notification_type == kSearchEngineNotificationType) {
996 *model_type = SEARCH_ENGINES;
998 } else if (notification_type == kSessionNotificationType) {
999 *model_type = SESSIONS;
1001 } else if (notification_type == kAutofillProfileNotificationType) {
1002 *model_type = AUTOFILL_PROFILE;
1004 } else if (notification_type == kAppSettingNotificationType) {
1005 *model_type = APP_SETTINGS;
1007 } else if (notification_type == kExtensionSettingNotificationType) {
1008 *model_type = EXTENSION_SETTINGS;
1010 } else if (notification_type == kAppNotificationNotificationType) {
1011 *model_type = APP_NOTIFICATIONS;
1013 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) {
1014 *model_type = HISTORY_DELETE_DIRECTIVES;
1016 } else if (notification_type == kSyncedNotificationType) {
1017 *model_type = SYNCED_NOTIFICATIONS;
1019 } else if (notification_type == kSyncedNotificationAppInfoType) {
1020 *model_type = SYNCED_NOTIFICATION_APP_INFO;
1022 } else if (notification_type == kDeviceInfoNotificationType) {
1023 *model_type = DEVICE_INFO;
1025 } else if (notification_type == kExperimentsNotificationType) {
1026 *model_type = EXPERIMENTS;
1028 } else if (notification_type == kPriorityPreferenceNotificationType) {
1029 *model_type = PRIORITY_PREFERENCES;
1031 } else if (notification_type == kDictionaryNotificationType) {
1032 *model_type = DICTIONARY;
1034 } else if (notification_type == kFaviconImageNotificationType) {
1035 *model_type = FAVICON_IMAGES;
1037 } else if (notification_type == kFaviconTrackingNotificationType) {
1038 *model_type = FAVICON_TRACKING;
1040 } else if (notification_type == kSupervisedUserSettingNotificationType) {
1041 *model_type = SUPERVISED_USER_SETTINGS;
1043 } else if (notification_type == kSupervisedUserNotificationType) {
1044 *model_type = SUPERVISED_USERS;
1046 } else if (notification_type ==
1047 kSupervisedUserSharedSettingNotificationType) {
1048 *model_type = SUPERVISED_USER_SHARED_SETTINGS;
1050 } else if (notification_type == kArticleNotificationType) {
1051 *model_type = ARTICLES;
1054 *model_type = UNSPECIFIED;
1058 bool IsRealDataType(ModelType model_type) {
1059 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT;
1062 bool IsProxyType(ModelType model_type) {
1063 return model_type >= FIRST_PROXY_TYPE && model_type <= LAST_PROXY_TYPE;
1066 bool IsActOnceDataType(ModelType model_type) {
1067 return model_type == HISTORY_DELETE_DIRECTIVES;
1070 } // namespace syncer