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

Side by Side 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 unified diff | Download patch
OLDNEW
(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_infobar_delegate_win.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_win.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.WindowsDesktopSearch.InfobarAction histogram.
25 enum WindowsDesktopSearchInfobarAction {
26 WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_MANAGE_SEARCH_SETTINGS = 0,
27 WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_DISMISS = 1,
28 WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_IGNORE = 2,
29 WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_MAX
30 };
31
32 void RecordWindowsDesktopSearchInfobarActionHistogram(
33 WindowsDesktopSearchInfobarAction action) {
34 DCHECK_LT(action, WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_MAX);
35 UMA_HISTOGRAM_ENUMERATION("Search.WindowsDesktopSearch.InfobarAction", action,
36 WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_MAX);
37 }
38
39 } // namespace
40
41 void WindowsDesktopSearchInfobarDelegate::Show(
42 infobars::InfoBarManager* infobar_manager,
43 const base::string16& default_search_engine_name,
44 const GURL& search_settings_url,
45 PrefService* pref_service) {
46 DCHECK(infobar_manager);
47 infobar_manager->AddInfoBar(
48 infobar_manager->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>(
49 new WindowsDesktopSearchInfobarDelegate(default_search_engine_name,
50 search_settings_url))));
51 pref_service->SetBoolean(
52 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
53 }
54
55 WindowsDesktopSearchInfobarDelegate::WindowsDesktopSearchInfobarDelegate(
56 const base::string16& default_search_engine_name,
57 const GURL& search_settings_url)
58 : default_search_engine_name_(default_search_engine_name),
59 search_settings_url_(search_settings_url),
60 closed_by_user_(false) {}
61
62 WindowsDesktopSearchInfobarDelegate::~WindowsDesktopSearchInfobarDelegate() {
63 if (!closed_by_user_) {
64 base::RecordAction(base::UserMetricsAction(
65 "WindowsDesktopSearchRedirectionInfoBar_Ignore"));
66 RecordWindowsDesktopSearchInfobarActionHistogram(
67 WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_IGNORE);
68 }
69 }
70
71 base::string16 WindowsDesktopSearchInfobarDelegate::GetMessageText() const {
72 return l10n_util::GetStringFUTF16(
73 IDS_WINDOWS_DESKTOP_SEARCH_REDIRECTION_INFOBAR_MESSAGE,
74 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.
75 }
76
77 int WindowsDesktopSearchInfobarDelegate::GetButtons() const {
78 return BUTTON_OK;
79 }
80
81 base::string16 WindowsDesktopSearchInfobarDelegate::GetButtonLabel(
82 InfoBarButton button) const {
83 return l10n_util::GetStringUTF16(
84 IDS_WINDOWS_DESKTOP_SEARCH_REDIRECTION_INFOBAR_BUTTON);
85 }
86
87 bool WindowsDesktopSearchInfobarDelegate::Accept() {
88 base::RecordAction(base::UserMetricsAction(
89 "WindowsDesktopSearchRedirectionInfoBar_ManageSearchSettings"));
90 RecordWindowsDesktopSearchInfobarActionHistogram(
91 WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_MANAGE_SEARCH_SETTINGS);
92 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.
93
94 // 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
95 return false;
96 }
97
98 infobars::InfoBarDelegate::InfoBarIdentifier
99 WindowsDesktopSearchInfobarDelegate::GetIdentifier() const {
100 return WINDOWS_DESKTOP_SEARCH_INFOBAR_DELEGATE;
101 }
102
103 void WindowsDesktopSearchInfobarDelegate::InfoBarDismissed() {
104 base::RecordAction(base::UserMetricsAction(
105 "WindowsDesktopSearchRedirectionInfoBar_Dismiss"));
106 RecordWindowsDesktopSearchInfobarActionHistogram(
107 WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_DISMISS);
108 closed_by_user_ = true;
109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698