| 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 Browser* GetBrowser() { | 24 Browser* GetBrowser() { |
| 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) { |
| 32 UMA_HISTOGRAM_BOOLEAN("Bluetooth.Web.ChooserInteraction", has_null_handler); |
| 33 } |
| 34 |
| 31 } // namespace | 35 } // namespace |
| 32 | 36 |
| 33 BluetoothChooserController::BluetoothChooserController( | 37 BluetoothChooserController::BluetoothChooserController( |
| 34 content::RenderFrameHost* owner, | 38 content::RenderFrameHost* owner, |
| 35 const content::BluetoothChooser::EventHandler& event_handler) | 39 const content::BluetoothChooser::EventHandler& event_handler) |
| 36 : ChooserController(owner, | 40 : ChooserController(owner, |
| 37 IDS_BLUETOOTH_DEVICE_CHOOSER_PROMPT_ORIGIN, | 41 IDS_BLUETOOTH_DEVICE_CHOOSER_PROMPT_ORIGIN, |
| 38 IDS_BLUETOOTH_DEVICE_CHOOSER_PROMPT_EXTENSION_NAME), | 42 IDS_BLUETOOTH_DEVICE_CHOOSER_PROMPT_EXTENSION_NAME), |
| 39 event_handler_(event_handler), | 43 event_handler_(event_handler), |
| 40 no_devices_text_(l10n_util::GetStringUTF16( | 44 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); | 75 const auto& it = device_name_counts_.find(device_name_it->second); |
| 72 DCHECK(it != device_name_counts_.end()); | 76 DCHECK(it != device_name_counts_.end()); |
| 73 return it->second == 1 | 77 return it->second == 1 |
| 74 ? device_name_it->second | 78 ? device_name_it->second |
| 75 : l10n_util::GetStringFUTF16( | 79 : l10n_util::GetStringFUTF16( |
| 76 IDS_DEVICE_CHOOSER_DEVICE_NAME_WITH_ID, | 80 IDS_DEVICE_CHOOSER_DEVICE_NAME_WITH_ID, |
| 77 device_name_it->second, base::UTF8ToUTF16(device_id)); | 81 device_name_it->second, base::UTF8ToUTF16(device_id)); |
| 78 } | 82 } |
| 79 | 83 |
| 80 void BluetoothChooserController::RefreshOptions() { | 84 void BluetoothChooserController::RefreshOptions() { |
| 85 RecordInteractionWithChooser(event_handler_.is_null()); |
| 81 if (event_handler_.is_null()) | 86 if (event_handler_.is_null()) |
| 82 return; | 87 return; |
| 83 ClearAllDevices(); | 88 ClearAllDevices(); |
| 84 event_handler_.Run(content::BluetoothChooser::Event::RESCAN, std::string()); | 89 event_handler_.Run(content::BluetoothChooser::Event::RESCAN, std::string()); |
| 85 } | 90 } |
| 86 | 91 |
| 87 base::string16 BluetoothChooserController::GetStatus() const { | 92 base::string16 BluetoothChooserController::GetStatus() const { |
| 88 return status_text_; | 93 return status_text_; |
| 89 } | 94 } |
| 90 | 95 |
| 91 void BluetoothChooserController::Select(size_t index) { | 96 void BluetoothChooserController::Select(size_t index) { |
| 97 RecordInteractionWithChooser(event_handler_.is_null()); |
| 92 if (event_handler_.is_null()) { | 98 if (event_handler_.is_null()) { |
| 93 content::RecordRequestDeviceOutcome( | |
| 94 content::UMARequestDeviceOutcome:: | |
| 95 BLUETOOTH_CHOOSER_EVENT_HANDLER_INVALID); | |
| 96 return; | 99 return; |
| 97 } | 100 } |
| 98 DCHECK_LT(index, devices_.size()); | 101 DCHECK_LT(index, devices_.size()); |
| 99 event_handler_.Run(content::BluetoothChooser::Event::SELECTED, | 102 event_handler_.Run(content::BluetoothChooser::Event::SELECTED, |
| 100 devices_[index].id); | 103 devices_[index].id); |
| 101 } | 104 } |
| 102 | 105 |
| 103 void BluetoothChooserController::Cancel() { | 106 void BluetoothChooserController::Cancel() { |
| 107 RecordInteractionWithChooser(event_handler_.is_null()); |
| 104 if (event_handler_.is_null()) | 108 if (event_handler_.is_null()) |
| 105 return; | 109 return; |
| 106 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, | 110 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, |
| 107 std::string()); | 111 std::string()); |
| 108 } | 112 } |
| 109 | 113 |
| 110 void BluetoothChooserController::Close() { | 114 void BluetoothChooserController::Close() { |
| 115 RecordInteractionWithChooser(event_handler_.is_null()); |
| 111 if (event_handler_.is_null()) | 116 if (event_handler_.is_null()) |
| 112 return; | 117 return; |
| 113 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, | 118 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, |
| 114 std::string()); | 119 std::string()); |
| 115 } | 120 } |
| 116 | 121 |
| 117 void BluetoothChooserController::OpenHelpCenterUrl() const { | 122 void BluetoothChooserController::OpenHelpCenterUrl() const { |
| 118 GetBrowser()->OpenURL(content::OpenURLParams( | 123 GetBrowser()->OpenURL(content::OpenURLParams( |
| 119 GURL(chrome::kChooserBluetoothOverviewURL), content::Referrer(), | 124 GURL(chrome::kChooserBluetoothOverviewURL), content::Referrer(), |
| 120 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 125 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 | 257 |
| 253 void BluetoothChooserController::ResetEventHandler() { | 258 void BluetoothChooserController::ResetEventHandler() { |
| 254 event_handler_.Reset(); | 259 event_handler_.Reset(); |
| 255 } | 260 } |
| 256 | 261 |
| 257 void BluetoothChooserController::ClearAllDevices() { | 262 void BluetoothChooserController::ClearAllDevices() { |
| 258 devices_.clear(); | 263 devices_.clear(); |
| 259 device_id_to_name_map_.clear(); | 264 device_id_to_name_map_.clear(); |
| 260 device_name_counts_.clear(); | 265 device_name_counts_.clear(); |
| 261 } | 266 } |
| OLD | NEW |