Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(534)

Side by Side Diff: sync/syncable/model_type.cc

Issue 1413233003: Organizing model type, notification type, root tag and model type string in map. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 ModelTypeInfo {
29 const ModelType model_type;
30 const char* const notification_type; // Model Type notification string.
31 const char* const root_tag; // Root tag for Model Type
32 const char* const model_type_string; // String value for Model Type
33 // Histogram value should be unique for the Model Type, Also none
34 // of these values should ever be modified, without updating "SyncModelTypes"
Nicolas Zea 2015/10/29 22:50:43 To be clear, existing histogram values should neve
Deepak 2015/10/30 05:27:34 I have updated this, Is it fine now !.
35 // enum in histograms.xml.
36 const int model_type_histogram_val;
37 };
38
39 const ModelTypeInfo kModelTypeInfoMap[] = {
Nicolas Zea 2015/10/29 22:50:43 Add a comment explaining that these must match the
Deepak 2015/10/30 05:27:34 Done.
40 {UNSPECIFIED, "", "", "Unspecified", 0},
41 {TOP_LEVEL_FOLDER, "", "", "Top Level Folder", 1},
42 {BOOKMARKS, "BOOKMARK", "bookmarks", "Bookmarks", 2},
43 {PREFERENCES, "PREFERENCE", "preferences", "Preferences", 3},
44 {PASSWORDS, "PASSWORD", "passwords", "Passwords", 4},
45 {AUTOFILL_PROFILE, "AUTOFILL_PROFILE", "autofill_profiles",
46 "Autofill Profiles", 5},
47 {AUTOFILL, "AUTOFILL", "autofill", "Autofill", 6},
48 {AUTOFILL_WALLET_DATA, "AUTOFILL_WALLET", "autofill_wallet",
49 "Autofill Wallet", 34},
50 {AUTOFILL_WALLET_METADATA, "AUTOFILL_WALLET_METADATA",
51 "autofill_wallet_metadata", "Autofill Wallet Metadata", 35},
52 {THEMES, "THEME", "themes", "Themes", 7},
53 {TYPED_URLS, "TYPED_URL", "typed_urls", "Typed URLs", 8},
54 {EXTENSIONS, "EXTENSION", "extensions", "Extensions", 9},
55 {SEARCH_ENGINES, "SEARCH_ENGINE", "search_engines", "Search Engines", 10},
56 {SESSIONS, "SESSION", "sessions", "Sessions", 11},
57 {APPS, "APP", "apps", "Apps", 12},
58 {APP_SETTINGS, "APP_SETTING", "app_settings", "App settings", 13},
59 {EXTENSION_SETTINGS, "EXTENSION_SETTING", "extension_settings",
60 "Extension settings", 14},
61 {APP_NOTIFICATIONS, "APP_NOTIFICATION", "app_notifications",
62 "App Notifications", 15},
63 {HISTORY_DELETE_DIRECTIVES, "HISTORY_DELETE_DIRECTIVE",
64 "history_delete_directives", "History Delete Directives", 16},
65 {SYNCED_NOTIFICATIONS, "SYNCED_NOTIFICATION", "synced_notifications",
66 "Synced Notifications", 20},
67 {SYNCED_NOTIFICATION_APP_INFO, "SYNCED_NOTIFICATION_APP_INFO",
68 "synced_notification_app_info", "Synced Notification App Info", 31},
69 {DICTIONARY, "DICTIONARY", "dictionary", "Dictionary", 22},
70 {FAVICON_IMAGES, "FAVICON_IMAGE", "favicon_images", "Favicon Images", 23},
71 {FAVICON_TRACKING, "FAVICON_TRACKING", "favicon_tracking",
72 "Favicon Tracking", 24},
73 {DEVICE_INFO, "DEVICE_INFO", "device_info", "Device Info", 18},
74 {PRIORITY_PREFERENCES, "PRIORITY_PREFERENCE", "priority_preferences",
75 "Priority Preferences", 21},
76 {SUPERVISED_USER_SETTINGS, "MANAGED_USER_SETTING", "managed_user_settings",
77 "Managed User Settings", 26},
78 {SUPERVISED_USERS, "MANAGED_USER", "managed_users", "Managed Users", 27},
79 {SUPERVISED_USER_SHARED_SETTINGS, "MANAGED_USER_SHARED_SETTING",
80 "managed_user_shared_settings", "Managed User Shared Settings", 30},
81 {ARTICLES, "ARTICLE", "articles", "Articles", 28},
82 {APP_LIST, "APP_LIST", "app_list", "App List", 29},
83 {WIFI_CREDENTIALS, "WIFI_CREDENTIAL", "wifi_credentials",
84 "WiFi Credentials", 32},
85 {SUPERVISED_USER_WHITELISTS, "MANAGED_USER_WHITELIST",
86 "managed_user_whitelists", "Managed User Whitelists", 33},
87 {PROXY_TABS, "", "", "Tabs", 25},
88 {NIGORI, "NIGORI", "nigori", "Encryption keys", 17},
89 {EXPERIMENTS, "EXPERIMENTS", "experiments", "Experiments", 19},
90 };
91 static_assert(arraysize(kModelTypeInfoMap) == MODEL_TYPE_COUNT,
92 "kModelTypeInfoMap should have MODEL_TYPE_COUNT elements");
93
28 // Notes: 94 // Notes:
29 // 1) This list must contain exactly the same elements as the set returned by 95 // 1) This list must contain exactly the same elements as the set returned by
30 // UserSelectableTypes(). 96 // UserSelectableTypes().
31 // 2) This list must be in the same order as the respective values in the 97 // 2) This list must be in the same order as the respective values in the
32 // ModelType enum. 98 // ModelType enum.
33 const char* kUserSelectableDataTypeNames[] = { 99 const char* kUserSelectableDataTypeNames[] = {
34 "bookmarks", 100 "bookmarks",
35 "preferences", 101 "preferences",
36 "passwords", 102 "passwords",
37 "autofill", 103 "autofill",
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { 227 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) {
162 ModelTypeSet protocol_types = ProtocolTypes(); 228 ModelTypeSet protocol_types = ProtocolTypes();
163 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); 229 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good();
164 iter.Inc()) { 230 iter.Inc()) {
165 if (GetSpecificsFieldNumberFromModelType(iter.Get()) == field_number) 231 if (GetSpecificsFieldNumberFromModelType(iter.Get()) == field_number)
166 return iter.Get(); 232 return iter.Get();
167 } 233 }
168 return UNSPECIFIED; 234 return UNSPECIFIED;
169 } 235 }
170 236
171 int GetSpecificsFieldNumberFromModelType(ModelType model_type) { 237 int GetSpecificsFieldNumberFromModelType(ModelType model_type) {
Nicolas Zea 2015/10/29 22:50:43 Could these field numbers also be part of the stru
Deepak 2015/10/30 05:27:34 Changes done, Have to check "ProtocolTypes().Has(m
172 DCHECK(ProtocolTypes().Has(model_type)) 238 DCHECK(ProtocolTypes().Has(model_type))
173 << "Only protocol types have field values."; 239 << "Only protocol types have field values.";
174 switch (model_type) { 240 switch (model_type) {
175 case BOOKMARKS: 241 case BOOKMARKS:
176 return sync_pb::EntitySpecifics::kBookmarkFieldNumber; 242 return sync_pb::EntitySpecifics::kBookmarkFieldNumber;
177 case PASSWORDS: 243 case PASSWORDS:
178 return sync_pb::EntitySpecifics::kPasswordFieldNumber; 244 return sync_pb::EntitySpecifics::kPasswordFieldNumber;
179 case PREFERENCES: 245 case PREFERENCES:
180 return sync_pb::EntitySpecifics::kPreferenceFieldNumber; 246 return sync_pb::EntitySpecifics::kPreferenceFieldNumber;
181 case AUTOFILL: 247 case AUTOFILL:
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 result.Put(APP_SETTINGS); 593 result.Put(APP_SETTINGS);
528 result.Put(EXTENSION_SETTINGS); 594 result.Put(EXTENSION_SETTINGS);
529 result.Put(PRIORITY_PREFERENCES); 595 result.Put(PRIORITY_PREFERENCES);
530 return result; 596 return result;
531 } 597 }
532 598
533 const char* ModelTypeToString(ModelType model_type) { 599 const char* ModelTypeToString(ModelType model_type) {
534 // This is used in serialization routines as well as for displaying debug 600 // 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 601 // information. Do not attempt to change these string values unless you know
536 // what you're doing. 602 // what you're doing.
537 switch (model_type) { 603 if (model_type >= UNSPECIFIED && model_type < MODEL_TYPE_COUNT)
538 case TOP_LEVEL_FOLDER: 604 return kModelTypeInfoMap[model_type].model_type_string;
539 return "Top Level Folder";
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 }
613 NOTREACHED() << "No known extension for model type."; 605 NOTREACHED() << "No known extension for model type.";
614 return "INVALID"; 606 return "INVALID";
615 } 607 }
616 608
617 // The normal rules about histograms apply here. Always append to the bottom of 609 // 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 610 // the list, and be careful to not reuse integer values that have already been
619 // assigned. 611 // assigned.
620 // 612 //
621 // Don't forget to update the "SyncModelTypes" enum in histograms.xml when you 613 // Don't forget to update the "SyncModelTypes" enum in histograms.xml when you
622 // make changes to this list. 614 // make changes to this list.
623 int ModelTypeToHistogramInt(ModelType model_type) { 615 int ModelTypeToHistogramInt(ModelType model_type) {
624 switch (model_type) { 616 if (model_type >= UNSPECIFIED && model_type < MODEL_TYPE_COUNT)
625 case UNSPECIFIED: 617 return kModelTypeInfoMap[model_type].model_type_histogram_val;
626 return 0;
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 }
701 return 0; 618 return 0;
702 } 619 }
703 620
704 base::StringValue* ModelTypeToValue(ModelType model_type) { 621 base::StringValue* ModelTypeToValue(ModelType model_type) {
705 if (model_type >= FIRST_REAL_MODEL_TYPE) { 622 if (model_type >= FIRST_REAL_MODEL_TYPE) {
706 return new base::StringValue(ModelTypeToString(model_type)); 623 return new base::StringValue(ModelTypeToString(model_type));
707 } else if (model_type == TOP_LEVEL_FOLDER) { 624 } else if (model_type == TOP_LEVEL_FOLDER) {
708 return new base::StringValue("Top-level folder"); 625 return new base::StringValue("Top-level folder");
709 } else if (model_type == UNSPECIFIED) { 626 } else if (model_type == UNSPECIFIED) {
710 return new base::StringValue("Unspecified"); 627 return new base::StringValue("Unspecified");
(...skipping 11 matching lines...) Expand all
722 int result; 639 int result;
723 CHECK(value.GetAsInteger(&result)); 640 CHECK(value.GetAsInteger(&result));
724 return ModelTypeFromInt(result); 641 return ModelTypeFromInt(result);
725 } else { 642 } else {
726 NOTREACHED() << "Unsupported value type: " << value.GetType(); 643 NOTREACHED() << "Unsupported value type: " << value.GetType();
727 return UNSPECIFIED; 644 return UNSPECIFIED;
728 } 645 }
729 } 646 }
730 647
731 ModelType ModelTypeFromString(const std::string& model_type_string) { 648 ModelType ModelTypeFromString(const std::string& model_type_string) {
732 if (model_type_string == "Bookmarks") 649 if (model_type_string != "Unspecified" &&
733 return BOOKMARKS; 650 model_type_string != "Top Level Folder") {
734 else if (model_type_string == "Preferences") 651 for (size_t i = 0; i < arraysize(kModelTypeInfoMap); ++i) {
735 return PREFERENCES; 652 if (kModelTypeInfoMap[i].model_type_string == model_type_string)
736 else if (model_type_string == "Passwords") 653 return kModelTypeInfoMap[i].model_type;
737 return PASSWORDS; 654 }
738 else if (model_type_string == "Autofill") 655 }
739 return AUTOFILL; 656 NOTREACHED() << "No known model type corresponding to " << model_type_string
740 else if (model_type_string == "Autofill Profiles") 657 << ".";
741 return AUTOFILL_PROFILE;
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; 658 return UNSPECIFIED;
804 } 659 }
805 660
806 std::string ModelTypeSetToString(ModelTypeSet model_types) { 661 std::string ModelTypeSetToString(ModelTypeSet model_types) {
807 std::string result; 662 std::string result;
808 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { 663 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) {
809 if (!result.empty()) { 664 if (!result.empty()) {
810 result += ", "; 665 result += ", ";
811 } 666 }
812 result += ModelTypeToString(it.Get()); 667 result += ModelTypeToString(it.Get());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 result.Put(ModelTypeFromValue(**i)); 708 result.Put(ModelTypeFromValue(**i));
854 } 709 }
855 return result; 710 return result;
856 } 711 }
857 712
858 // TODO(zea): remove all hardcoded tags in model associators and have them use 713 // TODO(zea): remove all hardcoded tags in model associators and have them use
859 // this instead. 714 // this instead.
860 // NOTE: Proxy types should return empty strings (so that we don't NOTREACHED 715 // NOTE: Proxy types should return empty strings (so that we don't NOTREACHED
861 // in tests when we verify they have no root node). 716 // in tests when we verify they have no root node).
862 std::string ModelTypeToRootTag(ModelType type) { 717 std::string ModelTypeToRootTag(ModelType type) {
863 switch (type) { 718 if (IsProxyType(type))
864 case BOOKMARKS: 719 return std::string();
865 return "google_chrome_bookmarks"; 720 if (IsRealDataType(type))
866 case PREFERENCES: 721 return "google_chrome_" + std::string(kModelTypeInfoMap[type].root_tag);
867 return "google_chrome_preferences";
868 case PASSWORDS:
869 return "google_chrome_passwords";
870 case AUTOFILL:
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 }
935 NOTREACHED() << "No known extension for model type."; 722 NOTREACHED() << "No known extension for model type.";
936 return "INVALID"; 723 return "INVALID";
937 } 724 }
938 725
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, 726 bool RealModelTypeToNotificationType(ModelType model_type,
983 std::string* notification_type) { 727 std::string* notification_type) {
984 switch (model_type) { 728 if (!ProtocolTypes().Has(model_type)) {
Nicolas Zea 2015/10/29 22:50:43 You can remove this condition right? And make the
Deepak 2015/10/30 05:27:34 Done.
985 case BOOKMARKS: 729 notification_type->clear();
986 *notification_type = kBookmarkNotificationType; 730 return false;
987 return true; 731 }
988 case PREFERENCES: 732 if (model_type >= BOOKMARKS && model_type < MODEL_TYPE_COUNT) {
989 *notification_type = kPreferenceNotificationType; 733 *notification_type = kModelTypeInfoMap[model_type].notification_type;
990 return true; 734 return true;
991 case PASSWORDS:
992 *notification_type = kPasswordNotificationType;
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 } 735 }
1087 notification_type->clear(); 736 notification_type->clear();
1088 return false; 737 return false;
1089 } 738 }
1090 739
1091 bool NotificationTypeToRealModelType(const std::string& notification_type, 740 bool NotificationTypeToRealModelType(const std::string& notification_type,
1092 ModelType* model_type) { 741 ModelType* model_type) {
1093 if (notification_type == kBookmarkNotificationType) { 742 if (notification_type.empty()) {
1094 *model_type = BOOKMARKS; 743 *model_type = UNSPECIFIED;
1095 return true; 744 return false;
1096 } else if (notification_type == kPreferenceNotificationType) { 745 }
1097 *model_type = PREFERENCES; 746 for (size_t i = 0; i < arraysize(kModelTypeInfoMap); ++i) {
1098 return true; 747 if (kModelTypeInfoMap[i].notification_type == notification_type) {
1099 } else if (notification_type == kPasswordNotificationType) { 748 *model_type = kModelTypeInfoMap[i].model_type;
1100 *model_type = PASSWORDS; 749 return true;
1101 return true; 750 }
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 } 751 }
1194 *model_type = UNSPECIFIED; 752 *model_type = UNSPECIFIED;
1195 return false; 753 return false;
1196 } 754 }
1197 755
1198 bool IsRealDataType(ModelType model_type) { 756 bool IsRealDataType(ModelType model_type) {
1199 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; 757 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT;
1200 } 758 }
1201 759
1202 bool IsProxyType(ModelType model_type) { 760 bool IsProxyType(ModelType model_type) {
(...skipping 16 matching lines...) Expand all
1219 bool TypeSupportsHierarchy(ModelType model_type) { 777 bool TypeSupportsHierarchy(ModelType model_type) {
1220 // TODO(stanisc): crbug/438313: Should this also include TOP_LEVEL_FOLDER? 778 // TODO(stanisc): crbug/438313: Should this also include TOP_LEVEL_FOLDER?
1221 return model_type == BOOKMARKS; 779 return model_type == BOOKMARKS;
1222 } 780 }
1223 781
1224 bool TypeSupportsOrdering(ModelType model_type) { 782 bool TypeSupportsOrdering(ModelType model_type) {
1225 return model_type == BOOKMARKS; 783 return model_type == BOOKMARKS;
1226 } 784 }
1227 785
1228 } // namespace syncer 786 } // namespace syncer
OLDNEW
« no previous file with comments | « no previous file | sync/syncable/model_type_unittest.cc » ('j') | sync/syncable/model_type_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698