Chromium Code Reviews| Index: chrome/browser/extensions/extension_disabled_ui.cc |
| diff --git a/chrome/browser/extensions/extension_disabled_ui.cc b/chrome/browser/extensions/extension_disabled_ui.cc |
| index 42767a1bf1f50f90fb4f771d9bf01f22a57dbf10..77c65e2064f50c72db7a692aa8f40c9f902c43e1 100644 |
| --- a/chrome/browser/extensions/extension_disabled_ui.cc |
| +++ b/chrome/browser/extensions/extension_disabled_ui.cc |
| @@ -7,9 +7,11 @@ |
| #include <string> |
| #include "base/bind.h" |
| +#include "base/callback_forward.h" |
| #include "base/lazy_instance.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| #include "base/message_loop/message_loop.h" |
| #include "base/metrics/histogram.h" |
| #include "base/strings/utf_string_conversions.h" |
| @@ -168,6 +170,9 @@ class ExtensionDisabledGlobalError : public GlobalError, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) OVERRIDE; |
| + // Callback to notify UI that extension has been removed. |
| + void HandleExtensionRemoved(const Extension* extension); |
| + |
| private: |
| ExtensionService* service_; |
| const Extension* extension_; |
| @@ -188,6 +193,8 @@ class ExtensionDisabledGlobalError : public GlobalError, |
| int menu_command_id_; |
| content::NotificationRegistrar registrar_; |
| + base::WeakPtrFactory<ExtensionDisabledGlobalError> weak_factory_; |
| + base::Callback<void(const Extension*)> on_removed_callback_; |
| }; |
| // TODO(yoz): create error at startup for disabled extensions. |
| @@ -199,7 +206,8 @@ ExtensionDisabledGlobalError::ExtensionDisabledGlobalError( |
| extension_(extension), |
| icon_(icon), |
| user_response_(IGNORED), |
| - menu_command_id_(GetMenuCommandID()) { |
| + menu_command_id_(GetMenuCommandID()), |
| + weak_factory_(this) { |
| if (icon_.IsEmpty()) { |
| icon_ = gfx::Image( |
| gfx::ImageSkiaOperations::CreateResizedImage( |
| @@ -209,10 +217,12 @@ ExtensionDisabledGlobalError::ExtensionDisabledGlobalError( |
| skia::ImageOperations::RESIZE_BEST, |
| gfx::Size(kIconSize, kIconSize))); |
| } |
| + on_removed_callback_ = base::Bind( |
| + &ExtensionDisabledGlobalError::HandleExtensionRemoved, |
| + weak_factory_.GetWeakPtr()); |
| + service_->RegisterExtensionRemovedCallback(on_removed_callback_); |
| registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| content::Source<Profile>(service->profile())); |
| - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_REMOVED, |
| - content::Source<Profile>(service->profile())); |
| } |
| ExtensionDisabledGlobalError::~ExtensionDisabledGlobalError() { |
| @@ -319,18 +329,24 @@ void ExtensionDisabledGlobalError::Observe( |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |
| // The error is invalidated if the extension has been loaded or removed. |
| - DCHECK(type == chrome::NOTIFICATION_EXTENSION_LOADED || |
| - type == chrome::NOTIFICATION_EXTENSION_REMOVED); |
| + DCHECK(type == chrome::NOTIFICATION_EXTENSION_LOADED); |
| const Extension* extension = content::Details<const Extension>(details).ptr(); |
| if (extension != extension_) |
| return; |
| GlobalErrorServiceFactory::GetForProfile(service_->profile())-> |
| RemoveGlobalError(this); |
| + user_response_ = REENABLE; |
| + delete this; |
| +} |
| - if (type == chrome::NOTIFICATION_EXTENSION_LOADED) |
| - user_response_ = REENABLE; |
| - else if (type == chrome::NOTIFICATION_EXTENSION_REMOVED) |
| - user_response_ = UNINSTALL; |
| +void ExtensionDisabledGlobalError::HandleExtensionRemoved( |
| + const Extension* extension) { |
| + if (extension != extension_) |
| + return; |
| + GlobalErrorServiceFactory::GetForProfile(service_->profile())-> |
| + RemoveGlobalError(this); |
| + user_response_ = UNINSTALL; |
| + service_->RemoveExtensionRemovedCallback(on_removed_callback_); |
|
Yoyo Zhou
2013/08/22 16:50:26
Seems like this should be in the destructor instea
Cait (Slow)
2013/08/26 18:01:46
Done.
|
| delete this; |
| } |