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