File: blocked_app_registry.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (91 lines) | stat: -rw-r--r-- 3,569 bytes parent folder | download | duplicates (6)
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
// 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_CHILD_ACCOUNTS_ON_DEVICE_CONTROLS_BLOCKED_APP_REGISTRY_H_
#define CHROME_BROWSER_ASH_CHILD_ACCOUNTS_ON_DEVICE_CONTROLS_BLOCKED_APP_REGISTRY_H_

#include <map>
#include <set>
#include <string>

#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "chrome/browser/apps/app_service/app_service_proxy_forward.h"
#include "chrome/browser/ash/child_accounts/on_device_controls/app_activity_watcher.h"
#include "chrome/browser/ash/child_accounts/on_device_controls/blocked_app_store.h"
#include "chrome/browser/ash/child_accounts/on_device_controls/blocked_app_types.h"
#include "components/services/app_service/public/cpp/app_registry_cache.h"

class PrefService;

namespace ash::on_device_controls {

// Keeps track of blocked apps and persists blocked apps on the disk.
// TODO(b/338246850): Handle app uninstall/reinstall.
// TODO(b/338247185): Persist blocked apps in a pref.
class BlockedAppRegistry : public apps::AppRegistryCache::Observer {
 public:
  BlockedAppRegistry(apps::AppServiceProxy* app_service,
                     PrefService* pref_service);
  BlockedAppRegistry(const BlockedAppRegistry&) = delete;
  BlockedAppRegistry& operator=(const BlockedAppRegistry&) = delete;
  ~BlockedAppRegistry() override;

  // Adds an app identified with `app_id` to the registry.
  // Mark app as blocked. It will have no effect if the app is already blocked.
  void AddApp(const std::string& app_id);

  // Removes an app identified with an `app_id` from the registry.
  // Marks app as unblocked. Will have no effect if the app is not blocked.
  void RemoveApp(const std::string& app_id);

  // Removes all apps from the registry and marks all blocked apps as unblocked.
  // No effect if the registry is empty.
  void RemoveAllApps();

  // Returns the set with ids for all blocked apps.
  std::set<std::string> GetBlockedApps();

  // Returns the local state of the app based on its presences in the registry
  LocalAppState GetAppState(const std::string& app_id) const;

 private:
  // apps::AppRegistryCache::Observer:
  void OnAppUpdate(const apps::AppUpdate& update) override;
  void OnAppRegistryCacheWillBeDestroyed(
      apps::AppRegistryCache* cache) override;

  apps::AppRegistryCache& GetAppCache();

  // Called when app is installed and at the beginning of each
  // user session. Restores the blocked state of the apps that are loaded or
  // reinstalled.
  void OnAppReady(const std::string& app_id);
  // Called when app is uninstalled.
  void OnAppUninstalled(const std::string& app_id);
  // Returns the number of blocked apps that are uninstalled.
  int GetUninstalledBlockedAppCount() const;
  // Removes the oldest uninstalled blocked app from the registry.
  void RemoveOldestUninstalledApp();

  // The in-memory registry of the locked apps.
  // Maps blocked app id to blocked ap metadata.
  BlockedAppMap registry_;

  // Manages persisting and restoring blocked apps.
  BlockedAppStore store_;

  const raw_ptr<apps::AppServiceProxy> app_service_;

  // Watches for instances of blocked apps launched from play.
  AppActivityWatcher app_activity_watcher_;

  base::ScopedObservation<apps::AppRegistryCache,
                          apps::AppRegistryCache::Observer>
      app_registry_cache_observer_{this};
};

}  // namespace ash::on_device_controls

#endif  // CHROME_BROWSER_ASH_CHILD_ACCOUNTS_ON_DEVICE_CONTROLS_BLOCKED_APP_REGISTRY_H_