123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- // Copyright 2019 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #include "components/sync/base/user_selectable_type.h"
- #include <type_traits>
- #include "base/notreached.h"
- #include "build/chromeos_buildflags.h"
- #include "components/sync/base/model_type.h"
- #include "components/sync/base/pref_names.h"
- #include "third_party/abseil-cpp/absl/types/optional.h"
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- #include "ash/constants/ash_features.h"
- #endif
- namespace syncer {
- namespace {
- struct UserSelectableTypeInfo {
- const char* const type_name;
- const ModelType canonical_model_type;
- const ModelTypeSet model_type_group;
- };
- constexpr char kBookmarksTypeName[] = "bookmarks";
- constexpr char kPreferencesTypeName[] = "preferences";
- constexpr char kPasswordsTypeName[] = "passwords";
- constexpr char kAutofillTypeName[] = "autofill";
- constexpr char kThemesTypeName[] = "themes";
- constexpr char kTypedUrlsTypeName[] = "typedUrls";
- constexpr char kExtensionsTypeName[] = "extensions";
- constexpr char kAppsTypeName[] = "apps";
- constexpr char kReadingListTypeName[] = "readingList";
- constexpr char kTabsTypeName[] = "tabs";
- constexpr char kWifiConfigurationsTypeName[] = "wifiConfigurations";
- UserSelectableTypeInfo GetUserSelectableTypeInfo(UserSelectableType type) {
- static_assert(40 == syncer::GetNumModelTypes(),
- "Almost always when adding a new ModelType, you must tie it to "
- "a UserSelectableType below (new or existing) so the user can "
- "disable syncing of that data. Today you must also update the "
- "UI code yourself; crbug.com/1067282 and related bugs will "
- "improve that");
- // UserSelectableTypeInfo::type_name is used in js code and shouldn't be
- // changed without updating js part.
- switch (type) {
- case UserSelectableType::kBookmarks:
- return {kBookmarksTypeName, BOOKMARKS, {BOOKMARKS}};
- case UserSelectableType::kPreferences: {
- ModelTypeSet model_types = {PREFERENCES, DICTIONARY, PRIORITY_PREFERENCES,
- SEARCH_ENGINES};
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- if (!chromeos::features::IsSyncSettingsCategorizationEnabled()) {
- // SyncSettingsCategorization makes Printers a separate OS setting.
- model_types.Put(PRINTERS);
- model_types.Put(PRINTERS_AUTHORIZATION_SERVERS);
- // Workspace desk template is an OS-only feature. When
- // SyncSettingsCategorization is disabled, WORKSPACE_DESK should be
- // enabled with user preferences. Otherwise, WORKSPACE_DESK should be
- // enabled with OS preferences below.
- model_types.Put(WORKSPACE_DESK);
- }
- #endif
- return {kPreferencesTypeName, PREFERENCES, model_types};
- }
- case UserSelectableType::kPasswords:
- return {kPasswordsTypeName, PASSWORDS, {PASSWORDS}};
- case UserSelectableType::kAutofill:
- return {kAutofillTypeName,
- AUTOFILL,
- {AUTOFILL, AUTOFILL_PROFILE, AUTOFILL_WALLET_DATA,
- AUTOFILL_WALLET_METADATA, AUTOFILL_WALLET_OFFER}};
- case UserSelectableType::kThemes:
- return {kThemesTypeName, THEMES, {THEMES}};
- case UserSelectableType::kHistory:
- return {kTypedUrlsTypeName,
- TYPED_URLS,
- {TYPED_URLS, HISTORY, HISTORY_DELETE_DIRECTIVES, SESSIONS,
- USER_EVENTS}};
- case UserSelectableType::kExtensions:
- return {
- kExtensionsTypeName, EXTENSIONS, {EXTENSIONS, EXTENSION_SETTINGS}};
- case UserSelectableType::kApps: {
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- // SyncSettingsCategorization moves apps to Chrome OS settings.
- if (chromeos::features::IsSyncSettingsCategorizationEnabled()) {
- return {kAppsTypeName, UNSPECIFIED};
- } else {
- return {kAppsTypeName,
- APPS,
- {APP_LIST, APPS, APP_SETTINGS, ARC_PACKAGE, WEB_APPS}};
- }
- #else
- return {kAppsTypeName, APPS, {APPS, APP_SETTINGS, WEB_APPS}};
- #endif
- }
- case UserSelectableType::kReadingList:
- return {kReadingListTypeName, READING_LIST, {READING_LIST}};
- case UserSelectableType::kTabs: {
- return {kTabsTypeName, PROXY_TABS, {PROXY_TABS, SESSIONS}};
- }
- case UserSelectableType::kWifiConfigurations: {
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- // SyncSettingsCategorization moves Wi-Fi configurations to Chrome OS
- // settings.
- if (chromeos::features::IsSyncSettingsCategorizationEnabled())
- return {kWifiConfigurationsTypeName, UNSPECIFIED};
- #endif
- return {kWifiConfigurationsTypeName,
- WIFI_CONFIGURATIONS,
- {WIFI_CONFIGURATIONS}};
- }
- }
- NOTREACHED();
- return {nullptr, UNSPECIFIED, {}};
- }
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- constexpr char kOsAppsTypeName[] = "osApps";
- constexpr char kOsPreferencesTypeName[] = "osPreferences";
- constexpr char kOsWifiConfigurationsTypeName[] = "osWifiConfigurations";
- UserSelectableTypeInfo GetUserSelectableOsTypeInfo(UserSelectableOsType type) {
- // UserSelectableTypeInfo::type_name is used in js code and shouldn't be
- // changed without updating js part.
- switch (type) {
- case UserSelectableOsType::kOsApps:
- return {kOsAppsTypeName,
- APPS,
- {APP_LIST, APPS, APP_SETTINGS, ARC_PACKAGE, WEB_APPS}};
- case UserSelectableOsType::kOsPreferences:
- return {kOsPreferencesTypeName,
- OS_PREFERENCES,
- {OS_PREFERENCES, OS_PRIORITY_PREFERENCES, PRINTERS,
- PRINTERS_AUTHORIZATION_SERVERS, WORKSPACE_DESK}};
- case UserSelectableOsType::kOsWifiConfigurations:
- return {kOsWifiConfigurationsTypeName,
- WIFI_CONFIGURATIONS,
- {WIFI_CONFIGURATIONS}};
- }
- }
- #endif // BUILDFLAG(IS_CHROMEOS_ASH)
- } // namespace
- const char* GetUserSelectableTypeName(UserSelectableType type) {
- return GetUserSelectableTypeInfo(type).type_name;
- }
- absl::optional<UserSelectableType> GetUserSelectableTypeFromString(
- const std::string& type) {
- if (type == kBookmarksTypeName) {
- return UserSelectableType::kBookmarks;
- }
- if (type == kPreferencesTypeName) {
- return UserSelectableType::kPreferences;
- }
- if (type == kPasswordsTypeName) {
- return UserSelectableType::kPasswords;
- }
- if (type == kAutofillTypeName) {
- return UserSelectableType::kAutofill;
- }
- if (type == kThemesTypeName) {
- return UserSelectableType::kThemes;
- }
- if (type == kTypedUrlsTypeName) {
- return UserSelectableType::kHistory;
- }
- if (type == kExtensionsTypeName) {
- return UserSelectableType::kExtensions;
- }
- if (type == kAppsTypeName) {
- return UserSelectableType::kApps;
- }
- if (type == kReadingListTypeName) {
- return UserSelectableType::kReadingList;
- }
- if (type == kTabsTypeName) {
- return UserSelectableType::kTabs;
- }
- if (type == kWifiConfigurationsTypeName) {
- return UserSelectableType::kWifiConfigurations;
- }
- return absl::nullopt;
- }
- std::string UserSelectableTypeSetToString(UserSelectableTypeSet types) {
- std::string result;
- for (UserSelectableType type : types) {
- if (!result.empty()) {
- result += ", ";
- }
- result += GetUserSelectableTypeName(type);
- }
- return result;
- }
- ModelTypeSet UserSelectableTypeToAllModelTypes(UserSelectableType type) {
- return GetUserSelectableTypeInfo(type).model_type_group;
- }
- ModelType UserSelectableTypeToCanonicalModelType(UserSelectableType type) {
- return GetUserSelectableTypeInfo(type).canonical_model_type;
- }
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- const char* GetUserSelectableOsTypeName(UserSelectableOsType type) {
- return GetUserSelectableOsTypeInfo(type).type_name;
- }
- std::string UserSelectableOsTypeSetToString(UserSelectableOsTypeSet types) {
- std::string result;
- for (UserSelectableOsType type : types) {
- if (!result.empty()) {
- result += ", ";
- }
- result += GetUserSelectableOsTypeName(type);
- }
- return result;
- }
- absl::optional<UserSelectableOsType> GetUserSelectableOsTypeFromString(
- const std::string& type) {
- if (type == kOsAppsTypeName) {
- return UserSelectableOsType::kOsApps;
- }
- if (type == kOsPreferencesTypeName) {
- return UserSelectableOsType::kOsPreferences;
- }
- if (type == kOsWifiConfigurationsTypeName) {
- return UserSelectableOsType::kOsWifiConfigurations;
- }
- // Some pref types migrated from browser prefs to OS prefs. Map the browser
- // type name to the OS type so that enterprise policy SyncTypesListDisabled
- // still applies to the migrated names during SyncSettingsCategorization
- // roll-out.
- // TODO(https://crbug.com/1059309): Rename "osApps" to "apps" and
- // "osWifiConfigurations" to "wifiConfigurations" after
- // SyncSettingsCategorization is the default, and remove the mapping for
- // "preferences".
- if (type == kAppsTypeName) {
- return UserSelectableOsType::kOsApps;
- }
- if (type == kWifiConfigurationsTypeName) {
- return UserSelectableOsType::kOsWifiConfigurations;
- }
- if (type == kPreferencesTypeName) {
- return UserSelectableOsType::kOsPreferences;
- }
- return absl::nullopt;
- }
- ModelTypeSet UserSelectableOsTypeToAllModelTypes(UserSelectableOsType type) {
- return GetUserSelectableOsTypeInfo(type).model_type_group;
- }
- ModelType UserSelectableOsTypeToCanonicalModelType(UserSelectableOsType type) {
- return GetUserSelectableOsTypeInfo(type).canonical_model_type;
- }
- #endif // BUILDFLAG(IS_CHROMEOS_ASH)
- } // namespace syncer
|