OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sync/internal_api/public/base/model_type.h" | 5 #include "sync/internal_api/public/base/model_type.h" |
6 | 6 |
7 #include "base/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "sync/protocol/app_notification_specifics.pb.h" | 9 #include "sync/protocol/app_notification_specifics.pb.h" |
10 #include "sync/protocol/app_setting_specifics.pb.h" | 10 #include "sync/protocol/app_setting_specifics.pb.h" |
11 #include "sync/protocol/app_specifics.pb.h" | 11 #include "sync/protocol/app_specifics.pb.h" |
12 #include "sync/protocol/autofill_specifics.pb.h" | 12 #include "sync/protocol/autofill_specifics.pb.h" |
13 #include "sync/protocol/bookmark_specifics.pb.h" | 13 #include "sync/protocol/bookmark_specifics.pb.h" |
14 #include "sync/protocol/extension_setting_specifics.pb.h" | 14 #include "sync/protocol/extension_setting_specifics.pb.h" |
15 #include "sync/protocol/extension_specifics.pb.h" | 15 #include "sync/protocol/extension_specifics.pb.h" |
16 #include "sync/protocol/nigori_specifics.pb.h" | 16 #include "sync/protocol/nigori_specifics.pb.h" |
17 #include "sync/protocol/password_specifics.pb.h" | 17 #include "sync/protocol/password_specifics.pb.h" |
18 #include "sync/protocol/preference_specifics.pb.h" | 18 #include "sync/protocol/preference_specifics.pb.h" |
19 #include "sync/protocol/search_engine_specifics.pb.h" | 19 #include "sync/protocol/search_engine_specifics.pb.h" |
20 #include "sync/protocol/session_specifics.pb.h" | 20 #include "sync/protocol/session_specifics.pb.h" |
21 #include "sync/protocol/sync.pb.h" | 21 #include "sync/protocol/sync.pb.h" |
22 #include "sync/protocol/theme_specifics.pb.h" | 22 #include "sync/protocol/theme_specifics.pb.h" |
23 #include "sync/protocol/typed_url_specifics.pb.h" | 23 #include "sync/protocol/typed_url_specifics.pb.h" |
24 #include "sync/syncable/syncable_proto_util.h" | 24 #include "sync/syncable/syncable_proto_util.h" |
25 | 25 |
26 namespace syncer { | 26 namespace syncer { |
27 | 27 |
28 struct ModelTypeToNotificationMap { | |
29 ModelType model_type; | |
30 const char* notification_type; | |
31 const char* root_tag; | |
32 const char* model_type_string; | |
33 int model_type_histogram_val; | |
34 }; | |
35 | |
36 ModelTypeToNotificationMap kModelTypeToNotificationMap[] = { | |
37 {UNSPECIFIED, "", "", "Unspecified", 0}, | |
38 {TOP_LEVEL_FOLDER, "", "", "Top Level Folder", 1}, | |
39 {BOOKMARKS, "BOOKMARK", "bookmarks", "Bookmarks", 2}, | |
40 {PREFERENCES, "PREFERENCE", "preferences", "Preferences", 3}, | |
41 {PASSWORDS, "PASSWORD", "passwords", "Passwords", 4}, | |
42 {AUTOFILL_PROFILE, "AUTOFILL_PROFILE", "autofill_profiles", | |
43 "Autofill Profiles", 5}, | |
44 {AUTOFILL, "AUTOFILL", "autofill", "Autofill", 6}, | |
45 {THEMES, "THEME", "themes", "Themes", 7}, | |
46 {TYPED_URLS, "TYPED_URL", "typed_urls", "Typed URLs", 8}, | |
47 {EXTENSIONS, "EXTENSION", "extensions", "Extensions", 9}, | |
48 {SEARCH_ENGINES, "SEARCH_ENGINE", "search_engines", "Search Engines", 10}, | |
49 {SESSIONS, "SESSION", "sessions", "Sessions", 11}, | |
50 {APPS, "APPs", "apps", "Apps", 12}, | |
51 {APP_SETTINGS, "APP_SETTING", "app_settings", "App settings", 13}, | |
52 {EXTENSION_SETTINGS, "EXTENSION_SETTING", "extension_settings", | |
53 "Extension settings", 14}, | |
54 {APP_NOTIFICATIONS, "APP_NOTIFICATION", "app_notifications", | |
55 "App Notifications", 15}, | |
56 {HISTORY_DELETE_DIRECTIVES, "HISTORY_DELETE_DIRECTIVE", | |
57 "history_delete_directives", "History Delete Directives", 16}, | |
58 {NIGORI, "NIGORI", "nigori", "Encryption keys", 17}, | |
59 {DEVICE_INFO, "DEVICE_INFO", "device_info", "Device Info", 18}, | |
60 {EXPERIMENTS, "EXPERIMENTS", "experiments", "Experiments", 19}, | |
61 {SYNCED_NOTIFICATIONS, "SYNCED_NOTIFICATION", "synced_notifications", | |
62 "Synced Notifications", 20}, | |
63 {PRIORITY_PREFERENCES, "PRIORITY_PREFERENCE", "priority_preferences", | |
64 "Priority Preferences", 21}, | |
65 {DICTIONARY, "DICTIONARY", "dictionary", "Dictionary", 22}, | |
66 {FAVICON_IMAGES, "FAVICON_IMAGE", "favicon_images", "Favicon Images", 23}, | |
67 {FAVICON_TRACKING, "FAVICON_TRACKING", "favicon_tracking", | |
68 "Favicon Tracking", 24}, | |
69 {PROXY_TABS, "", "", "Tabs", 25}, | |
70 {SUPERVISED_USER_SETTINGS, "MANAGED_USER_SETTING", "managed_user_settings", | |
71 "Managed User Settings", 26}, | |
72 {SUPERVISED_USERS, "MANAGED_USER", "managed_users", "Managed Users", 27}, | |
73 {ARTICLES, "ARTICLE", "articles", "Articles", 28}, | |
74 {APP_LIST, "APP_LIST", "app_list", "App List", 29}, | |
75 {SUPERVISED_USER_SHARED_SETTINGS, "MANAGED_USER_SHARED_SETTING", | |
76 "managed_user_shared_settings", "Managed User Shared Settings", 30}, | |
77 {SYNCED_NOTIFICATION_APP_INFO, "SYNCED_NOTIFICATION_APP_INFO", | |
78 "synced_notification_app_info", "Synced Notification App Info", 31}, | |
79 {WIFI_CREDENTIALS, "WIFI_CREDENTIAL", "wifi_credentials", | |
80 "WiFi Credentials", 32}, | |
81 {SUPERVISED_USER_WHITELISTS, "MANAGED_USER_WHITELIST", | |
82 "managed_user_whitelists", "Managed User Whitelists", 33}, | |
83 {AUTOFILL_WALLET_DATA, "AUTOFILL_WALLET", "autofill_wallet", | |
84 "Autofill Wallet", 34}, | |
85 {AUTOFILL_WALLET_METADATA, "AUTOFILL_WALLET_METADATA", | |
86 "autofill_wallet_metadata", "Autofill Wallet Metadata", 35}, | |
87 }; | |
28 // Notes: | 88 // Notes: |
29 // 1) This list must contain exactly the same elements as the set returned by | 89 // 1) This list must contain exactly the same elements as the set returned by |
30 // UserSelectableTypes(). | 90 // UserSelectableTypes(). |
31 // 2) This list must be in the same order as the respective values in the | 91 // 2) This list must be in the same order as the respective values in the |
32 // ModelType enum. | 92 // ModelType enum. |
33 const char* kUserSelectableDataTypeNames[] = { | 93 const char* kUserSelectableDataTypeNames[] = { |
34 "bookmarks", | 94 "bookmarks", |
35 "preferences", | 95 "preferences", |
36 "passwords", | 96 "passwords", |
37 "autofill", | 97 "autofill", |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 result.Put(APP_SETTINGS); | 587 result.Put(APP_SETTINGS); |
528 result.Put(EXTENSION_SETTINGS); | 588 result.Put(EXTENSION_SETTINGS); |
529 result.Put(PRIORITY_PREFERENCES); | 589 result.Put(PRIORITY_PREFERENCES); |
530 return result; | 590 return result; |
531 } | 591 } |
532 | 592 |
533 const char* ModelTypeToString(ModelType model_type) { | 593 const char* ModelTypeToString(ModelType model_type) { |
534 // This is used in serialization routines as well as for displaying debug | 594 // This is used in serialization routines as well as for displaying debug |
535 // information. Do not attempt to change these string values unless you know | 595 // information. Do not attempt to change these string values unless you know |
536 // what you're doing. | 596 // what you're doing. |
537 switch (model_type) { | 597 for (const ModelTypeToNotificationMap& entry : kModelTypeToNotificationMap) { |
538 case TOP_LEVEL_FOLDER: | 598 if (entry.model_type == model_type) |
539 return "Top Level Folder"; | 599 return entry.model_type_string; |
540 case UNSPECIFIED: | |
541 return "Unspecified"; | |
542 case BOOKMARKS: | |
543 return "Bookmarks"; | |
544 case PREFERENCES: | |
545 return "Preferences"; | |
546 case PASSWORDS: | |
547 return "Passwords"; | |
548 case AUTOFILL: | |
549 return "Autofill"; | |
550 case THEMES: | |
551 return "Themes"; | |
552 case TYPED_URLS: | |
553 return "Typed URLs"; | |
554 case EXTENSIONS: | |
555 return "Extensions"; | |
556 case NIGORI: | |
557 return "Encryption keys"; | |
558 case SEARCH_ENGINES: | |
559 return "Search Engines"; | |
560 case SESSIONS: | |
561 return "Sessions"; | |
562 case APPS: | |
563 return "Apps"; | |
564 case APP_LIST: | |
565 return "App List"; | |
566 case AUTOFILL_PROFILE: | |
567 return "Autofill Profiles"; | |
568 case APP_SETTINGS: | |
569 return "App settings"; | |
570 case EXTENSION_SETTINGS: | |
571 return "Extension settings"; | |
572 case APP_NOTIFICATIONS: | |
573 return "App Notifications"; | |
574 case HISTORY_DELETE_DIRECTIVES: | |
575 return "History Delete Directives"; | |
576 case SYNCED_NOTIFICATIONS: | |
577 return "Synced Notifications"; | |
578 case SYNCED_NOTIFICATION_APP_INFO: | |
579 return "Synced Notification App Info"; | |
580 case DEVICE_INFO: | |
581 return "Device Info"; | |
582 case EXPERIMENTS: | |
583 return "Experiments"; | |
584 case PRIORITY_PREFERENCES: | |
585 return "Priority Preferences"; | |
586 case DICTIONARY: | |
587 return "Dictionary"; | |
588 case FAVICON_IMAGES: | |
589 return "Favicon Images"; | |
590 case FAVICON_TRACKING: | |
591 return "Favicon Tracking"; | |
592 case SUPERVISED_USER_SETTINGS: | |
593 return "Managed User Settings"; | |
594 case SUPERVISED_USERS: | |
595 return "Managed Users"; | |
596 case SUPERVISED_USER_SHARED_SETTINGS: | |
597 return "Managed User Shared Settings"; | |
598 case SUPERVISED_USER_WHITELISTS: | |
599 return "Managed User Whitelists"; | |
600 case ARTICLES: | |
601 return "Articles"; | |
602 case WIFI_CREDENTIALS: | |
603 return "WiFi Credentials"; | |
604 case PROXY_TABS: | |
605 return "Tabs"; | |
606 case AUTOFILL_WALLET_DATA: | |
607 return "Autofill Wallet"; | |
608 case AUTOFILL_WALLET_METADATA: | |
609 return "Autofill Wallet Metadata"; | |
610 default: | |
611 break; | |
612 } | 600 } |
613 NOTREACHED() << "No known extension for model type."; | 601 NOTREACHED() << "No known extension for model type."; |
614 return "INVALID"; | 602 return "INVALID"; |
615 } | 603 } |
616 | 604 |
617 // The normal rules about histograms apply here. Always append to the bottom of | 605 // The normal rules about histograms apply here. Always append to the bottom of |
618 // the list, and be careful to not reuse integer values that have already been | 606 // the list, and be careful to not reuse integer values that have already been |
619 // assigned. | 607 // assigned. |
620 // | 608 // |
621 // Don't forget to update the "SyncModelTypes" enum in histograms.xml when you | 609 // Don't forget to update the "SyncModelTypes" enum in histograms.xml when you |
622 // make changes to this list. | 610 // make changes to this list. |
623 int ModelTypeToHistogramInt(ModelType model_type) { | 611 int ModelTypeToHistogramInt(ModelType model_type) { |
624 switch (model_type) { | 612 for (const ModelTypeToNotificationMap& entry : kModelTypeToNotificationMap) { |
625 case UNSPECIFIED: | 613 if (entry.model_type == model_type) |
626 return 0; | 614 return entry.model_type_histogram_val; |
627 case TOP_LEVEL_FOLDER: | |
628 return 1; | |
629 case BOOKMARKS: | |
630 return 2; | |
631 case PREFERENCES: | |
632 return 3; | |
633 case PASSWORDS: | |
634 return 4; | |
635 case AUTOFILL_PROFILE: | |
636 return 5; | |
637 case AUTOFILL: | |
638 return 6; | |
639 case THEMES: | |
640 return 7; | |
641 case TYPED_URLS: | |
642 return 8; | |
643 case EXTENSIONS: | |
644 return 9; | |
645 case SEARCH_ENGINES: | |
646 return 10; | |
647 case SESSIONS: | |
648 return 11; | |
649 case APPS: | |
650 return 12; | |
651 case APP_SETTINGS: | |
652 return 13; | |
653 case EXTENSION_SETTINGS: | |
654 return 14; | |
655 case APP_NOTIFICATIONS: | |
656 return 15; | |
657 case HISTORY_DELETE_DIRECTIVES: | |
658 return 16; | |
659 case NIGORI: | |
660 return 17; | |
661 case DEVICE_INFO: | |
662 return 18; | |
663 case EXPERIMENTS: | |
664 return 19; | |
665 case SYNCED_NOTIFICATIONS: | |
666 return 20; | |
667 case PRIORITY_PREFERENCES: | |
668 return 21; | |
669 case DICTIONARY: | |
670 return 22; | |
671 case FAVICON_IMAGES: | |
672 return 23; | |
673 case FAVICON_TRACKING: | |
674 return 24; | |
675 case PROXY_TABS: | |
676 return 25; | |
677 case SUPERVISED_USER_SETTINGS: | |
678 return 26; | |
679 case SUPERVISED_USERS: | |
680 return 27; | |
681 case ARTICLES: | |
682 return 28; | |
683 case APP_LIST: | |
684 return 29; | |
685 case SUPERVISED_USER_SHARED_SETTINGS: | |
686 return 30; | |
687 case SYNCED_NOTIFICATION_APP_INFO: | |
688 return 31; | |
689 case WIFI_CREDENTIALS: | |
690 return 32; | |
691 case SUPERVISED_USER_WHITELISTS: | |
692 return 33; | |
693 case AUTOFILL_WALLET_DATA: | |
694 return 34; | |
695 case AUTOFILL_WALLET_METADATA: | |
696 return 35; | |
697 // Silence a compiler warning. | |
698 case MODEL_TYPE_COUNT: | |
699 return 0; | |
700 } | 615 } |
701 return 0; | 616 return 0; |
702 } | 617 } |
703 | 618 |
704 base::StringValue* ModelTypeToValue(ModelType model_type) { | 619 base::StringValue* ModelTypeToValue(ModelType model_type) { |
705 if (model_type >= FIRST_REAL_MODEL_TYPE) { | 620 if (model_type >= FIRST_REAL_MODEL_TYPE) { |
706 return new base::StringValue(ModelTypeToString(model_type)); | 621 return new base::StringValue(ModelTypeToString(model_type)); |
707 } else if (model_type == TOP_LEVEL_FOLDER) { | 622 } else if (model_type == TOP_LEVEL_FOLDER) { |
708 return new base::StringValue("Top-level folder"); | 623 return new base::StringValue("Top-level folder"); |
709 } else if (model_type == UNSPECIFIED) { | 624 } else if (model_type == UNSPECIFIED) { |
(...skipping 12 matching lines...) Expand all Loading... | |
722 int result; | 637 int result; |
723 CHECK(value.GetAsInteger(&result)); | 638 CHECK(value.GetAsInteger(&result)); |
724 return ModelTypeFromInt(result); | 639 return ModelTypeFromInt(result); |
725 } else { | 640 } else { |
726 NOTREACHED() << "Unsupported value type: " << value.GetType(); | 641 NOTREACHED() << "Unsupported value type: " << value.GetType(); |
727 return UNSPECIFIED; | 642 return UNSPECIFIED; |
728 } | 643 } |
729 } | 644 } |
730 | 645 |
731 ModelType ModelTypeFromString(const std::string& model_type_string) { | 646 ModelType ModelTypeFromString(const std::string& model_type_string) { |
732 if (model_type_string == "Bookmarks") | 647 if (model_type_string != "Unspecified" && |
AKV
2015/10/27 10:01:33
early return pls
Deepak
2015/10/27 12:26:54
Done.
| |
733 return BOOKMARKS; | 648 model_type_string != "Top Level Folder") { |
734 else if (model_type_string == "Preferences") | 649 for (const ModelTypeToNotificationMap& entry : |
735 return PREFERENCES; | 650 kModelTypeToNotificationMap) { |
736 else if (model_type_string == "Passwords") | 651 if (entry.model_type_string == model_type_string) |
737 return PASSWORDS; | 652 return entry.model_type; |
738 else if (model_type_string == "Autofill") | 653 } |
739 return AUTOFILL; | 654 } |
740 else if (model_type_string == "Autofill Profiles") | 655 NOTREACHED() << "No known model type corresponding to " << model_type_string |
741 return AUTOFILL_PROFILE; | 656 << "."; |
742 else if (model_type_string == "Autofill Wallet") | |
743 return AUTOFILL_WALLET_DATA; | |
744 else if (model_type_string == "Autofill Wallet Metadata") | |
745 return AUTOFILL_WALLET_METADATA; | |
746 else if (model_type_string == "Themes") | |
747 return THEMES; | |
748 else if (model_type_string == "Typed URLs") | |
749 return TYPED_URLS; | |
750 else if (model_type_string == "Extensions") | |
751 return EXTENSIONS; | |
752 else if (model_type_string == "Encryption keys") | |
753 return NIGORI; | |
754 else if (model_type_string == "Search Engines") | |
755 return SEARCH_ENGINES; | |
756 else if (model_type_string == "Sessions") | |
757 return SESSIONS; | |
758 else if (model_type_string == "Apps") | |
759 return APPS; | |
760 else if (model_type_string == "App List") | |
761 return APP_LIST; | |
762 else if (model_type_string == "App settings") | |
763 return APP_SETTINGS; | |
764 else if (model_type_string == "Extension settings") | |
765 return EXTENSION_SETTINGS; | |
766 else if (model_type_string == "App Notifications") | |
767 return APP_NOTIFICATIONS; | |
768 else if (model_type_string == "History Delete Directives") | |
769 return HISTORY_DELETE_DIRECTIVES; | |
770 else if (model_type_string == "Synced Notifications") | |
771 return SYNCED_NOTIFICATIONS; | |
772 else if (model_type_string == "Synced Notification App Info") | |
773 return SYNCED_NOTIFICATION_APP_INFO; | |
774 else if (model_type_string == "Device Info") | |
775 return DEVICE_INFO; | |
776 else if (model_type_string == "Experiments") | |
777 return EXPERIMENTS; | |
778 else if (model_type_string == "Priority Preferences") | |
779 return PRIORITY_PREFERENCES; | |
780 else if (model_type_string == "Dictionary") | |
781 return DICTIONARY; | |
782 else if (model_type_string == "Favicon Images") | |
783 return FAVICON_IMAGES; | |
784 else if (model_type_string == "Favicon Tracking") | |
785 return FAVICON_TRACKING; | |
786 else if (model_type_string == "Managed User Settings") | |
787 return SUPERVISED_USER_SETTINGS; | |
788 else if (model_type_string == "Managed Users") | |
789 return SUPERVISED_USERS; | |
790 else if (model_type_string == "Managed User Shared Settings") | |
791 return SUPERVISED_USER_SHARED_SETTINGS; | |
792 else if (model_type_string == "Managed User Whitelists") | |
793 return SUPERVISED_USER_WHITELISTS; | |
794 else if (model_type_string == "Articles") | |
795 return ARTICLES; | |
796 else if (model_type_string == "WiFi Credentials") | |
797 return WIFI_CREDENTIALS; | |
798 else if (model_type_string == "Tabs") | |
799 return PROXY_TABS; | |
800 else | |
801 NOTREACHED() << "No known model type corresponding to " | |
802 << model_type_string << "."; | |
803 return UNSPECIFIED; | 657 return UNSPECIFIED; |
804 } | 658 } |
805 | 659 |
806 std::string ModelTypeSetToString(ModelTypeSet model_types) { | 660 std::string ModelTypeSetToString(ModelTypeSet model_types) { |
807 std::string result; | 661 std::string result; |
808 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { | 662 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { |
809 if (!result.empty()) { | 663 if (!result.empty()) { |
810 result += ", "; | 664 result += ", "; |
811 } | 665 } |
812 result += ModelTypeToString(it.Get()); | 666 result += ModelTypeToString(it.Get()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
853 result.Put(ModelTypeFromValue(**i)); | 707 result.Put(ModelTypeFromValue(**i)); |
854 } | 708 } |
855 return result; | 709 return result; |
856 } | 710 } |
857 | 711 |
858 // TODO(zea): remove all hardcoded tags in model associators and have them use | 712 // TODO(zea): remove all hardcoded tags in model associators and have them use |
859 // this instead. | 713 // this instead. |
860 // NOTE: Proxy types should return empty strings (so that we don't NOTREACHED | 714 // NOTE: Proxy types should return empty strings (so that we don't NOTREACHED |
861 // in tests when we verify they have no root node). | 715 // in tests when we verify they have no root node). |
862 std::string ModelTypeToRootTag(ModelType type) { | 716 std::string ModelTypeToRootTag(ModelType type) { |
863 switch (type) { | 717 if (type == PROXY_TABS) |
864 case BOOKMARKS: | 718 return std::string(); |
865 return "google_chrome_bookmarks"; | 719 if (type != UNSPECIFIED && type != TOP_LEVEL_FOLDER) { |
AKV
2015/10/27 10:01:32
early return pls.
Deepak
2015/10/27 12:26:54
Done.
| |
866 case PREFERENCES: | 720 for (const ModelTypeToNotificationMap& entry : |
867 return "google_chrome_preferences"; | 721 kModelTypeToNotificationMap) { |
868 case PASSWORDS: | 722 if (entry.model_type == type) |
869 return "google_chrome_passwords"; | 723 return "google_chrome_" + std::string(entry.root_tag); |
870 case AUTOFILL: | 724 } |
871 return "google_chrome_autofill"; | |
872 case THEMES: | |
873 return "google_chrome_themes"; | |
874 case TYPED_URLS: | |
875 return "google_chrome_typed_urls"; | |
876 case EXTENSIONS: | |
877 return "google_chrome_extensions"; | |
878 case NIGORI: | |
879 return "google_chrome_nigori"; | |
880 case SEARCH_ENGINES: | |
881 return "google_chrome_search_engines"; | |
882 case SESSIONS: | |
883 return "google_chrome_sessions"; | |
884 case APPS: | |
885 return "google_chrome_apps"; | |
886 case APP_LIST: | |
887 return "google_chrome_app_list"; | |
888 case AUTOFILL_PROFILE: | |
889 return "google_chrome_autofill_profiles"; | |
890 case AUTOFILL_WALLET_DATA: | |
891 return "google_chrome_autofill_wallet"; | |
892 case AUTOFILL_WALLET_METADATA: | |
893 return "google_chrome_autofill_wallet_metadata"; | |
894 case APP_SETTINGS: | |
895 return "google_chrome_app_settings"; | |
896 case EXTENSION_SETTINGS: | |
897 return "google_chrome_extension_settings"; | |
898 case APP_NOTIFICATIONS: | |
899 return "google_chrome_app_notifications"; | |
900 case HISTORY_DELETE_DIRECTIVES: | |
901 return "google_chrome_history_delete_directives"; | |
902 case SYNCED_NOTIFICATIONS: | |
903 return "google_chrome_synced_notifications"; | |
904 case SYNCED_NOTIFICATION_APP_INFO: | |
905 return "google_chrome_synced_notification_app_info"; | |
906 case DEVICE_INFO: | |
907 return "google_chrome_device_info"; | |
908 case EXPERIMENTS: | |
909 return "google_chrome_experiments"; | |
910 case PRIORITY_PREFERENCES: | |
911 return "google_chrome_priority_preferences"; | |
912 case DICTIONARY: | |
913 return "google_chrome_dictionary"; | |
914 case FAVICON_IMAGES: | |
915 return "google_chrome_favicon_images"; | |
916 case FAVICON_TRACKING: | |
917 return "google_chrome_favicon_tracking"; | |
918 case SUPERVISED_USER_SETTINGS: | |
919 return "google_chrome_managed_user_settings"; | |
920 case SUPERVISED_USERS: | |
921 return "google_chrome_managed_users"; | |
922 case SUPERVISED_USER_SHARED_SETTINGS: | |
923 return "google_chrome_managed_user_shared_settings"; | |
924 case SUPERVISED_USER_WHITELISTS: | |
925 return "google_chrome_managed_user_whitelists"; | |
926 case ARTICLES: | |
927 return "google_chrome_articles"; | |
928 case WIFI_CREDENTIALS: | |
929 return "google_chrome_wifi_credentials"; | |
930 case PROXY_TABS: | |
931 return std::string(); | |
932 default: | |
933 break; | |
934 } | 725 } |
935 NOTREACHED() << "No known extension for model type."; | 726 NOTREACHED() << "No known extension for model type."; |
936 return "INVALID"; | 727 return "INVALID"; |
937 } | 728 } |
938 | 729 |
939 // TODO(akalin): Figure out a better way to do these mappings. | |
940 // Note: Do not include proxy types in this list. They should never receive | |
941 // or trigger notifications. | |
942 namespace { | |
943 const char kBookmarkNotificationType[] = "BOOKMARK"; | |
944 const char kPreferenceNotificationType[] = "PREFERENCE"; | |
945 const char kPasswordNotificationType[] = "PASSWORD"; | |
946 const char kAutofillNotificationType[] = "AUTOFILL"; | |
947 const char kThemeNotificationType[] = "THEME"; | |
948 const char kTypedUrlNotificationType[] = "TYPED_URL"; | |
949 const char kExtensionNotificationType[] = "EXTENSION"; | |
950 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; | |
951 const char kNigoriNotificationType[] = "NIGORI"; | |
952 const char kAppSettingNotificationType[] = "APP_SETTING"; | |
953 const char kAppNotificationType[] = "APP"; | |
954 const char kAppListNotificationType[] = "APP_LIST"; | |
955 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; | |
956 const char kSessionNotificationType[] = "SESSION"; | |
957 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; | |
958 const char kAutofillWalletMetadataNotificationType[] = | |
959 "AUTOFILL_WALLET_METADATA"; | |
960 const char kAutofillWalletNotificationType[] = "AUTOFILL_WALLET"; | |
961 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; | |
962 const char kHistoryDeleteDirectiveNotificationType[] = | |
963 "HISTORY_DELETE_DIRECTIVE"; | |
964 const char kSyncedNotificationType[] = "SYNCED_NOTIFICATION"; | |
965 const char kSyncedNotificationAppInfoType[] = "SYNCED_NOTIFICATION_APP_INFO"; | |
966 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; | |
967 const char kExperimentsNotificationType[] = "EXPERIMENTS"; | |
968 const char kPriorityPreferenceNotificationType[] = "PRIORITY_PREFERENCE"; | |
969 const char kDictionaryNotificationType[] = "DICTIONARY"; | |
970 const char kFaviconImageNotificationType[] = "FAVICON_IMAGE"; | |
971 const char kFaviconTrackingNotificationType[] = "FAVICON_TRACKING"; | |
972 const char kSupervisedUserSettingNotificationType[] = "MANAGED_USER_SETTING"; | |
973 const char kSupervisedUserNotificationType[] = "MANAGED_USER"; | |
974 const char kSupervisedUserSharedSettingNotificationType[] = | |
975 "MANAGED_USER_SHARED_SETTING"; | |
976 const char kSupervisedUserWhitelistNotificationType[] = | |
977 "MANAGED_USER_WHITELIST"; | |
978 const char kArticleNotificationType[] = "ARTICLE"; | |
979 const char kWifiCredentialNotificationType[] = "WIFI_CREDENTIAL"; | |
980 } // namespace | |
981 | |
982 bool RealModelTypeToNotificationType(ModelType model_type, | 730 bool RealModelTypeToNotificationType(ModelType model_type, |
983 std::string* notification_type) { | 731 std::string* notification_type) { |
984 switch (model_type) { | 732 if (model_type != UNSPECIFIED && model_type != TOP_LEVEL_FOLDER && |
AKV
2015/10/27 10:01:33
early return pls
Deepak
2015/10/27 12:26:54
Done.
| |
985 case BOOKMARKS: | 733 model_type != PROXY_TABS) { |
986 *notification_type = kBookmarkNotificationType; | 734 for (const ModelTypeToNotificationMap& entry : |
987 return true; | 735 kModelTypeToNotificationMap) { |
988 case PREFERENCES: | 736 if (entry.model_type == model_type) { |
989 *notification_type = kPreferenceNotificationType; | 737 *notification_type = entry.notification_type; |
990 return true; | 738 return true; |
991 case PASSWORDS: | 739 } |
992 *notification_type = kPasswordNotificationType; | 740 } |
993 return true; | |
994 case AUTOFILL: | |
995 *notification_type = kAutofillNotificationType; | |
996 return true; | |
997 case THEMES: | |
998 *notification_type = kThemeNotificationType; | |
999 return true; | |
1000 case TYPED_URLS: | |
1001 *notification_type = kTypedUrlNotificationType; | |
1002 return true; | |
1003 case EXTENSIONS: | |
1004 *notification_type = kExtensionNotificationType; | |
1005 return true; | |
1006 case NIGORI: | |
1007 *notification_type = kNigoriNotificationType; | |
1008 return true; | |
1009 case APP_SETTINGS: | |
1010 *notification_type = kAppSettingNotificationType; | |
1011 return true; | |
1012 case APPS: | |
1013 *notification_type = kAppNotificationType; | |
1014 return true; | |
1015 case APP_LIST: | |
1016 *notification_type = kAppListNotificationType; | |
1017 return true; | |
1018 case SEARCH_ENGINES: | |
1019 *notification_type = kSearchEngineNotificationType; | |
1020 return true; | |
1021 case SESSIONS: | |
1022 *notification_type = kSessionNotificationType; | |
1023 return true; | |
1024 case AUTOFILL_PROFILE: | |
1025 *notification_type = kAutofillProfileNotificationType; | |
1026 return true; | |
1027 case AUTOFILL_WALLET_DATA: | |
1028 *notification_type = kAutofillWalletNotificationType; | |
1029 return true; | |
1030 case AUTOFILL_WALLET_METADATA: | |
1031 *notification_type = kAutofillWalletMetadataNotificationType; | |
1032 return true; | |
1033 case EXTENSION_SETTINGS: | |
1034 *notification_type = kExtensionSettingNotificationType; | |
1035 return true; | |
1036 case APP_NOTIFICATIONS: | |
1037 *notification_type = kAppNotificationNotificationType; | |
1038 return true; | |
1039 case HISTORY_DELETE_DIRECTIVES: | |
1040 *notification_type = kHistoryDeleteDirectiveNotificationType; | |
1041 return true; | |
1042 case SYNCED_NOTIFICATIONS: | |
1043 *notification_type = kSyncedNotificationType; | |
1044 return true; | |
1045 case SYNCED_NOTIFICATION_APP_INFO: | |
1046 *notification_type = kSyncedNotificationAppInfoType; | |
1047 return true; | |
1048 case DEVICE_INFO: | |
1049 *notification_type = kDeviceInfoNotificationType; | |
1050 return true; | |
1051 case EXPERIMENTS: | |
1052 *notification_type = kExperimentsNotificationType; | |
1053 return true; | |
1054 case PRIORITY_PREFERENCES: | |
1055 *notification_type = kPriorityPreferenceNotificationType; | |
1056 return true; | |
1057 case DICTIONARY: | |
1058 *notification_type = kDictionaryNotificationType; | |
1059 return true; | |
1060 case FAVICON_IMAGES: | |
1061 *notification_type = kFaviconImageNotificationType; | |
1062 return true; | |
1063 case FAVICON_TRACKING: | |
1064 *notification_type = kFaviconTrackingNotificationType; | |
1065 return true; | |
1066 case SUPERVISED_USER_SETTINGS: | |
1067 *notification_type = kSupervisedUserSettingNotificationType; | |
1068 return true; | |
1069 case SUPERVISED_USERS: | |
1070 *notification_type = kSupervisedUserNotificationType; | |
1071 return true; | |
1072 case SUPERVISED_USER_SHARED_SETTINGS: | |
1073 *notification_type = kSupervisedUserSharedSettingNotificationType; | |
1074 return true; | |
1075 case SUPERVISED_USER_WHITELISTS: | |
1076 *notification_type = kSupervisedUserWhitelistNotificationType; | |
1077 return true; | |
1078 case ARTICLES: | |
1079 *notification_type = kArticleNotificationType; | |
1080 return true; | |
1081 case WIFI_CREDENTIALS: | |
1082 *notification_type = kWifiCredentialNotificationType; | |
1083 return true; | |
1084 default: | |
1085 break; | |
1086 } | 741 } |
1087 notification_type->clear(); | 742 notification_type->clear(); |
1088 return false; | 743 return false; |
1089 } | 744 } |
1090 | 745 |
1091 bool NotificationTypeToRealModelType(const std::string& notification_type, | 746 bool NotificationTypeToRealModelType(const std::string& notification_type, |
1092 ModelType* model_type) { | 747 ModelType* model_type) { |
1093 if (notification_type == kBookmarkNotificationType) { | 748 if (notification_type != std::string()) { |
AKV
2015/10/27 10:01:33
Early return
if (notification_type.empty()) {
*m
Deepak
2015/10/27 12:26:54
Done.
| |
1094 *model_type = BOOKMARKS; | 749 for (const ModelTypeToNotificationMap& entry : |
1095 return true; | 750 kModelTypeToNotificationMap) { |
1096 } else if (notification_type == kPreferenceNotificationType) { | 751 if (entry.notification_type == notification_type) { |
1097 *model_type = PREFERENCES; | 752 *model_type = entry.model_type; |
1098 return true; | 753 return true; |
1099 } else if (notification_type == kPasswordNotificationType) { | 754 } |
1100 *model_type = PASSWORDS; | 755 } |
1101 return true; | |
1102 } else if (notification_type == kAutofillNotificationType) { | |
1103 *model_type = AUTOFILL; | |
1104 return true; | |
1105 } else if (notification_type == kThemeNotificationType) { | |
1106 *model_type = THEMES; | |
1107 return true; | |
1108 } else if (notification_type == kTypedUrlNotificationType) { | |
1109 *model_type = TYPED_URLS; | |
1110 return true; | |
1111 } else if (notification_type == kExtensionNotificationType) { | |
1112 *model_type = EXTENSIONS; | |
1113 return true; | |
1114 } else if (notification_type == kNigoriNotificationType) { | |
1115 *model_type = NIGORI; | |
1116 return true; | |
1117 } else if (notification_type == kAppNotificationType) { | |
1118 *model_type = APPS; | |
1119 return true; | |
1120 } else if (notification_type == kAppListNotificationType) { | |
1121 *model_type = APP_LIST; | |
1122 return true; | |
1123 } else if (notification_type == kSearchEngineNotificationType) { | |
1124 *model_type = SEARCH_ENGINES; | |
1125 return true; | |
1126 } else if (notification_type == kSessionNotificationType) { | |
1127 *model_type = SESSIONS; | |
1128 return true; | |
1129 } else if (notification_type == kAutofillProfileNotificationType) { | |
1130 *model_type = AUTOFILL_PROFILE; | |
1131 return true; | |
1132 } else if (notification_type == kAutofillWalletNotificationType) { | |
1133 *model_type = AUTOFILL_WALLET_DATA; | |
1134 return true; | |
1135 } else if (notification_type == kAutofillWalletMetadataNotificationType) { | |
1136 *model_type = AUTOFILL_WALLET_METADATA; | |
1137 return true; | |
1138 } else if (notification_type == kAppSettingNotificationType) { | |
1139 *model_type = APP_SETTINGS; | |
1140 return true; | |
1141 } else if (notification_type == kExtensionSettingNotificationType) { | |
1142 *model_type = EXTENSION_SETTINGS; | |
1143 return true; | |
1144 } else if (notification_type == kAppNotificationNotificationType) { | |
1145 *model_type = APP_NOTIFICATIONS; | |
1146 return true; | |
1147 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) { | |
1148 *model_type = HISTORY_DELETE_DIRECTIVES; | |
1149 return true; | |
1150 } else if (notification_type == kSyncedNotificationType) { | |
1151 *model_type = SYNCED_NOTIFICATIONS; | |
1152 return true; | |
1153 } else if (notification_type == kSyncedNotificationAppInfoType) { | |
1154 *model_type = SYNCED_NOTIFICATION_APP_INFO; | |
1155 return true; | |
1156 } else if (notification_type == kDeviceInfoNotificationType) { | |
1157 *model_type = DEVICE_INFO; | |
1158 return true; | |
1159 } else if (notification_type == kExperimentsNotificationType) { | |
1160 *model_type = EXPERIMENTS; | |
1161 return true; | |
1162 } else if (notification_type == kPriorityPreferenceNotificationType) { | |
1163 *model_type = PRIORITY_PREFERENCES; | |
1164 return true; | |
1165 } else if (notification_type == kDictionaryNotificationType) { | |
1166 *model_type = DICTIONARY; | |
1167 return true; | |
1168 } else if (notification_type == kFaviconImageNotificationType) { | |
1169 *model_type = FAVICON_IMAGES; | |
1170 return true; | |
1171 } else if (notification_type == kFaviconTrackingNotificationType) { | |
1172 *model_type = FAVICON_TRACKING; | |
1173 return true; | |
1174 } else if (notification_type == kSupervisedUserSettingNotificationType) { | |
1175 *model_type = SUPERVISED_USER_SETTINGS; | |
1176 return true; | |
1177 } else if (notification_type == kSupervisedUserNotificationType) { | |
1178 *model_type = SUPERVISED_USERS; | |
1179 return true; | |
1180 } else if (notification_type == | |
1181 kSupervisedUserSharedSettingNotificationType) { | |
1182 *model_type = SUPERVISED_USER_SHARED_SETTINGS; | |
1183 return true; | |
1184 } else if (notification_type == kSupervisedUserWhitelistNotificationType) { | |
1185 *model_type = SUPERVISED_USER_WHITELISTS; | |
1186 return true; | |
1187 } else if (notification_type == kArticleNotificationType) { | |
1188 *model_type = ARTICLES; | |
1189 return true; | |
1190 } else if (notification_type == kWifiCredentialNotificationType) { | |
1191 *model_type = WIFI_CREDENTIALS; | |
1192 return true; | |
1193 } | 756 } |
1194 *model_type = UNSPECIFIED; | 757 *model_type = UNSPECIFIED; |
1195 return false; | 758 return false; |
1196 } | 759 } |
1197 | 760 |
1198 bool IsRealDataType(ModelType model_type) { | 761 bool IsRealDataType(ModelType model_type) { |
1199 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; | 762 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; |
1200 } | 763 } |
1201 | 764 |
1202 bool IsProxyType(ModelType model_type) { | 765 bool IsProxyType(ModelType model_type) { |
(...skipping 16 matching lines...) Expand all Loading... | |
1219 bool TypeSupportsHierarchy(ModelType model_type) { | 782 bool TypeSupportsHierarchy(ModelType model_type) { |
1220 // TODO(stanisc): crbug/438313: Should this also include TOP_LEVEL_FOLDER? | 783 // TODO(stanisc): crbug/438313: Should this also include TOP_LEVEL_FOLDER? |
1221 return model_type == BOOKMARKS; | 784 return model_type == BOOKMARKS; |
1222 } | 785 } |
1223 | 786 |
1224 bool TypeSupportsOrdering(ModelType model_type) { | 787 bool TypeSupportsOrdering(ModelType model_type) { |
1225 return model_type == BOOKMARKS; | 788 return model_type == BOOKMARKS; |
1226 } | 789 } |
1227 | 790 |
1228 } // namespace syncer | 791 } // namespace syncer |
OLD | NEW |