Devlin Cronin | 4d5fbc9 | 2019-07-01 19:11:35 | [diff] [blame] | 1 | // Copyright 2019 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSER_WINDOW_HELPER_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSER_WINDOW_HELPER_H_ |
| 7 | |
| 8 | #include "base/macros.h" |
| 9 | #include "base/scoped_observer.h" |
Evan Stade | 75872a6 | 2019-09-06 21:17:38 | [diff] [blame] | 10 | #include "extensions/browser/extension_registry.h" |
Devlin Cronin | 4d5fbc9 | 2019-07-01 19:11:35 | [diff] [blame] | 11 | #include "extensions/browser/extension_registry_observer.h" |
| 12 | |
| 13 | class Browser; |
| 14 | |
| 15 | namespace extensions { |
| 16 | |
| 17 | // A helper object for extensions-related management for Browser* objects. |
| 18 | class ExtensionBrowserWindowHelper : public ExtensionRegistryObserver { |
| 19 | public: |
| 20 | // Note: |browser| must outlive this object. |
| 21 | explicit ExtensionBrowserWindowHelper(Browser* browser); |
| 22 | ~ExtensionBrowserWindowHelper() override; |
| 23 | |
| 24 | private: |
| 25 | // ExtensionRegistryObserver: |
| 26 | void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 27 | const Extension* extension) override; |
| 28 | void OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 29 | const Extension* extension, |
| 30 | UnloadedExtensionReason reason) override; |
| 31 | |
| 32 | // Closes any tabs owned by the extension with the given |extension_id| and |
| 33 | // unmutes others if necessary. |
| 34 | void CleanUpTabsOnUnload(const ExtensionId& extension_id); |
| 35 | |
| 36 | // The associated browser. Must outlive this object. |
| 37 | Browser* const browser_ = nullptr; |
| 38 | |
| 39 | ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
Evan Stade | 75872a6 | 2019-09-06 21:17:38 | [diff] [blame] | 40 | registry_observer_{this}; |
Devlin Cronin | 4d5fbc9 | 2019-07-01 19:11:35 | [diff] [blame] | 41 | |
| 42 | DISALLOW_COPY_AND_ASSIGN(ExtensionBrowserWindowHelper); |
| 43 | }; |
| 44 | |
| 45 | } // namespace extensions |
| 46 | |
| 47 | #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSER_WINDOW_HELPER_H_ |