15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef EXTENSIONS_BROWSER_EXTENSION_REGISTRY_OBSERVER_H_
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define EXTENSIONS_BROWSER_EXTENSION_REGISTRY_OBSERVER_H_
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
85f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "extensions/browser/uninstall_reason.h"
90529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "extensions/common/extension.h"
100529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
11c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochnamespace content {
12c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochclass BrowserContext;
13c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch}
14c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace extensions {
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class Extension;
1846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)class ExtensionRegistry;
190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstruct UnloadedExtensionInfo;
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Observer for ExtensionRegistry. Exists in a separate header file to reduce
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// the include file burden for typical clients of ExtensionRegistry.
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class ExtensionRegistryObserver {
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~ExtensionRegistryObserver() {}
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
27effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // Called after an extension is loaded. The extension will exclusively exist
28effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // in the enabled_extensions set of ExtensionRegistry.
29c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  virtual void OnExtensionLoaded(
30c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      content::BrowserContext* browser_context,
31c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      const Extension* extension) {}
32effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Called after an extension is unloaded. The extension no longer exists in
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // any of the ExtensionRegistry sets (enabled, disabled, etc.).
350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  virtual void OnExtensionUnloaded(content::BrowserContext* browser_context,
360529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                                   const Extension* extension,
370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                                   UnloadedExtensionInfo::Reason reason) {}
38cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
39cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Called when |extension| is about to be installed. |is_update| is true if
40cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // the installation is the result of it updating, in which case |old_name| is
41cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // the name of the extension's previous version.
42cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // If true, |from_ephemeral| indicates that the extension was previously
43cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // installed ephemerally and has been promoted to a regular installed
44cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // extension. |is_update| will be true, although the version has not
45cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // necessarily changed.
46cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // The ExtensionRegistry will not be tracking |extension| at the time this
47cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // event is fired, but will be immediately afterwards (note: not necessarily
48cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // enabled; it might be installed in the disabled or even blacklisted sets,
49cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // for example).
50cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Note that it's much more common to care about extensions being loaded
51cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // (OnExtensionLoaded).
52cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  //
53cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // TODO(tmdiep): We should stash the state of the previous extension version
54cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // somewhere and have observers retrieve it. |is_update|, |from_ephemeral|
55cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // and |old_name| can be removed when this is done.
56cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual void OnExtensionWillBeInstalled(
57cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      content::BrowserContext* browser_context,
58cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      const Extension* extension,
59cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      bool is_update,
60cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      bool from_ephemeral,
61cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      const std::string& old_name) {}
62cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
63f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Called when the installation of |extension| is complete. At this point the
64f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // extension is tracked in one of the ExtensionRegistry sets, but is not
65f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // necessarily enabled.
66f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual void OnExtensionInstalled(content::BrowserContext* browser_context,
67116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                                    const Extension* extension,
68116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                                    bool is_update) {}
69f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
70f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Called after an extension is uninstalled. The extension no longer exists in
71cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // any of the ExtensionRegistry sets (enabled, disabled, etc.).
72cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual void OnExtensionUninstalled(content::BrowserContext* browser_context,
735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                      const Extension* extension,
745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                      UninstallReason reason) {}
7546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
7646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // Notifies observers that the observed object is going away.
7746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  virtual void OnShutdown(ExtensionRegistry* registry) {}
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
80c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch}  // namespace extensions
815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif  // EXTENSIONS_BROWSER_EXTENSION_REGISTRY_OBSERVER_H_
83