1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_APPS_APP_PRELOAD_SERVICE_PRELOAD_APP_DEFINITION_H_
#define CHROME_BROWSER_APPS_APP_PRELOAD_SERVICE_PRELOAD_APP_DEFINITION_H_
#include <map>
#include <ostream>
#include <string>
#include <variant>
#include "chrome/browser/apps/app_preload_service/proto/app_preload.pb.h"
#include "chrome/browser/apps/app_service/app_install/app_install_types.h"
#include "components/services/app_service/public/cpp/app_types.h"
#include "components/services/app_service/public/cpp/package_id.h"
class GURL;
namespace apps {
// A wrapper class around an App Preload Server App proto to allow for easier
// extraction and conversion of information.
class PreloadAppDefinition {
public:
explicit PreloadAppDefinition(proto::AppPreloadListResponse_App app_proto);
PreloadAppDefinition(const PreloadAppDefinition&);
PreloadAppDefinition& operator=(const PreloadAppDefinition&);
~PreloadAppDefinition();
std::optional<PackageId> GetPackageId() const;
std::string GetName() const;
PackageType GetPlatform() const;
bool IsDefaultApp() const;
bool IsOemApp() const;
bool IsTestApp() const;
AppInstallSurface GetInstallSurface() const;
// Returns the android package name. This is derived from the package
// identifier of the app. Must only be called if `GetPlatform()` returns
// `AppType::kArc`.
std::string GetAndroidPackageName() const;
// Returns the Web App manifest URL for the app, which hosts the manifest of
// the app in a JSON format. The URL could point to a local file, or a web
// address. Does not attempt to validate the GURL. Must only be called if
// `GetPlatform()` returns `AppType::kWeb`.
GURL GetWebAppManifestUrl() const;
// Returns the original Web App manifest URL for the app. This is the URL
// where the manifest was originally hosted. Does not attempt to validate the
// GURL. Must only be called if `GetPlatform()` returns `AppType::kWeb`.
GURL GetWebAppOriginalManifestUrl() const;
// Returns the manifest ID of the Web App. This is derived from the package
// identifier of the app. Does not attempt to validate the GURL. Must only be
// called if `GetPlatform()` returns `AppType::kWeb`.
GURL GetWebAppManifestId() const;
AppInstallData ToAppInstallData() const;
private:
proto::AppPreloadListResponse_App app_proto_;
std::optional<apps::PackageId> package_id_;
};
std::ostream& operator<<(std::ostream& os, const PreloadAppDefinition& app);
// Wrapper for App Preload Server ShelfConfig proto. Map of PackageId to order.
using ShelfPinOrdering = std::map<apps::PackageId, uint32_t>;
// Wrappers for App Preload Server LauncherConfig proto:
// LauncherItem is either an app represented by a PackageId, or a folder
// represented by a string.
using LauncherItem = std::variant<apps::PackageId, std::string>;
// LauncherItemData is the associated data for a LauncherItem.
struct LauncherItemData {
proto::AppPreloadListResponse_LauncherType type;
uint32_t order;
};
// Map of LauncherItem to LauncherItemData.
using LauncherItemMap = std::map<LauncherItem, LauncherItemData>;
// Map of folder to LauncherItemMap. Root folder always exists and is keyed by
// empty string.
using LauncherOrdering = std::map<std::string, LauncherItemMap>;
} // namespace apps
#endif // CHROME_BROWSER_APPS_APP_PRELOAD_SERVICE_PRELOAD_APP_DEFINITION_H_
|