[Extensions] Don't dispatch a chrome update event unconditionally
Currently, we always dispatch the onInstalled event, regardless of
whether an extension has registered a listener. The reason for this is
because if an extension is just installed (either a first installation
or an update), then it won't have registered its listeners, and we won't
know if we need to dispatch the event or not.
However, we also dispatch the onInstalled event in the case of chrome
updates (see crbug.com/148898). In this case, there's no reason we
wouldn't know whether an extension has registered a listener for the
onInstalled event, so we can choose to only dispatch the event if a
listener is registered.
Add a test ensuring extensions are only woken when a listener is
registered.
BUG=451268
Review-Url: https://codereview.chromium.org/2941153002
Cr-Commit-Position: refs/heads/master@{#481583}
diff --git a/chrome/browser/extensions/chrome_extensions_browser_client.cc b/chrome/browser/extensions/chrome_extensions_browser_client.cc
index 0e03d73..c7aee0a 100644
--- a/chrome/browser/extensions/chrome_extensions_browser_client.cc
+++ b/chrome/browser/extensions/chrome_extensions_browser_client.cc
@@ -72,6 +72,14 @@
namespace extensions {
+namespace {
+
+// If true, the extensions client will behave as though there is always a
+// new chrome update.
+bool g_did_chrome_update_for_testing = false;
+
+} // namespace
+
ChromeExtensionsBrowserClient::ChromeExtensionsBrowserClient() {
process_manager_delegate_.reset(new ChromeProcessManagerDelegate);
api_client_.reset(new ChromeExtensionsAPIClient);
@@ -209,6 +217,9 @@
if (!extension_prefs)
return false;
+ if (g_did_chrome_update_for_testing)
+ return true;
+
// If we're inside a browser test, then assume prefs are all up to date.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType))
return false;
@@ -450,4 +461,11 @@
return false;
#endif
}
+
+// static
+void ChromeExtensionsBrowserClient::set_did_chrome_update_for_testing(
+ bool did_update) {
+ g_did_chrome_update_for_testing = did_update;
+}
+
} // namespace extensions