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/metrics/histogram_macros.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 chrome::ScopedTabbedBrowserDisplayer browser_displayer( | 25 chrome::ScopedTabbedBrowserDisplayer browser_displayer( |
26 ProfileManager::GetActiveUserProfile()); | 26 ProfileManager::GetActiveUserProfile()); |
27 DCHECK(browser_displayer.browser()); | 27 DCHECK(browser_displayer.browser()); |
28 return browser_displayer.browser(); | 28 return browser_displayer.browser(); |
29 } | 29 } |
30 | 30 |
31 void RecordInteractionWithChooser(bool has_null_handler) { | 31 void RecordInteractionWithChooser(bool has_null_handler) { |
32 UMA_HISTOGRAM_BOOLEAN("Bluetooth.Web.ChooserInteraction", has_null_handler); | 32 UMA_HISTOGRAM_BOOLEAN("Bluetooth.Web.ChooserInteraction", has_null_handler); |
33 } | 33 } |
34 | 34 |
35 void RecordNumOfDevices(size_t num_of_devices) { | |
36 UMA_HISTOGRAM_SPARSE_SLOWLY( | |
37 "Bluetooth.Web.RequestDevice." | |
38 "NumOfDevicesInChooserWhenNotAcceptingAllDevices", | |
39 num_of_devices); | |
40 } | |
41 | |
35 } // namespace | 42 } // namespace |
36 | 43 |
37 BluetoothChooserController::BluetoothChooserController( | 44 BluetoothChooserController::BluetoothChooserController( |
38 content::RenderFrameHost* owner, | 45 content::RenderFrameHost* owner, |
39 const content::BluetoothChooser::EventHandler& event_handler) | 46 const content::BluetoothChooser::EventHandler& event_handler, |
47 bool accept_all_devices) | |
40 : ChooserController(owner, | 48 : ChooserController(owner, |
41 IDS_BLUETOOTH_DEVICE_CHOOSER_PROMPT_ORIGIN, | 49 IDS_BLUETOOTH_DEVICE_CHOOSER_PROMPT_ORIGIN, |
42 IDS_BLUETOOTH_DEVICE_CHOOSER_PROMPT_EXTENSION_NAME), | 50 IDS_BLUETOOTH_DEVICE_CHOOSER_PROMPT_EXTENSION_NAME), |
43 event_handler_(event_handler) {} | 51 event_handler_(event_handler), |
52 accept_all_devices_(accept_all_devices) {} | |
44 | 53 |
45 BluetoothChooserController::~BluetoothChooserController() {} | 54 BluetoothChooserController::~BluetoothChooserController() {} |
46 | 55 |
47 bool BluetoothChooserController::ShouldShowIconBeforeText() const { | 56 bool BluetoothChooserController::ShouldShowIconBeforeText() const { |
48 return true; | 57 return true; |
49 } | 58 } |
50 | 59 |
51 base::string16 BluetoothChooserController::GetNoOptionsText() const { | 60 base::string16 BluetoothChooserController::GetNoOptionsText() const { |
52 return l10n_util::GetStringUTF16( | 61 return l10n_util::GetStringUTF16( |
53 IDS_BLUETOOTH_DEVICE_CHOOSER_NO_DEVICES_FOUND_PROMPT); | 62 IDS_BLUETOOTH_DEVICE_CHOOSER_NO_DEVICES_FOUND_PROMPT); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 } | 117 } |
109 | 118 |
110 void BluetoothChooserController::Select(const std::vector<size_t>& indices) { | 119 void BluetoothChooserController::Select(const std::vector<size_t>& indices) { |
111 DCHECK_EQ(1u, indices.size()); | 120 DCHECK_EQ(1u, indices.size()); |
112 size_t index = indices[0]; | 121 size_t index = indices[0]; |
113 RecordInteractionWithChooser(event_handler_.is_null()); | 122 RecordInteractionWithChooser(event_handler_.is_null()); |
114 if (event_handler_.is_null()) { | 123 if (event_handler_.is_null()) { |
115 return; | 124 return; |
116 } | 125 } |
117 DCHECK_LT(index, devices_.size()); | 126 DCHECK_LT(index, devices_.size()); |
127 if (!accept_all_devices_) | |
scheib
2016/12/16 06:36:16
Perhaps move the if check to the Record method?
juncai
2016/12/16 18:34:40
Done.
| |
128 RecordNumOfDevices(devices_.size()); | |
118 event_handler_.Run(content::BluetoothChooser::Event::SELECTED, | 129 event_handler_.Run(content::BluetoothChooser::Event::SELECTED, |
119 devices_[index].id); | 130 devices_[index].id); |
120 } | 131 } |
121 | 132 |
122 void BluetoothChooserController::Cancel() { | 133 void BluetoothChooserController::Cancel() { |
123 RecordInteractionWithChooser(event_handler_.is_null()); | 134 RecordInteractionWithChooser(event_handler_.is_null()); |
124 if (event_handler_.is_null()) | 135 if (event_handler_.is_null()) |
125 return; | 136 return; |
126 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, | 137 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, |
127 std::string()); | 138 std::string()); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 | 282 |
272 void BluetoothChooserController::ResetEventHandler() { | 283 void BluetoothChooserController::ResetEventHandler() { |
273 event_handler_.Reset(); | 284 event_handler_.Reset(); |
274 } | 285 } |
275 | 286 |
276 void BluetoothChooserController::ClearAllDevices() { | 287 void BluetoothChooserController::ClearAllDevices() { |
277 devices_.clear(); | 288 devices_.clear(); |
278 device_id_to_name_map_.clear(); | 289 device_id_to_name_map_.clear(); |
279 device_name_counts_.clear(); | 290 device_name_counts_.clear(); |
280 } | 291 } |
OLD | NEW |