1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_delegate.h"
7 #include "base/logging.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/time/time.h"
10 #include "chrome/browser/extensions/extension_toolbar_model.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/pref_names.h"
13 #include "extensions/common/feature_switch.h"
14 #include "grit/chromium_strings.h"
15 #include "grit/generated_resources.h"
16 #include "ui/base/l10n/l10n_util.h"
20 void AcknowledgeInPrefs(PrefService
* prefs
) {
21 prefs
->SetBoolean(prefs::kToolbarIconSurfacingBubbleAcknowledged
, true);
22 // Once the bubble is acknowledged, we no longer need to store the last
24 if (prefs
->HasPrefPath(prefs::kToolbarIconSurfacingBubbleLastShowTime
))
25 prefs
->ClearPref(prefs::kToolbarIconSurfacingBubbleLastShowTime
);
30 ExtensionToolbarIconSurfacingBubbleDelegate::
31 ExtensionToolbarIconSurfacingBubbleDelegate(Profile
* profile
)
35 ExtensionToolbarIconSurfacingBubbleDelegate::
36 ~ExtensionToolbarIconSurfacingBubbleDelegate() {
39 bool ExtensionToolbarIconSurfacingBubbleDelegate::ShouldShowForProfile(
41 // If the redesign isn't running, or the user has already acknowledged it,
42 // we don't show the bubble.
43 PrefService
* prefs
= profile
->GetPrefs();
44 if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled() ||
45 (prefs
->HasPrefPath(prefs::kToolbarIconSurfacingBubbleAcknowledged
) &&
46 prefs
->GetBoolean(prefs::kToolbarIconSurfacingBubbleAcknowledged
)))
49 // We don't show more than once per day.
50 if (prefs
->HasPrefPath(prefs::kToolbarIconSurfacingBubbleLastShowTime
)) {
51 base::Time last_shown_time
= base::Time::FromInternalValue(
52 prefs
->GetInt64(prefs::kToolbarIconSurfacingBubbleLastShowTime
));
53 if (base::Time::Now() - last_shown_time
< base::TimeDelta::FromDays(1))
57 if (!extensions::ExtensionToolbarModel::Get(profile
)->
58 RedesignIsShowingNewIcons()) {
59 // We only show the bubble if there are any new icons present - otherwise,
60 // the user won't see anything different, so we treat it as acknowledged.
61 AcknowledgeInPrefs(prefs
);
68 base::string16
ExtensionToolbarIconSurfacingBubbleDelegate::GetHeadingText() {
69 return l10n_util::GetStringUTF16(IDS_EXTENSION_TOOLBAR_BUBBLE_HEADING
);
72 base::string16
ExtensionToolbarIconSurfacingBubbleDelegate::GetBodyText() {
73 return l10n_util::GetStringUTF16(IDS_EXTENSION_TOOLBAR_BUBBLE_CONTENT
);
76 base::string16
ExtensionToolbarIconSurfacingBubbleDelegate::GetItemListText() {
77 return base::string16();
81 ExtensionToolbarIconSurfacingBubbleDelegate::GetActionButtonText() {
82 return l10n_util::GetStringUTF16(IDS_EXTENSION_TOOLBAR_BUBBLE_OK
);
86 ExtensionToolbarIconSurfacingBubbleDelegate::GetDismissButtonText() {
87 return base::string16(); // No dismiss button.
91 ExtensionToolbarIconSurfacingBubbleDelegate::GetLearnMoreButtonText() {
92 return base::string16(); // No learn more link.
95 void ExtensionToolbarIconSurfacingBubbleDelegate::OnBubbleShown() {
96 // Record the last time the bubble was shown.
97 profile_
->GetPrefs()->SetInt64(
98 prefs::kToolbarIconSurfacingBubbleLastShowTime
,
99 base::Time::Now().ToInternalValue());
102 void ExtensionToolbarIconSurfacingBubbleDelegate::OnBubbleClosed(
103 CloseAction action
) {
104 if (action
== CLOSE_EXECUTE
)
105 AcknowledgeInPrefs(profile_
->GetPrefs());
106 extensions::ExtensionToolbarModel::Get(profile_
)->StopHighlighting();