1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef EXTENSIONS_BROWSER_EXTENSION_REGISTRY_OBSERVER_H_
6#define EXTENSIONS_BROWSER_EXTENSION_REGISTRY_OBSERVER_H_
7
8#include "extensions/browser/uninstall_reason.h"
9#include "extensions/common/extension.h"
10
11namespace content {
12class BrowserContext;
13}
14
15namespace extensions {
16
17class Extension;
18class ExtensionRegistry;
19struct UnloadedExtensionInfo;
20
21// Observer for ExtensionRegistry. Exists in a separate header file to reduce
22// the include file burden for typical clients of ExtensionRegistry.
23class ExtensionRegistryObserver {
24 public:
25  virtual ~ExtensionRegistryObserver() {}
26
27  // Called after an extension is loaded. The extension will exclusively exist
28  // in the enabled_extensions set of ExtensionRegistry.
29  virtual void OnExtensionLoaded(
30      content::BrowserContext* browser_context,
31      const Extension* extension) {}
32
33  // Called after an extension is unloaded. The extension no longer exists in
34  // any of the ExtensionRegistry sets (enabled, disabled, etc.).
35  virtual void OnExtensionUnloaded(content::BrowserContext* browser_context,
36                                   const Extension* extension,
37                                   UnloadedExtensionInfo::Reason reason) {}
38
39  // Called when |extension| is about to be installed. |is_update| is true if
40  // the installation is the result of it updating, in which case |old_name| is
41  // the name of the extension's previous version.
42  // If true, |from_ephemeral| indicates that the extension was previously
43  // installed ephemerally and has been promoted to a regular installed
44  // extension. |is_update| will be true, although the version has not
45  // necessarily changed.
46  // The ExtensionRegistry will not be tracking |extension| at the time this
47  // event is fired, but will be immediately afterwards (note: not necessarily
48  // enabled; it might be installed in the disabled or even blacklisted sets,
49  // for example).
50  // Note that it's much more common to care about extensions being loaded
51  // (OnExtensionLoaded).
52  //
53  // TODO(tmdiep): We should stash the state of the previous extension version
54  // somewhere and have observers retrieve it. |is_update|, |from_ephemeral|
55  // and |old_name| can be removed when this is done.
56  virtual void OnExtensionWillBeInstalled(
57      content::BrowserContext* browser_context,
58      const Extension* extension,
59      bool is_update,
60      bool from_ephemeral,
61      const std::string& old_name) {}
62
63  // Called when the installation of |extension| is complete. At this point the
64  // extension is tracked in one of the ExtensionRegistry sets, but is not
65  // necessarily enabled.
66  virtual void OnExtensionInstalled(content::BrowserContext* browser_context,
67                                    const Extension* extension,
68                                    bool is_update) {}
69
70  // Called after an extension is uninstalled. The extension no longer exists in
71  // any of the ExtensionRegistry sets (enabled, disabled, etc.).
72  virtual void OnExtensionUninstalled(content::BrowserContext* browser_context,
73                                      const Extension* extension,
74                                      UninstallReason reason) {}
75
76  // Notifies observers that the observed object is going away.
77  virtual void OnShutdown(ExtensionRegistry* registry) {}
78};
79
80}  // namespace extensions
81
82#endif  // EXTENSIONS_BROWSER_EXTENSION_REGISTRY_OBSERVER_H_
83