Chromium Code Reviews| Index: components/search_engines/desktop_search_redirection_infobar_delegate.cc |
| diff --git a/components/search_engines/desktop_search_redirection_infobar_delegate.cc b/components/search_engines/desktop_search_redirection_infobar_delegate.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2ba6af7ed9011860eecfe1f1098e7a9bc669e790 |
| --- /dev/null |
| +++ b/components/search_engines/desktop_search_redirection_infobar_delegate.cc |
| @@ -0,0 +1,117 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/search_engines/desktop_search_redirection_infobar_delegate.h" |
| + |
| +#include <vector> |
| + |
| +#include "base/logging.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/metrics/histogram_macros.h" |
| +#include "base/metrics/user_metrics.h" |
| +#include "base/prefs/pref_service.h" |
| +#include "components/infobars/core/infobar.h" |
| +#include "components/infobars/core/infobar_delegate.h" |
| +#include "components/infobars/core/infobar_manager.h" |
| +#include "components/search_engines/desktop_search_utils.h" |
| +#include "grit/components_strings.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| +#include "ui/base/window_open_disposition.h" |
| + |
| +namespace { |
| + |
| +// Values for the Search.DesktopSearch.RedirectionInfobarCloseAction histogram. |
| +enum DesktopSearchRedirectionInfobarCloseAction { |
| + DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_MANAGE_SEARCH_SETTINGS = 0, |
| + DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_DISMISS = 1, |
| + DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_IGNORE = 2, |
| + DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_MAX |
| +}; |
| + |
| +void RecordDesktopSearchInfobarCloseActionHistogram( |
| + DesktopSearchRedirectionInfobarCloseAction action) { |
| + DCHECK_LT(action, DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_MAX); |
| + UMA_HISTOGRAM_ENUMERATION( |
| + "Search.DesktopSearch.RedirectionInfobarCloseAction", action, |
| + DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_MAX); |
| +} |
| + |
| +} // namespace |
| + |
| +void DesktopSearchRedirectionInfobarDelegate::Show( |
| + infobars::InfoBarManager* infobar_manager, |
| + const base::string16& default_search_engine_name, |
| + const base::Closure& manage_search_settings_callback, |
| + PrefService* pref_service) { |
| + DCHECK(infobar_manager); |
| + infobar_manager->AddInfoBar( |
| + infobar_manager->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( |
| + new DesktopSearchRedirectionInfobarDelegate( |
| + default_search_engine_name, manage_search_settings_callback)))); |
| + pref_service->SetBoolean(prefs::kDesktopSearchRedirectionInfobarShownPref, |
| + true); |
| + |
|
Peter Kasting
2016/01/22 00:38:57
Nit: No need for this blank line.
fdoray
2016/02/01 15:15:53
Done.
|
| + base::RecordAction( |
| + base::UserMetricsAction("DesktopSearchRedirectionInfoBar_Shown")); |
| +} |
| + |
| +DesktopSearchRedirectionInfobarDelegate:: |
| + DesktopSearchRedirectionInfobarDelegate( |
| + const base::string16& default_search_engine_name, |
| + const base::Closure& manage_search_settings_callback) |
| + : default_search_engine_name_(default_search_engine_name), |
| + manage_search_settings_callback_(manage_search_settings_callback), |
| + closed_by_user_(false) {} |
| + |
| +DesktopSearchRedirectionInfobarDelegate:: |
| + ~DesktopSearchRedirectionInfobarDelegate() { |
| + if (!closed_by_user_) { |
| + base::RecordAction( |
| + base::UserMetricsAction("DesktopSearchRedirectionInfoBar_Ignore")); |
| + RecordDesktopSearchInfobarCloseActionHistogram( |
| + DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_IGNORE); |
| + } |
| +} |
| + |
| +infobars::InfoBarDelegate::InfoBarIdentifier |
| +DesktopSearchRedirectionInfobarDelegate::GetIdentifier() const { |
| + return DESKTOP_SEARCH_REDIRECTION_INFOBAR_DELEGATE; |
| +} |
| + |
| +void DesktopSearchRedirectionInfobarDelegate::InfoBarDismissed() { |
| + base::RecordAction( |
| + base::UserMetricsAction("DesktopSearchRedirectionInfoBar_Dismiss")); |
| + RecordDesktopSearchInfobarCloseActionHistogram( |
| + DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_DISMISS); |
| + closed_by_user_ = true; |
| +} |
| + |
| +base::string16 DesktopSearchRedirectionInfobarDelegate::GetMessageText() const { |
| + return l10n_util::GetStringFUTF16( |
| + IDS_DESKTOP_SEARCH_REDIRECTION_INFOBAR_MESSAGE, |
| + default_search_engine_name_); |
| +} |
| + |
| +int DesktopSearchRedirectionInfobarDelegate::GetButtons() const { |
| + return BUTTON_OK; |
| +} |
| + |
| +base::string16 DesktopSearchRedirectionInfobarDelegate::GetButtonLabel( |
| + InfoBarButton button) const { |
| + return l10n_util::GetStringUTF16( |
| + IDS_DESKTOP_SEARCH_REDIRECTION_INFOBAR_BUTTON); |
| +} |
| + |
| +bool DesktopSearchRedirectionInfobarDelegate::Accept() { |
| + base::RecordAction(base::UserMetricsAction( |
| + "DesktopSearchRedirectionInfoBar_ManageSearchSettings")); |
| + 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.
|
| + DESKTOP_SEARCH_REDIRECTION_INFOBAR_CLOSE_ACTION_MANAGE_SEARCH_SETTINGS); |
| + |
| + manage_search_settings_callback_.Run(); |
| + |
| + // Close the infobar. |
| + closed_by_user_ = true; |
| + return true; |
| +} |