summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-13 22:22:23 +0000
committeryoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-13 22:22:23 +0000
commit8b280303f86249ce8d13916fcda774a3129ac9ac (patch)
treef015f72f91927f0651cfcf1b2d5123ae5de89154
parentc08950d205ff5366e6e26059cd6568cb89b28c90 (diff)
downloadchromium_src-8b280303f86249ce8d13916fcda774a3129ac9ac.zip
chromium_src-8b280303f86249ce8d13916fcda774a3129ac9ac.tar.gz
chromium_src-8b280303f86249ce8d13916fcda774a3129ac9ac.tar.bz2
Fix some AllSources observers of EXTENSION_UNLOADED.
Most such observers use it to remove state they are tracking about particular extensions. extension_menu_manager should be okay even without this. desktop_notification_service might have had subtle wrongness. BUG=99391 TEST=existing tests Review URL: http://codereview.chromium.org/8253005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105390 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/extension_menu_manager.cc10
-rw-r--r--chrome/browser/extensions/extension_menu_manager.h2
-rw-r--r--chrome/browser/extensions/extension_menu_manager_unittest.cc4
-rw-r--r--chrome/browser/extensions/extension_service.cc1
-rw-r--r--chrome/browser/notifications/desktop_notification_service.cc6
5 files changed, 12 insertions, 11 deletions
diff --git a/chrome/browser/extensions/extension_menu_manager.cc b/chrome/browser/extensions/extension_menu_manager.cc
index eb2038e..cf282d4 100644
--- a/chrome/browser/extensions/extension_menu_manager.cc
+++ b/chrome/browser/extensions/extension_menu_manager.cc
@@ -92,9 +92,9 @@ void ExtensionMenuItem::AddChild(ExtensionMenuItem* item) {
children_.push_back(item);
}
-ExtensionMenuManager::ExtensionMenuManager() {
+ExtensionMenuManager::ExtensionMenuManager(Profile* profile) {
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
- NotificationService::AllSources());
+ Source<Profile>(profile));
}
ExtensionMenuManager::~ExtensionMenuManager() {
@@ -449,11 +449,9 @@ void ExtensionMenuManager::ExecuteCommand(
void ExtensionMenuManager::Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) {
+ DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED);
+
// Remove menu items for disabled/uninstalled extensions.
- if (type != chrome::NOTIFICATION_EXTENSION_UNLOADED) {
- NOTREACHED();
- return;
- }
const Extension* extension =
Details<UnloadedExtensionInfo>(details)->extension;
if (ContainsKey(context_items_, extension->id())) {
diff --git a/chrome/browser/extensions/extension_menu_manager.h b/chrome/browser/extensions/extension_menu_manager.h
index af8345f..3d39950 100644
--- a/chrome/browser/extensions/extension_menu_manager.h
+++ b/chrome/browser/extensions/extension_menu_manager.h
@@ -194,7 +194,7 @@ class ExtensionMenuItem {
// This class keeps track of menu items added by extensions.
class ExtensionMenuManager : public NotificationObserver {
public:
- ExtensionMenuManager();
+ explicit ExtensionMenuManager(Profile* profile);
virtual ~ExtensionMenuManager();
// Returns the ids of extensions which have menu items registered.
diff --git a/chrome/browser/extensions/extension_menu_manager_unittest.cc b/chrome/browser/extensions/extension_menu_manager_unittest.cc
index eef1afd..a1bfdbb 100644
--- a/chrome/browser/extensions/extension_menu_manager_unittest.cc
+++ b/chrome/browser/extensions/extension_menu_manager_unittest.cc
@@ -35,6 +35,7 @@ class ExtensionMenuManagerTest : public testing::Test {
ExtensionMenuManagerTest()
: ui_thread_(BrowserThread::UI, &message_loop_),
file_thread_(BrowserThread::FILE, &message_loop_),
+ manager_(&profile_),
next_id_(1) {
}
@@ -55,6 +56,7 @@ class ExtensionMenuManagerTest : public testing::Test {
}
protected:
+ TestingProfile profile_;
MessageLoopForUI message_loop_;
BrowserThread ui_thread_;
BrowserThread file_thread_;
@@ -333,7 +335,7 @@ TEST_F(ExtensionMenuManagerTest, ExtensionUnloadRemovesMenuItems) {
UnloadedExtensionInfo details(
extension1, extension_misc::UNLOAD_REASON_DISABLE);
notifier->Notify(chrome::NOTIFICATION_EXTENSION_UNLOADED,
- Source<Profile>(NULL),
+ Source<Profile>(&profile_),
Details<UnloadedExtensionInfo>(&details));
ASSERT_EQ(NULL, manager_.MenuItems(extension1->id()));
ASSERT_EQ(1u, manager_.MenuItems(extension2->id())->size());
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index ceaa22e..0d21a53 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -602,6 +602,7 @@ ExtensionService::ExtensionService(Profile* profile,
show_extensions_prompts_(true),
ready_(false),
toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
+ menu_manager_(profile),
app_notification_manager_(new AppNotificationManager(profile)),
permissions_manager_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
apps_promo_(profile->GetPrefs()),
diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc
index 09451ed..3f77f43 100644
--- a/chrome/browser/notifications/desktop_notification_service.cc
+++ b/chrome/browser/notifications/desktop_notification_service.cc
@@ -226,7 +226,7 @@ DesktopNotificationService::~DesktopNotificationService() {
void DesktopNotificationService::StartObserving() {
if (!profile_->IsOffTheRecord()) {
notification_registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
- NotificationService::AllSources());
+ Source<Profile>(profile_));
}
notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
Source<Profile>(profile_));
@@ -261,14 +261,14 @@ void DesktopNotificationService::DenyPermission(const GURL& origin) {
void DesktopNotificationService::Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) {
- if (chrome::NOTIFICATION_EXTENSION_UNLOADED == type) {
+ if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
// Remove all notifications currently shown or queued by the extension
// which was unloaded.
const Extension* extension =
Details<UnloadedExtensionInfo>(details)->extension;
if (extension)
ui_manager_->CancelAllBySourceOrigin(extension->url());
- } else if (chrome::NOTIFICATION_PROFILE_DESTROYED == type) {
+ } else if (type == chrome::NOTIFICATION_PROFILE_DESTROYED) {
StopObserving();
}
}