Chromium Code Reviews| Index: sync/syncable/model_type.cc |
| diff --git a/sync/syncable/model_type.cc b/sync/syncable/model_type.cc |
| index 3ef7bac67f48b629cede84a5a5a86ed19dbaed00..a65fae93f87048c3b913dde583064a51304392a4 100644 |
| --- a/sync/syncable/model_type.cc |
| +++ b/sync/syncable/model_type.cc |
| @@ -25,6 +25,64 @@ |
| namespace syncer { |
| +struct ModelTypeToNotificationMap { |
| + ModelType model_type; |
| + const char* notification_type; |
| + const char* root_tag; |
| + const char* model_type_string; |
| + int model_type_histogram_val; |
| +}; |
| + |
| +ModelTypeToNotificationMap kModelTypeToNotificationMap[] = { |
| + {BOOKMARKS, "BOOKMARK", "bookmarks", "Bookmarks", 2}, |
|
AKV
2015/10/26 10:32:00
Why 0 and 1 for model_type_histogram_val, UNSPECIF
Deepak
2015/10/26 12:04:46
Done.
|
| + {PREFERENCES, "PREFERENCE", "preferences", "Preferences", 3}, |
| + {PASSWORDS, "PASSWORD", "passwords", "Passwords", 4}, |
| + {AUTOFILL_PROFILE, "AUTOFILL_PROFILE", "autofill_profiles", |
| + "Autofill Profiles", 5}, |
| + {AUTOFILL, "AUTOFILL", "autofill", "Autofill", 6}, |
| + {THEMES, "THEME", "themes", "Themes", 7}, |
| + {TYPED_URLS, "TYPED_URL", "typed_urls", "Typed URLs", 8}, |
| + {EXTENSIONS, "EXTENSION", "extensions", "Extensions", 9}, |
| + {SEARCH_ENGINES, "SEARCH_ENGINE", "search_engines", "Search Engines", 10}, |
| + {SESSIONS, "SESSION", "sessions", "Sessions", 11}, |
| + {APPS, "APPs", "apps", "Apps", 12}, |
| + {APP_SETTINGS, "APP_SETTING", "app_settings", "App settings", 13}, |
| + {EXTENSION_SETTINGS, "EXTENSION_SETTING", "extension_settings", |
| + "Extension settings", 14}, |
| + {APP_NOTIFICATIONS, "APP_NOTIFICATION", "app_notifications", |
| + "App Notifications", 15}, |
| + {HISTORY_DELETE_DIRECTIVES, "HISTORY_DELETE_DIRECTIVE", |
| + "history_delete_directives", "History Delete Directives", 16}, |
| + {NIGORI, "NIGORI", "nigori", "Encryption keys", 17}, |
| + {DEVICE_INFO, "DEVICE_INFO", "device_info", "Device Info", 18}, |
| + {EXPERIMENTS, "EXPERIMENTS", "experiments", "Experiments", 19}, |
| + {SYNCED_NOTIFICATIONS, "SYNCED_NOTIFICATION", "synced_notifications", |
| + "Synced Notifications", 20}, |
| + {PRIORITY_PREFERENCES, "PRIORITY_PREFERENCE", "priority_preferences", |
| + "Priority Preferences", 21}, |
| + {DICTIONARY, "DICTIONARY", "dictionary", "Dictionary", 22}, |
| + {FAVICON_IMAGES, "FAVICON_IMAGE", "favicon_images", "Favicon Images", 23}, |
| + {FAVICON_TRACKING, "FAVICON_TRACKING", "favicon_tracking", |
| + "Favicon Tracking", 24}, |
| + {PROXY_TABS, "", "", "Tabs", 25}, |
| + {SUPERVISED_USER_SETTINGS, "MANAGED_USER_SETTING", "managed_user_settings", |
| + "Managed User Settings", 26}, |
| + {SUPERVISED_USERS, "MANAGED_USER", "managed_users", "Managed Users", 27}, |
| + {ARTICLES, "ARTICLE", "articles", "Articles", 28}, |
| + {APP_LIST, "APP_LIST", "app_list", "App List", 29}, |
| + {SUPERVISED_USER_SHARED_SETTINGS, "MANAGED_USER_SHARED_SETTING", |
| + "managed_user_shared_settings", "Managed User Shared Settings", 30}, |
| + {SYNCED_NOTIFICATION_APP_INFO, "SYNCED_NOTIFICATION_APP_INFO", |
| + "synced_notification_app_info", "Synced Notification App Info", 31}, |
| + {WIFI_CREDENTIALS, "WIFI_CREDENTIAL", "wifi_credentials", |
| + "WiFi Credentials", 32}, |
| + {SUPERVISED_USER_WHITELISTS, "MANAGED_USER_WHITELIST", |
| + "managed_user_whitelists", "Managed User Whitelists", 33}, |
| + {AUTOFILL_WALLET_DATA, "AUTOFILL_WALLET", "autofill_wallet", |
| + "Autofill Wallet", 34}, |
| + {AUTOFILL_WALLET_METADATA, "AUTOFILL_WALLET_METADATA", |
| + "autofill_wallet_metadata", "Autofill Wallet Metadata", 35}, |
| +}; |
| // Notes: |
| // 1) This list must contain exactly the same elements as the set returned by |
| // UserSelectableTypes(). |
| @@ -534,81 +592,16 @@ const char* ModelTypeToString(ModelType model_type) { |
| // This is used in serialization routines as well as for displaying debug |
| // information. Do not attempt to change these string values unless you know |
| // what you're doing. |
| - switch (model_type) { |
| - case TOP_LEVEL_FOLDER: |
| - return "Top Level Folder"; |
| - case UNSPECIFIED: |
| - return "Unspecified"; |
| - case BOOKMARKS: |
| - return "Bookmarks"; |
| - case PREFERENCES: |
| - return "Preferences"; |
| - case PASSWORDS: |
| - return "Passwords"; |
| - case AUTOFILL: |
| - return "Autofill"; |
| - case THEMES: |
| - return "Themes"; |
| - case TYPED_URLS: |
| - return "Typed URLs"; |
| - case EXTENSIONS: |
| - return "Extensions"; |
| - case NIGORI: |
| - return "Encryption keys"; |
| - case SEARCH_ENGINES: |
| - return "Search Engines"; |
| - case SESSIONS: |
| - return "Sessions"; |
| - case APPS: |
| - return "Apps"; |
| - case APP_LIST: |
| - return "App List"; |
| - case AUTOFILL_PROFILE: |
| - return "Autofill Profiles"; |
| - case APP_SETTINGS: |
| - return "App settings"; |
| - case EXTENSION_SETTINGS: |
| - return "Extension settings"; |
| - case APP_NOTIFICATIONS: |
| - return "App Notifications"; |
| - case HISTORY_DELETE_DIRECTIVES: |
| - return "History Delete Directives"; |
| - case SYNCED_NOTIFICATIONS: |
| - return "Synced Notifications"; |
| - case SYNCED_NOTIFICATION_APP_INFO: |
| - return "Synced Notification App Info"; |
| - case DEVICE_INFO: |
| - return "Device Info"; |
| - case EXPERIMENTS: |
| - return "Experiments"; |
| - case PRIORITY_PREFERENCES: |
| - return "Priority Preferences"; |
| - case DICTIONARY: |
| - return "Dictionary"; |
| - case FAVICON_IMAGES: |
| - return "Favicon Images"; |
| - case FAVICON_TRACKING: |
| - return "Favicon Tracking"; |
| - case SUPERVISED_USER_SETTINGS: |
| - return "Managed User Settings"; |
| - case SUPERVISED_USERS: |
| - return "Managed Users"; |
| - case SUPERVISED_USER_SHARED_SETTINGS: |
| - return "Managed User Shared Settings"; |
| - case SUPERVISED_USER_WHITELISTS: |
| - return "Managed User Whitelists"; |
| - case ARTICLES: |
| - return "Articles"; |
| - case WIFI_CREDENTIALS: |
| - return "WiFi Credentials"; |
| - case PROXY_TABS: |
| - return "Tabs"; |
| - case AUTOFILL_WALLET_DATA: |
| - return "Autofill Wallet"; |
| - case AUTOFILL_WALLET_METADATA: |
| - return "Autofill Wallet Metadata"; |
| - default: |
| - break; |
| + if (model_type == TOP_LEVEL_FOLDER) |
| + return "Top Level Folder"; |
| + else if (model_type == UNSPECIFIED) |
| + return "Unspecified"; |
| + else { |
| + for (const ModelTypeToNotificationMap& entry : |
| + kModelTypeToNotificationMap) { |
| + if (entry.model_type == model_type) |
| + return entry.model_type_string; |
| + } |
| } |
| NOTREACHED() << "No known extension for model type."; |
| return "INVALID"; |
| @@ -621,82 +614,16 @@ const char* ModelTypeToString(ModelType model_type) { |
| // Don't forget to update the "SyncModelTypes" enum in histograms.xml when you |
| // make changes to this list. |
| int ModelTypeToHistogramInt(ModelType model_type) { |
| - switch (model_type) { |
| - case UNSPECIFIED: |
| - return 0; |
| - case TOP_LEVEL_FOLDER: |
| - return 1; |
| - case BOOKMARKS: |
| - return 2; |
| - case PREFERENCES: |
| - return 3; |
| - case PASSWORDS: |
| - return 4; |
| - case AUTOFILL_PROFILE: |
| - return 5; |
| - case AUTOFILL: |
| - return 6; |
| - case THEMES: |
| - return 7; |
| - case TYPED_URLS: |
| - return 8; |
| - case EXTENSIONS: |
| - return 9; |
| - case SEARCH_ENGINES: |
| - return 10; |
| - case SESSIONS: |
| - return 11; |
| - case APPS: |
| - return 12; |
| - case APP_SETTINGS: |
| - return 13; |
| - case EXTENSION_SETTINGS: |
| - return 14; |
| - case APP_NOTIFICATIONS: |
| - return 15; |
| - case HISTORY_DELETE_DIRECTIVES: |
| - return 16; |
| - case NIGORI: |
| - return 17; |
| - case DEVICE_INFO: |
| - return 18; |
| - case EXPERIMENTS: |
| - return 19; |
| - case SYNCED_NOTIFICATIONS: |
| - return 20; |
| - case PRIORITY_PREFERENCES: |
| - return 21; |
| - case DICTIONARY: |
| - return 22; |
| - case FAVICON_IMAGES: |
| - return 23; |
| - case FAVICON_TRACKING: |
| - return 24; |
| - case PROXY_TABS: |
| - return 25; |
| - case SUPERVISED_USER_SETTINGS: |
| - return 26; |
| - case SUPERVISED_USERS: |
| - return 27; |
| - case ARTICLES: |
| - return 28; |
| - case APP_LIST: |
| - return 29; |
| - case SUPERVISED_USER_SHARED_SETTINGS: |
| - return 30; |
| - case SYNCED_NOTIFICATION_APP_INFO: |
| - return 31; |
| - case WIFI_CREDENTIALS: |
| - return 32; |
| - case SUPERVISED_USER_WHITELISTS: |
| - return 33; |
| - case AUTOFILL_WALLET_DATA: |
| - return 34; |
| - case AUTOFILL_WALLET_METADATA: |
| - return 35; |
| - // Silence a compiler warning. |
| - case MODEL_TYPE_COUNT: |
| - return 0; |
| + if (model_type == UNSPECIFIED) |
| + return 0; |
| + else if (model_type == TOP_LEVEL_FOLDER) |
| + return 1; |
| + else { |
| + for (const ModelTypeToNotificationMap& entry : |
| + kModelTypeToNotificationMap) { |
| + if (entry.model_type == model_type) |
| + return entry.model_type_histogram_val; |
| + } |
| } |
| return 0; |
| } |
| @@ -729,77 +656,12 @@ ModelType ModelTypeFromValue(const base::Value& value) { |
| } |
| ModelType ModelTypeFromString(const std::string& model_type_string) { |
| - if (model_type_string == "Bookmarks") |
| - return BOOKMARKS; |
| - else if (model_type_string == "Preferences") |
| - return PREFERENCES; |
| - else if (model_type_string == "Passwords") |
| - return PASSWORDS; |
| - else if (model_type_string == "Autofill") |
| - return AUTOFILL; |
| - else if (model_type_string == "Autofill Profiles") |
| - return AUTOFILL_PROFILE; |
| - else if (model_type_string == "Autofill Wallet") |
| - return AUTOFILL_WALLET_DATA; |
| - else if (model_type_string == "Autofill Wallet Metadata") |
| - return AUTOFILL_WALLET_METADATA; |
| - else if (model_type_string == "Themes") |
| - return THEMES; |
| - else if (model_type_string == "Typed URLs") |
| - return TYPED_URLS; |
| - else if (model_type_string == "Extensions") |
| - return EXTENSIONS; |
| - else if (model_type_string == "Encryption keys") |
| - return NIGORI; |
| - else if (model_type_string == "Search Engines") |
| - return SEARCH_ENGINES; |
| - else if (model_type_string == "Sessions") |
| - return SESSIONS; |
| - else if (model_type_string == "Apps") |
| - return APPS; |
| - else if (model_type_string == "App List") |
| - return APP_LIST; |
| - else if (model_type_string == "App settings") |
| - return APP_SETTINGS; |
| - else if (model_type_string == "Extension settings") |
| - return EXTENSION_SETTINGS; |
| - else if (model_type_string == "App Notifications") |
| - return APP_NOTIFICATIONS; |
| - else if (model_type_string == "History Delete Directives") |
| - return HISTORY_DELETE_DIRECTIVES; |
| - else if (model_type_string == "Synced Notifications") |
| - return SYNCED_NOTIFICATIONS; |
| - else if (model_type_string == "Synced Notification App Info") |
| - return SYNCED_NOTIFICATION_APP_INFO; |
| - else if (model_type_string == "Device Info") |
| - return DEVICE_INFO; |
| - else if (model_type_string == "Experiments") |
| - return EXPERIMENTS; |
| - else if (model_type_string == "Priority Preferences") |
| - return PRIORITY_PREFERENCES; |
| - else if (model_type_string == "Dictionary") |
| - return DICTIONARY; |
| - else if (model_type_string == "Favicon Images") |
| - return FAVICON_IMAGES; |
| - else if (model_type_string == "Favicon Tracking") |
| - return FAVICON_TRACKING; |
| - else if (model_type_string == "Managed User Settings") |
| - return SUPERVISED_USER_SETTINGS; |
| - else if (model_type_string == "Managed Users") |
| - return SUPERVISED_USERS; |
| - else if (model_type_string == "Managed User Shared Settings") |
| - return SUPERVISED_USER_SHARED_SETTINGS; |
| - else if (model_type_string == "Managed User Whitelists") |
| - return SUPERVISED_USER_WHITELISTS; |
| - else if (model_type_string == "Articles") |
| - return ARTICLES; |
| - else if (model_type_string == "WiFi Credentials") |
| - return WIFI_CREDENTIALS; |
| - else if (model_type_string == "Tabs") |
| - return PROXY_TABS; |
| - else |
| - NOTREACHED() << "No known model type corresponding to " |
| - << model_type_string << "."; |
| + for (const ModelTypeToNotificationMap& entry : kModelTypeToNotificationMap) { |
| + if (entry.model_type_string == model_type_string) |
| + return entry.model_type; |
| + } |
| + NOTREACHED() << "No known model type corresponding to " << model_type_string |
| + << "."; |
| return UNSPECIFIED; |
| } |
| @@ -860,229 +722,26 @@ ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value) { |
| // NOTE: Proxy types should return empty strings (so that we don't NOTREACHED |
| // in tests when we verify they have no root node). |
| std::string ModelTypeToRootTag(ModelType type) { |
| - switch (type) { |
| - case BOOKMARKS: |
| - return "google_chrome_bookmarks"; |
| - case PREFERENCES: |
| - return "google_chrome_preferences"; |
| - case PASSWORDS: |
| - return "google_chrome_passwords"; |
| - case AUTOFILL: |
| - return "google_chrome_autofill"; |
| - case THEMES: |
| - return "google_chrome_themes"; |
| - case TYPED_URLS: |
| - return "google_chrome_typed_urls"; |
| - case EXTENSIONS: |
| - return "google_chrome_extensions"; |
| - case NIGORI: |
| - return "google_chrome_nigori"; |
| - case SEARCH_ENGINES: |
| - return "google_chrome_search_engines"; |
| - case SESSIONS: |
| - return "google_chrome_sessions"; |
| - case APPS: |
| - return "google_chrome_apps"; |
| - case APP_LIST: |
| - return "google_chrome_app_list"; |
| - case AUTOFILL_PROFILE: |
| - return "google_chrome_autofill_profiles"; |
| - case AUTOFILL_WALLET_DATA: |
| - return "google_chrome_autofill_wallet"; |
| - case AUTOFILL_WALLET_METADATA: |
| - return "google_chrome_autofill_wallet_metadata"; |
| - case APP_SETTINGS: |
| - return "google_chrome_app_settings"; |
| - case EXTENSION_SETTINGS: |
| - return "google_chrome_extension_settings"; |
| - case APP_NOTIFICATIONS: |
| - return "google_chrome_app_notifications"; |
| - case HISTORY_DELETE_DIRECTIVES: |
| - return "google_chrome_history_delete_directives"; |
| - case SYNCED_NOTIFICATIONS: |
| - return "google_chrome_synced_notifications"; |
| - case SYNCED_NOTIFICATION_APP_INFO: |
| - return "google_chrome_synced_notification_app_info"; |
| - case DEVICE_INFO: |
| - return "google_chrome_device_info"; |
| - case EXPERIMENTS: |
| - return "google_chrome_experiments"; |
| - case PRIORITY_PREFERENCES: |
| - return "google_chrome_priority_preferences"; |
| - case DICTIONARY: |
| - return "google_chrome_dictionary"; |
| - case FAVICON_IMAGES: |
| - return "google_chrome_favicon_images"; |
| - case FAVICON_TRACKING: |
| - return "google_chrome_favicon_tracking"; |
| - case SUPERVISED_USER_SETTINGS: |
| - return "google_chrome_managed_user_settings"; |
| - case SUPERVISED_USERS: |
| - return "google_chrome_managed_users"; |
| - case SUPERVISED_USER_SHARED_SETTINGS: |
| - return "google_chrome_managed_user_shared_settings"; |
| - case SUPERVISED_USER_WHITELISTS: |
| - return "google_chrome_managed_user_whitelists"; |
| - case ARTICLES: |
| - return "google_chrome_articles"; |
| - case WIFI_CREDENTIALS: |
| - return "google_chrome_wifi_credentials"; |
| - case PROXY_TABS: |
| - return std::string(); |
| - default: |
| - break; |
| + if (type == PROXY_TABS) |
| + return std::string(); |
| + for (const ModelTypeToNotificationMap& entry : kModelTypeToNotificationMap) { |
| + if (entry.model_type == type) |
| + return "google_chrome_" + std::string(entry.root_tag); |
| } |
| NOTREACHED() << "No known extension for model type."; |
| return "INVALID"; |
| } |
| -// TODO(akalin): Figure out a better way to do these mappings. |
| -// Note: Do not include proxy types in this list. They should never receive |
| -// or trigger notifications. |
| -namespace { |
| -const char kBookmarkNotificationType[] = "BOOKMARK"; |
| -const char kPreferenceNotificationType[] = "PREFERENCE"; |
| -const char kPasswordNotificationType[] = "PASSWORD"; |
| -const char kAutofillNotificationType[] = "AUTOFILL"; |
| -const char kThemeNotificationType[] = "THEME"; |
| -const char kTypedUrlNotificationType[] = "TYPED_URL"; |
| -const char kExtensionNotificationType[] = "EXTENSION"; |
| -const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; |
| -const char kNigoriNotificationType[] = "NIGORI"; |
| -const char kAppSettingNotificationType[] = "APP_SETTING"; |
| -const char kAppNotificationType[] = "APP"; |
| -const char kAppListNotificationType[] = "APP_LIST"; |
| -const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; |
| -const char kSessionNotificationType[] = "SESSION"; |
| -const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; |
| -const char kAutofillWalletMetadataNotificationType[] = |
| - "AUTOFILL_WALLET_METADATA"; |
| -const char kAutofillWalletNotificationType[] = "AUTOFILL_WALLET"; |
| -const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; |
| -const char kHistoryDeleteDirectiveNotificationType[] = |
| - "HISTORY_DELETE_DIRECTIVE"; |
| -const char kSyncedNotificationType[] = "SYNCED_NOTIFICATION"; |
| -const char kSyncedNotificationAppInfoType[] = "SYNCED_NOTIFICATION_APP_INFO"; |
| -const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; |
| -const char kExperimentsNotificationType[] = "EXPERIMENTS"; |
| -const char kPriorityPreferenceNotificationType[] = "PRIORITY_PREFERENCE"; |
| -const char kDictionaryNotificationType[] = "DICTIONARY"; |
| -const char kFaviconImageNotificationType[] = "FAVICON_IMAGE"; |
| -const char kFaviconTrackingNotificationType[] = "FAVICON_TRACKING"; |
| -const char kSupervisedUserSettingNotificationType[] = "MANAGED_USER_SETTING"; |
| -const char kSupervisedUserNotificationType[] = "MANAGED_USER"; |
| -const char kSupervisedUserSharedSettingNotificationType[] = |
| - "MANAGED_USER_SHARED_SETTING"; |
| -const char kSupervisedUserWhitelistNotificationType[] = |
| - "MANAGED_USER_WHITELIST"; |
| -const char kArticleNotificationType[] = "ARTICLE"; |
| -const char kWifiCredentialNotificationType[] = "WIFI_CREDENTIAL"; |
| -} // namespace |
| - |
| bool RealModelTypeToNotificationType(ModelType model_type, |
| std::string* notification_type) { |
| - switch (model_type) { |
| - case BOOKMARKS: |
| - *notification_type = kBookmarkNotificationType; |
| - return true; |
| - case PREFERENCES: |
| - *notification_type = kPreferenceNotificationType; |
| - return true; |
| - case PASSWORDS: |
| - *notification_type = kPasswordNotificationType; |
| - return true; |
| - case AUTOFILL: |
| - *notification_type = kAutofillNotificationType; |
| - return true; |
| - case THEMES: |
| - *notification_type = kThemeNotificationType; |
| - return true; |
| - case TYPED_URLS: |
| - *notification_type = kTypedUrlNotificationType; |
| - return true; |
| - case EXTENSIONS: |
| - *notification_type = kExtensionNotificationType; |
| - return true; |
| - case NIGORI: |
| - *notification_type = kNigoriNotificationType; |
| - return true; |
| - case APP_SETTINGS: |
| - *notification_type = kAppSettingNotificationType; |
| - return true; |
| - case APPS: |
| - *notification_type = kAppNotificationType; |
| - return true; |
| - case APP_LIST: |
| - *notification_type = kAppListNotificationType; |
| - return true; |
| - case SEARCH_ENGINES: |
| - *notification_type = kSearchEngineNotificationType; |
| - return true; |
| - case SESSIONS: |
| - *notification_type = kSessionNotificationType; |
| - return true; |
| - case AUTOFILL_PROFILE: |
| - *notification_type = kAutofillProfileNotificationType; |
| - return true; |
| - case AUTOFILL_WALLET_DATA: |
| - *notification_type = kAutofillWalletNotificationType; |
| - return true; |
| - case AUTOFILL_WALLET_METADATA: |
| - *notification_type = kAutofillWalletMetadataNotificationType; |
| - return true; |
| - case EXTENSION_SETTINGS: |
| - *notification_type = kExtensionSettingNotificationType; |
| - return true; |
| - case APP_NOTIFICATIONS: |
| - *notification_type = kAppNotificationNotificationType; |
| - return true; |
| - case HISTORY_DELETE_DIRECTIVES: |
| - *notification_type = kHistoryDeleteDirectiveNotificationType; |
| - return true; |
| - case SYNCED_NOTIFICATIONS: |
| - *notification_type = kSyncedNotificationType; |
| - return true; |
| - case SYNCED_NOTIFICATION_APP_INFO: |
| - *notification_type = kSyncedNotificationAppInfoType; |
| - return true; |
| - case DEVICE_INFO: |
| - *notification_type = kDeviceInfoNotificationType; |
| - return true; |
| - case EXPERIMENTS: |
| - *notification_type = kExperimentsNotificationType; |
| - return true; |
| - case PRIORITY_PREFERENCES: |
| - *notification_type = kPriorityPreferenceNotificationType; |
| - return true; |
| - case DICTIONARY: |
| - *notification_type = kDictionaryNotificationType; |
| - return true; |
| - case FAVICON_IMAGES: |
| - *notification_type = kFaviconImageNotificationType; |
| - return true; |
| - case FAVICON_TRACKING: |
| - *notification_type = kFaviconTrackingNotificationType; |
| - return true; |
| - case SUPERVISED_USER_SETTINGS: |
| - *notification_type = kSupervisedUserSettingNotificationType; |
| - return true; |
| - case SUPERVISED_USERS: |
| - *notification_type = kSupervisedUserNotificationType; |
| - return true; |
| - case SUPERVISED_USER_SHARED_SETTINGS: |
| - *notification_type = kSupervisedUserSharedSettingNotificationType; |
| - return true; |
| - case SUPERVISED_USER_WHITELISTS: |
| - *notification_type = kSupervisedUserWhitelistNotificationType; |
| - return true; |
| - case ARTICLES: |
| - *notification_type = kArticleNotificationType; |
| - return true; |
| - case WIFI_CREDENTIALS: |
| - *notification_type = kWifiCredentialNotificationType; |
| - return true; |
| - default: |
| - break; |
| + if (model_type != PROXY_TABS) { |
|
AKV
2015/10/26 10:32:00
Why explicitly checking for PROXY_TABS ?
Deepak
2015/10/26 12:04:46
Because for PROXY_TABS,UNSPECIFIED and TOP_LEVEL_F
|
| + for (const ModelTypeToNotificationMap& entry : |
| + kModelTypeToNotificationMap) { |
| + if (entry.model_type == model_type) { |
| + *notification_type = entry.notification_type; |
| + return true; |
| + } |
| + } |
| } |
| notification_type->clear(); |
| return false; |
| @@ -1090,106 +749,14 @@ bool RealModelTypeToNotificationType(ModelType model_type, |
| bool NotificationTypeToRealModelType(const std::string& notification_type, |
| ModelType* model_type) { |
| - if (notification_type == kBookmarkNotificationType) { |
| - *model_type = BOOKMARKS; |
| - return true; |
| - } else if (notification_type == kPreferenceNotificationType) { |
| - *model_type = PREFERENCES; |
| - return true; |
| - } else if (notification_type == kPasswordNotificationType) { |
| - *model_type = PASSWORDS; |
| - return true; |
| - } else if (notification_type == kAutofillNotificationType) { |
| - *model_type = AUTOFILL; |
| - return true; |
| - } else if (notification_type == kThemeNotificationType) { |
| - *model_type = THEMES; |
| - return true; |
| - } else if (notification_type == kTypedUrlNotificationType) { |
| - *model_type = TYPED_URLS; |
| - return true; |
| - } else if (notification_type == kExtensionNotificationType) { |
| - *model_type = EXTENSIONS; |
| - return true; |
| - } else if (notification_type == kNigoriNotificationType) { |
| - *model_type = NIGORI; |
| - return true; |
| - } else if (notification_type == kAppNotificationType) { |
| - *model_type = APPS; |
| - return true; |
| - } else if (notification_type == kAppListNotificationType) { |
| - *model_type = APP_LIST; |
| - return true; |
| - } else if (notification_type == kSearchEngineNotificationType) { |
| - *model_type = SEARCH_ENGINES; |
| - return true; |
| - } else if (notification_type == kSessionNotificationType) { |
| - *model_type = SESSIONS; |
| - return true; |
| - } else if (notification_type == kAutofillProfileNotificationType) { |
| - *model_type = AUTOFILL_PROFILE; |
| - return true; |
| - } else if (notification_type == kAutofillWalletNotificationType) { |
| - *model_type = AUTOFILL_WALLET_DATA; |
| - return true; |
| - } else if (notification_type == kAutofillWalletMetadataNotificationType) { |
| - *model_type = AUTOFILL_WALLET_METADATA; |
| - return true; |
| - } else if (notification_type == kAppSettingNotificationType) { |
| - *model_type = APP_SETTINGS; |
| - return true; |
| - } else if (notification_type == kExtensionSettingNotificationType) { |
| - *model_type = EXTENSION_SETTINGS; |
| - return true; |
| - } else if (notification_type == kAppNotificationNotificationType) { |
| - *model_type = APP_NOTIFICATIONS; |
| - return true; |
| - } else if (notification_type == kHistoryDeleteDirectiveNotificationType) { |
| - *model_type = HISTORY_DELETE_DIRECTIVES; |
| - return true; |
| - } else if (notification_type == kSyncedNotificationType) { |
| - *model_type = SYNCED_NOTIFICATIONS; |
| - return true; |
| - } else if (notification_type == kSyncedNotificationAppInfoType) { |
| - *model_type = SYNCED_NOTIFICATION_APP_INFO; |
| - return true; |
| - } else if (notification_type == kDeviceInfoNotificationType) { |
| - *model_type = DEVICE_INFO; |
| - return true; |
| - } else if (notification_type == kExperimentsNotificationType) { |
| - *model_type = EXPERIMENTS; |
| - return true; |
| - } else if (notification_type == kPriorityPreferenceNotificationType) { |
| - *model_type = PRIORITY_PREFERENCES; |
| - return true; |
| - } else if (notification_type == kDictionaryNotificationType) { |
| - *model_type = DICTIONARY; |
| - return true; |
| - } else if (notification_type == kFaviconImageNotificationType) { |
| - *model_type = FAVICON_IMAGES; |
| - return true; |
| - } else if (notification_type == kFaviconTrackingNotificationType) { |
| - *model_type = FAVICON_TRACKING; |
| - return true; |
| - } else if (notification_type == kSupervisedUserSettingNotificationType) { |
| - *model_type = SUPERVISED_USER_SETTINGS; |
| - return true; |
| - } else if (notification_type == kSupervisedUserNotificationType) { |
| - *model_type = SUPERVISED_USERS; |
| - return true; |
| - } else if (notification_type == |
| - kSupervisedUserSharedSettingNotificationType) { |
| - *model_type = SUPERVISED_USER_SHARED_SETTINGS; |
| - return true; |
| - } else if (notification_type == kSupervisedUserWhitelistNotificationType) { |
| - *model_type = SUPERVISED_USER_WHITELISTS; |
| - return true; |
| - } else if (notification_type == kArticleNotificationType) { |
| - *model_type = ARTICLES; |
| - return true; |
| - } else if (notification_type == kWifiCredentialNotificationType) { |
| - *model_type = WIFI_CREDENTIALS; |
| - return true; |
| + if (notification_type != "") { |
|
AKV
2015/10/26 10:32:00
empty() method we can use and do early return by s
Deepak
2015/10/26 12:04:46
Done.
|
| + for (const ModelTypeToNotificationMap& entry : |
| + kModelTypeToNotificationMap) { |
| + if (entry.notification_type == notification_type) { |
| + *model_type = entry.model_type; |
| + return true; |
| + } |
| + } |
| } |
| *model_type = UNSPECIFIED; |
| return false; |