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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/net/referrer.h" | 9 #include "chrome/browser/net/referrer.h" |
10 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
11 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h" | 11 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 13 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
| 16 #include "content/browser/bluetooth/bluetooth_metrics.h" |
16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 Browser* GetBrowser() { | 22 Browser* GetBrowser() { |
22 chrome::ScopedTabbedBrowserDisplayer browser_displayer( | 23 chrome::ScopedTabbedBrowserDisplayer browser_displayer( |
23 ProfileManager::GetActiveUserProfile()); | 24 ProfileManager::GetActiveUserProfile()); |
24 DCHECK(browser_displayer.browser()); | 25 DCHECK(browser_displayer.browser()); |
25 return browser_displayer.browser(); | 26 return browser_displayer.browser(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 const auto& it = device_name_map_.find(device_name); | 59 const auto& it = device_name_map_.find(device_name); |
59 DCHECK(it != device_name_map_.end()); | 60 DCHECK(it != device_name_map_.end()); |
60 return it->second == 1 | 61 return it->second == 1 |
61 ? device_name | 62 ? device_name |
62 : l10n_util::GetStringFUTF16( | 63 : l10n_util::GetStringFUTF16( |
63 IDS_DEVICE_CHOOSER_DEVICE_NAME_WITH_ID, device_name, | 64 IDS_DEVICE_CHOOSER_DEVICE_NAME_WITH_ID, device_name, |
64 base::UTF8ToUTF16(device_names_and_ids_[index].second)); | 65 base::UTF8ToUTF16(device_names_and_ids_[index].second)); |
65 } | 66 } |
66 | 67 |
67 void BluetoothChooserController::RefreshOptions() { | 68 void BluetoothChooserController::RefreshOptions() { |
| 69 if (event_handler_.is_null()) |
| 70 return; |
68 ClearAllDevices(); | 71 ClearAllDevices(); |
69 event_handler_.Run(content::BluetoothChooser::Event::RESCAN, std::string()); | 72 event_handler_.Run(content::BluetoothChooser::Event::RESCAN, std::string()); |
70 } | 73 } |
71 | 74 |
72 base::string16 BluetoothChooserController::GetStatus() const { | 75 base::string16 BluetoothChooserController::GetStatus() const { |
73 return status_text_; | 76 return status_text_; |
74 } | 77 } |
75 | 78 |
76 void BluetoothChooserController::Select(size_t index) { | 79 void BluetoothChooserController::Select(size_t index) { |
| 80 if (event_handler_.is_null()) { |
| 81 content::RecordRequestDeviceOutcome( |
| 82 content::UMARequestDeviceOutcome:: |
| 83 BLUETOOTH_CHOOSER_EVENT_HANDLER_INVALID); |
| 84 return; |
| 85 } |
77 DCHECK_LT(index, device_names_and_ids_.size()); | 86 DCHECK_LT(index, device_names_and_ids_.size()); |
78 event_handler_.Run(content::BluetoothChooser::Event::SELECTED, | 87 event_handler_.Run(content::BluetoothChooser::Event::SELECTED, |
79 device_names_and_ids_[index].second); | 88 device_names_and_ids_[index].second); |
80 } | 89 } |
81 | 90 |
82 void BluetoothChooserController::Cancel() { | 91 void BluetoothChooserController::Cancel() { |
| 92 if (event_handler_.is_null()) |
| 93 return; |
83 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, | 94 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, |
84 std::string()); | 95 std::string()); |
85 } | 96 } |
86 | 97 |
87 void BluetoothChooserController::Close() { | 98 void BluetoothChooserController::Close() { |
| 99 if (event_handler_.is_null()) |
| 100 return; |
88 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, | 101 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, |
89 std::string()); | 102 std::string()); |
90 } | 103 } |
91 | 104 |
92 void BluetoothChooserController::OpenHelpCenterUrl() const { | 105 void BluetoothChooserController::OpenHelpCenterUrl() const { |
93 GetBrowser()->OpenURL(content::OpenURLParams( | 106 GetBrowser()->OpenURL(content::OpenURLParams( |
94 GURL(chrome::kChooserBluetoothOverviewURL), content::Referrer(), | 107 GURL(chrome::kChooserBluetoothOverviewURL), content::Referrer(), |
95 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 108 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
96 false /* is_renderer_initialized */)); | 109 false /* is_renderer_initialized */)); |
97 } | 110 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 if (--device_name_map_[it->first] == 0) | 178 if (--device_name_map_[it->first] == 0) |
166 device_name_map_.erase(it->first); | 179 device_name_map_.erase(it->first); |
167 device_names_and_ids_.erase(it); | 180 device_names_and_ids_.erase(it); |
168 if (view()) | 181 if (view()) |
169 view()->OnOptionRemoved(index); | 182 view()->OnOptionRemoved(index); |
170 return; | 183 return; |
171 } | 184 } |
172 } | 185 } |
173 } | 186 } |
174 | 187 |
| 188 void BluetoothChooserController::ResetEventHandler() { |
| 189 event_handler_.Reset(); |
| 190 } |
| 191 |
175 void BluetoothChooserController::ClearAllDevices() { | 192 void BluetoothChooserController::ClearAllDevices() { |
176 device_names_and_ids_.clear(); | 193 device_names_and_ids_.clear(); |
177 device_name_map_.clear(); | 194 device_name_map_.clear(); |
178 } | 195 } |
OLD | NEW |