File: preload_app_definition.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (93 lines) | stat: -rw-r--r-- 3,498 bytes parent folder | download | duplicates (5)
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_