File: kiosk_iwa_manager.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 (104 lines) | stat: -rw-r--r-- 4,016 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
94
95
96
97
98
99
100
101
102
103
104
// Copyright 2024 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_ISOLATED_WEB_APP_KIOSK_IWA_MANAGER_H_
#define CHROME_BROWSER_ASH_APP_MODE_ISOLATED_WEB_APP_KIOSK_IWA_MANAGER_H_

#include <map>
#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "base/memory/raw_ref.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ash/app_mode/isolated_web_app/kiosk_iwa_data.h"
#include "chrome/browser/ash/app_mode/kiosk_app_manager_base.h"
#include "chrome/browser/ash/app_mode/kiosk_app_types.h"
#include "chrome/browser/ash/policy/core/device_local_account.h"
#include "chrome/browser/chromeos/app_mode/kiosk_web_app_update_observer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "components/account_id/account_id.h"

class PrefService;
class PrefRegistrySimple;

namespace ash {

class KioskIwaManager : public KioskAppManagerBase {
 public:
  static const char kIwaKioskDictionaryName[];

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

  // Returns the manager instance or will crash if it not yet initiazlied.
  static KioskIwaManager* Get();
  explicit KioskIwaManager(PrefService& local_state);
  KioskIwaManager(const KioskIwaManager&) = delete;
  KioskIwaManager& operator=(const KioskIwaManager&) = delete;
  ~KioskIwaManager() override;

  // KioskAppManagerBase overrides:
  KioskAppManagerBase::AppList GetApps() const override;

  // Returns app data associated with `account_id`.
  const KioskIwaData* GetApp(const AccountId& account_id) const;

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

  // Returns a valid account id if an IWA kiosk is configured for auto launch.
  // Returns a nullopt otherwise.
  const std::optional<AccountId>& GetAutoLaunchAccountId() const;

  // 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);

  // Adds fake apps in tests.
  void AddAppForTesting(const policy::DeviceLocalAccount& account);

 private:
  void UpdateAppsFromPolicy() override;

  void Reset();
  void MaybeSetAutoLaunchInfo(const std::string& policy_account_id,
                              const AccountId& kiosk_app_account_id);
  void CancelCryptohomeRemovalsForCurrentApps();

  using KioskIwaDataMap = std::map<std::string, std::unique_ptr<KioskIwaData>>;
  // Clears object's internal state (apps list and autolaunch info) and returns
  // a map of previous app data.
  KioskIwaDataMap GetAppsAndReset();

  // Removes accounts associated with `previous_apps`.
  void RemoveApps(const KioskIwaDataMap& previous_apps) const;

  // Creates app data from `account` and adds it to the list of current apps.
  // Removes the matching app data from `previous_apps` that will be later
  // removed.
  void ProcessDeviceLocalAccount(const policy::DeviceLocalAccount& account,
                                 KioskIwaDataMap& previous_apps);

  const raw_ref<PrefService> local_state_;

  // TODO(crbug.com/377878781): Make common helpers for all kiosk app managers.
  std::vector<std::unique_ptr<KioskIwaData>> isolated_web_apps_;
  std::optional<AccountId> auto_launch_id_;

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

  base::WeakPtrFactory<KioskIwaManager> weak_ptr_factory_{this};
};
}  // namespace ash

#endif  // CHROME_BROWSER_ASH_APP_MODE_ISOLATED_WEB_APP_KIOSK_IWA_MANAGER_H_