Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2457)

Unified Diff: chrome/browser/extensions/dev_mode_bubble_controller.cc

Issue 134103002: Refactor the extension message bubbles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..b8eb88df18047f38d47d10527bde6c0bdcd77638 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,125 +26,131 @@
namespace {
-static base::LazyInstance<extensions::ProfileKeyedAPIFactory<
- extensions::DevModeBubbleController> >
-g_factory = LAZY_INSTANCE_INITIALIZER;
-
-} // namespace
-
-namespace extensions {
+base::LazyInstance<std::set<Profile*> > g_shown_for_profiles =
+ LAZY_INSTANCE_INITIALIZER;
////////////////////////////////////////////////////////////////////////////////
-// 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);
+DevModeBubbleDelegate::DevModeBubbleDelegate(ExtensionService* service)
+ : service_(service) {
}
-bool DevModeBubbleController::IsDevModeExtension(
- const Extension* extension) const {
- if (!extensions::FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) {
- if (chrome::VersionInfo::GetChannel() <
- chrome::VersionInfo::CHANNEL_BETA)
- return false;
- }
- return extension->location() == Manifest::UNPACKED ||
- extension->location() == Manifest::COMMAND_LINE;
+DevModeBubbleDelegate::~DevModeBubbleDelegate() {
}
-bool DevModeBubbleController::ShouldIncludeExtension(
+bool DevModeBubbleDelegate::ShouldIncludeExtension(
const std::string& extension_id) {
- const Extension* extension = service_->GetExtensionById(extension_id, false);
+ const extensions::Extension* extension =
+ service_->GetExtensionById(extension_id, false);
if (!extension)
return false;
- return IsDevModeExtension(extension);
+ return extensions::DevModeBubbleController::IsDevModeExtension(extension);
}
-void DevModeBubbleController::AcknowledgeExtension(
+void DevModeBubbleDelegate::AcknowledgeExtension(
const std::string& extension_id,
ExtensionMessageBubbleController::BubbleAction user_action) {
}
-void DevModeBubbleController::PerformAction(
- const ExtensionIdList& list) {
- for (size_t i = 0; i < list.size(); ++i)
- service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION);
+void DevModeBubbleDelegate::PerformAction(
+ const extensions::ExtensionIdList& list) {
+ for (size_t i = 0; i < list.size(); ++i) {
+ service_->DisableExtension(
+ list[i], extensions::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());
+} // namespace
+
+namespace extensions {
+
+////////////////////////////////////////////////////////////////////////////////
+// DevModeBubbleController
+
+// static
+void DevModeBubbleController::ClearProfileListForTesting() {
+ g_shown_for_profiles.Get().clear();
+}
+
+// static
+bool DevModeBubbleController::IsDevModeExtension(
+ const Extension* extension) {
+ if (!extensions::FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) {
+ if (chrome::VersionInfo::GetChannel() <
+ chrome::VersionInfo::CHANNEL_BETA)
+ return false;
+ }
+ return extension->location() == Manifest::UNPACKED ||
+ extension->location() == Manifest::COMMAND_LINE;
+}
+
+DevModeBubbleController::DevModeBubbleController(Profile* profile)
+ : ExtensionMessageBubbleController(
+ new DevModeBubbleDelegate(
+ extensions::ExtensionSystem::Get(profile)->extension_service()),
+ 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);
}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698