Chromium Code Reviews| Index: chrome/browser/extensions/dev_mode_bubble_controller.cc |
| diff --git a/chrome/browser/extensions/dev_mode_bubble_controller.cc b/chrome/browser/extensions/dev_mode_bubble_controller.cc |
| index 885e62930333ec14cab8d7e31db9ff64b8c7551d..3ed21f4abdd964d67c5aadb0c1238d47779f6dc6 100644 |
| --- a/chrome/browser/extensions/dev_mode_bubble_controller.cc |
| +++ b/chrome/browser/extensions/dev_mode_bubble_controller.cc |
| @@ -5,6 +5,7 @@ |
| #include "chrome/browser/extensions/dev_mode_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/chrome_notification_types.h" |
| @@ -25,42 +26,18 @@ |
| namespace { |
| -static base::LazyInstance<extensions::ProfileKeyedAPIFactory< |
| - extensions::DevModeBubbleController> > |
| -g_factory = LAZY_INSTANCE_INITIALIZER; |
| +base::LazyInstance<std::set<Profile*> > g_shown_for_profiles = |
| + LAZY_INSTANCE_INITIALIZER; |
| } // namespace |
| namespace extensions { |
| //////////////////////////////////////////////////////////////////////////////// |
| -// DevModeBubbleController |
| - |
| -DevModeBubbleController::DevModeBubbleController( |
| - Profile* profile) |
| - : ExtensionMessageBubbleController(this, profile), |
| - service_(extensions::ExtensionSystem::Get(profile)->extension_service()), |
| - profile_(profile) { |
| -} |
| - |
| -DevModeBubbleController::~DevModeBubbleController() { |
| -} |
| - |
| -// static |
| -ProfileKeyedAPIFactory<DevModeBubbleController>* |
| -DevModeBubbleController::GetFactoryInstance() { |
| - return &g_factory.Get(); |
| -} |
| +// DevModeBubbleDelegate |
| // static |
| -DevModeBubbleController* DevModeBubbleController::Get( |
| - Profile* profile) { |
| - return ProfileKeyedAPIFactory< |
| - DevModeBubbleController>::GetForProfile(profile); |
| -} |
| - |
| -bool DevModeBubbleController::IsDevModeExtension( |
| - const Extension* extension) const { |
| +bool DevModeBubbleDelegate::IsDevModeExtension(const Extension* extension) { |
| if (!extensions::FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) { |
| if (chrome::VersionInfo::GetChannel() < |
| chrome::VersionInfo::CHANNEL_BETA) |
| @@ -70,7 +47,14 @@ bool DevModeBubbleController::IsDevModeExtension( |
| extension->location() == Manifest::COMMAND_LINE; |
| } |
| -bool DevModeBubbleController::ShouldIncludeExtension( |
| +DevModeBubbleDelegate::DevModeBubbleDelegate(Profile* profile) |
| + : service_(extensions::ExtensionSystem::Get(profile)->extension_service()) { |
|
not at google - send to devlin
2014/01/10 21:28:43
perhaps just pass in the ExtensionService directly
Finnur
2014/01/13 15:36:32
Done.
|
| +} |
| + |
| +DevModeBubbleDelegate::~DevModeBubbleDelegate() { |
| +} |
| + |
| +bool DevModeBubbleDelegate::ShouldIncludeExtension( |
| const std::string& extension_id) { |
| const Extension* extension = service_->GetExtensionById(extension_id, false); |
| if (!extension) |
| @@ -78,72 +62,88 @@ bool DevModeBubbleController::ShouldIncludeExtension( |
| return IsDevModeExtension(extension); |
| } |
| -void DevModeBubbleController::AcknowledgeExtension( |
| +void DevModeBubbleDelegate::AcknowledgeExtension( |
| const std::string& extension_id, |
| ExtensionMessageBubbleController::BubbleAction user_action) { |
| } |
| -void DevModeBubbleController::PerformAction( |
| +void DevModeBubbleDelegate::PerformAction( |
| const ExtensionIdList& list) { |
| for (size_t i = 0; i < list.size(); ++i) |
| service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION); |
| } |
| -base::string16 DevModeBubbleController::GetTitle() const { |
| +base::string16 DevModeBubbleDelegate::GetTitle() const { |
| return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE); |
| } |
| -base::string16 DevModeBubbleController::GetMessageBody() const { |
| +base::string16 DevModeBubbleDelegate::GetMessageBody() const { |
| return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY); |
| } |
| -base::string16 DevModeBubbleController::GetOverflowText( |
| +base::string16 DevModeBubbleDelegate::GetOverflowText( |
| const base::string16& overflow_count) const { |
| return l10n_util::GetStringFUTF16( |
| IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE, |
| overflow_count); |
| } |
| -base::string16 DevModeBubbleController::GetLearnMoreLabel() const { |
| +base::string16 DevModeBubbleDelegate::GetLearnMoreLabel() const { |
| return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| } |
| -GURL DevModeBubbleController::GetLearnMoreUrl() const { |
| +GURL DevModeBubbleDelegate::GetLearnMoreUrl() const { |
| return GURL(chrome::kChromeUIExtensionsURL); |
| } |
| -base::string16 DevModeBubbleController::GetActionButtonLabel() const { |
| +base::string16 DevModeBubbleDelegate::GetActionButtonLabel() const { |
| return l10n_util::GetStringUTF16(IDS_DISABLE); |
| } |
| -base::string16 DevModeBubbleController::GetDismissButtonLabel() const { |
| +base::string16 DevModeBubbleDelegate::GetDismissButtonLabel() const { |
| return l10n_util::GetStringUTF16(IDS_CANCEL); |
| } |
| -bool DevModeBubbleController::ShouldShowExtensionList() const { |
| +bool DevModeBubbleDelegate::ShouldShowExtensionList() const { |
| return false; |
| } |
| -std::vector<base::string16> DevModeBubbleController::GetExtensions() { |
| - return GetExtensionList(); |
| -} |
| - |
| -void DevModeBubbleController::LogExtensionCount(size_t count) { |
| +void DevModeBubbleDelegate::LogExtensionCount(size_t count) { |
| UMA_HISTOGRAM_COUNTS_100( |
| "DevModeExtensionBubble.ExtensionsInDevModeCount", count); |
| } |
| -void DevModeBubbleController::LogAction( |
| +void DevModeBubbleDelegate::LogAction( |
| ExtensionMessageBubbleController::BubbleAction action) { |
| UMA_HISTOGRAM_ENUMERATION( |
| "DevModeExtensionBubble.UserSelection", |
| action, ExtensionMessageBubbleController::ACTION_BOUNDARY); |
| } |
| -template <> |
| -void ProfileKeyedAPIFactory< |
| - DevModeBubbleController>::DeclareFactoryDependencies() { |
| - DependsOn(extensions::ExtensionSystemFactory::GetInstance()); |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// DevModeBubbleController |
| + |
| +DevModeBubbleController::DevModeBubbleController(Profile* profile) |
| + : ExtensionMessageBubbleController( |
| + new DevModeBubbleDelegate(profile), profile), |
| + profile_(profile) { |
| +} |
| + |
| +DevModeBubbleController::~DevModeBubbleController() { |
| +} |
| + |
| +bool DevModeBubbleController::ShouldShow() { |
| + return !g_shown_for_profiles.Get().count(profile_) && |
| + !GetExtensionList().empty(); |
| +} |
| + |
| +void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) { |
| + g_shown_for_profiles.Get().insert(profile_); |
| + ExtensionMessageBubbleController::Show(bubble); |
| +} |
| + |
| +void DevModeBubbleController::ClearProfileListForTesting() { |
| + g_shown_for_profiles.Get().clear(); |
| } |
| } // namespace extensions |