Chromium Code Reviews| Index: chrome/browser/extensions/suspicious_extension_bubble_controller.cc |
| diff --git a/chrome/browser/extensions/suspicious_extension_bubble_controller.cc b/chrome/browser/extensions/suspicious_extension_bubble_controller.cc |
| index 736acd9c229e11138e9e7187e68188b2c945c9fd..d72673565b1b0705a5340fb05ebac74ae93b3428 100644 |
| --- a/chrome/browser/extensions/suspicious_extension_bubble_controller.cc |
| +++ b/chrome/browser/extensions/suspicious_extension_bubble_controller.cc |
| @@ -5,6 +5,7 @@ |
| #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" |
| #include "base/bind.h" |
| +#include "base/lazy_instance.h" |
| #include "base/metrics/histogram.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "chrome/browser/extensions/extension_message_bubble.h" |
| @@ -20,42 +21,25 @@ |
| namespace { |
| -static base::LazyInstance<extensions::ProfileKeyedAPIFactory< |
| - extensions::SuspiciousExtensionBubbleController> > |
| -g_factory = LAZY_INSTANCE_INITIALIZER; |
| +base::LazyInstance<std::set<Profile*> > g_shown_for_profiles = |
| + LAZY_INSTANCE_INITIALIZER; |
| } // namespace |
| namespace extensions { |
| //////////////////////////////////////////////////////////////////////////////// |
| -// SuspiciousExtensionBubbleController |
| +// SuspiciousExtensionBubbleDelegate |
| -SuspiciousExtensionBubbleController::SuspiciousExtensionBubbleController( |
| +SuspiciousExtensionBubbleDelegate::SuspiciousExtensionBubbleDelegate( |
| Profile* profile) |
| - : ExtensionMessageBubbleController(this, profile), |
| - service_(extensions::ExtensionSystem::Get(profile)->extension_service()), |
| - profile_(profile) { |
| -} |
| - |
| -SuspiciousExtensionBubbleController:: |
| - ~SuspiciousExtensionBubbleController() { |
| -} |
| - |
| -// static |
| -ProfileKeyedAPIFactory<SuspiciousExtensionBubbleController>* |
| -SuspiciousExtensionBubbleController::GetFactoryInstance() { |
| - return &g_factory.Get(); |
| + : service_(extensions::ExtensionSystem::Get(profile)->extension_service()) { |
|
not at google - send to devlin
2014/01/10 21:28:43
likewise, only need prefs not whole profile
Finnur
2014/01/13 15:36:32
Done.
|
| } |
| -// static |
| -SuspiciousExtensionBubbleController* |
| -SuspiciousExtensionBubbleController::Get(Profile* profile) { |
| - return ProfileKeyedAPIFactory< |
| - SuspiciousExtensionBubbleController>::GetForProfile(profile); |
| +SuspiciousExtensionBubbleDelegate::~SuspiciousExtensionBubbleDelegate() { |
| } |
| -bool SuspiciousExtensionBubbleController::ShouldIncludeExtension( |
| +bool SuspiciousExtensionBubbleDelegate::ShouldIncludeExtension( |
| const std::string& extension_id) { |
| ExtensionPrefs* prefs = service_->extension_prefs(); |
| if (!prefs->IsExtensionDisabled(extension_id)) |
| @@ -68,29 +52,29 @@ bool SuspiciousExtensionBubbleController::ShouldIncludeExtension( |
| return false; |
| } |
| -void SuspiciousExtensionBubbleController::AcknowledgeExtension( |
| +void SuspiciousExtensionBubbleDelegate::AcknowledgeExtension( |
| const std::string& extension_id, |
| ExtensionMessageBubbleController::BubbleAction user_action) { |
| ExtensionPrefs* prefs = service_->extension_prefs(); |
| prefs->SetWipeoutAcknowledged(extension_id, true); |
| } |
| -void SuspiciousExtensionBubbleController::PerformAction( |
| +void SuspiciousExtensionBubbleDelegate::PerformAction( |
| const ExtensionIdList& list) { |
| // This bubble solicits no action from the user. Or as Nimoy would have it: |
| // "Well, my work here is done". |
| } |
| -base::string16 SuspiciousExtensionBubbleController::GetTitle() const { |
| +base::string16 SuspiciousExtensionBubbleDelegate::GetTitle() const { |
| return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_TITLE); |
| } |
| -base::string16 SuspiciousExtensionBubbleController::GetMessageBody() const { |
| +base::string16 SuspiciousExtensionBubbleDelegate::GetMessageBody() const { |
| return l10n_util::GetStringFUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_BODY, |
| l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)); |
| } |
| -base::string16 SuspiciousExtensionBubbleController::GetOverflowText( |
| +base::string16 SuspiciousExtensionBubbleDelegate::GetOverflowText( |
| const base::string16& overflow_count) const { |
| base::string16 overflow_string = l10n_util::GetStringUTF16( |
| IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE); |
| @@ -112,51 +96,67 @@ base::string16 SuspiciousExtensionBubbleController::GetOverflowText( |
| } |
| base::string16 |
| -SuspiciousExtensionBubbleController::GetLearnMoreLabel() const { |
| +SuspiciousExtensionBubbleDelegate::GetLearnMoreLabel() const { |
| return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| } |
| -GURL SuspiciousExtensionBubbleController::GetLearnMoreUrl() const { |
| +GURL SuspiciousExtensionBubbleDelegate::GetLearnMoreUrl() const { |
| return GURL(chrome::kRemoveNonCWSExtensionURL); |
| } |
| base::string16 |
| -SuspiciousExtensionBubbleController::GetActionButtonLabel() const { |
| +SuspiciousExtensionBubbleDelegate::GetActionButtonLabel() const { |
| return base::string16(); |
| } |
| base::string16 |
| -SuspiciousExtensionBubbleController::GetDismissButtonLabel() const { |
| +SuspiciousExtensionBubbleDelegate::GetDismissButtonLabel() const { |
| return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_BUTTON); |
| } |
| bool |
| -SuspiciousExtensionBubbleController::ShouldShowExtensionList() const { |
| +SuspiciousExtensionBubbleDelegate::ShouldShowExtensionList() const { |
| return true; |
| } |
| -std::vector<base::string16> |
| -SuspiciousExtensionBubbleController::GetExtensions() { |
| - return GetExtensionList(); |
| -} |
| - |
| -void SuspiciousExtensionBubbleController::LogExtensionCount( |
| +void SuspiciousExtensionBubbleDelegate::LogExtensionCount( |
| size_t count) { |
| UMA_HISTOGRAM_COUNTS_100( |
| "ExtensionWipeoutBubble.ExtensionWipeoutCount", count); |
| } |
| -void SuspiciousExtensionBubbleController::LogAction( |
| +void SuspiciousExtensionBubbleDelegate::LogAction( |
| ExtensionMessageBubbleController::BubbleAction action) { |
| UMA_HISTOGRAM_ENUMERATION( |
| "ExtensionWipeoutBubble.UserSelection", |
| action, ExtensionMessageBubbleController::ACTION_BOUNDARY); |
| } |
| -template <> |
| -void ProfileKeyedAPIFactory< |
| - SuspiciousExtensionBubbleController>::DeclareFactoryDependencies() { |
| - DependsOn(extensions::ExtensionSystemFactory::GetInstance()); |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// SuspiciousExtensionBubbleController |
| + |
| +SuspiciousExtensionBubbleController::SuspiciousExtensionBubbleController( |
| + Profile* profile) |
| + : ExtensionMessageBubbleController( |
| + new SuspiciousExtensionBubbleDelegate(profile), profile), |
| + profile_(profile) { |
| +} |
| + |
| +SuspiciousExtensionBubbleController::~SuspiciousExtensionBubbleController() { |
| +} |
| + |
| +bool SuspiciousExtensionBubbleController::ShouldShow() { |
| + return !g_shown_for_profiles.Get().count(profile_) && |
| + !GetExtensionList().empty(); |
| +} |
| + |
| +void SuspiciousExtensionBubbleController::Show(ExtensionMessageBubble* bubble) { |
| + g_shown_for_profiles.Get().insert(profile_); |
| + ExtensionMessageBubbleController::Show(bubble); |
| +} |
| + |
| +void SuspiciousExtensionBubbleController::ClearProfileListForTesting() { |
| + g_shown_for_profiles.Get().clear(); |
| } |
| } // namespace extensions |