Commit 731ce553 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Remove NOTIFICATION_PROFILE_DESTROYED from extensions::MenuManager

Bug: 268984
Change-Id: I4c22030636127c620c3a0af2fbf9b1d9635d15c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1869025Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708340}
parent ca12a09d
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_tab_util.h" #include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/menu_manager_factory.h" #include "chrome/browser/extensions/menu_manager_factory.h"
#include "chrome/browser/extensions/tab_helper.h" #include "chrome/browser/extensions/tab_helper.h"
...@@ -24,9 +23,6 @@ ...@@ -24,9 +23,6 @@
#include "chrome/common/extensions/api/chrome_web_view_internal.h" #include "chrome/common/extensions/api/chrome_web_view_internal.h"
#include "chrome/common/extensions/api/context_menus.h" #include "chrome/common/extensions/api/context_menus.h"
#include "chrome/common/extensions/api/url_handlers/url_handlers_parser.h" #include "chrome/common/extensions/api/url_handlers/url_handlers_parser.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/child_process_host.h" #include "content/public/common/child_process_host.h"
#include "content/public/common/context_menu_params.h" #include "content/public/common/context_menu_params.h"
...@@ -317,14 +313,15 @@ const char MenuManager::kOnWebviewContextMenus[] = ...@@ -317,14 +313,15 @@ const char MenuManager::kOnWebviewContextMenus[] =
MenuManager::MenuManager(content::BrowserContext* context, StateStore* store) MenuManager::MenuManager(content::BrowserContext* context, StateStore* store)
: browser_context_(context), store_(store) { : browser_context_(context), store_(store) {
extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, Profile* profile = Profile::FromBrowserContext(context);
content::NotificationService::AllSources()); observed_profiles_.Add(profile);
if (profile->HasOffTheRecordProfile())
observed_profiles_.Add(profile->GetOffTheRecordProfile());
if (store_) if (store_)
store_->RegisterKey(kContextMenusKey); store_->RegisterKey(kContextMenusKey);
} }
MenuManager::~MenuManager() { MenuManager::~MenuManager() = default;
}
// static // static
MenuManager* MenuManager::Get(content::BrowserContext* context) { MenuManager* MenuManager::Get(content::BrowserContext* context) {
...@@ -883,18 +880,14 @@ void MenuManager::OnExtensionUnloaded(content::BrowserContext* browser_context, ...@@ -883,18 +880,14 @@ void MenuManager::OnExtensionUnloaded(content::BrowserContext* browser_context,
} }
} }
void MenuManager::Observe(int type, void MenuManager::OnOffTheRecordProfileCreated(Profile* off_the_record) {
const content::NotificationSource& source, observed_profiles_.Add(off_the_record);
const content::NotificationDetails& details) { }
DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type);
Profile* profile = content::Source<Profile>(source).ptr(); void MenuManager::OnProfileWillBeDestroyed(Profile* profile) {
// We cannot use profile_->HasOffTheRecordProfile as it may already be observed_profiles_.Remove(profile);
// false at this point, if for example the incognito profile was destroyed if (profile->IsOffTheRecord())
// using DestroyOffTheRecordProfile.
if (profile->GetOriginalProfile() == browser_context_ &&
profile->GetOriginalProfile() != profile) {
RemoveAllIncognitoContextItems(); RemoveAllIncognitoContextItems();
}
} }
gfx::Image MenuManager::GetIconForExtension(const std::string& extension_id) { gfx::Image MenuManager::GetIconForExtension(const std::string& extension_id) {
......
...@@ -22,9 +22,9 @@ ...@@ -22,9 +22,9 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/extensions/extension_icon_manager.h" #include "chrome/browser/extensions/extension_icon_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_registry_observer.h" #include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/url_pattern_set.h" #include "extensions/common/url_pattern_set.h"
...@@ -282,7 +282,7 @@ class MenuItem { ...@@ -282,7 +282,7 @@ class MenuItem {
}; };
// This class keeps track of menu items added by extensions. // This class keeps track of menu items added by extensions.
class MenuManager : public content::NotificationObserver, class MenuManager : public ProfileObserver,
public base::SupportsWeakPtr<MenuManager>, public base::SupportsWeakPtr<MenuManager>,
public KeyedService, public KeyedService,
public ExtensionRegistryObserver { public ExtensionRegistryObserver {
...@@ -355,10 +355,9 @@ class MenuManager : public content::NotificationObserver, ...@@ -355,10 +355,9 @@ class MenuManager : public content::NotificationObserver,
// default extension icon. // default extension icon.
gfx::Image GetIconForExtension(const std::string& extension_id); gfx::Image GetIconForExtension(const std::string& extension_id);
// content::NotificationObserver implementation. // ProfileObserver:
void Observe(int type, void OnOffTheRecordProfileCreated(Profile* off_the_record) override;
const content::NotificationSource& source, void OnProfileWillBeDestroyed(Profile* profile) override;
const content::NotificationDetails& details) override;
// ExtensionRegistryObserver implementation. // ExtensionRegistryObserver implementation.
void OnExtensionLoaded(content::BrowserContext* browser_context, void OnExtensionLoaded(content::BrowserContext* browser_context,
...@@ -404,12 +403,12 @@ class MenuManager : public content::NotificationObserver, ...@@ -404,12 +403,12 @@ class MenuManager : public content::NotificationObserver,
// items. // items.
std::map<MenuItem::Id, MenuItem*> items_by_id_; std::map<MenuItem::Id, MenuItem*> items_by_id_;
content::NotificationRegistrar registrar_; // Listen to extension load, unloaded events.
// Listen to extension load, unloaded notifications.
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
extension_registry_observer_{this}; extension_registry_observer_{this};
ScopedObserver<Profile, ProfileObserver> observed_profiles_{this};
ExtensionIconManager icon_manager_; ExtensionIconManager icon_manager_;
content::BrowserContext* browser_context_; content::BrowserContext* browser_context_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment