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 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/menu_manager_factory.h"
#include "chrome/browser/extensions/tab_helper.h"
......@@ -24,9 +23,6 @@
#include "chrome/common/extensions/api/chrome_web_view_internal.h"
#include "chrome/common/extensions/api/context_menus.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/common/child_process_host.h"
#include "content/public/common/context_menu_params.h"
......@@ -317,14 +313,15 @@ const char MenuManager::kOnWebviewContextMenus[] =
MenuManager::MenuManager(content::BrowserContext* context, StateStore* store)
: browser_context_(context), store_(store) {
extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
content::NotificationService::AllSources());
Profile* profile = Profile::FromBrowserContext(context);
observed_profiles_.Add(profile);
if (profile->HasOffTheRecordProfile())
observed_profiles_.Add(profile->GetOffTheRecordProfile());
if (store_)
store_->RegisterKey(kContextMenusKey);
}
MenuManager::~MenuManager() {
}
MenuManager::~MenuManager() = default;
// static
MenuManager* MenuManager::Get(content::BrowserContext* context) {
......@@ -883,18 +880,14 @@ void MenuManager::OnExtensionUnloaded(content::BrowserContext* browser_context,
}
}
void MenuManager::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type);
Profile* profile = content::Source<Profile>(source).ptr();
// We cannot use profile_->HasOffTheRecordProfile as it may already be
// false at this point, if for example the incognito profile was destroyed
// using DestroyOffTheRecordProfile.
if (profile->GetOriginalProfile() == browser_context_ &&
profile->GetOriginalProfile() != profile) {
void MenuManager::OnOffTheRecordProfileCreated(Profile* off_the_record) {
observed_profiles_.Add(off_the_record);
}
void MenuManager::OnProfileWillBeDestroyed(Profile* profile) {
observed_profiles_.Remove(profile);
if (profile->IsOffTheRecord())
RemoveAllIncognitoContextItems();
}
}
gfx::Image MenuManager::GetIconForExtension(const std::string& extension_id) {
......
......@@ -22,9 +22,9 @@
#include "base/strings/string16.h"
#include "base/values.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 "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/url_pattern_set.h"
......@@ -282,7 +282,7 @@ class MenuItem {
};
// This class keeps track of menu items added by extensions.
class MenuManager : public content::NotificationObserver,
class MenuManager : public ProfileObserver,
public base::SupportsWeakPtr<MenuManager>,
public KeyedService,
public ExtensionRegistryObserver {
......@@ -355,10 +355,9 @@ class MenuManager : public content::NotificationObserver,
// default extension icon.
gfx::Image GetIconForExtension(const std::string& extension_id);
// content::NotificationObserver implementation.
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
// ProfileObserver:
void OnOffTheRecordProfileCreated(Profile* off_the_record) override;
void OnProfileWillBeDestroyed(Profile* profile) override;
// ExtensionRegistryObserver implementation.
void OnExtensionLoaded(content::BrowserContext* browser_context,
......@@ -404,12 +403,12 @@ class MenuManager : public content::NotificationObserver,
// items.
std::map<MenuItem::Id, MenuItem*> items_by_id_;
content::NotificationRegistrar registrar_;
// Listen to extension load, unloaded notifications.
// Listen to extension load, unloaded events.
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
extension_registry_observer_{this};
ScopedObserver<Profile, ProfileObserver> observed_profiles_{this};
ExtensionIconManager icon_manager_;
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