chromium/components/sync/base/user_selectable_type.cc

// Copyright 2019 The Chromium Authors
// 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 <optional>
#include <ostream>

#include "base/notreached.h"
#include "build/chromeos_buildflags.h"
#include "components/sync/base/data_type.h"

namespace syncer {

namespace {

struct UserSelectableTypeInfo {};

constexpr char kBookmarksTypeName[] =;
constexpr char kPreferencesTypeName[] =;
constexpr char kPasswordsTypeName[] =;
constexpr char kAutofillTypeName[] =;
constexpr char kThemesTypeName[] =;
// Note: The type name for History is "typedUrls" for historic reasons. This
// name is used in JS (sync settings) and in the SyncTypesListDisabled policy,
// so it's fairly hard to change.
constexpr char kHistoryTypeName[] =;
constexpr char kExtensionsTypeName[] =;
constexpr char kAppsTypeName[] =;
constexpr char kReadingListTypeName[] =;
constexpr char kTabsTypeName[] =;
constexpr char kSavedTabGroupsTypeName[] =;
constexpr char kSharedTabGroupDataTypeName[] =;
constexpr char kPaymentsTypeName[] =;
constexpr char kProductComparisonTypeName[] =;
constexpr char kCookiesTypeName[] =;

UserSelectableTypeInfo GetUserSelectableTypeInfo(UserSelectableType type) {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
constexpr char kOsAppsTypeName[] = "osApps";
constexpr char kOsPreferencesTypeName[] = "osPreferences";
constexpr char kOsWifiConfigurationsTypeName[] = "osWifiConfigurations";
constexpr char kWifiConfigurationsTypeName[] = "wifiConfigurations";

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) {}

std::optional<UserSelectableType> GetUserSelectableTypeFromString(
    const std::string& type) {}

std::string UserSelectableTypeSetToString(UserSelectableTypeSet types) {}

DataTypeSet UserSelectableTypeToAllDataTypes(UserSelectableType type) {}

DataType UserSelectableTypeToCanonicalDataType(UserSelectableType 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;
}

std::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.
  // TODO(crbug.com/40678410): Rename "osApps" to "apps" and
  // "osWifiConfigurations" to "wifiConfigurations", 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 std::nullopt;
}

DataTypeSet UserSelectableOsTypeToAllDataTypes(UserSelectableOsType type) {
  return GetUserSelectableOsTypeInfo(type).data_type_group;
}

DataType UserSelectableOsTypeToCanonicalDataType(UserSelectableOsType type) {
  return GetUserSelectableOsTypeInfo(type).canonical_data_type;
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

std::ostream& operator<<(std::ostream& stream, const UserSelectableType& type) {}

std::ostream& operator<<(std::ostream& stream,
                         const UserSelectableTypeSet& types) {}

}  // namespace syncer