OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_d
elegate.h" |
| 6 |
| 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" |
| 17 |
| 18 namespace { |
| 19 |
| 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 |
| 23 // show time. |
| 24 if (prefs->HasPrefPath(prefs::kToolbarIconSurfacingBubbleLastShowTime)) |
| 25 prefs->ClearPref(prefs::kToolbarIconSurfacingBubbleLastShowTime); |
| 26 } |
| 27 |
| 28 } // namespace |
| 29 |
| 30 ExtensionToolbarIconSurfacingBubbleDelegate:: |
| 31 ExtensionToolbarIconSurfacingBubbleDelegate(Profile* profile) |
| 32 : profile_(profile) { |
| 33 } |
| 34 |
| 35 ExtensionToolbarIconSurfacingBubbleDelegate:: |
| 36 ~ExtensionToolbarIconSurfacingBubbleDelegate() { |
| 37 } |
| 38 |
| 39 bool ExtensionToolbarIconSurfacingBubbleDelegate::ShouldShowForProfile( |
| 40 Profile* profile) { |
| 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))) |
| 47 return false; |
| 48 |
| 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)) |
| 54 return false; |
| 55 } |
| 56 |
| 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); |
| 62 return false; |
| 63 } |
| 64 |
| 65 return true; |
| 66 } |
| 67 |
| 68 base::string16 ExtensionToolbarIconSurfacingBubbleDelegate::GetHeadingText() { |
| 69 return l10n_util::GetStringUTF16(IDS_EXTENSION_TOOLBAR_BUBBLE_HEADING); |
| 70 } |
| 71 |
| 72 base::string16 ExtensionToolbarIconSurfacingBubbleDelegate::GetBodyText() { |
| 73 return l10n_util::GetStringUTF16(IDS_EXTENSION_TOOLBAR_BUBBLE_CONTENT); |
| 74 } |
| 75 |
| 76 base::string16 |
| 77 ExtensionToolbarIconSurfacingBubbleDelegate::GetActionButtonText() { |
| 78 return l10n_util::GetStringUTF16(IDS_EXTENSION_TOOLBAR_BUBBLE_OK); |
| 79 } |
| 80 |
| 81 base::string16 |
| 82 ExtensionToolbarIconSurfacingBubbleDelegate::GetDismissButtonText() { |
| 83 return base::string16(); // No dismiss button. |
| 84 } |
| 85 |
| 86 base::string16 |
| 87 ExtensionToolbarIconSurfacingBubbleDelegate::GetLearnMoreButtonText() { |
| 88 return base::string16(); // No learn more link. |
| 89 } |
| 90 |
| 91 void ExtensionToolbarIconSurfacingBubbleDelegate::OnBubbleShown() { |
| 92 // Record the last time the bubble was shown. |
| 93 profile_->GetPrefs()->SetInt64( |
| 94 prefs::kToolbarIconSurfacingBubbleLastShowTime, |
| 95 base::Time::Now().ToInternalValue()); |
| 96 } |
| 97 |
| 98 void ExtensionToolbarIconSurfacingBubbleDelegate::OnBubbleClosed( |
| 99 CloseAction action) { |
| 100 if (action == CLOSE_EXECUTE) |
| 101 AcknowledgeInPrefs(profile_->GetPrefs()); |
| 102 } |
OLD | NEW |