Migrate upgrade notifications to observer
NotificationService makes it too easy for a random piece of code to hook
into another, so this CL migrates upgrade notification to observer.
BUG=724540,268984
Review-Url: https://codereview.chromium.org/2925973002
Cr-Commit-Position: refs/heads/master@{#478127}
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index 66bbac7..2e7bc53 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -60,6 +60,7 @@
#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
#include "chrome/browser/ui/webui/favicon_source.h"
#include "chrome/browser/ui/webui/theme_source.h"
+#include "chrome/browser/upgrade_detector.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/crash_keys.h"
#include "chrome/common/extensions/extension_constants.h"
@@ -351,12 +352,12 @@
content::NotificationService::AllBrowserContextsAndSources());
registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
content::NotificationService::AllBrowserContextsAndSources());
- registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
- content::NotificationService::AllBrowserContextsAndSources());
registrar_.Add(this,
chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
content::Source<Profile>(profile_));
+ UpgradeDetector::GetInstance()->AddObserver(this);
+
extensions::ExtensionManagementFactory::GetForBrowserContext(profile_)
->AddObserver(this);
@@ -413,6 +414,7 @@
}
ExtensionService::~ExtensionService() {
+ UpgradeDetector::GetInstance()->RemoveObserver(this);
// No need to unload extensions here because they are profile-scoped, and the
// profile is in the process of being deleted.
for (const auto& provider : external_extension_providers_)
@@ -2248,12 +2250,6 @@
system_->info_map(), process->GetID()));
break;
}
- case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
- // Notify observers that chrome update is available.
- for (auto& observer : update_observers_)
- observer.OnChromeUpdateAvailable();
- break;
- }
case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: {
OnProfileDestructionStarted();
break;
@@ -2359,6 +2355,12 @@
base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
}
+void ExtensionService::OnUpgradeRecommended() {
+ // Notify observers that chrome update is available.
+ for (auto& observer : update_observers_)
+ observer.OnChromeUpdateAvailable();
+}
+
void ExtensionService::ManageBlacklist(
const extensions::Blacklist::BlacklistStateMap& state_map) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);