[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 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 | |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 8 | #include "extensions/browser/uninstall_reason.h" |
[email protected] | e51232f3 | 2014-04-18 20:05:36 | [diff] [blame] | 9 | #include "extensions/common/extension.h" |
| 10 | |
[email protected] | 50703fc | 2014-04-08 04:01:06 | [diff] [blame] | 11 | namespace content { |
| 12 | class BrowserContext; |
| 13 | } |
| 14 | |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 15 | namespace extensions { |
| 16 | |
| 17 | class Extension; |
[email protected] | a9b55a1 | 2014-06-06 14:08:45 | [diff] [blame] | 18 | class ExtensionRegistry; |
[email protected] | e51232f3 | 2014-04-18 20:05:36 | [diff] [blame] | 19 | struct UnloadedExtensionInfo; |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 20 | |
| 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 { |
| 24 | public: |
| 25 | virtual ~ExtensionRegistryObserver() {} |
| 26 | |
[email protected] | dcc4764 | 2014-03-26 22:03:49 | [diff] [blame] | 27 | // Called after an extension is loaded. The extension will exclusively exist |
| 28 | // in the enabled_extensions set of ExtensionRegistry. |
[email protected] | 50703fc | 2014-04-08 04:01:06 | [diff] [blame] | 29 | virtual void OnExtensionLoaded( |
| 30 | content::BrowserContext* browser_context, |
| 31 | const Extension* extension) {} |
[email protected] | dcc4764 | 2014-03-26 22:03:49 | [diff] [blame] | 32 | |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 33 | // Called after an extension is unloaded. The extension no longer exists in |
| 34 | // any of the ExtensionRegistry sets (enabled, disabled, etc.). |
[email protected] | e51232f3 | 2014-04-18 20:05:36 | [diff] [blame] | 35 | virtual void OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 36 | const Extension* extension, |
| 37 | UnloadedExtensionInfo::Reason reason) {} |
[email protected] | 17f0782 | 2014-05-22 08:45:15 | [diff] [blame] | 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. |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 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. |
[email protected] | 17f0782 | 2014-05-22 08:45:15 | [diff] [blame] | 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). |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 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. |
[email protected] | 17f0782 | 2014-05-22 08:45:15 | [diff] [blame] | 56 | virtual void OnExtensionWillBeInstalled( |
| 57 | content::BrowserContext* browser_context, |
| 58 | const Extension* extension, |
| 59 | bool is_update, |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 60 | bool from_ephemeral, |
[email protected] | 17f0782 | 2014-05-22 08:45:15 | [diff] [blame] | 61 | const std::string& old_name) {} |
[email protected] | 1d7f248 | 2014-05-24 00:11:51 | [diff] [blame] | 62 | |
[email protected] | bc44b5da | 2014-06-12 14:20:00 | [diff] [blame] | 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, |
[email protected] | 38e87253 | 2014-07-16 23:27:51 | [diff] [blame] | 67 | const Extension* extension, |
| 68 | bool is_update) {} |
[email protected] | bc44b5da | 2014-06-12 14:20:00 | [diff] [blame] | 69 | |
| 70 | // Called after an extension is uninstalled. The extension no longer exists in |
[email protected] | 1d7f248 | 2014-05-24 00:11:51 | [diff] [blame] | 71 | // any of the ExtensionRegistry sets (enabled, disabled, etc.). |
| 72 | virtual void OnExtensionUninstalled(content::BrowserContext* browser_context, |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 73 | const Extension* extension, |
| 74 | UninstallReason reason) {} |
[email protected] | a9b55a1 | 2014-06-06 14:08:45 | [diff] [blame] | 75 | |
| 76 | // Notifies observers that the observed object is going away. |
| 77 | virtual void OnShutdown(ExtensionRegistry* registry) {} |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 78 | }; |
| 79 | |
[email protected] | 50703fc | 2014-04-08 04:01:06 | [diff] [blame] | 80 | } // namespace extensions |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 81 | |
| 82 | #endif // EXTENSIONS_BROWSER_EXTENSION_REGISTRY_OBSERVER_H_ |