[Extensions] Move ExtensionRegistry watching out of browser.cc
Extract the ExtensionRegistry observation from browser.cc to a dedicated
ExtensionBrowserWindowHelper class, and have this class handle the
cleaning up of tab state, updating the toolbar, and notifying the
command controller. This helps a) reduce the already-massive browser.cc
file, and b) move a bit more extension-related code to an extensions
class.
This should have no behavior change.
Bug: None
Test: Covered by existing tests
Change-Id: Ia2d7b09dde6dbda1349ff8ca0df7d51b65df5037
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1672763
Commit-Queue: Devlin <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Reviewed-by: Istiaque Ahmed <[email protected]>
Cr-Commit-Position: refs/heads/master@{#673771}
diff --git a/chrome/browser/extensions/extension_browser_window_helper.h b/chrome/browser/extensions/extension_browser_window_helper.h
new file mode 100644
index 0000000..3ba0c49
--- /dev/null
+++ b/chrome/browser/extensions/extension_browser_window_helper.h
@@ -0,0 +1,46 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSER_WINDOW_HELPER_H_
+#define CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSER_WINDOW_HELPER_H_
+
+#include "base/macros.h"
+#include "base/scoped_observer.h"
+#include "extensions/browser/extension_registry_observer.h"
+
+class Browser;
+
+namespace extensions {
+
+// A helper object for extensions-related management for Browser* objects.
+class ExtensionBrowserWindowHelper : public ExtensionRegistryObserver {
+ public:
+ // Note: |browser| must outlive this object.
+ explicit ExtensionBrowserWindowHelper(Browser* browser);
+ ~ExtensionBrowserWindowHelper() override;
+
+ private:
+ // ExtensionRegistryObserver:
+ void OnExtensionLoaded(content::BrowserContext* browser_context,
+ const Extension* extension) override;
+ void OnExtensionUnloaded(content::BrowserContext* browser_context,
+ const Extension* extension,
+ UnloadedExtensionReason reason) override;
+
+ // Closes any tabs owned by the extension with the given |extension_id| and
+ // unmutes others if necessary.
+ void CleanUpTabsOnUnload(const ExtensionId& extension_id);
+
+ // The associated browser. Must outlive this object.
+ Browser* const browser_ = nullptr;
+
+ ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
+ registry_observer_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExtensionBrowserWindowHelper);
+};
+
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSER_WINDOW_HELPER_H_