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