Chromium Code Reviews| Index: components/search_engines/desktop_search_infobar_delegate_win.cc |
| diff --git a/components/search_engines/desktop_search_infobar_delegate_win.cc b/components/search_engines/desktop_search_infobar_delegate_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..41a557e3dbc7042bc5ba7489f1d9e829bc9d3e1f |
| --- /dev/null |
| +++ b/components/search_engines/desktop_search_infobar_delegate_win.cc |
| @@ -0,0 +1,103 @@ |
| +// 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_infobar_delegate_win.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 "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_win.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.WindowsDesktopSearch.InfobarAction histogram. |
| +enum WindowsDesktopSearchInfobarAction { |
| + WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_MANAGE_SEARCH_SETTINGS = 0, |
| + WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_DISMISS = 1, |
| + WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_IGNORE = 2, |
| + WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_MAX |
| +}; |
| + |
| +void RecordWindowsDesktopSearchInfobarActionHistogram( |
| + WindowsDesktopSearchInfobarAction action) { |
| + DCHECK_LT(action, WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_MAX); |
| + UMA_HISTOGRAM_ENUMERATION("Search.WindowsDesktopSearch.InfobarAction", action, |
| + WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_MAX); |
| +} |
| +} // namespace |
|
Alexei Svitkine (slow)
2016/01/18 16:08:51
Nit: Add empty lines within it.
fdoray
2016/01/18 18:51:45
Done.
|
| + |
| +void WindowsDesktopSearchInfobarDelegate::Show( |
| + infobars::InfoBarManager* infobar_manager, |
| + const base::string16& default_search_engine_name, |
| + const GURL& search_settings_url) { |
| + DCHECK(infobar_manager); |
| + infobar_manager->AddInfoBar( |
| + infobar_manager->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( |
| + new WindowsDesktopSearchInfobarDelegate(default_search_engine_name, |
| + search_settings_url)))); |
| +} |
| + |
| +WindowsDesktopSearchInfobarDelegate::WindowsDesktopSearchInfobarDelegate( |
| + const base::string16& default_search_engine_name, |
| + const GURL& search_settings_url) |
| + : default_search_engine_name_(default_search_engine_name), |
| + search_settings_url_(search_settings_url), |
| + closed_by_user_(false) {} |
| + |
| +WindowsDesktopSearchInfobarDelegate::~WindowsDesktopSearchInfobarDelegate() { |
| + if (!closed_by_user_) { |
| + base::RecordAction(base::UserMetricsAction( |
| + "WindowsDesktopSearchRedirectionInfoBar_Ignore")); |
| + RecordWindowsDesktopSearchInfobarActionHistogram( |
| + WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_IGNORE); |
| + } |
| +} |
| + |
| +base::string16 WindowsDesktopSearchInfobarDelegate::GetMessageText() const { |
| + return l10n_util::GetStringFUTF16( |
| + IDS_WINDOWS_DESKTOP_SEARCH_REDIRECTION_INFOBAR_MESSAGE, |
| + std::vector<base::string16>(1, default_search_engine_name_), nullptr); |
| +} |
| + |
| +int WindowsDesktopSearchInfobarDelegate::GetButtons() const { |
| + return BUTTON_OK; |
| +} |
| + |
| +base::string16 WindowsDesktopSearchInfobarDelegate::GetButtonLabel( |
| + InfoBarButton button) const { |
| + return l10n_util::GetStringUTF16( |
| + IDS_WINDOWS_DESKTOP_SEARCH_REDIRECTION_INFOBAR_BUTTON); |
| +} |
| + |
| +bool WindowsDesktopSearchInfobarDelegate::Accept() { |
| + base::RecordAction(base::UserMetricsAction( |
| + "WindowsDesktopSearchRedirectionInfoBar_ManageSearchSettings")); |
| + RecordWindowsDesktopSearchInfobarActionHistogram( |
| + WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_MANAGE_SEARCH_SETTINGS); |
| + infobar()->owner()->OpenURL(search_settings_url_, NEW_FOREGROUND_TAB); |
| + |
| + // Do not close the infobar. |
| + return false; |
| +} |
| + |
| +infobars::InfoBarDelegate::InfoBarIdentifier |
| +WindowsDesktopSearchInfobarDelegate::GetIdentifier() const { |
| + return WINDOWS_DESKTOP_SEARCH_INFOBAR_DELEGATE; |
| +} |
| + |
| +void WindowsDesktopSearchInfobarDelegate::InfoBarDismissed() { |
| + base::RecordAction(base::UserMetricsAction( |
| + "WindowsDesktopSearchRedirectionInfoBar_Dismiss")); |
| + RecordWindowsDesktopSearchInfobarActionHistogram( |
| + WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_DISMISS); |
| + closed_by_user_ = true; |
| +} |