Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Unified Diff: components/search_engines/desktop_search_infobar_delegate_win.cc

Issue 1598553003: Implement the Windows desktop search redirection feature. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: don't assume that a Browser exists + fix nits Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..48e3ceb0f70daf9535fc74114dab2b730a6ab1d3
--- /dev/null
+++ b/components/search_engines/desktop_search_infobar_delegate_win.cc
@@ -0,0 +1,109 @@
+// 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 "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_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
+
+void WindowsDesktopSearchInfobarDelegate::Show(
+ infobars::InfoBarManager* infobar_manager,
+ const base::string16& default_search_engine_name,
+ const GURL& search_settings_url,
+ PrefService* pref_service) {
+ DCHECK(infobar_manager);
+ infobar_manager->AddInfoBar(
+ infobar_manager->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>(
+ new WindowsDesktopSearchInfobarDelegate(default_search_engine_name,
+ search_settings_url))));
+ pref_service->SetBoolean(
+ prefs::kWindowsDesktopSearchRedirectionInfobarShownPref, true);
Peter Kasting 2016/01/20 03:03:01 What if the user navigates quickly and never reall
fdoray 2016/01/21 21:02:33 ainslie@: What do you think? Should we show the in
+}
+
+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);
Peter Kasting 2016/01/20 03:03:01 Why not just call return l10n_util::GetStringFU
fdoray 2016/01/21 21:02:33 Done.
+}
+
+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);
Peter Kasting 2016/01/20 03:03:01 If we already have a settings page open, will this
fdoray 2016/01/21 21:02:33 Done.
+
+ // Do not close the infobar.
Peter Kasting 2016/01/20 03:03:01 Why? Also, doesn't this mean we'll always record
fdoray 2016/01/21 21:02:33 Done. Once the user has interacted with the infoba
+ 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;
+}

Powered by Google App Engine
This is Rietveld 408576698