Chromium Code Reviews| 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" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 const auto& it = device_name_map_.find(device_name); | 58 const auto& it = device_name_map_.find(device_name); |
| 59 DCHECK(it != device_name_map_.end()); | 59 DCHECK(it != device_name_map_.end()); |
| 60 return it->second == 1 | 60 return it->second == 1 |
| 61 ? device_name | 61 ? device_name |
| 62 : l10n_util::GetStringFUTF16( | 62 : l10n_util::GetStringFUTF16( |
| 63 IDS_DEVICE_CHOOSER_DEVICE_NAME_WITH_ID, device_name, | 63 IDS_DEVICE_CHOOSER_DEVICE_NAME_WITH_ID, device_name, |
| 64 base::UTF8ToUTF16(device_names_and_ids_[index].second)); | 64 base::UTF8ToUTF16(device_names_and_ids_[index].second)); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void BluetoothChooserController::RefreshOptions() { | 67 void BluetoothChooserController::RefreshOptions() { |
| 68 if (event_handler_.is_null()) | |
| 69 return; | |
| 68 ClearAllDevices(); | 70 ClearAllDevices(); |
| 69 event_handler_.Run(content::BluetoothChooser::Event::RESCAN, std::string()); | 71 event_handler_.Run(content::BluetoothChooser::Event::RESCAN, std::string()); |
| 70 } | 72 } |
| 71 | 73 |
| 72 base::string16 BluetoothChooserController::GetStatus() const { | 74 base::string16 BluetoothChooserController::GetStatus() const { |
| 73 return status_text_; | 75 return status_text_; |
| 74 } | 76 } |
| 75 | 77 |
| 76 void BluetoothChooserController::Select(size_t index) { | 78 void BluetoothChooserController::Select(size_t index) { |
| 79 if (event_handler_.is_null()) | |
|
Jeffrey Yasskin
2016/08/05 20:37:51
Would it make sense to record how often this happe
juncai
2016/08/05 22:51:58
Done.
| |
| 80 return; | |
| 77 DCHECK_LT(index, device_names_and_ids_.size()); | 81 DCHECK_LT(index, device_names_and_ids_.size()); |
| 78 event_handler_.Run(content::BluetoothChooser::Event::SELECTED, | 82 event_handler_.Run(content::BluetoothChooser::Event::SELECTED, |
| 79 device_names_and_ids_[index].second); | 83 device_names_and_ids_[index].second); |
| 80 } | 84 } |
| 81 | 85 |
| 82 void BluetoothChooserController::Cancel() { | 86 void BluetoothChooserController::Cancel() { |
| 87 if (event_handler_.is_null()) | |
| 88 return; | |
| 83 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, | 89 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, |
| 84 std::string()); | 90 std::string()); |
| 85 } | 91 } |
| 86 | 92 |
| 87 void BluetoothChooserController::Close() { | 93 void BluetoothChooserController::Close() { |
| 94 if (event_handler_.is_null()) | |
| 95 return; | |
| 88 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, | 96 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, |
| 89 std::string()); | 97 std::string()); |
| 90 } | 98 } |
| 91 | 99 |
| 92 void BluetoothChooserController::OpenHelpCenterUrl() const { | 100 void BluetoothChooserController::OpenHelpCenterUrl() const { |
| 93 GetBrowser()->OpenURL(content::OpenURLParams( | 101 GetBrowser()->OpenURL(content::OpenURLParams( |
| 94 GURL(chrome::kChooserBluetoothOverviewURL), content::Referrer(), | 102 GURL(chrome::kChooserBluetoothOverviewURL), content::Referrer(), |
| 95 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 103 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 96 false /* is_renderer_initialized */)); | 104 false /* is_renderer_initialized */)); |
| 97 } | 105 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 if (--device_name_map_[it->first] == 0) | 173 if (--device_name_map_[it->first] == 0) |
| 166 device_name_map_.erase(it->first); | 174 device_name_map_.erase(it->first); |
| 167 device_names_and_ids_.erase(it); | 175 device_names_and_ids_.erase(it); |
| 168 if (view()) | 176 if (view()) |
| 169 view()->OnOptionRemoved(index); | 177 view()->OnOptionRemoved(index); |
| 170 return; | 178 return; |
| 171 } | 179 } |
| 172 } | 180 } |
| 173 } | 181 } |
| 174 | 182 |
| 183 void BluetoothChooserController::ResetEventHandler() { | |
| 184 event_handler_.Reset(); | |
| 185 } | |
| 186 | |
| 175 void BluetoothChooserController::ClearAllDevices() { | 187 void BluetoothChooserController::ClearAllDevices() { |
| 176 device_names_and_ids_.clear(); | 188 device_names_and_ids_.clear(); |
| 177 device_name_map_.clear(); | 189 device_name_map_.clear(); |
| 178 } | 190 } |
| OLD | NEW |