File: kiosk_web_app_manager.h

package info (click to toggle)
chromium 139.0.7258.138-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,120,676 kB
  • sloc: cpp: 35,100,869; 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 (99 lines) | stat: -rw-r--r-- 3,413 bytes parent folder | download | duplicates (3)
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
94
95
96
97
98
99
// 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.

#ifndef CHROME_BROWSER_ASH_APP_MODE_WEB_APP_KIOSK_WEB_APP_MANAGER_H_
#define CHROME_BROWSER_ASH_APP_MODE_WEB_APP_KIOSK_WEB_APP_MANAGER_H_

#include <memory>
#include <string>
#include <vector>

#include "chrome/browser/ash/app_mode/kiosk_app_manager_base.h"
#include "chrome/browser/ash/app_mode/kiosk_app_types.h"
#include "chrome/browser/chromeos/app_mode/kiosk_web_app_update_observer.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "components/account_id/account_id.h"
#include "url/gurl.h"

class PrefRegistrySimple;
class Profile;

namespace web_app {
struct WebAppInstallInfo;
}  // namespace web_app

namespace ash {

class KioskWebAppData;

// Does the management of web kiosk apps.
class KioskWebAppManager : public KioskAppManagerBase {
 public:
  static const char kWebKioskDictionaryName[];

  // Whether the manager was already created.
  static bool IsInitialized();

  // Will return the manager instance or will crash if it not yet initiazlied.
  static KioskWebAppManager* Get();
  KioskWebAppManager();
  KioskWebAppManager(const KioskWebAppManager&) = delete;
  KioskWebAppManager& operator=(const KioskWebAppManager&) = delete;
  ~KioskWebAppManager() override;

  // Registers kiosk app entries in local state.
  static void RegisterPrefs(PrefRegistrySimple* registry);

  // Create app instance by app data.
  static KioskAppManagerBase::App CreateAppByData(const KioskWebAppData& data);

  // `KioskAppManagerBase` implementation.
  std::vector<App> GetApps() const override;

  void LoadIcons();

  // Returns auto launched account id. If there is none, account is invalid,
  // thus is_valid() returns empty AccountId.
  const AccountId& GetAutoLaunchAccountId() const;

  // Obtains an app associated with given `account_id`.
  const KioskWebAppData* GetAppByAccountId(const AccountId& account_id) const;

  // Updates app by the data obtained during installation.
  void UpdateAppFromInstallInfo(const AccountId& account_id,
                                const web_app::WebAppInstallInfo& app_info);

  // Updates app by title, start_url and icon_bitmaps.
  void UpdateApp(const AccountId& account_id,
                 const std::string& title,
                 const GURL& start_url,
                 const web_app::IconBitmaps& icon_bitmaps);

  // Adds fake apps in tests.
  void AddAppForTesting(const AccountId& account_id, const GURL& install_url);

  // Notify this manager that a Kiosk session started with the given `app_id`.
  void OnKioskSessionStarted(const KioskAppId& app_id);

  // Starts observing web app updates from App Service in a Kiosk session.
  void StartObservingAppUpdate(Profile* profile, const AccountId& account_id);

 private:
  // `KioskAppManagerBase` implementation.
  // Updates `apps_` based on CrosSettings.
  void UpdateAppsFromPolicy() override;

  std::vector<std::unique_ptr<KioskWebAppData>> apps_;
  AccountId auto_launch_account_id_;

  // Observes web Kiosk app updates. Persists through the whole web Kiosk
  // session.
  std::unique_ptr<chromeos::KioskWebAppUpdateObserver> app_update_observer_;

  base::WeakPtrFactory<KioskWebAppManager> weak_ptr_factory_{this};
};

}  // namespace ash

#endif  // CHROME_BROWSER_ASH_APP_MODE_WEB_APP_KIOSK_WEB_APP_MANAGER_H_