Index: chrome/browser/ui/cocoa/extensions/extension_action_context_menu.mm |
diff --git a/chrome/browser/ui/cocoa/extensions/extension_action_context_menu.mm b/chrome/browser/ui/cocoa/extensions/extension_action_context_menu.mm |
index 705276e95e3ebbaef453021d1216b7741b3b9905..b8475eac9cdb0ae944cfdb219df236101fc5a896 100644 |
--- a/chrome/browser/ui/cocoa/extensions/extension_action_context_menu.mm |
+++ b/chrome/browser/ui/cocoa/extensions/extension_action_context_menu.mm |
@@ -25,6 +25,7 @@ |
#include "chrome/common/extensions/extension_constants.h" |
#include "chrome/common/notification_details.h" |
#include "chrome/common/notification_observer.h" |
+#include "chrome/common/notification_source.h" |
#include "chrome/common/notification_type.h" |
#include "chrome/common/pref_names.h" |
#include "chrome/common/url_constants.h" |
@@ -92,6 +93,34 @@ class DevmodeObserver : public NotificationObserver { |
PrefChangeRegistrar registrar_; |
}; |
+class ProfileObserverBridge : public NotificationObserver { |
+ public: |
+ ProfileObserverBridge(ExtensionActionContextMenu* owner, |
+ const Profile* profile) |
+ : owner_(owner), |
+ profile_(profile) { |
+ registrar_.Add(this, NotificationType::PROFILE_DESTROYED, |
+ Source<Profile>(profile)); |
+ } |
+ |
+ ~ProfileObserverBridge() {} |
+ |
+ // Overridden from NotificationObserver |
+ void Observe(NotificationType type, |
+ const NotificationSource& source, |
+ const NotificationDetails& details) { |
+ if (type == NotificationType::PROFILE_DESTROYED && |
+ source == Source<Profile>(profile_)) { |
+ [owner_ invalidateProfile]; |
+ } |
+ } |
+ |
+ private: |
+ ExtensionActionContextMenu* owner_; |
+ const Profile* profile_; |
+ NotificationRegistrar registrar_; |
+}; |
+ |
} // namespace extension_action_context_menu |
@interface ExtensionActionContextMenu(Private) |
@@ -177,6 +206,9 @@ int CurrentTabId() { |
PrefService* service = profile_->GetPrefs(); |
observer_.reset( |
new extension_action_context_menu::DevmodeObserver(self, service)); |
+ profile_observer_.reset( |
+ new extension_action_context_menu::ProfileObserverBridge(self, |
+ profile)); |
[self updateInspectorItem]; |
return self; |
@@ -275,4 +307,9 @@ int CurrentTabId() { |
return YES; |
} |
+- (void)invalidateProfile { |
+ observer_.reset(); |
+ profile_ = NULL; |
+} |
+ |
@end |