OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 "components/search_engines/desktop_search_redirection_infobar_delegate.
h" |
| 6 |
| 7 #include <vector> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/metrics/user_metrics.h" |
| 13 #include "base/prefs/pref_service.h" |
| 14 #include "components/infobars/core/infobar.h" |
| 15 #include "components/infobars/core/infobar_delegate.h" |
| 16 #include "components/infobars/core/infobar_manager.h" |
| 17 #include "components/search_engines/desktop_search_utils.h" |
| 18 #include "grit/components_strings.h" |
| 19 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/window_open_disposition.h" |
| 21 |
| 22 namespace { |
| 23 |
| 24 // Values for the Search.DesktopSearch.RedirectionInfobarCloseAction histogram. |
| 25 enum DesktopSearchRedirectionInfobarCloseAction { |
| 26 DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_MANAGE_SEARCH_SETTINGS = 0, |
| 27 DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_DISMISS = 1, |
| 28 DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_IGNORE = 2, |
| 29 DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_MAX |
| 30 }; |
| 31 |
| 32 void RecordDesktopSearchInfobarCloseActionHistogram( |
| 33 DesktopSearchRedirectionInfobarCloseAction action) { |
| 34 DCHECK_LT(action, DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_MAX); |
| 35 UMA_HISTOGRAM_ENUMERATION( |
| 36 "Search.DesktopSearch.RedirectionInfobarCloseAction", action, |
| 37 DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_MAX); |
| 38 } |
| 39 |
| 40 } // namespace |
| 41 |
| 42 void DesktopSearchRedirectionInfobarDelegate::Show( |
| 43 infobars::InfoBarManager* infobar_manager, |
| 44 const base::string16& default_search_engine_name, |
| 45 const base::Closure& manage_search_settings_callback, |
| 46 PrefService* pref_service) { |
| 47 DCHECK(infobar_manager); |
| 48 infobar_manager->AddInfoBar( |
| 49 infobar_manager->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( |
| 50 new DesktopSearchRedirectionInfobarDelegate( |
| 51 default_search_engine_name, manage_search_settings_callback)))); |
| 52 pref_service->SetBoolean(prefs::kDesktopSearchRedirectionInfobarShownPref, |
| 53 true); |
| 54 base::RecordAction( |
| 55 base::UserMetricsAction("DesktopSearchRedirectionInfoBar_Shown")); |
| 56 } |
| 57 |
| 58 DesktopSearchRedirectionInfobarDelegate:: |
| 59 DesktopSearchRedirectionInfobarDelegate( |
| 60 const base::string16& default_search_engine_name, |
| 61 const base::Closure& manage_search_settings_callback) |
| 62 : default_search_engine_name_(default_search_engine_name), |
| 63 manage_search_settings_callback_(manage_search_settings_callback), |
| 64 closed_by_user_(false) {} |
| 65 |
| 66 DesktopSearchRedirectionInfobarDelegate:: |
| 67 ~DesktopSearchRedirectionInfobarDelegate() { |
| 68 if (!closed_by_user_) { |
| 69 base::RecordAction( |
| 70 base::UserMetricsAction("DesktopSearchRedirectionInfoBar_Ignore")); |
| 71 RecordDesktopSearchInfobarCloseActionHistogram( |
| 72 DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_IGNORE); |
| 73 } |
| 74 } |
| 75 |
| 76 infobars::InfoBarDelegate::InfoBarIdentifier |
| 77 DesktopSearchRedirectionInfobarDelegate::GetIdentifier() const { |
| 78 return DESKTOP_SEARCH_REDIRECTION_INFOBAR_DELEGATE; |
| 79 } |
| 80 |
| 81 void DesktopSearchRedirectionInfobarDelegate::InfoBarDismissed() { |
| 82 base::RecordAction( |
| 83 base::UserMetricsAction("DesktopSearchRedirectionInfoBar_Dismiss")); |
| 84 RecordDesktopSearchInfobarCloseActionHistogram( |
| 85 DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_DISMISS); |
| 86 closed_by_user_ = true; |
| 87 } |
| 88 |
| 89 base::string16 DesktopSearchRedirectionInfobarDelegate::GetMessageText() const { |
| 90 return l10n_util::GetStringFUTF16( |
| 91 IDS_DESKTOP_SEARCH_REDIRECTION_INFOBAR_MESSAGE, |
| 92 default_search_engine_name_); |
| 93 } |
| 94 |
| 95 int DesktopSearchRedirectionInfobarDelegate::GetButtons() const { |
| 96 return BUTTON_OK; |
| 97 } |
| 98 |
| 99 base::string16 DesktopSearchRedirectionInfobarDelegate::GetButtonLabel( |
| 100 InfoBarButton button) const { |
| 101 return l10n_util::GetStringUTF16( |
| 102 IDS_DESKTOP_SEARCH_REDIRECTION_INFOBAR_BUTTON); |
| 103 } |
| 104 |
| 105 bool DesktopSearchRedirectionInfobarDelegate::Accept() { |
| 106 base::RecordAction(base::UserMetricsAction( |
| 107 "DesktopSearchRedirectionInfoBar_ManageSearchSettings")); |
| 108 manage_search_settings_callback_.Run(); |
| 109 |
| 110 // Close the infobar. |
| 111 RecordDesktopSearchInfobarCloseActionHistogram( |
| 112 DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_MANAGE_SEARCH_SETTINGS); |
| 113 closed_by_user_ = true; |
| 114 return true; |
| 115 } |
OLD | NEW |