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"
29 // 1) This list must contain exactly the same elements as the set returned by
30 // UserSelectableTypes().
31 // 2) This list must be in the same order as the respective values in the
33 const char* kUserSelectableDataTypeNames
[] = {
47 34 == MODEL_TYPE_COUNT
,
48 "update kUserSelectableDataTypeName to match UserSelectableTypes");
50 void AddDefaultFieldValue(ModelType datatype
,
51 sync_pb::EntitySpecifics
* specifics
) {
52 if (!ProtocolTypes().Has(datatype
)) {
53 NOTREACHED() << "Only protocol types have field values.";
58 specifics
->mutable_bookmark();
61 specifics
->mutable_password();
64 specifics
->mutable_preference();
67 specifics
->mutable_autofill();
69 case AUTOFILL_PROFILE
:
70 specifics
->mutable_autofill_profile();
73 specifics
->mutable_theme();
76 specifics
->mutable_typed_url();
79 specifics
->mutable_extension();
82 specifics
->mutable_nigori();
85 specifics
->mutable_search_engine();
88 specifics
->mutable_session();
91 specifics
->mutable_app();
94 specifics
->mutable_app_list();
97 specifics
->mutable_app_setting();
99 case EXTENSION_SETTINGS
:
100 specifics
->mutable_extension_setting();
102 case APP_NOTIFICATIONS
:
103 specifics
->mutable_app_notification();
105 case HISTORY_DELETE_DIRECTIVES
:
106 specifics
->mutable_history_delete_directive();
108 case SYNCED_NOTIFICATIONS
:
109 specifics
->mutable_synced_notification();
111 case SYNCED_NOTIFICATION_APP_INFO
:
112 specifics
->mutable_synced_notification_app_info();
115 specifics
->mutable_device_info();
118 specifics
->mutable_experiments();
120 case PRIORITY_PREFERENCES
:
121 specifics
->mutable_priority_preference();
124 specifics
->mutable_dictionary();
127 specifics
->mutable_favicon_image();
129 case FAVICON_TRACKING
:
130 specifics
->mutable_favicon_tracking();
132 case SUPERVISED_USER_SETTINGS
:
133 specifics
->mutable_managed_user_setting();
135 case SUPERVISED_USERS
:
136 specifics
->mutable_managed_user();
138 case SUPERVISED_USER_SHARED_SETTINGS
:
139 specifics
->mutable_managed_user_shared_setting();
141 case SUPERVISED_USER_WHITELISTS
:
142 specifics
->mutable_managed_user_whitelist();
145 specifics
->mutable_article();
147 case WIFI_CREDENTIALS
:
148 specifics
->mutable_wifi_credential();
151 NOTREACHED() << "No known extension for model type.";
155 ModelType
GetModelTypeFromSpecificsFieldNumber(int field_number
) {
156 ModelTypeSet protocol_types
= ProtocolTypes();
157 for (ModelTypeSet::Iterator iter
= protocol_types
.First(); iter
.Good();
159 if (GetSpecificsFieldNumberFromModelType(iter
.Get()) == field_number
)
165 int GetSpecificsFieldNumberFromModelType(ModelType model_type
) {
166 DCHECK(ProtocolTypes().Has(model_type
))
167 << "Only protocol types have field values.";
168 switch (model_type
) {
170 return sync_pb::EntitySpecifics::kBookmarkFieldNumber
;
172 return sync_pb::EntitySpecifics::kPasswordFieldNumber
;
174 return sync_pb::EntitySpecifics::kPreferenceFieldNumber
;
176 return sync_pb::EntitySpecifics::kAutofillFieldNumber
;
177 case AUTOFILL_PROFILE
:
178 return sync_pb::EntitySpecifics::kAutofillProfileFieldNumber
;
180 return sync_pb::EntitySpecifics::kThemeFieldNumber
;
182 return sync_pb::EntitySpecifics::kTypedUrlFieldNumber
;
184 return sync_pb::EntitySpecifics::kExtensionFieldNumber
;
186 return sync_pb::EntitySpecifics::kNigoriFieldNumber
;
188 return sync_pb::EntitySpecifics::kSearchEngineFieldNumber
;
190 return sync_pb::EntitySpecifics::kSessionFieldNumber
;
192 return sync_pb::EntitySpecifics::kAppFieldNumber
;
194 return sync_pb::EntitySpecifics::kAppListFieldNumber
;
196 return sync_pb::EntitySpecifics::kAppSettingFieldNumber
;
197 case EXTENSION_SETTINGS
:
198 return sync_pb::EntitySpecifics::kExtensionSettingFieldNumber
;
199 case APP_NOTIFICATIONS
:
200 return sync_pb::EntitySpecifics::kAppNotificationFieldNumber
;
201 case HISTORY_DELETE_DIRECTIVES
:
202 return sync_pb::EntitySpecifics::kHistoryDeleteDirectiveFieldNumber
;
203 case SYNCED_NOTIFICATIONS
:
204 return sync_pb::EntitySpecifics::kSyncedNotificationFieldNumber
;
205 case SYNCED_NOTIFICATION_APP_INFO
:
206 return sync_pb::EntitySpecifics::kSyncedNotificationAppInfoFieldNumber
;
208 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber
;
210 return sync_pb::EntitySpecifics::kExperimentsFieldNumber
;
211 case PRIORITY_PREFERENCES
:
212 return sync_pb::EntitySpecifics::kPriorityPreferenceFieldNumber
;
214 return sync_pb::EntitySpecifics::kDictionaryFieldNumber
;
216 return sync_pb::EntitySpecifics::kFaviconImageFieldNumber
;
217 case FAVICON_TRACKING
:
218 return sync_pb::EntitySpecifics::kFaviconTrackingFieldNumber
;
219 case SUPERVISED_USER_SETTINGS
:
220 return sync_pb::EntitySpecifics::kManagedUserSettingFieldNumber
;
221 case SUPERVISED_USERS
:
222 return sync_pb::EntitySpecifics::kManagedUserFieldNumber
;
223 case SUPERVISED_USER_SHARED_SETTINGS
:
224 return sync_pb::EntitySpecifics::kManagedUserSharedSettingFieldNumber
;
225 case SUPERVISED_USER_WHITELISTS
:
226 return sync_pb::EntitySpecifics::kManagedUserWhitelistFieldNumber
;
228 return sync_pb::EntitySpecifics::kArticleFieldNumber
;
229 case WIFI_CREDENTIALS
:
230 return sync_pb::EntitySpecifics::kWifiCredentialFieldNumber
;
232 NOTREACHED() << "No known extension for model type.";
237 FullModelTypeSet
ToFullModelTypeSet(ModelTypeSet in
) {
238 FullModelTypeSet out
;
239 for (ModelTypeSet::Iterator i
= in
.First(); i
.Good(); i
.Inc()) {
245 // Note: keep this consistent with GetModelType in entry.cc!
246 ModelType
GetModelType(const sync_pb::SyncEntity
& sync_entity
) {
247 DCHECK(!IsRoot(sync_entity
)); // Root shouldn't ever go over the wire.
249 // Backwards compatibility with old (pre-specifics) protocol.
250 if (sync_entity
.has_bookmarkdata())
253 ModelType specifics_type
= GetModelTypeFromSpecifics(sync_entity
.specifics());
254 if (specifics_type
!= UNSPECIFIED
)
255 return specifics_type
;
257 // Loose check for server-created top-level folders that aren't
258 // bound to a particular model type.
259 if (!sync_entity
.server_defined_unique_tag().empty() &&
260 IsFolder(sync_entity
)) {
261 return TOP_LEVEL_FOLDER
;
264 // This is an item of a datatype we can't understand. Maybe it's
265 // from the future? Either we mis-encoded the object, or the
266 // server sent us entries it shouldn't have.
267 NOTREACHED() << "Unknown datatype in sync proto.";
271 ModelType
GetModelTypeFromSpecifics(const sync_pb::EntitySpecifics
& specifics
) {
272 if (specifics
.has_bookmark())
275 if (specifics
.has_password())
278 if (specifics
.has_preference())
281 if (specifics
.has_autofill())
284 if (specifics
.has_autofill_profile())
285 return AUTOFILL_PROFILE
;
287 if (specifics
.has_theme())
290 if (specifics
.has_typed_url())
293 if (specifics
.has_extension())
296 if (specifics
.has_nigori())
299 if (specifics
.has_app())
302 if (specifics
.has_app_list())
305 if (specifics
.has_search_engine())
306 return SEARCH_ENGINES
;
308 if (specifics
.has_session())
311 if (specifics
.has_app_setting())
314 if (specifics
.has_extension_setting())
315 return EXTENSION_SETTINGS
;
317 if (specifics
.has_app_notification())
318 return APP_NOTIFICATIONS
;
320 if (specifics
.has_history_delete_directive())
321 return HISTORY_DELETE_DIRECTIVES
;
323 if (specifics
.has_synced_notification())
324 return SYNCED_NOTIFICATIONS
;
326 if (specifics
.has_synced_notification_app_info())
327 return SYNCED_NOTIFICATION_APP_INFO
;
329 if (specifics
.has_device_info())
332 if (specifics
.has_experiments())
335 if (specifics
.has_priority_preference())
336 return PRIORITY_PREFERENCES
;
338 if (specifics
.has_dictionary())
341 if (specifics
.has_favicon_image())
342 return FAVICON_IMAGES
;
344 if (specifics
.has_favicon_tracking())
345 return FAVICON_TRACKING
;
347 if (specifics
.has_managed_user_setting())
348 return SUPERVISED_USER_SETTINGS
;
350 if (specifics
.has_managed_user())
351 return SUPERVISED_USERS
;
353 if (specifics
.has_managed_user_shared_setting())
354 return SUPERVISED_USER_SHARED_SETTINGS
;
356 if (specifics
.has_managed_user_whitelist())
357 return SUPERVISED_USER_WHITELISTS
;
359 if (specifics
.has_article())
362 if (specifics
.has_wifi_credential())
363 return WIFI_CREDENTIALS
;
368 ModelTypeSet
ProtocolTypes() {
369 ModelTypeSet set
= ModelTypeSet::All();
370 set
.RemoveAll(ProxyTypes());
374 ModelTypeSet
UserTypes() {
376 // TODO(sync): We should be able to build the actual enumset's internal
377 // bitset value here at compile time, rather than performing an iteration
379 for (int i
= FIRST_USER_MODEL_TYPE
; i
<= LAST_USER_MODEL_TYPE
; ++i
) {
380 set
.Put(ModelTypeFromInt(i
));
385 ModelTypeSet
UserSelectableTypes() {
387 // Although the order doesn't technically matter here, it's clearer to keep
388 // these in the same order as their definition in the ModelType enum.
390 set
.Put(PREFERENCES
);
397 set
.Put(WIFI_CREDENTIALS
);
402 bool IsUserSelectableType(ModelType model_type
) {
403 return UserSelectableTypes().Has(model_type
);
406 ModelTypeNameMap
GetUserSelectableTypeNameMap() {
407 ModelTypeNameMap type_names
;
408 ModelTypeSet type_set
= UserSelectableTypes();
409 ModelTypeSet::Iterator it
= type_set
.First();
410 DCHECK_EQ(arraysize(kUserSelectableDataTypeNames
), type_set
.Size());
411 for (size_t i
= 0; i
< arraysize(kUserSelectableDataTypeNames
) && it
.Good();
413 type_names
[it
.Get()] = kUserSelectableDataTypeNames
[i
];
418 ModelTypeSet
EncryptableUserTypes() {
419 ModelTypeSet encryptable_user_types
= UserTypes();
420 // We never encrypt history delete directives.
421 encryptable_user_types
.Remove(HISTORY_DELETE_DIRECTIVES
);
422 // Synced notifications are not encrypted since the server must see changes.
423 encryptable_user_types
.Remove(SYNCED_NOTIFICATIONS
);
424 // Synced Notification App Info does not have private data, so it is not
426 encryptable_user_types
.Remove(SYNCED_NOTIFICATION_APP_INFO
);
427 // Device info data is not encrypted because it might be synced before
428 // encryption is ready.
429 encryptable_user_types
.Remove(DEVICE_INFO
);
430 // Priority preferences are not encrypted because they might be synced before
431 // encryption is ready.
432 encryptable_user_types
.Remove(PRIORITY_PREFERENCES
);
433 // Supervised user settings are not encrypted since they are set server-side.
434 encryptable_user_types
.Remove(SUPERVISED_USER_SETTINGS
);
435 // Supervised users are not encrypted since they are managed server-side.
436 encryptable_user_types
.Remove(SUPERVISED_USERS
);
437 // Supervised user shared settings are not encrypted since they are managed
438 // server-side and shared between manager and supervised user.
439 encryptable_user_types
.Remove(SUPERVISED_USER_SHARED_SETTINGS
);
440 // Supervised user whitelists are not encrypted since they are managed
442 encryptable_user_types
.Remove(SUPERVISED_USER_WHITELISTS
);
443 // Proxy types have no sync representation and are therefore not encrypted.
444 // Note however that proxy types map to one or more protocol types, which
445 // may or may not be encrypted themselves.
446 encryptable_user_types
.RemoveAll(ProxyTypes());
447 return encryptable_user_types
;
450 ModelTypeSet
PriorityUserTypes() {
451 return ModelTypeSet(DEVICE_INFO
, PRIORITY_PREFERENCES
);
454 ModelTypeSet
ControlTypes() {
456 // TODO(sync): We should be able to build the actual enumset's internal
457 // bitset value here at compile time, rather than performing an iteration
459 for (int i
= FIRST_CONTROL_MODEL_TYPE
; i
<= LAST_CONTROL_MODEL_TYPE
; ++i
) {
460 set
.Put(ModelTypeFromInt(i
));
466 ModelTypeSet
ProxyTypes() {
472 bool IsControlType(ModelType model_type
) {
473 return ControlTypes().Has(model_type
);
476 ModelTypeSet
CoreTypes() {
477 syncer::ModelTypeSet result
;
478 result
.PutAll(PriorityCoreTypes());
480 // The following are low priority core types.
481 result
.Put(SYNCED_NOTIFICATIONS
);
482 result
.Put(SYNCED_NOTIFICATION_APP_INFO
);
483 result
.Put(SUPERVISED_USER_SHARED_SETTINGS
);
484 result
.Put(SUPERVISED_USER_WHITELISTS
);
489 ModelTypeSet
PriorityCoreTypes() {
490 syncer::ModelTypeSet result
;
491 result
.PutAll(ControlTypes());
493 // The following are non-control core types.
494 result
.Put(SUPERVISED_USERS
);
495 result
.Put(SUPERVISED_USER_SETTINGS
);
500 ModelTypeSet
BackupTypes() {
502 result
.Put(BOOKMARKS
);
503 result
.Put(PREFERENCES
);
505 result
.Put(EXTENSIONS
);
506 result
.Put(SEARCH_ENGINES
);
508 result
.Put(APP_LIST
);
509 result
.Put(APP_SETTINGS
);
510 result
.Put(EXTENSION_SETTINGS
);
511 result
.Put(PRIORITY_PREFERENCES
);
515 const char* ModelTypeToString(ModelType model_type
) {
516 // This is used in serialization routines as well as for displaying debug
517 // information. Do not attempt to change these string values unless you know
518 // what you're doing.
519 switch (model_type
) {
520 case TOP_LEVEL_FOLDER
:
521 return "Top Level Folder";
523 return "Unspecified";
527 return "Preferences";
539 return "Encryption keys";
541 return "Search Engines";
548 case AUTOFILL_PROFILE
:
549 return "Autofill Profiles";
551 return "App settings";
552 case EXTENSION_SETTINGS
:
553 return "Extension settings";
554 case APP_NOTIFICATIONS
:
555 return "App Notifications";
556 case HISTORY_DELETE_DIRECTIVES
:
557 return "History Delete Directives";
558 case SYNCED_NOTIFICATIONS
:
559 return "Synced Notifications";
560 case SYNCED_NOTIFICATION_APP_INFO
:
561 return "Synced Notification App Info";
563 return "Device Info";
565 return "Experiments";
566 case PRIORITY_PREFERENCES
:
567 return "Priority Preferences";
571 return "Favicon Images";
572 case FAVICON_TRACKING
:
573 return "Favicon Tracking";
574 case SUPERVISED_USER_SETTINGS
:
575 return "Managed User Settings";
576 case SUPERVISED_USERS
:
577 return "Managed Users";
578 case SUPERVISED_USER_SHARED_SETTINGS
:
579 return "Managed User Shared Settings";
580 case SUPERVISED_USER_WHITELISTS
:
581 return "Managed User Whitelists";
584 case WIFI_CREDENTIALS
:
585 return "WiFi Credentials";
591 NOTREACHED() << "No known extension for model type.";
595 // The normal rules about histograms apply here. Always append to the bottom of
596 // the list, and be careful to not reuse integer values that have already been
597 // assigned. Don't forget to update histograms.xml when you make changes to
599 int ModelTypeToHistogramInt(ModelType model_type
) {
600 switch (model_type
) {
603 case TOP_LEVEL_FOLDER
:
611 case AUTOFILL_PROFILE
:
629 case EXTENSION_SETTINGS
:
631 case APP_NOTIFICATIONS
:
633 case HISTORY_DELETE_DIRECTIVES
:
641 case SYNCED_NOTIFICATIONS
:
643 case PRIORITY_PREFERENCES
:
649 case FAVICON_TRACKING
:
653 case SUPERVISED_USER_SETTINGS
:
655 case SUPERVISED_USERS
:
661 case SUPERVISED_USER_SHARED_SETTINGS
:
663 case SYNCED_NOTIFICATION_APP_INFO
:
665 case WIFI_CREDENTIALS
:
667 case SUPERVISED_USER_WHITELISTS
:
669 // Silence a compiler warning.
670 case MODEL_TYPE_COUNT
:
676 base::StringValue
* ModelTypeToValue(ModelType model_type
) {
677 if (model_type
>= FIRST_REAL_MODEL_TYPE
) {
678 return new base::StringValue(ModelTypeToString(model_type
));
679 } else if (model_type
== TOP_LEVEL_FOLDER
) {
680 return new base::StringValue("Top-level folder");
681 } else if (model_type
== UNSPECIFIED
) {
682 return new base::StringValue("Unspecified");
685 return new base::StringValue(std::string());
688 ModelType
ModelTypeFromValue(const base::Value
& value
) {
689 if (value
.IsType(base::Value::TYPE_STRING
)) {
691 CHECK(value
.GetAsString(&result
));
692 return ModelTypeFromString(result
);
693 } else if (value
.IsType(base::Value::TYPE_INTEGER
)) {
695 CHECK(value
.GetAsInteger(&result
));
696 return ModelTypeFromInt(result
);
698 NOTREACHED() << "Unsupported value type: " << value
.GetType();
703 ModelType
ModelTypeFromString(const std::string
& model_type_string
) {
704 if (model_type_string
== "Bookmarks")
706 else if (model_type_string
== "Preferences")
708 else if (model_type_string
== "Passwords")
710 else if (model_type_string
== "Autofill")
712 else if (model_type_string
== "Autofill Profiles")
713 return AUTOFILL_PROFILE
;
714 else if (model_type_string
== "Themes")
716 else if (model_type_string
== "Typed URLs")
718 else if (model_type_string
== "Extensions")
720 else if (model_type_string
== "Encryption keys")
722 else if (model_type_string
== "Search Engines")
723 return SEARCH_ENGINES
;
724 else if (model_type_string
== "Sessions")
726 else if (model_type_string
== "Apps")
728 else if (model_type_string
== "App List")
730 else if (model_type_string
== "App settings")
732 else if (model_type_string
== "Extension settings")
733 return EXTENSION_SETTINGS
;
734 else if (model_type_string
== "App Notifications")
735 return APP_NOTIFICATIONS
;
736 else if (model_type_string
== "History Delete Directives")
737 return HISTORY_DELETE_DIRECTIVES
;
738 else if (model_type_string
== "Synced Notifications")
739 return SYNCED_NOTIFICATIONS
;
740 else if (model_type_string
== "Synced Notification App Info")
741 return SYNCED_NOTIFICATION_APP_INFO
;
742 else if (model_type_string
== "Device Info")
744 else if (model_type_string
== "Experiments")
746 else if (model_type_string
== "Priority Preferences")
747 return PRIORITY_PREFERENCES
;
748 else if (model_type_string
== "Dictionary")
750 else if (model_type_string
== "Favicon Images")
751 return FAVICON_IMAGES
;
752 else if (model_type_string
== "Favicon Tracking")
753 return FAVICON_TRACKING
;
754 else if (model_type_string
== "Managed User Settings")
755 return SUPERVISED_USER_SETTINGS
;
756 else if (model_type_string
== "Managed Users")
757 return SUPERVISED_USERS
;
758 else if (model_type_string
== "Managed User Shared Settings")
759 return SUPERVISED_USER_SHARED_SETTINGS
;
760 else if (model_type_string
== "Managed User Whitelists")
761 return SUPERVISED_USER_WHITELISTS
;
762 else if (model_type_string
== "Articles")
764 else if (model_type_string
== "WiFi Credentials")
765 return WIFI_CREDENTIALS
;
766 else if (model_type_string
== "Tabs")
769 NOTREACHED() << "No known model type corresponding to "
770 << model_type_string
<< ".";
774 std::string
ModelTypeSetToString(ModelTypeSet model_types
) {
776 for (ModelTypeSet::Iterator it
= model_types
.First(); it
.Good(); it
.Inc()) {
777 if (!result
.empty()) {
780 result
+= ModelTypeToString(it
.Get());
785 ModelTypeSet
ModelTypeSetFromString(const std::string
& model_types_string
) {
786 std::string working_copy
= model_types_string
;
787 ModelTypeSet model_types
;
788 while (!working_copy
.empty()) {
789 // Remove any leading spaces.
790 working_copy
= working_copy
.substr(working_copy
.find_first_not_of(' '));
791 if (working_copy
.empty())
793 std::string type_str
;
794 size_t end
= working_copy
.find(',');
795 if (end
== std::string::npos
) {
796 end
= working_copy
.length() - 1;
797 type_str
= working_copy
;
799 type_str
= working_copy
.substr(0, end
);
801 syncer::ModelType type
= ModelTypeFromString(type_str
);
802 if (IsRealDataType(type
))
803 model_types
.Put(type
);
804 working_copy
= working_copy
.substr(end
+ 1);
809 base::ListValue
* ModelTypeSetToValue(ModelTypeSet model_types
) {
810 base::ListValue
* value
= new base::ListValue();
811 for (ModelTypeSet::Iterator it
= model_types
.First(); it
.Good(); it
.Inc()) {
812 value
->Append(new base::StringValue(ModelTypeToString(it
.Get())));
817 ModelTypeSet
ModelTypeSetFromValue(const base::ListValue
& value
) {
819 for (base::ListValue::const_iterator i
= value
.begin();
820 i
!= value
.end(); ++i
) {
821 result
.Put(ModelTypeFromValue(**i
));
826 // TODO(zea): remove all hardcoded tags in model associators and have them use
828 // NOTE: Proxy types should return empty strings (so that we don't NOTREACHED
829 // in tests when we verify they have no root node).
830 std::string
ModelTypeToRootTag(ModelType type
) {
833 return "google_chrome_bookmarks";
835 return "google_chrome_preferences";
837 return "google_chrome_passwords";
839 return "google_chrome_autofill";
841 return "google_chrome_themes";
843 return "google_chrome_typed_urls";
845 return "google_chrome_extensions";
847 return "google_chrome_nigori";
849 return "google_chrome_search_engines";
851 return "google_chrome_sessions";
853 return "google_chrome_apps";
855 return "google_chrome_app_list";
856 case AUTOFILL_PROFILE
:
857 return "google_chrome_autofill_profiles";
859 return "google_chrome_app_settings";
860 case EXTENSION_SETTINGS
:
861 return "google_chrome_extension_settings";
862 case APP_NOTIFICATIONS
:
863 return "google_chrome_app_notifications";
864 case HISTORY_DELETE_DIRECTIVES
:
865 return "google_chrome_history_delete_directives";
866 case SYNCED_NOTIFICATIONS
:
867 return "google_chrome_synced_notifications";
868 case SYNCED_NOTIFICATION_APP_INFO
:
869 return "google_chrome_synced_notification_app_info";
871 return "google_chrome_device_info";
873 return "google_chrome_experiments";
874 case PRIORITY_PREFERENCES
:
875 return "google_chrome_priority_preferences";
877 return "google_chrome_dictionary";
879 return "google_chrome_favicon_images";
880 case FAVICON_TRACKING
:
881 return "google_chrome_favicon_tracking";
882 case SUPERVISED_USER_SETTINGS
:
883 return "google_chrome_managed_user_settings";
884 case SUPERVISED_USERS
:
885 return "google_chrome_managed_users";
886 case SUPERVISED_USER_SHARED_SETTINGS
:
887 return "google_chrome_managed_user_shared_settings";
888 case SUPERVISED_USER_WHITELISTS
:
889 return "google_chrome_managed_user_whitelists";
891 return "google_chrome_articles";
892 case WIFI_CREDENTIALS
:
893 return "google_chrome_wifi_credentials";
895 return std::string();
899 NOTREACHED() << "No known extension for model type.";
903 // TODO(akalin): Figure out a better way to do these mappings.
904 // Note: Do not include proxy types in this list. They should never receive
905 // or trigger notifications.
907 const char kBookmarkNotificationType
[] = "BOOKMARK";
908 const char kPreferenceNotificationType
[] = "PREFERENCE";
909 const char kPasswordNotificationType
[] = "PASSWORD";
910 const char kAutofillNotificationType
[] = "AUTOFILL";
911 const char kThemeNotificationType
[] = "THEME";
912 const char kTypedUrlNotificationType
[] = "TYPED_URL";
913 const char kExtensionNotificationType
[] = "EXTENSION";
914 const char kExtensionSettingNotificationType
[] = "EXTENSION_SETTING";
915 const char kNigoriNotificationType
[] = "NIGORI";
916 const char kAppSettingNotificationType
[] = "APP_SETTING";
917 const char kAppNotificationType
[] = "APP";
918 const char kAppListNotificationType
[] = "APP_LIST";
919 const char kSearchEngineNotificationType
[] = "SEARCH_ENGINE";
920 const char kSessionNotificationType
[] = "SESSION";
921 const char kAutofillProfileNotificationType
[] = "AUTOFILL_PROFILE";
922 const char kAppNotificationNotificationType
[] = "APP_NOTIFICATION";
923 const char kHistoryDeleteDirectiveNotificationType
[] =
924 "HISTORY_DELETE_DIRECTIVE";
925 const char kSyncedNotificationType
[] = "SYNCED_NOTIFICATION";
926 const char kSyncedNotificationAppInfoType
[] = "SYNCED_NOTIFICATION_APP_INFO";
927 const char kDeviceInfoNotificationType
[] = "DEVICE_INFO";
928 const char kExperimentsNotificationType
[] = "EXPERIMENTS";
929 const char kPriorityPreferenceNotificationType
[] = "PRIORITY_PREFERENCE";
930 const char kDictionaryNotificationType
[] = "DICTIONARY";
931 const char kFaviconImageNotificationType
[] = "FAVICON_IMAGE";
932 const char kFaviconTrackingNotificationType
[] = "FAVICON_TRACKING";
933 const char kSupervisedUserSettingNotificationType
[] = "MANAGED_USER_SETTING";
934 const char kSupervisedUserNotificationType
[] = "MANAGED_USER";
935 const char kSupervisedUserSharedSettingNotificationType
[] =
936 "MANAGED_USER_SHARED_SETTING";
937 const char kSupervisedUserWhitelistNotificationType
[] =
938 "MANAGED_USER_WHITELIST";
939 const char kArticleNotificationType
[] = "ARTICLE";
940 const char kWifiCredentialNotificationType
[] = "WIFI_CREDENTIAL";
943 bool RealModelTypeToNotificationType(ModelType model_type
,
944 std::string
* notification_type
) {
945 switch (model_type
) {
947 *notification_type
= kBookmarkNotificationType
;
950 *notification_type
= kPreferenceNotificationType
;
953 *notification_type
= kPasswordNotificationType
;
956 *notification_type
= kAutofillNotificationType
;
959 *notification_type
= kThemeNotificationType
;
962 *notification_type
= kTypedUrlNotificationType
;
965 *notification_type
= kExtensionNotificationType
;
968 *notification_type
= kNigoriNotificationType
;
971 *notification_type
= kAppSettingNotificationType
;
974 *notification_type
= kAppNotificationType
;
977 *notification_type
= kAppListNotificationType
;
980 *notification_type
= kSearchEngineNotificationType
;
983 *notification_type
= kSessionNotificationType
;
985 case AUTOFILL_PROFILE
:
986 *notification_type
= kAutofillProfileNotificationType
;
988 case EXTENSION_SETTINGS
:
989 *notification_type
= kExtensionSettingNotificationType
;
991 case APP_NOTIFICATIONS
:
992 *notification_type
= kAppNotificationNotificationType
;
994 case HISTORY_DELETE_DIRECTIVES
:
995 *notification_type
= kHistoryDeleteDirectiveNotificationType
;
997 case SYNCED_NOTIFICATIONS
:
998 *notification_type
= kSyncedNotificationType
;
1000 case SYNCED_NOTIFICATION_APP_INFO
:
1001 *notification_type
= kSyncedNotificationAppInfoType
;
1004 *notification_type
= kDeviceInfoNotificationType
;
1007 *notification_type
= kExperimentsNotificationType
;
1009 case PRIORITY_PREFERENCES
:
1010 *notification_type
= kPriorityPreferenceNotificationType
;
1013 *notification_type
= kDictionaryNotificationType
;
1015 case FAVICON_IMAGES
:
1016 *notification_type
= kFaviconImageNotificationType
;
1018 case FAVICON_TRACKING
:
1019 *notification_type
= kFaviconTrackingNotificationType
;
1021 case SUPERVISED_USER_SETTINGS
:
1022 *notification_type
= kSupervisedUserSettingNotificationType
;
1024 case SUPERVISED_USERS
:
1025 *notification_type
= kSupervisedUserNotificationType
;
1027 case SUPERVISED_USER_SHARED_SETTINGS
:
1028 *notification_type
= kSupervisedUserSharedSettingNotificationType
;
1030 case SUPERVISED_USER_WHITELISTS
:
1031 *notification_type
= kSupervisedUserWhitelistNotificationType
;
1034 *notification_type
= kArticleNotificationType
;
1036 case WIFI_CREDENTIALS
:
1037 *notification_type
= kWifiCredentialNotificationType
;
1042 notification_type
->clear();
1046 bool NotificationTypeToRealModelType(const std::string
& notification_type
,
1047 ModelType
* model_type
) {
1048 if (notification_type
== kBookmarkNotificationType
) {
1049 *model_type
= BOOKMARKS
;
1051 } else if (notification_type
== kPreferenceNotificationType
) {
1052 *model_type
= PREFERENCES
;
1054 } else if (notification_type
== kPasswordNotificationType
) {
1055 *model_type
= PASSWORDS
;
1057 } else if (notification_type
== kAutofillNotificationType
) {
1058 *model_type
= AUTOFILL
;
1060 } else if (notification_type
== kThemeNotificationType
) {
1061 *model_type
= THEMES
;
1063 } else if (notification_type
== kTypedUrlNotificationType
) {
1064 *model_type
= TYPED_URLS
;
1066 } else if (notification_type
== kExtensionNotificationType
) {
1067 *model_type
= EXTENSIONS
;
1069 } else if (notification_type
== kNigoriNotificationType
) {
1070 *model_type
= NIGORI
;
1072 } else if (notification_type
== kAppNotificationType
) {
1075 } else if (notification_type
== kAppListNotificationType
) {
1076 *model_type
= APP_LIST
;
1078 } else if (notification_type
== kSearchEngineNotificationType
) {
1079 *model_type
= SEARCH_ENGINES
;
1081 } else if (notification_type
== kSessionNotificationType
) {
1082 *model_type
= SESSIONS
;
1084 } else if (notification_type
== kAutofillProfileNotificationType
) {
1085 *model_type
= AUTOFILL_PROFILE
;
1087 } else if (notification_type
== kAppSettingNotificationType
) {
1088 *model_type
= APP_SETTINGS
;
1090 } else if (notification_type
== kExtensionSettingNotificationType
) {
1091 *model_type
= EXTENSION_SETTINGS
;
1093 } else if (notification_type
== kAppNotificationNotificationType
) {
1094 *model_type
= APP_NOTIFICATIONS
;
1096 } else if (notification_type
== kHistoryDeleteDirectiveNotificationType
) {
1097 *model_type
= HISTORY_DELETE_DIRECTIVES
;
1099 } else if (notification_type
== kSyncedNotificationType
) {
1100 *model_type
= SYNCED_NOTIFICATIONS
;
1102 } else if (notification_type
== kSyncedNotificationAppInfoType
) {
1103 *model_type
= SYNCED_NOTIFICATION_APP_INFO
;
1105 } else if (notification_type
== kDeviceInfoNotificationType
) {
1106 *model_type
= DEVICE_INFO
;
1108 } else if (notification_type
== kExperimentsNotificationType
) {
1109 *model_type
= EXPERIMENTS
;
1111 } else if (notification_type
== kPriorityPreferenceNotificationType
) {
1112 *model_type
= PRIORITY_PREFERENCES
;
1114 } else if (notification_type
== kDictionaryNotificationType
) {
1115 *model_type
= DICTIONARY
;
1117 } else if (notification_type
== kFaviconImageNotificationType
) {
1118 *model_type
= FAVICON_IMAGES
;
1120 } else if (notification_type
== kFaviconTrackingNotificationType
) {
1121 *model_type
= FAVICON_TRACKING
;
1123 } else if (notification_type
== kSupervisedUserSettingNotificationType
) {
1124 *model_type
= SUPERVISED_USER_SETTINGS
;
1126 } else if (notification_type
== kSupervisedUserNotificationType
) {
1127 *model_type
= SUPERVISED_USERS
;
1129 } else if (notification_type
==
1130 kSupervisedUserSharedSettingNotificationType
) {
1131 *model_type
= SUPERVISED_USER_SHARED_SETTINGS
;
1133 } else if (notification_type
== kSupervisedUserWhitelistNotificationType
) {
1134 *model_type
= SUPERVISED_USER_WHITELISTS
;
1136 } else if (notification_type
== kArticleNotificationType
) {
1137 *model_type
= ARTICLES
;
1139 } else if (notification_type
== kWifiCredentialNotificationType
) {
1140 *model_type
= WIFI_CREDENTIALS
;
1143 *model_type
= UNSPECIFIED
;
1147 bool IsRealDataType(ModelType model_type
) {
1148 return model_type
>= FIRST_REAL_MODEL_TYPE
&& model_type
< MODEL_TYPE_COUNT
;
1151 bool IsProxyType(ModelType model_type
) {
1152 return model_type
>= FIRST_PROXY_TYPE
&& model_type
<= LAST_PROXY_TYPE
;
1155 bool IsActOnceDataType(ModelType model_type
) {
1156 return model_type
== HISTORY_DELETE_DIRECTIVES
;
1159 } // namespace syncer