File: delayed_install_manager.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; 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,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 (105 lines) | stat: -rw-r--r-- 4,199 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
105
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef EXTENSIONS_BROWSER_DELAYED_INSTALL_MANAGER_H_
#define EXTENSIONS_BROWSER_DELAYED_INSTALL_MANAGER_H_

#include <map>

#include "base/memory/raw_ptr.h"
#include "components/keyed_service/core/keyed_service.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/install_gate.h"
#include "extensions/buildflags/buildflags.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/extension_set.h"

static_assert(BUILDFLAG(ENABLE_EXTENSIONS_CORE));

namespace content {
class BrowserContext;
}

namespace extensions {
class ExtensionPrefs;
class ExtensionRegistrar;
class InstallGate;

// Manages a set of extension installs delayed for various reasons.  The reason
// for delayed install is stored in ExtensionPrefs. These are not part of
// ExtensionRegistry because they are not yet installed.
class DelayedInstallManager : public KeyedService {
 public:
  explicit DelayedInstallManager(content::BrowserContext* context);
  DelayedInstallManager(const DelayedInstallManager&) = delete;
  DelayedInstallManager& operator=(const DelayedInstallManager&) = delete;
  ~DelayedInstallManager() override;

  static DelayedInstallManager* Get(content::BrowserContext* context);

  // KeyedService:
  void Shutdown() override;

  // Returns true if an extension is in the delayed install set.
  bool Contains(const ExtensionId& id) const;

  // Adds an extension to the delayed install set.
  void Insert(scoped_refptr<const Extension> extension);

  // Removes an extension from the delayed install set.
  void Remove(const ExtensionId& id);

  // Returns an update for an extension with the specified id, if installation
  // of that update was previously delayed because the extension was in use. If
  // no updates are pending for the extension returns null.
  const Extension* GetPendingExtensionUpdate(const ExtensionId& id) const;

  // Finish install (if possible) of extensions that were still delayed while
  // the browser was shut down.
  void FinishInstallationsDelayedByShutdown();

  // Checks for delayed installation for all pending installs.
  void MaybeFinishDelayedInstallations();

  // Attempts finishing installation of an update for an extension with the
  // specified id, when installation of that extension was previously delayed.
  // `install_immediately` - Whether the extension should be installed if it's
  // currently in use.
  // Returns whether the extension installation was finished.
  bool FinishDelayedInstallationIfReady(const ExtensionId& extension_id,
                                        bool install_immediately);

  // Register/unregister an InstallGate with the service.
  void RegisterInstallGate(ExtensionPrefs::DelayReason reason,
                           InstallGate* install_delayer);
  void UnregisterInstallGate(InstallGate* install_delayer);

  // Helper to determine if installing an extensions should proceed immediately,
  // or if we should delay the install until further notice, or if the install
  // should be aborted. A pending install is delayed or aborted when any of the
  // delayers say so and only proceeds when all delayers return INSTALL.
  // `extension` is the extension to be installed. `install_immediately` is the
  // install flag set with the install. `reason` is the reason associated with
  // the install delayer that wants to defer or abort the install.
  InstallGate::Action ShouldDelayExtensionInstall(
      const Extension* extension,
      bool install_immediately,
      ExtensionPrefs::DelayReason* reason) const;

  const ExtensionSet& delayed_installs() const { return delayed_installs_; }

 private:
  raw_ptr<ExtensionPrefs> extension_prefs_;
  raw_ptr<ExtensionRegistrar> extension_registrar_;

  ExtensionSet delayed_installs_;

  using InstallGateRegistry = std::map<ExtensionPrefs::DelayReason,
                                       raw_ptr<InstallGate, CtnExperimental>>;
  InstallGateRegistry install_delayer_registry_;
};

}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_DELAYED_INSTALL_MANAGER_H_