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_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 "components/infobars/core/infobar.h" | |
14 #include "components/infobars/core/infobar_delegate.h" | |
15 #include "components/infobars/core/infobar_manager.h" | |
16 #include "components/search_engines/desktop_search_utils_win.h" | |
17 #include "grit/components_strings.h" | |
18 #include "ui/base/l10n/l10n_util.h" | |
19 #include "ui/base/window_open_disposition.h" | |
20 | |
21 namespace { | |
22 // Values for the Search.WindowsDesktopSearch.InfobarAction histogram. | |
23 enum WindowsDesktopSearchInfobarAction { | |
24 WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_MANAGE_SEARCH_SETTINGS = 0, | |
25 WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_DISMISS = 1, | |
26 WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_IGNORE = 2, | |
27 WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_MAX | |
28 }; | |
29 | |
30 void RecordWindowsDesktopSearchInfobarActionHistogram( | |
31 WindowsDesktopSearchInfobarAction action) { | |
32 DCHECK_LT(action, WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_MAX); | |
33 UMA_HISTOGRAM_ENUMERATION("Search.WindowsDesktopSearch.InfobarAction", action, | |
34 WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_MAX); | |
35 } | |
36 } // namespace | |
Alexei Svitkine (slow)
2016/01/18 16:08:51
Nit: Add empty lines within it.
fdoray
2016/01/18 18:51:45
Done.
| |
37 | |
38 void WindowsDesktopSearchInfobarDelegate::Show( | |
39 infobars::InfoBarManager* infobar_manager, | |
40 const base::string16& default_search_engine_name, | |
41 const GURL& search_settings_url) { | |
42 DCHECK(infobar_manager); | |
43 infobar_manager->AddInfoBar( | |
44 infobar_manager->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( | |
45 new WindowsDesktopSearchInfobarDelegate(default_search_engine_name, | |
46 search_settings_url)))); | |
47 } | |
48 | |
49 WindowsDesktopSearchInfobarDelegate::WindowsDesktopSearchInfobarDelegate( | |
50 const base::string16& default_search_engine_name, | |
51 const GURL& search_settings_url) | |
52 : default_search_engine_name_(default_search_engine_name), | |
53 search_settings_url_(search_settings_url), | |
54 closed_by_user_(false) {} | |
55 | |
56 WindowsDesktopSearchInfobarDelegate::~WindowsDesktopSearchInfobarDelegate() { | |
57 if (!closed_by_user_) { | |
58 base::RecordAction(base::UserMetricsAction( | |
59 "WindowsDesktopSearchRedirectionInfoBar_Ignore")); | |
60 RecordWindowsDesktopSearchInfobarActionHistogram( | |
61 WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_IGNORE); | |
62 } | |
63 } | |
64 | |
65 base::string16 WindowsDesktopSearchInfobarDelegate::GetMessageText() const { | |
66 return l10n_util::GetStringFUTF16( | |
67 IDS_WINDOWS_DESKTOP_SEARCH_REDIRECTION_INFOBAR_MESSAGE, | |
68 std::vector<base::string16>(1, default_search_engine_name_), nullptr); | |
69 } | |
70 | |
71 int WindowsDesktopSearchInfobarDelegate::GetButtons() const { | |
72 return BUTTON_OK; | |
73 } | |
74 | |
75 base::string16 WindowsDesktopSearchInfobarDelegate::GetButtonLabel( | |
76 InfoBarButton button) const { | |
77 return l10n_util::GetStringUTF16( | |
78 IDS_WINDOWS_DESKTOP_SEARCH_REDIRECTION_INFOBAR_BUTTON); | |
79 } | |
80 | |
81 bool WindowsDesktopSearchInfobarDelegate::Accept() { | |
82 base::RecordAction(base::UserMetricsAction( | |
83 "WindowsDesktopSearchRedirectionInfoBar_ManageSearchSettings")); | |
84 RecordWindowsDesktopSearchInfobarActionHistogram( | |
85 WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_MANAGE_SEARCH_SETTINGS); | |
86 infobar()->owner()->OpenURL(search_settings_url_, NEW_FOREGROUND_TAB); | |
87 | |
88 // Do not close the infobar. | |
89 return false; | |
90 } | |
91 | |
92 infobars::InfoBarDelegate::InfoBarIdentifier | |
93 WindowsDesktopSearchInfobarDelegate::GetIdentifier() const { | |
94 return WINDOWS_DESKTOP_SEARCH_INFOBAR_DELEGATE; | |
95 } | |
96 | |
97 void WindowsDesktopSearchInfobarDelegate::InfoBarDismissed() { | |
98 base::RecordAction(base::UserMetricsAction( | |
99 "WindowsDesktopSearchRedirectionInfoBar_Dismiss")); | |
100 RecordWindowsDesktopSearchInfobarActionHistogram( | |
101 WINDOWS_DESKTOP_SEARCH_INFOBAR_ACTION_DISMISS); | |
102 closed_by_user_ = true; | |
103 } | |
OLD | NEW |