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 35 == 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();
72 case AUTOFILL_WALLET_DATA
:
73 specifics
->mutable_autofill_wallet();
76 specifics
->mutable_theme();
79 specifics
->mutable_typed_url();
82 specifics
->mutable_extension();
85 specifics
->mutable_nigori();
88 specifics
->mutable_search_engine();
91 specifics
->mutable_session();
94 specifics
->mutable_app();
97 specifics
->mutable_app_list();
100 specifics
->mutable_app_setting();
102 case EXTENSION_SETTINGS
:
103 specifics
->mutable_extension_setting();
105 case APP_NOTIFICATIONS
:
106 specifics
->mutable_app_notification();
108 case HISTORY_DELETE_DIRECTIVES
:
109 specifics
->mutable_history_delete_directive();
111 case SYNCED_NOTIFICATIONS
:
112 specifics
->mutable_synced_notification();
114 case SYNCED_NOTIFICATION_APP_INFO
:
115 specifics
->mutable_synced_notification_app_info();
118 specifics
->mutable_device_info();
121 specifics
->mutable_experiments();
123 case PRIORITY_PREFERENCES
:
124 specifics
->mutable_priority_preference();
127 specifics
->mutable_dictionary();
130 specifics
->mutable_favicon_image();
132 case FAVICON_TRACKING
:
133 specifics
->mutable_favicon_tracking();
135 case SUPERVISED_USER_SETTINGS
:
136 specifics
->mutable_managed_user_setting();
138 case SUPERVISED_USERS
:
139 specifics
->mutable_managed_user();
141 case SUPERVISED_USER_SHARED_SETTINGS
:
142 specifics
->mutable_managed_user_shared_setting();
144 case SUPERVISED_USER_WHITELISTS
:
145 specifics
->mutable_managed_user_whitelist();
148 specifics
->mutable_article();
150 case WIFI_CREDENTIALS
:
151 specifics
->mutable_wifi_credential();
154 NOTREACHED() << "No known extension for model type.";
158 ModelType
GetModelTypeFromSpecificsFieldNumber(int field_number
) {
159 ModelTypeSet protocol_types
= ProtocolTypes();
160 for (ModelTypeSet::Iterator iter
= protocol_types
.First(); iter
.Good();
162 if (GetSpecificsFieldNumberFromModelType(iter
.Get()) == field_number
)
168 int GetSpecificsFieldNumberFromModelType(ModelType model_type
) {
169 DCHECK(ProtocolTypes().Has(model_type
))
170 << "Only protocol types have field values.";
171 switch (model_type
) {
173 return sync_pb::EntitySpecifics::kBookmarkFieldNumber
;
175 return sync_pb::EntitySpecifics::kPasswordFieldNumber
;
177 return sync_pb::EntitySpecifics::kPreferenceFieldNumber
;
179 return sync_pb::EntitySpecifics::kAutofillFieldNumber
;
180 case AUTOFILL_PROFILE
:
181 return sync_pb::EntitySpecifics::kAutofillProfileFieldNumber
;
182 case AUTOFILL_WALLET_DATA
:
183 return sync_pb::EntitySpecifics::kAutofillWalletFieldNumber
;
185 return sync_pb::EntitySpecifics::kThemeFieldNumber
;
187 return sync_pb::EntitySpecifics::kTypedUrlFieldNumber
;
189 return sync_pb::EntitySpecifics::kExtensionFieldNumber
;
191 return sync_pb::EntitySpecifics::kNigoriFieldNumber
;
193 return sync_pb::EntitySpecifics::kSearchEngineFieldNumber
;
195 return sync_pb::EntitySpecifics::kSessionFieldNumber
;
197 return sync_pb::EntitySpecifics::kAppFieldNumber
;
199 return sync_pb::EntitySpecifics::kAppListFieldNumber
;
201 return sync_pb::EntitySpecifics::kAppSettingFieldNumber
;
202 case EXTENSION_SETTINGS
:
203 return sync_pb::EntitySpecifics::kExtensionSettingFieldNumber
;
204 case APP_NOTIFICATIONS
:
205 return sync_pb::EntitySpecifics::kAppNotificationFieldNumber
;
206 case HISTORY_DELETE_DIRECTIVES
:
207 return sync_pb::EntitySpecifics::kHistoryDeleteDirectiveFieldNumber
;
208 case SYNCED_NOTIFICATIONS
:
209 return sync_pb::EntitySpecifics::kSyncedNotificationFieldNumber
;
210 case SYNCED_NOTIFICATION_APP_INFO
:
211 return sync_pb::EntitySpecifics::kSyncedNotificationAppInfoFieldNumber
;
213 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber
;
215 return sync_pb::EntitySpecifics::kExperimentsFieldNumber
;
216 case PRIORITY_PREFERENCES
:
217 return sync_pb::EntitySpecifics::kPriorityPreferenceFieldNumber
;
219 return sync_pb::EntitySpecifics::kDictionaryFieldNumber
;
221 return sync_pb::EntitySpecifics::kFaviconImageFieldNumber
;
222 case FAVICON_TRACKING
:
223 return sync_pb::EntitySpecifics::kFaviconTrackingFieldNumber
;
224 case SUPERVISED_USER_SETTINGS
:
225 return sync_pb::EntitySpecifics::kManagedUserSettingFieldNumber
;
226 case SUPERVISED_USERS
:
227 return sync_pb::EntitySpecifics::kManagedUserFieldNumber
;
228 case SUPERVISED_USER_SHARED_SETTINGS
:
229 return sync_pb::EntitySpecifics::kManagedUserSharedSettingFieldNumber
;
230 case SUPERVISED_USER_WHITELISTS
:
231 return sync_pb::EntitySpecifics::kManagedUserWhitelistFieldNumber
;
233 return sync_pb::EntitySpecifics::kArticleFieldNumber
;
234 case WIFI_CREDENTIALS
:
235 return sync_pb::EntitySpecifics::kWifiCredentialFieldNumber
;
237 NOTREACHED() << "No known extension for model type.";
242 FullModelTypeSet
ToFullModelTypeSet(ModelTypeSet in
) {
243 FullModelTypeSet out
;
244 for (ModelTypeSet::Iterator i
= in
.First(); i
.Good(); i
.Inc()) {
250 // Note: keep this consistent with GetModelType in entry.cc!
251 ModelType
GetModelType(const sync_pb::SyncEntity
& sync_entity
) {
252 DCHECK(!IsRoot(sync_entity
)); // Root shouldn't ever go over the wire.
254 // Backwards compatibility with old (pre-specifics) protocol.
255 if (sync_entity
.has_bookmarkdata())
258 ModelType specifics_type
= GetModelTypeFromSpecifics(sync_entity
.specifics());
259 if (specifics_type
!= UNSPECIFIED
)
260 return specifics_type
;
262 // Loose check for server-created top-level folders that aren't
263 // bound to a particular model type.
264 if (!sync_entity
.server_defined_unique_tag().empty() &&
265 IsFolder(sync_entity
)) {
266 return TOP_LEVEL_FOLDER
;
269 // This is an item of a datatype we can't understand. Maybe it's
270 // from the future? Either we mis-encoded the object, or the
271 // server sent us entries it shouldn't have.
272 NOTREACHED() << "Unknown datatype in sync proto.";
276 ModelType
GetModelTypeFromSpecifics(const sync_pb::EntitySpecifics
& specifics
) {
277 if (specifics
.has_bookmark())
280 if (specifics
.has_password())
283 if (specifics
.has_preference())
286 if (specifics
.has_autofill())
289 if (specifics
.has_autofill_profile())
290 return AUTOFILL_PROFILE
;
292 if (specifics
.has_autofill_wallet())
293 return AUTOFILL_WALLET_DATA
;
295 if (specifics
.has_theme())
298 if (specifics
.has_typed_url())
301 if (specifics
.has_extension())
304 if (specifics
.has_nigori())
307 if (specifics
.has_app())
310 if (specifics
.has_app_list())
313 if (specifics
.has_search_engine())
314 return SEARCH_ENGINES
;
316 if (specifics
.has_session())
319 if (specifics
.has_app_setting())
322 if (specifics
.has_extension_setting())
323 return EXTENSION_SETTINGS
;
325 if (specifics
.has_app_notification())
326 return APP_NOTIFICATIONS
;
328 if (specifics
.has_history_delete_directive())
329 return HISTORY_DELETE_DIRECTIVES
;
331 if (specifics
.has_synced_notification())
332 return SYNCED_NOTIFICATIONS
;
334 if (specifics
.has_synced_notification_app_info())
335 return SYNCED_NOTIFICATION_APP_INFO
;
337 if (specifics
.has_device_info())
340 if (specifics
.has_experiments())
343 if (specifics
.has_priority_preference())
344 return PRIORITY_PREFERENCES
;
346 if (specifics
.has_dictionary())
349 if (specifics
.has_favicon_image())
350 return FAVICON_IMAGES
;
352 if (specifics
.has_favicon_tracking())
353 return FAVICON_TRACKING
;
355 if (specifics
.has_managed_user_setting())
356 return SUPERVISED_USER_SETTINGS
;
358 if (specifics
.has_managed_user())
359 return SUPERVISED_USERS
;
361 if (specifics
.has_managed_user_shared_setting())
362 return SUPERVISED_USER_SHARED_SETTINGS
;
364 if (specifics
.has_managed_user_whitelist())
365 return SUPERVISED_USER_WHITELISTS
;
367 if (specifics
.has_article())
370 if (specifics
.has_wifi_credential())
371 return WIFI_CREDENTIALS
;
376 ModelTypeSet
ProtocolTypes() {
377 ModelTypeSet set
= ModelTypeSet::All();
378 set
.RemoveAll(ProxyTypes());
382 ModelTypeSet
UserTypes() {
384 // TODO(sync): We should be able to build the actual enumset's internal
385 // bitset value here at compile time, rather than performing an iteration
387 for (int i
= FIRST_USER_MODEL_TYPE
; i
<= LAST_USER_MODEL_TYPE
; ++i
) {
388 set
.Put(ModelTypeFromInt(i
));
393 ModelTypeSet
UserSelectableTypes() {
395 // Although the order doesn't technically matter here, it's clearer to keep
396 // these in the same order as their definition in the ModelType enum.
398 set
.Put(PREFERENCES
);
405 set
.Put(WIFI_CREDENTIALS
);
410 bool IsUserSelectableType(ModelType model_type
) {
411 return UserSelectableTypes().Has(model_type
);
414 ModelTypeNameMap
GetUserSelectableTypeNameMap() {
415 ModelTypeNameMap type_names
;
416 ModelTypeSet type_set
= UserSelectableTypes();
417 ModelTypeSet::Iterator it
= type_set
.First();
418 DCHECK_EQ(arraysize(kUserSelectableDataTypeNames
), type_set
.Size());
419 for (size_t i
= 0; i
< arraysize(kUserSelectableDataTypeNames
) && it
.Good();
421 type_names
[it
.Get()] = kUserSelectableDataTypeNames
[i
];
426 ModelTypeSet
EncryptableUserTypes() {
427 ModelTypeSet encryptable_user_types
= UserTypes();
428 // We never encrypt history delete directives.
429 encryptable_user_types
.Remove(HISTORY_DELETE_DIRECTIVES
);
430 // Synced notifications are not encrypted since the server must see changes.
431 encryptable_user_types
.Remove(SYNCED_NOTIFICATIONS
);
432 // Synced Notification App Info does not have private data, so it is not
434 encryptable_user_types
.Remove(SYNCED_NOTIFICATION_APP_INFO
);
435 // Device info data is not encrypted because it might be synced before
436 // encryption is ready.
437 encryptable_user_types
.Remove(DEVICE_INFO
);
438 // Priority preferences are not encrypted because they might be synced before
439 // encryption is ready.
440 encryptable_user_types
.Remove(PRIORITY_PREFERENCES
);
441 // Supervised user settings are not encrypted since they are set server-side.
442 encryptable_user_types
.Remove(SUPERVISED_USER_SETTINGS
);
443 // Supervised users are not encrypted since they are managed server-side.
444 encryptable_user_types
.Remove(SUPERVISED_USERS
);
445 // Supervised user shared settings are not encrypted since they are managed
446 // server-side and shared between manager and supervised user.
447 encryptable_user_types
.Remove(SUPERVISED_USER_SHARED_SETTINGS
);
448 // Supervised user whitelists are not encrypted since they are managed
450 encryptable_user_types
.Remove(SUPERVISED_USER_WHITELISTS
);
451 // Proxy types have no sync representation and are therefore not encrypted.
452 // Note however that proxy types map to one or more protocol types, which
453 // may or may not be encrypted themselves.
454 encryptable_user_types
.RemoveAll(ProxyTypes());
455 // Wallet data is not encrypted since it actually originates on the server.
456 encryptable_user_types
.Remove(AUTOFILL_WALLET_DATA
);
457 return encryptable_user_types
;
460 ModelTypeSet
PriorityUserTypes() {
461 return ModelTypeSet(DEVICE_INFO
, PRIORITY_PREFERENCES
);
464 ModelTypeSet
ControlTypes() {
466 // TODO(sync): We should be able to build the actual enumset's internal
467 // bitset value here at compile time, rather than performing an iteration
469 for (int i
= FIRST_CONTROL_MODEL_TYPE
; i
<= LAST_CONTROL_MODEL_TYPE
; ++i
) {
470 set
.Put(ModelTypeFromInt(i
));
476 ModelTypeSet
ProxyTypes() {
482 bool IsControlType(ModelType model_type
) {
483 return ControlTypes().Has(model_type
);
486 ModelTypeSet
CoreTypes() {
487 syncer::ModelTypeSet result
;
488 result
.PutAll(PriorityCoreTypes());
490 // The following are low priority core types.
491 result
.Put(SYNCED_NOTIFICATIONS
);
492 result
.Put(SYNCED_NOTIFICATION_APP_INFO
);
493 result
.Put(SUPERVISED_USER_SHARED_SETTINGS
);
494 result
.Put(SUPERVISED_USER_WHITELISTS
);
499 ModelTypeSet
PriorityCoreTypes() {
500 syncer::ModelTypeSet result
;
501 result
.PutAll(ControlTypes());
503 // The following are non-control core types.
504 result
.Put(SUPERVISED_USERS
);
505 result
.Put(SUPERVISED_USER_SETTINGS
);
510 ModelTypeSet
BackupTypes() {
512 result
.Put(BOOKMARKS
);
513 result
.Put(PREFERENCES
);
515 result
.Put(EXTENSIONS
);
516 result
.Put(SEARCH_ENGINES
);
518 result
.Put(APP_LIST
);
519 result
.Put(APP_SETTINGS
);
520 result
.Put(EXTENSION_SETTINGS
);
521 result
.Put(PRIORITY_PREFERENCES
);
525 const char* ModelTypeToString(ModelType model_type
) {
526 // This is used in serialization routines as well as for displaying debug
527 // information. Do not attempt to change these string values unless you know
528 // what you're doing.
529 switch (model_type
) {
530 case TOP_LEVEL_FOLDER
:
531 return "Top Level Folder";
533 return "Unspecified";
537 return "Preferences";
549 return "Encryption keys";
551 return "Search Engines";
558 case AUTOFILL_PROFILE
:
559 return "Autofill Profiles";
561 return "App settings";
562 case EXTENSION_SETTINGS
:
563 return "Extension settings";
564 case APP_NOTIFICATIONS
:
565 return "App Notifications";
566 case HISTORY_DELETE_DIRECTIVES
:
567 return "History Delete Directives";
568 case SYNCED_NOTIFICATIONS
:
569 return "Synced Notifications";
570 case SYNCED_NOTIFICATION_APP_INFO
:
571 return "Synced Notification App Info";
573 return "Device Info";
575 return "Experiments";
576 case PRIORITY_PREFERENCES
:
577 return "Priority Preferences";
581 return "Favicon Images";
582 case FAVICON_TRACKING
:
583 return "Favicon Tracking";
584 case SUPERVISED_USER_SETTINGS
:
585 return "Managed User Settings";
586 case SUPERVISED_USERS
:
587 return "Managed Users";
588 case SUPERVISED_USER_SHARED_SETTINGS
:
589 return "Managed User Shared Settings";
590 case SUPERVISED_USER_WHITELISTS
:
591 return "Managed User Whitelists";
594 case WIFI_CREDENTIALS
:
595 return "WiFi Credentials";
598 case AUTOFILL_WALLET_DATA
:
599 return "Autofill Wallet";
603 NOTREACHED() << "No known extension for model type.";
607 // 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
611 // Don't forget to update the "SyncModelTypes" enum in histograms.xml when you
612 // make changes to this list.
613 int ModelTypeToHistogramInt(ModelType model_type
) {
614 switch (model_type
) {
617 case TOP_LEVEL_FOLDER
:
625 case AUTOFILL_PROFILE
:
643 case EXTENSION_SETTINGS
:
645 case APP_NOTIFICATIONS
:
647 case HISTORY_DELETE_DIRECTIVES
:
655 case SYNCED_NOTIFICATIONS
:
657 case PRIORITY_PREFERENCES
:
663 case FAVICON_TRACKING
:
667 case SUPERVISED_USER_SETTINGS
:
669 case SUPERVISED_USERS
:
675 case SUPERVISED_USER_SHARED_SETTINGS
:
677 case SYNCED_NOTIFICATION_APP_INFO
:
679 case WIFI_CREDENTIALS
:
681 case SUPERVISED_USER_WHITELISTS
:
683 case AUTOFILL_WALLET_DATA
:
685 // Silence a compiler warning.
686 case MODEL_TYPE_COUNT
:
692 base::StringValue
* ModelTypeToValue(ModelType model_type
) {
693 if (model_type
>= FIRST_REAL_MODEL_TYPE
) {
694 return new base::StringValue(ModelTypeToString(model_type
));
695 } else if (model_type
== TOP_LEVEL_FOLDER
) {
696 return new base::StringValue("Top-level folder");
697 } else if (model_type
== UNSPECIFIED
) {
698 return new base::StringValue("Unspecified");
701 return new base::StringValue(std::string());
704 ModelType
ModelTypeFromValue(const base::Value
& value
) {
705 if (value
.IsType(base::Value::TYPE_STRING
)) {
707 CHECK(value
.GetAsString(&result
));
708 return ModelTypeFromString(result
);
709 } else if (value
.IsType(base::Value::TYPE_INTEGER
)) {
711 CHECK(value
.GetAsInteger(&result
));
712 return ModelTypeFromInt(result
);
714 NOTREACHED() << "Unsupported value type: " << value
.GetType();
719 ModelType
ModelTypeFromString(const std::string
& model_type_string
) {
720 if (model_type_string
== "Bookmarks")
722 else if (model_type_string
== "Preferences")
724 else if (model_type_string
== "Passwords")
726 else if (model_type_string
== "Autofill")
728 else if (model_type_string
== "Autofill Profiles")
729 return AUTOFILL_PROFILE
;
730 else if (model_type_string
== "Autofill Wallet")
731 return AUTOFILL_WALLET_DATA
;
732 else if (model_type_string
== "Themes")
734 else if (model_type_string
== "Typed URLs")
736 else if (model_type_string
== "Extensions")
738 else if (model_type_string
== "Encryption keys")
740 else if (model_type_string
== "Search Engines")
741 return SEARCH_ENGINES
;
742 else if (model_type_string
== "Sessions")
744 else if (model_type_string
== "Apps")
746 else if (model_type_string
== "App List")
748 else if (model_type_string
== "App settings")
750 else if (model_type_string
== "Extension settings")
751 return EXTENSION_SETTINGS
;
752 else if (model_type_string
== "App Notifications")
753 return APP_NOTIFICATIONS
;
754 else if (model_type_string
== "History Delete Directives")
755 return HISTORY_DELETE_DIRECTIVES
;
756 else if (model_type_string
== "Synced Notifications")
757 return SYNCED_NOTIFICATIONS
;
758 else if (model_type_string
== "Synced Notification App Info")
759 return SYNCED_NOTIFICATION_APP_INFO
;
760 else if (model_type_string
== "Device Info")
762 else if (model_type_string
== "Experiments")
764 else if (model_type_string
== "Priority Preferences")
765 return PRIORITY_PREFERENCES
;
766 else if (model_type_string
== "Dictionary")
768 else if (model_type_string
== "Favicon Images")
769 return FAVICON_IMAGES
;
770 else if (model_type_string
== "Favicon Tracking")
771 return FAVICON_TRACKING
;
772 else if (model_type_string
== "Managed User Settings")
773 return SUPERVISED_USER_SETTINGS
;
774 else if (model_type_string
== "Managed Users")
775 return SUPERVISED_USERS
;
776 else if (model_type_string
== "Managed User Shared Settings")
777 return SUPERVISED_USER_SHARED_SETTINGS
;
778 else if (model_type_string
== "Managed User Whitelists")
779 return SUPERVISED_USER_WHITELISTS
;
780 else if (model_type_string
== "Articles")
782 else if (model_type_string
== "WiFi Credentials")
783 return WIFI_CREDENTIALS
;
784 else if (model_type_string
== "Tabs")
787 NOTREACHED() << "No known model type corresponding to "
788 << model_type_string
<< ".";
792 std::string
ModelTypeSetToString(ModelTypeSet model_types
) {
794 for (ModelTypeSet::Iterator it
= model_types
.First(); it
.Good(); it
.Inc()) {
795 if (!result
.empty()) {
798 result
+= ModelTypeToString(it
.Get());
803 ModelTypeSet
ModelTypeSetFromString(const std::string
& model_types_string
) {
804 std::string working_copy
= model_types_string
;
805 ModelTypeSet model_types
;
806 while (!working_copy
.empty()) {
807 // Remove any leading spaces.
808 working_copy
= working_copy
.substr(working_copy
.find_first_not_of(' '));
809 if (working_copy
.empty())
811 std::string type_str
;
812 size_t end
= working_copy
.find(',');
813 if (end
== std::string::npos
) {
814 end
= working_copy
.length() - 1;
815 type_str
= working_copy
;
817 type_str
= working_copy
.substr(0, end
);
819 syncer::ModelType type
= ModelTypeFromString(type_str
);
820 if (IsRealDataType(type
))
821 model_types
.Put(type
);
822 working_copy
= working_copy
.substr(end
+ 1);
827 base::ListValue
* ModelTypeSetToValue(ModelTypeSet model_types
) {
828 base::ListValue
* value
= new base::ListValue();
829 for (ModelTypeSet::Iterator it
= model_types
.First(); it
.Good(); it
.Inc()) {
830 value
->Append(new base::StringValue(ModelTypeToString(it
.Get())));
835 ModelTypeSet
ModelTypeSetFromValue(const base::ListValue
& value
) {
837 for (base::ListValue::const_iterator i
= value
.begin();
838 i
!= value
.end(); ++i
) {
839 result
.Put(ModelTypeFromValue(**i
));
844 // TODO(zea): remove all hardcoded tags in model associators and have them use
846 // NOTE: Proxy types should return empty strings (so that we don't NOTREACHED
847 // in tests when we verify they have no root node).
848 std::string
ModelTypeToRootTag(ModelType type
) {
851 return "google_chrome_bookmarks";
853 return "google_chrome_preferences";
855 return "google_chrome_passwords";
857 return "google_chrome_autofill";
859 return "google_chrome_themes";
861 return "google_chrome_typed_urls";
863 return "google_chrome_extensions";
865 return "google_chrome_nigori";
867 return "google_chrome_search_engines";
869 return "google_chrome_sessions";
871 return "google_chrome_apps";
873 return "google_chrome_app_list";
874 case AUTOFILL_PROFILE
:
875 return "google_chrome_autofill_profiles";
876 case AUTOFILL_WALLET_DATA
:
877 return "google_chrome_autofill_wallet";
879 return "google_chrome_app_settings";
880 case EXTENSION_SETTINGS
:
881 return "google_chrome_extension_settings";
882 case APP_NOTIFICATIONS
:
883 return "google_chrome_app_notifications";
884 case HISTORY_DELETE_DIRECTIVES
:
885 return "google_chrome_history_delete_directives";
886 case SYNCED_NOTIFICATIONS
:
887 return "google_chrome_synced_notifications";
888 case SYNCED_NOTIFICATION_APP_INFO
:
889 return "google_chrome_synced_notification_app_info";
891 return "google_chrome_device_info";
893 return "google_chrome_experiments";
894 case PRIORITY_PREFERENCES
:
895 return "google_chrome_priority_preferences";
897 return "google_chrome_dictionary";
899 return "google_chrome_favicon_images";
900 case FAVICON_TRACKING
:
901 return "google_chrome_favicon_tracking";
902 case SUPERVISED_USER_SETTINGS
:
903 return "google_chrome_managed_user_settings";
904 case SUPERVISED_USERS
:
905 return "google_chrome_managed_users";
906 case SUPERVISED_USER_SHARED_SETTINGS
:
907 return "google_chrome_managed_user_shared_settings";
908 case SUPERVISED_USER_WHITELISTS
:
909 return "google_chrome_managed_user_whitelists";
911 return "google_chrome_articles";
912 case WIFI_CREDENTIALS
:
913 return "google_chrome_wifi_credentials";
915 return std::string();
919 NOTREACHED() << "No known extension for model type.";
923 // TODO(akalin): Figure out a better way to do these mappings.
924 // Note: Do not include proxy types in this list. They should never receive
925 // or trigger notifications.
927 const char kBookmarkNotificationType
[] = "BOOKMARK";
928 const char kPreferenceNotificationType
[] = "PREFERENCE";
929 const char kPasswordNotificationType
[] = "PASSWORD";
930 const char kAutofillNotificationType
[] = "AUTOFILL";
931 const char kThemeNotificationType
[] = "THEME";
932 const char kTypedUrlNotificationType
[] = "TYPED_URL";
933 const char kExtensionNotificationType
[] = "EXTENSION";
934 const char kExtensionSettingNotificationType
[] = "EXTENSION_SETTING";
935 const char kNigoriNotificationType
[] = "NIGORI";
936 const char kAppSettingNotificationType
[] = "APP_SETTING";
937 const char kAppNotificationType
[] = "APP";
938 const char kAppListNotificationType
[] = "APP_LIST";
939 const char kSearchEngineNotificationType
[] = "SEARCH_ENGINE";
940 const char kSessionNotificationType
[] = "SESSION";
941 const char kAutofillProfileNotificationType
[] = "AUTOFILL_PROFILE";
942 const char kAutofillWalletNotificationType
[] = "AUTOFILL_WALLET";
943 const char kAppNotificationNotificationType
[] = "APP_NOTIFICATION";
944 const char kHistoryDeleteDirectiveNotificationType
[] =
945 "HISTORY_DELETE_DIRECTIVE";
946 const char kSyncedNotificationType
[] = "SYNCED_NOTIFICATION";
947 const char kSyncedNotificationAppInfoType
[] = "SYNCED_NOTIFICATION_APP_INFO";
948 const char kDeviceInfoNotificationType
[] = "DEVICE_INFO";
949 const char kExperimentsNotificationType
[] = "EXPERIMENTS";
950 const char kPriorityPreferenceNotificationType
[] = "PRIORITY_PREFERENCE";
951 const char kDictionaryNotificationType
[] = "DICTIONARY";
952 const char kFaviconImageNotificationType
[] = "FAVICON_IMAGE";
953 const char kFaviconTrackingNotificationType
[] = "FAVICON_TRACKING";
954 const char kSupervisedUserSettingNotificationType
[] = "MANAGED_USER_SETTING";
955 const char kSupervisedUserNotificationType
[] = "MANAGED_USER";
956 const char kSupervisedUserSharedSettingNotificationType
[] =
957 "MANAGED_USER_SHARED_SETTING";
958 const char kSupervisedUserWhitelistNotificationType
[] =
959 "MANAGED_USER_WHITELIST";
960 const char kArticleNotificationType
[] = "ARTICLE";
961 const char kWifiCredentialNotificationType
[] = "WIFI_CREDENTIAL";
964 bool RealModelTypeToNotificationType(ModelType model_type
,
965 std::string
* notification_type
) {
966 switch (model_type
) {
968 *notification_type
= kBookmarkNotificationType
;
971 *notification_type
= kPreferenceNotificationType
;
974 *notification_type
= kPasswordNotificationType
;
977 *notification_type
= kAutofillNotificationType
;
980 *notification_type
= kThemeNotificationType
;
983 *notification_type
= kTypedUrlNotificationType
;
986 *notification_type
= kExtensionNotificationType
;
989 *notification_type
= kNigoriNotificationType
;
992 *notification_type
= kAppSettingNotificationType
;
995 *notification_type
= kAppNotificationType
;
998 *notification_type
= kAppListNotificationType
;
1000 case SEARCH_ENGINES
:
1001 *notification_type
= kSearchEngineNotificationType
;
1004 *notification_type
= kSessionNotificationType
;
1006 case AUTOFILL_PROFILE
:
1007 *notification_type
= kAutofillProfileNotificationType
;
1009 case AUTOFILL_WALLET_DATA
:
1010 *notification_type
= kAutofillWalletNotificationType
;
1012 case EXTENSION_SETTINGS
:
1013 *notification_type
= kExtensionSettingNotificationType
;
1015 case APP_NOTIFICATIONS
:
1016 *notification_type
= kAppNotificationNotificationType
;
1018 case HISTORY_DELETE_DIRECTIVES
:
1019 *notification_type
= kHistoryDeleteDirectiveNotificationType
;
1021 case SYNCED_NOTIFICATIONS
:
1022 *notification_type
= kSyncedNotificationType
;
1024 case SYNCED_NOTIFICATION_APP_INFO
:
1025 *notification_type
= kSyncedNotificationAppInfoType
;
1028 *notification_type
= kDeviceInfoNotificationType
;
1031 *notification_type
= kExperimentsNotificationType
;
1033 case PRIORITY_PREFERENCES
:
1034 *notification_type
= kPriorityPreferenceNotificationType
;
1037 *notification_type
= kDictionaryNotificationType
;
1039 case FAVICON_IMAGES
:
1040 *notification_type
= kFaviconImageNotificationType
;
1042 case FAVICON_TRACKING
:
1043 *notification_type
= kFaviconTrackingNotificationType
;
1045 case SUPERVISED_USER_SETTINGS
:
1046 *notification_type
= kSupervisedUserSettingNotificationType
;
1048 case SUPERVISED_USERS
:
1049 *notification_type
= kSupervisedUserNotificationType
;
1051 case SUPERVISED_USER_SHARED_SETTINGS
:
1052 *notification_type
= kSupervisedUserSharedSettingNotificationType
;
1054 case SUPERVISED_USER_WHITELISTS
:
1055 *notification_type
= kSupervisedUserWhitelistNotificationType
;
1058 *notification_type
= kArticleNotificationType
;
1060 case WIFI_CREDENTIALS
:
1061 *notification_type
= kWifiCredentialNotificationType
;
1066 notification_type
->clear();
1070 bool NotificationTypeToRealModelType(const std::string
& notification_type
,
1071 ModelType
* model_type
) {
1072 if (notification_type
== kBookmarkNotificationType
) {
1073 *model_type
= BOOKMARKS
;
1075 } else if (notification_type
== kPreferenceNotificationType
) {
1076 *model_type
= PREFERENCES
;
1078 } else if (notification_type
== kPasswordNotificationType
) {
1079 *model_type
= PASSWORDS
;
1081 } else if (notification_type
== kAutofillNotificationType
) {
1082 *model_type
= AUTOFILL
;
1084 } else if (notification_type
== kThemeNotificationType
) {
1085 *model_type
= THEMES
;
1087 } else if (notification_type
== kTypedUrlNotificationType
) {
1088 *model_type
= TYPED_URLS
;
1090 } else if (notification_type
== kExtensionNotificationType
) {
1091 *model_type
= EXTENSIONS
;
1093 } else if (notification_type
== kNigoriNotificationType
) {
1094 *model_type
= NIGORI
;
1096 } else if (notification_type
== kAppNotificationType
) {
1099 } else if (notification_type
== kAppListNotificationType
) {
1100 *model_type
= APP_LIST
;
1102 } else if (notification_type
== kSearchEngineNotificationType
) {
1103 *model_type
= SEARCH_ENGINES
;
1105 } else if (notification_type
== kSessionNotificationType
) {
1106 *model_type
= SESSIONS
;
1108 } else if (notification_type
== kAutofillProfileNotificationType
) {
1109 *model_type
= AUTOFILL_PROFILE
;
1111 } else if (notification_type
== kAutofillWalletNotificationType
) {
1112 *model_type
= AUTOFILL_WALLET_DATA
;
1114 } else if (notification_type
== kAppSettingNotificationType
) {
1115 *model_type
= APP_SETTINGS
;
1117 } else if (notification_type
== kExtensionSettingNotificationType
) {
1118 *model_type
= EXTENSION_SETTINGS
;
1120 } else if (notification_type
== kAppNotificationNotificationType
) {
1121 *model_type
= APP_NOTIFICATIONS
;
1123 } else if (notification_type
== kHistoryDeleteDirectiveNotificationType
) {
1124 *model_type
= HISTORY_DELETE_DIRECTIVES
;
1126 } else if (notification_type
== kSyncedNotificationType
) {
1127 *model_type
= SYNCED_NOTIFICATIONS
;
1129 } else if (notification_type
== kSyncedNotificationAppInfoType
) {
1130 *model_type
= SYNCED_NOTIFICATION_APP_INFO
;
1132 } else if (notification_type
== kDeviceInfoNotificationType
) {
1133 *model_type
= DEVICE_INFO
;
1135 } else if (notification_type
== kExperimentsNotificationType
) {
1136 *model_type
= EXPERIMENTS
;
1138 } else if (notification_type
== kPriorityPreferenceNotificationType
) {
1139 *model_type
= PRIORITY_PREFERENCES
;
1141 } else if (notification_type
== kDictionaryNotificationType
) {
1142 *model_type
= DICTIONARY
;
1144 } else if (notification_type
== kFaviconImageNotificationType
) {
1145 *model_type
= FAVICON_IMAGES
;
1147 } else if (notification_type
== kFaviconTrackingNotificationType
) {
1148 *model_type
= FAVICON_TRACKING
;
1150 } else if (notification_type
== kSupervisedUserSettingNotificationType
) {
1151 *model_type
= SUPERVISED_USER_SETTINGS
;
1153 } else if (notification_type
== kSupervisedUserNotificationType
) {
1154 *model_type
= SUPERVISED_USERS
;
1156 } else if (notification_type
==
1157 kSupervisedUserSharedSettingNotificationType
) {
1158 *model_type
= SUPERVISED_USER_SHARED_SETTINGS
;
1160 } else if (notification_type
== kSupervisedUserWhitelistNotificationType
) {
1161 *model_type
= SUPERVISED_USER_WHITELISTS
;
1163 } else if (notification_type
== kArticleNotificationType
) {
1164 *model_type
= ARTICLES
;
1166 } else if (notification_type
== kWifiCredentialNotificationType
) {
1167 *model_type
= WIFI_CREDENTIALS
;
1170 *model_type
= UNSPECIFIED
;
1174 bool IsRealDataType(ModelType model_type
) {
1175 return model_type
>= FIRST_REAL_MODEL_TYPE
&& model_type
< MODEL_TYPE_COUNT
;
1178 bool IsProxyType(ModelType model_type
) {
1179 return model_type
>= FIRST_PROXY_TYPE
&& model_type
<= LAST_PROXY_TYPE
;
1182 bool IsActOnceDataType(ModelType model_type
) {
1183 return model_type
== HISTORY_DELETE_DIRECTIVES
;
1186 bool IsTypeWithServerGeneratedRoot(ModelType model_type
) {
1187 return model_type
== BOOKMARKS
|| model_type
== NIGORI
;
1190 bool IsTypeWithClientGeneratedRoot(ModelType model_type
) {
1191 return IsRealDataType(model_type
) &&
1192 !IsTypeWithServerGeneratedRoot(model_type
);
1195 } // namespace syncer