File: extension_prefs_observer.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 (102 lines) | stat: -rw-r--r-- 4,708 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
// Copyright 2014 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_EXTENSION_PREFS_OBSERVER_H_
#define EXTENSIONS_BROWSER_EXTENSION_PREFS_OBSERVER_H_

#include "base/time/time.h"
#include "extensions/browser/disable_reason.h"
#include "extensions/common/extension_id.h"

namespace extensions {

class ExtensionPrefs;

class ExtensionPrefsObserver {
 public:
  // Called when the reasons for an extension being disabled have changed.
  virtual void OnExtensionDisableReasonsChanged(
      const ExtensionId& extension_id,
      DisableReasonSet disabled_reasons) {}

  // Called when an extension is registered with ExtensionPrefs.
  virtual void OnExtensionRegistered(const ExtensionId& extension_id,
                                     const base::Time& install_time,
                                     bool is_enabled) {}

  // Called when an extension's prefs have been loaded.
  virtual void OnExtensionPrefsLoaded(const ExtensionId& extension_id,
                                      const ExtensionPrefs* prefs) {}

  // Called when an extension's prefs are deleted.
  virtual void OnExtensionPrefsDeleted(const ExtensionId& extension_id) {}

  // Called when an extension's enabled state pref is changed.
  // Note: This does not necessarily correspond to the extension being loaded/
  // unloaded. For that, observe the ExtensionRegistry, and reconcile that the
  // events might not match up.
  // TODO(crbug.com/40554334): Remove this and migrate consumers to
  // OnExtensionDisableReasonsChanged.
  virtual void OnExtensionStateChanged(const ExtensionId& extension_id,
                                       bool state) {}

  // Called when an extension's pref has been updated or changed.
  virtual void OnExtensionPrefsUpdated(const ExtensionId& extension_id) {}

  // Called when the runtime permissions for an extension are changed.
  // TODO(devlin): This is a bit out of place here, and may be better suited on
  // a general "extension permissions" observer, if/when we have one. See
  // discussion at
  // https://chromium-review.googlesource.com/c/chromium/src/+/1196107/3/chrome/browser/extensions/runtime_permissions_observer.h#26.
  virtual void OnExtensionRuntimePermissionsChanged(
      const ExtensionId& extension_id) {}

  // Called when an extension's last-launch-time has changed.
  virtual void OnExtensionLastLaunchTimeChanged(
      const ExtensionId& extension_id,
      const base::Time& last_launch_time) {}

  // Called when the ExtensionPrefs object (the thing that this observer
  // observes) will be destroyed. In response, the observer, `this`, should
  // call "prefs->RemoveObserver(this)", whether directly or indirectly (e.g.
  // via ScopedObservation::Reset).
  virtual void OnExtensionPrefsWillBeDestroyed(ExtensionPrefs* prefs) {}
};

// An ExtensionPrefsObserver that's part of the GetEarlyExtensionPrefsObservers
// mechanism, where the ExtensionPrefsObserver needs to connect to an
// ExtensionPrefs, but the ExtensionPrefs doesn't exist yet. This
// OnExtensionPrefsAvailable method lets the connection happen during or
// shortly after the ExtensionPrefs constructor.
class EarlyExtensionPrefsObserver {
 public:
  // Called when "prefs->AddObserver(observer)" should be called, during or
  // shortly after `prefs`' constructor. OnExtensionPrefsAvailable
  // implementations should make that AddObserver call, but are also
  // responsible for making the matching RemoveObserver call at an appropriate
  // time, no later than during the observer's destructor. Otherwise, the
  // observee (the `prefs` object) will follow a dangling pointer whenever the
  // next event occurs.
  //
  // Making that RemoveObserver call at the right time has to be the
  // responsibility of the observer, not the observee, since the observee does
  // not know when the observer is destroyed or is otherwise no longer
  // interested in events.
  //
  // Given that the observer is responsible for calling RemoveObserver, it is
  // cleaner for the observer, not the observee, to also be responsible for
  // calling AddObserver.
  //
  // The recommended technique for ensuring matching AddObserver and
  // RemoveObserver calls is to used a ScopedObservation.
  //
  // Unlike other ExtensionPrefsObserver methods, this method does not have an
  // "const ExtensionId& extension_id" argument. It is not about any one
  // particular extension, it is about the extension preferences as a whole.
  virtual void OnExtensionPrefsAvailable(ExtensionPrefs* prefs) = 0;
};

}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_EXTENSION_PREFS_OBSERVER_H_