| Index: chrome/browser/extensions/extension_message_bubble_controller.cc
|
| diff --git a/chrome/browser/extensions/extension_message_bubble_controller.cc b/chrome/browser/extensions/extension_message_bubble_controller.cc
|
| index 8dd016057749e0613b4ab8652c853360e89c643c..7c9d2ce0e23324051f79cc6474a082481f87586e 100644
|
| --- a/chrome/browser/extensions/extension_message_bubble_controller.cc
|
| +++ b/chrome/browser/extensions/extension_message_bubble_controller.cc
|
| @@ -5,6 +5,7 @@
|
| #include "chrome/browser/extensions/extension_message_bubble_controller.h"
|
|
|
| #include "base/bind.h"
|
| +#include "base/lazy_instance.h"
|
| #include "base/metrics/histogram.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/string_util.h"
|
| @@ -24,12 +25,18 @@
|
| namespace extensions {
|
|
|
| namespace {
|
| +
|
| // How many extensions to show in the bubble (max).
|
| const int kMaxExtensionsToShow = 7;
|
|
|
| // Whether or not to ignore the learn more link navigation for testing.
|
| bool g_should_ignore_learn_more_for_testing = false;
|
| -}
|
| +
|
| +using ProfileSetMap = std::map<std::string, std::set<Profile*>>;
|
| +base::LazyInstance<ProfileSetMap> g_shown_for_profiles =
|
| + LAZY_INSTANCE_INITIALIZER;
|
| +
|
| +} // namespace
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // ExtensionMessageBubbleController::Delegate
|
| @@ -48,6 +55,10 @@ base::string16 ExtensionMessageBubbleController::Delegate::GetLearnMoreLabel()
|
| return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
|
| }
|
|
|
| +bool ExtensionMessageBubbleController::Delegate::ClearProfileSetAfterAction() {
|
| + return true;
|
| +}
|
| +
|
| bool ExtensionMessageBubbleController::Delegate::HasBubbleInfoBeenAcknowledged(
|
| const std::string& extension_id) {
|
| std::string pref_name = get_acknowledged_flag_pref_name();
|
| @@ -71,11 +82,6 @@ void ExtensionMessageBubbleController::Delegate::SetBubbleInfoBeenAcknowledged(
|
| value ? new base::FundamentalValue(value) : NULL);
|
| }
|
|
|
| -std::set<Profile*>*
|
| -ExtensionMessageBubbleController::Delegate::GetProfileSet() {
|
| - return nullptr;
|
| -}
|
| -
|
| std::string
|
| ExtensionMessageBubbleController::Delegate::get_acknowledged_flag_pref_name()
|
| const {
|
| @@ -108,8 +114,8 @@ Profile* ExtensionMessageBubbleController::profile() {
|
| }
|
|
|
| bool ExtensionMessageBubbleController::ShouldShow() {
|
| - std::set<Profile*>* profiles = delegate_->GetProfileSet();
|
| - return (!profiles || !profiles->count(profile()->GetOriginalProfile())) &&
|
| + std::set<Profile*>* profiles = GetProfileSet();
|
| + return !profiles->count(profile()->GetOriginalProfile()) &&
|
| !GetExtensionList().empty();
|
| }
|
|
|
| @@ -170,9 +176,7 @@ void ExtensionMessageBubbleController::HighlightExtensionsIfNecessary() {
|
| }
|
|
|
| void ExtensionMessageBubbleController::OnShown() {
|
| - std::set<Profile*>* profiles = delegate_->GetProfileSet();
|
| - if (profiles)
|
| - profiles->insert(profile()->GetOriginalProfile());
|
| + GetProfileSet()->insert(profile()->GetOriginalProfile());
|
| }
|
|
|
| void ExtensionMessageBubbleController::OnBubbleAction() {
|
| @@ -185,18 +189,21 @@ void ExtensionMessageBubbleController::OnBubbleAction() {
|
| OnClose();
|
| }
|
|
|
| -void ExtensionMessageBubbleController::OnBubbleDismiss() {
|
| +void ExtensionMessageBubbleController::OnBubbleDismiss(
|
| + bool closed_by_deactivation) {
|
| // OnBubbleDismiss() can be called twice when we receive multiple
|
| // "OnWidgetDestroying" notifications (this can at least happen when we close
|
| // a window with a notification open). Handle this gracefully.
|
| if (user_action_ != ACTION_BOUNDARY) {
|
| - DCHECK(user_action_ == ACTION_DISMISS);
|
| + DCHECK(user_action_ == ACTION_DISMISS_USER_ACTION ||
|
| + user_action_ == ACTION_DISMISS_DEACTIVATION);
|
| return;
|
| }
|
|
|
| - user_action_ = ACTION_DISMISS;
|
| + user_action_ = closed_by_deactivation ? ACTION_DISMISS_DEACTIVATION
|
| + : ACTION_DISMISS_USER_ACTION;
|
|
|
| - delegate_->LogAction(ACTION_DISMISS);
|
| + delegate_->LogAction(user_action_);
|
|
|
| OnClose();
|
| }
|
| @@ -217,6 +224,10 @@ void ExtensionMessageBubbleController::OnLinkClicked() {
|
| OnClose();
|
| }
|
|
|
| +void ExtensionMessageBubbleController::ClearProfileListForTesting() {
|
| + GetProfileSet()->clear();
|
| +}
|
| +
|
| // static
|
| void ExtensionMessageBubbleController::set_should_ignore_learn_more_for_testing(
|
| bool should_ignore) {
|
| @@ -252,9 +263,22 @@ ExtensionIdList* ExtensionMessageBubbleController::GetOrCreateExtensionList() {
|
| }
|
|
|
| void ExtensionMessageBubbleController::OnClose() {
|
| - AcknowledgeExtensions();
|
| + DCHECK_NE(ACTION_BOUNDARY, user_action_);
|
| + // If the bubble was closed due to deactivation, don't treat it as
|
| + // acknowledgment so that the user will see the bubble again (until they
|
| + // explicitly take an action).
|
| + if (user_action_ != ACTION_DISMISS_DEACTIVATION) {
|
| + AcknowledgeExtensions();
|
| + if (delegate_->ClearProfileSetAfterAction())
|
| + GetProfileSet()->clear();
|
| + }
|
| +
|
| if (did_highlight_)
|
| ToolbarActionsModel::Get(profile())->StopHighlighting();
|
| }
|
|
|
| +std::set<Profile*>* ExtensionMessageBubbleController::GetProfileSet() {
|
| + return &g_shown_for_profiles.Get()[delegate_->GetKey()];
|
| +}
|
| +
|
| } // namespace extensions
|
|
|