File: user_uninstalled_preinstalled_web_app_prefs.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; 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 (83 lines) | stat: -rw-r--r-- 3,471 bytes parent folder | download | duplicates (4)
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
// 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_WEB_APPLICATIONS_USER_UNINSTALLED_PREINSTALLED_WEB_APP_PREFS_H_
#define CHROME_BROWSER_WEB_APPLICATIONS_USER_UNINSTALLED_PREINSTALLED_WEB_APP_PREFS_H_

#include "base/containers/flat_set.h"
#include "base/memory/raw_ptr.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/browser/web_applications/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_management_type.h"
#include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/webapps/common/web_app_id.h"
#include "url/gurl.h"

class GURL;
class PrefService;

namespace user_prefs {
class PrefRegistrySyncable;
}

namespace web_app {
// A Prefs-backed map from preinstalled web app IDs to their install URLs.
//
// Preinstalled apps are the only type of externally installed apps that
// can be uninstalled by user. So if an user has uninstalled a preinstalled app,
// then it should stay uninstalled on startup.
//
// To prevent that, we keep track of the install URLs of preinstalled apps
// outside of the web_app DB so that on every startup, the WebAppSystem can
// keep the user uninstalled preinstalled apps uninstalled,
// thereby maintaining its synchronization.
//
// The prefs are stored in prefs::kUserUninstalledPreinstalledWebAppPref and
// they are stored as map<webapps::AppId, Set<Install URLs>>, e.g.
// {"app_id": {"https://install_url1.com", "https://install_url2.com"}}
//
// They can be seen on chrome://web-app-internals under the
// PreinstalledAppsUninstalledByUserConfigs json for debugging purposes.
class UserUninstalledPreinstalledWebAppPrefs {
 public:
  static const char kUserUninstalledPreinstalledAppAction[];
  explicit UserUninstalledPreinstalledWebAppPrefs(PrefService* pref_service);
  UserUninstalledPreinstalledWebAppPrefs(
      const UserUninstalledPreinstalledWebAppPrefs&) = delete;
  UserUninstalledPreinstalledWebAppPrefs& operator=(
      const UserUninstalledPreinstalledWebAppPrefs&) = delete;

  static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
  void Add(const webapps::AppId& app_id, base::flat_set<GURL> install_urls);
  std::optional<webapps::AppId> LookUpAppIdByInstallUrl(
      const GURL& install_url);
  bool DoesAppIdExist(const webapps::AppId& app_id);
  void AppendExistingInstallUrlsPerAppId(const webapps::AppId& app_id,
                                         base::flat_set<GURL>& urls);
  int Size();
  bool RemoveByInstallUrl(const webapps::AppId& app_id,
                          const GURL& install_url);
  bool RemoveByAppId(const webapps::AppId& app_id);
  bool AppIdContainsAllUrls(
      const webapps::AppId& app_id,
      const base::flat_map<WebAppManagement::Type,
                           WebApp::ExternalManagementConfig>& url_map,
      const bool only_default);
#if BUILDFLAG(IS_CHROMEOS)
  // Clear all apps marked as user uninstalled. Only used for Lacros
  // disablement.
  // TODO(crbug.com/380780352): Remove after stepping stone.
  void ClearAllApps();
#endif

 private:
  const raw_ptr<PrefService> pref_service_;
};

}  // namespace web_app

#endif  // CHROME_BROWSER_WEB_APPLICATIONS_USER_UNINSTALLED_PREINSTALLED_WEB_APP_PREFS_H_