chromium/chrome/browser/web_applications/preinstalled_web_apps/preinstalled_web_apps.cc

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/web_applications/preinstalled_web_apps/preinstalled_web_apps.h"

#include <optional>
#include <string>
#include <utility>

#include "base/check_op.h"
#include "base/command_line.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "build/buildflag.h"
#include "chrome/browser/web_applications/preinstalled_app_install_features.h"
#include "chrome/common/chrome_switches.h"

#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
#include "chrome/browser/web_applications/preinstalled_web_apps/gmail.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/google_docs.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/google_drive.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/google_sheets.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/google_slides.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/youtube.h"

#if BUILDFLAG(IS_CHROMEOS)
#include "base/feature_list.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/app_mall.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/calculator.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/container.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/google_calendar.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/google_chat.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/google_meet.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/messages_dogfood.h"
#include "chrome/browser/web_applications/web_app_id_constants.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chromeos/constants/chromeos_features.h"
#include "extensions/common/constants.h"
#include "google_apis/gaia/gaia_auth_util.h"
#endif  // BUILDFLAG(IS_CHROMEOS)

#endif  // BUILDFLAG(GOOGLE_CHROME_BRANDING)

namespace web_app {
namespace {

std::vector<ExternalInstallOptions>* g_preinstalled_app_data_for_testing =;

#if BUILDFLAG(GOOGLE_CHROME_BRANDING)

#if BUILDFLAG(IS_CHROMEOS)
bool IsGoogleInternalAccount() {
  Profile* profile = ProfileManager::GetActiveUserProfile();
  if (!profile)
    return false;
  return gaia::IsGoogleInternalAccountEmail(profile->GetProfileUserName());
}
#endif  // BUILDFLAG(IS_CHROMEOS)

std::vector<ExternalInstallOptions> GetChromeBrandedApps(
    Profile& profile,
    const std::optional<DeviceInfo>& device_info) {
  bool is_standalone_tabbed =
      IsPreinstalledDocsSheetsSlidesDriveStandaloneTabbed(profile);
  // TODO(crbug.com/40705277): Replace these C++ configs with JSON configs like
  // those seen in: chrome/test/data/web_app_default_apps/good_json
  // This requires:
  // - Mimicking the directory packaging used by
  //   chrome/browser/resources/default_apps.
  // - Hooking up a second JSON config load to PreinstalledWebAppManager.
  // - Validating everything works on all OSs (Mac bundles things differently).
  // - Ensure that these resources are correctly installed by our Chrome
  //   installers on every desktop platform.
  // clang-format off
  std::vector<ExternalInstallOptions> apps = {
      GetConfigForGmail(),
      GetConfigForGoogleDocs(is_standalone_tabbed),
      GetConfigForGoogleDrive(/*is_standalone=*/is_standalone_tabbed),
      GetConfigForGoogleSheets(is_standalone_tabbed),
      GetConfigForGoogleSlides(is_standalone_tabbed),
      GetConfigForYouTube(),
  };
#if BUILDFLAG(IS_CHROMEOS)
  if (!base::FeatureList::IsEnabled(
          chromeos::features::kPreinstalledWebAppsCoreOnly)) {
    apps.insert(apps.end(), {
      GetConfigForAppMall(),
      GetConfigForCalculator(),
      GetConfigForContainer(device_info),
      GetConfigForGoogleCalendar(),
      GetConfigForGoogleChat(),
      GetConfigForGoogleMeet(),
    });
  }
#endif  // BUILDFLAG(IS_CHROMEOS)
  // clang-format on

  return apps;
}
#endif  // BUILDFLAG(GOOGLE_CHROME_BRANDING)

}  // namespace

DeviceInfo::DeviceInfo() = default;

DeviceInfo::DeviceInfo(const DeviceInfo&) = default;

DeviceInfo::DeviceInfo(DeviceInfo&&) = default;

DeviceInfo& DeviceInfo::operator=(const DeviceInfo&) = default;

DeviceInfo& DeviceInfo::operator=(DeviceInfo&&) = default;

DeviceInfo::~DeviceInfo() = default;

bool PreinstalledWebAppsDisabled() {}

std::vector<ExternalInstallOptions> GetPreinstalledWebApps(
    Profile& profile,
    const std::optional<DeviceInfo>& device_info) {}

ScopedTestingPreinstalledAppData::ScopedTestingPreinstalledAppData() {}

ScopedTestingPreinstalledAppData::~ScopedTestingPreinstalledAppData() {}

PreinstalledWebAppMigration::PreinstalledWebAppMigration() = default;
PreinstalledWebAppMigration::PreinstalledWebAppMigration(
    PreinstalledWebAppMigration&&) noexcept = default;
PreinstalledWebAppMigration::~PreinstalledWebAppMigration() = default;

std::vector<PreinstalledWebAppMigration> GetPreinstalledWebAppMigrations(
    Profile& profile) {}

}  // namespace web_app