Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / extensions / extension_toolbar_icon_surfacing_bubble_delegate.cc
blobd355351e416a8f7991a17cd0cf5e122e9276635b
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/profiles/profile.h"
11 #include "chrome/browser/ui/toolbar/toolbar_actions_model.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"
18 namespace {
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);
28 } // namespace
30 ExtensionToolbarIconSurfacingBubbleDelegate::
31 ExtensionToolbarIconSurfacingBubbleDelegate(Profile* profile)
32 : profile_(profile) {
35 ExtensionToolbarIconSurfacingBubbleDelegate::
36 ~ExtensionToolbarIconSurfacingBubbleDelegate() {
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;
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;
57 if (!ToolbarActionsModel::Get(profile)->RedesignIsShowingNewIcons()) {
58 // We only show the bubble if there are any new icons present - otherwise,
59 // the user won't see anything different, so we treat it as acknowledged.
60 AcknowledgeInPrefs(prefs);
61 return false;
64 return true;
67 base::string16 ExtensionToolbarIconSurfacingBubbleDelegate::GetHeadingText() {
68 return l10n_util::GetStringUTF16(IDS_EXTENSION_TOOLBAR_BUBBLE_HEADING);
71 base::string16 ExtensionToolbarIconSurfacingBubbleDelegate::GetBodyText() {
72 return l10n_util::GetStringUTF16(IDS_EXTENSION_TOOLBAR_BUBBLE_CONTENT);
75 base::string16 ExtensionToolbarIconSurfacingBubbleDelegate::GetItemListText() {
76 return base::string16();
79 base::string16
80 ExtensionToolbarIconSurfacingBubbleDelegate::GetActionButtonText() {
81 return l10n_util::GetStringUTF16(IDS_EXTENSION_TOOLBAR_BUBBLE_OK);
84 base::string16
85 ExtensionToolbarIconSurfacingBubbleDelegate::GetDismissButtonText() {
86 return base::string16(); // No dismiss button.
89 base::string16
90 ExtensionToolbarIconSurfacingBubbleDelegate::GetLearnMoreButtonText() {
91 return base::string16(); // No learn more link.
94 void ExtensionToolbarIconSurfacingBubbleDelegate::OnBubbleShown() {
95 // Record the last time the bubble was shown.
96 profile_->GetPrefs()->SetInt64(
97 prefs::kToolbarIconSurfacingBubbleLastShowTime,
98 base::Time::Now().ToInternalValue());
101 void ExtensionToolbarIconSurfacingBubbleDelegate::OnBubbleClosed(
102 CloseAction action) {
103 if (action == CLOSE_EXECUTE)
104 AcknowledgeInPrefs(profile_->GetPrefs());
105 ToolbarActionsModel::Get(profile_)->StopHighlighting();