OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_controller.h" | 5 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram_macros.h" | |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/net/referrer.h" | 12 #include "chrome/browser/net/referrer.h" |
12 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
13 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h" | 14 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h" |
14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 16 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
16 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
17 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
18 #include "content/browser/bluetooth/bluetooth_metrics.h" | |
19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
20 #include "url/gurl.h" | 20 #include "url/gurl.h" |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 enum class BluetoothChooserInteractionType { VALID = 0, INVALID = 1, COUNT }; | |
25 | |
24 Browser* GetBrowser() { | 26 Browser* GetBrowser() { |
25 chrome::ScopedTabbedBrowserDisplayer browser_displayer( | 27 chrome::ScopedTabbedBrowserDisplayer browser_displayer( |
26 ProfileManager::GetActiveUserProfile()); | 28 ProfileManager::GetActiveUserProfile()); |
27 DCHECK(browser_displayer.browser()); | 29 DCHECK(browser_displayer.browser()); |
28 return browser_displayer.browser(); | 30 return browser_displayer.browser(); |
29 } | 31 } |
30 | 32 |
33 void RecordInteractionWithChooser(bool has_null_handler) { | |
34 UMA_HISTOGRAM_ENUMERATION( | |
Ilya Sherman
2016/08/26 00:17:44
nit: UMA_HISTOGRAM_BOOLEAN probably is the best ch
ortuno
2016/08/26 16:14:36
Done.
| |
35 "Bluetooth.Web.ChooserInteraction", | |
36 static_cast<int>(has_null_handler | |
37 ? BluetoothChooserInteractionType::INVALID | |
38 : BluetoothChooserInteractionType::VALID), | |
39 static_cast<int>(BluetoothChooserInteractionType::COUNT)); | |
40 } | |
41 | |
31 } // namespace | 42 } // namespace |
32 | 43 |
33 BluetoothChooserController::BluetoothChooserController( | 44 BluetoothChooserController::BluetoothChooserController( |
34 content::RenderFrameHost* owner, | 45 content::RenderFrameHost* owner, |
35 const content::BluetoothChooser::EventHandler& event_handler) | 46 const content::BluetoothChooser::EventHandler& event_handler) |
36 : ChooserController(owner, | 47 : ChooserController(owner, |
37 IDS_BLUETOOTH_DEVICE_CHOOSER_PROMPT_ORIGIN, | 48 IDS_BLUETOOTH_DEVICE_CHOOSER_PROMPT_ORIGIN, |
38 IDS_BLUETOOTH_DEVICE_CHOOSER_PROMPT_EXTENSION_NAME), | 49 IDS_BLUETOOTH_DEVICE_CHOOSER_PROMPT_EXTENSION_NAME), |
39 event_handler_(event_handler), | 50 event_handler_(event_handler), |
40 no_devices_text_(l10n_util::GetStringUTF16( | 51 no_devices_text_(l10n_util::GetStringUTF16( |
(...skipping 30 matching lines...) Expand all Loading... | |
71 const auto& it = device_name_counts_.find(device_name_it->second); | 82 const auto& it = device_name_counts_.find(device_name_it->second); |
72 DCHECK(it != device_name_counts_.end()); | 83 DCHECK(it != device_name_counts_.end()); |
73 return it->second == 1 | 84 return it->second == 1 |
74 ? device_name_it->second | 85 ? device_name_it->second |
75 : l10n_util::GetStringFUTF16( | 86 : l10n_util::GetStringFUTF16( |
76 IDS_DEVICE_CHOOSER_DEVICE_NAME_WITH_ID, | 87 IDS_DEVICE_CHOOSER_DEVICE_NAME_WITH_ID, |
77 device_name_it->second, base::UTF8ToUTF16(device_id)); | 88 device_name_it->second, base::UTF8ToUTF16(device_id)); |
78 } | 89 } |
79 | 90 |
80 void BluetoothChooserController::RefreshOptions() { | 91 void BluetoothChooserController::RefreshOptions() { |
92 RecordInteractionWithChooser(event_handler_.is_null()); | |
81 if (event_handler_.is_null()) | 93 if (event_handler_.is_null()) |
82 return; | 94 return; |
83 ClearAllDevices(); | 95 ClearAllDevices(); |
84 event_handler_.Run(content::BluetoothChooser::Event::RESCAN, std::string()); | 96 event_handler_.Run(content::BluetoothChooser::Event::RESCAN, std::string()); |
85 } | 97 } |
86 | 98 |
87 base::string16 BluetoothChooserController::GetStatus() const { | 99 base::string16 BluetoothChooserController::GetStatus() const { |
88 return status_text_; | 100 return status_text_; |
89 } | 101 } |
90 | 102 |
91 void BluetoothChooserController::Select(size_t index) { | 103 void BluetoothChooserController::Select(size_t index) { |
104 RecordInteractionWithChooser(event_handler_.is_null()); | |
92 if (event_handler_.is_null()) { | 105 if (event_handler_.is_null()) { |
93 content::RecordRequestDeviceOutcome( | |
94 content::UMARequestDeviceOutcome:: | |
95 BLUETOOTH_CHOOSER_EVENT_HANDLER_INVALID); | |
96 return; | 106 return; |
97 } | 107 } |
98 DCHECK_LT(index, devices_.size()); | 108 DCHECK_LT(index, devices_.size()); |
99 event_handler_.Run(content::BluetoothChooser::Event::SELECTED, | 109 event_handler_.Run(content::BluetoothChooser::Event::SELECTED, |
100 devices_[index].id); | 110 devices_[index].id); |
101 } | 111 } |
102 | 112 |
103 void BluetoothChooserController::Cancel() { | 113 void BluetoothChooserController::Cancel() { |
114 RecordInteractionWithChooser(event_handler_.is_null()); | |
104 if (event_handler_.is_null()) | 115 if (event_handler_.is_null()) |
105 return; | 116 return; |
106 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, | 117 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, |
107 std::string()); | 118 std::string()); |
108 } | 119 } |
109 | 120 |
110 void BluetoothChooserController::Close() { | 121 void BluetoothChooserController::Close() { |
122 RecordInteractionWithChooser(event_handler_.is_null()); | |
111 if (event_handler_.is_null()) | 123 if (event_handler_.is_null()) |
112 return; | 124 return; |
113 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, | 125 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, |
114 std::string()); | 126 std::string()); |
115 } | 127 } |
116 | 128 |
117 void BluetoothChooserController::OpenHelpCenterUrl() const { | 129 void BluetoothChooserController::OpenHelpCenterUrl() const { |
118 GetBrowser()->OpenURL(content::OpenURLParams( | 130 GetBrowser()->OpenURL(content::OpenURLParams( |
119 GURL(chrome::kChooserBluetoothOverviewURL), content::Referrer(), | 131 GURL(chrome::kChooserBluetoothOverviewURL), content::Referrer(), |
120 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 132 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 | 264 |
253 void BluetoothChooserController::ResetEventHandler() { | 265 void BluetoothChooserController::ResetEventHandler() { |
254 event_handler_.Reset(); | 266 event_handler_.Reset(); |
255 } | 267 } |
256 | 268 |
257 void BluetoothChooserController::ClearAllDevices() { | 269 void BluetoothChooserController::ClearAllDevices() { |
258 devices_.clear(); | 270 devices_.clear(); |
259 device_id_to_name_map_.clear(); | 271 device_id_to_name_map_.clear(); |
260 device_name_counts_.clear(); | 272 device_name_counts_.clear(); |
261 } | 273 } |
OLD | NEW |