Chromium Code Reviews| 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 | |
|
Peter Kasting
2016/01/22 00:38:57
Nit: No need for this blank line.
fdoray
2016/02/01 15:15:53
Done.
| |
| 55 base::RecordAction( | |
| 56 base::UserMetricsAction("DesktopSearchRedirectionInfoBar_Shown")); | |
| 57 } | |
| 58 | |
| 59 DesktopSearchRedirectionInfobarDelegate:: | |
| 60 DesktopSearchRedirectionInfobarDelegate( | |
| 61 const base::string16& default_search_engine_name, | |
| 62 const base::Closure& manage_search_settings_callback) | |
| 63 : default_search_engine_name_(default_search_engine_name), | |
| 64 manage_search_settings_callback_(manage_search_settings_callback), | |
| 65 closed_by_user_(false) {} | |
| 66 | |
| 67 DesktopSearchRedirectionInfobarDelegate:: | |
| 68 ~DesktopSearchRedirectionInfobarDelegate() { | |
| 69 if (!closed_by_user_) { | |
| 70 base::RecordAction( | |
| 71 base::UserMetricsAction("DesktopSearchRedirectionInfoBar_Ignore")); | |
| 72 RecordDesktopSearchInfobarCloseActionHistogram( | |
| 73 DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_IGNORE); | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 infobars::InfoBarDelegate::InfoBarIdentifier | |
| 78 DesktopSearchRedirectionInfobarDelegate::GetIdentifier() const { | |
| 79 return DESKTOP_SEARCH_REDIRECTION_INFOBAR_DELEGATE; | |
| 80 } | |
| 81 | |
| 82 void DesktopSearchRedirectionInfobarDelegate::InfoBarDismissed() { | |
| 83 base::RecordAction( | |
| 84 base::UserMetricsAction("DesktopSearchRedirectionInfoBar_Dismiss")); | |
| 85 RecordDesktopSearchInfobarCloseActionHistogram( | |
| 86 DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_DISMISS); | |
| 87 closed_by_user_ = true; | |
| 88 } | |
| 89 | |
| 90 base::string16 DesktopSearchRedirectionInfobarDelegate::GetMessageText() const { | |
| 91 return l10n_util::GetStringFUTF16( | |
| 92 IDS_DESKTOP_SEARCH_REDIRECTION_INFOBAR_MESSAGE, | |
| 93 default_search_engine_name_); | |
| 94 } | |
| 95 | |
| 96 int DesktopSearchRedirectionInfobarDelegate::GetButtons() const { | |
| 97 return BUTTON_OK; | |
| 98 } | |
| 99 | |
| 100 base::string16 DesktopSearchRedirectionInfobarDelegate::GetButtonLabel( | |
| 101 InfoBarButton button) const { | |
| 102 return l10n_util::GetStringUTF16( | |
| 103 IDS_DESKTOP_SEARCH_REDIRECTION_INFOBAR_BUTTON); | |
| 104 } | |
| 105 | |
| 106 bool DesktopSearchRedirectionInfobarDelegate::Accept() { | |
| 107 base::RecordAction(base::UserMetricsAction( | |
| 108 "DesktopSearchRedirectionInfoBar_ManageSearchSettings")); | |
| 109 RecordDesktopSearchInfobarCloseActionHistogram( | |
|
Peter Kasting
2016/01/22 00:38:57
Nit: I'd probably put this statement down just und
fdoray
2016/02/01 15:15:53
Done.
| |
| 110 DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_MANAGE_SEARCH_SETTINGS); | |
| 111 | |
| 112 manage_search_settings_callback_.Run(); | |
| 113 | |
| 114 // Close the infobar. | |
| 115 closed_by_user_ = true; | |
| 116 return true; | |
| 117 } | |
| OLD | NEW |