| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 content::BluetoothChooser::AdapterPresence presence) { | 100 content::BluetoothChooser::AdapterPresence presence) { |
| 101 ClearAllDevices(); | 101 ClearAllDevices(); |
| 102 switch (presence) { | 102 switch (presence) { |
| 103 case content::BluetoothChooser::AdapterPresence::ABSENT: | 103 case content::BluetoothChooser::AdapterPresence::ABSENT: |
| 104 NOTREACHED(); | 104 NOTREACHED(); |
| 105 break; | 105 break; |
| 106 case content::BluetoothChooser::AdapterPresence::POWERED_OFF: | 106 case content::BluetoothChooser::AdapterPresence::POWERED_OFF: |
| 107 no_devices_text_ = | 107 no_devices_text_ = |
| 108 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_ADAPTER_OFF); | 108 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_ADAPTER_OFF); |
| 109 status_text_ = base::string16(); | 109 status_text_ = base::string16(); |
| 110 if (observer()) | 110 if (view()) { |
| 111 observer()->OnAdapterEnabledChanged( | 111 view()->OnAdapterEnabledChanged( |
| 112 false /* Bluetooth adapter is turned off */); | 112 false /* Bluetooth adapter is turned off */); |
| 113 } |
| 113 break; | 114 break; |
| 114 case content::BluetoothChooser::AdapterPresence::POWERED_ON: | 115 case content::BluetoothChooser::AdapterPresence::POWERED_ON: |
| 115 no_devices_text_ = | 116 no_devices_text_ = |
| 116 l10n_util::GetStringUTF16(IDS_DEVICE_CHOOSER_NO_DEVICES_FOUND_PROMPT); | 117 l10n_util::GetStringUTF16(IDS_DEVICE_CHOOSER_NO_DEVICES_FOUND_PROMPT); |
| 117 status_text_ = | 118 status_text_ = |
| 118 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN); | 119 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN); |
| 119 if (observer()) | 120 if (view()) { |
| 120 observer()->OnAdapterEnabledChanged( | 121 view()->OnAdapterEnabledChanged( |
| 121 true /* Bluetooth adapter is turned on */); | 122 true /* Bluetooth adapter is turned on */); |
| 123 } |
| 122 break; | 124 break; |
| 123 } | 125 } |
| 124 } | 126 } |
| 125 | 127 |
| 126 void BluetoothChooserController::OnDiscoveryStateChanged( | 128 void BluetoothChooserController::OnDiscoveryStateChanged( |
| 127 content::BluetoothChooser::DiscoveryState state) { | 129 content::BluetoothChooser::DiscoveryState state) { |
| 128 switch (state) { | 130 switch (state) { |
| 129 case content::BluetoothChooser::DiscoveryState::DISCOVERING: | 131 case content::BluetoothChooser::DiscoveryState::DISCOVERING: |
| 130 status_text_ = | 132 status_text_ = |
| 131 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING); | 133 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING); |
| 132 if (observer()) | 134 if (view()) { |
| 133 observer()->OnRefreshStateChanged( | 135 view()->OnRefreshStateChanged( |
| 134 true /* Refreshing options is in progress */); | 136 true /* Refreshing options is in progress */); |
| 137 } |
| 135 break; | 138 break; |
| 136 case content::BluetoothChooser::DiscoveryState::IDLE: | 139 case content::BluetoothChooser::DiscoveryState::IDLE: |
| 137 case content::BluetoothChooser::DiscoveryState::FAILED_TO_START: | 140 case content::BluetoothChooser::DiscoveryState::FAILED_TO_START: |
| 138 status_text_ = | 141 status_text_ = |
| 139 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN); | 142 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN); |
| 140 if (observer()) | 143 if (view()) { |
| 141 observer()->OnRefreshStateChanged( | 144 view()->OnRefreshStateChanged( |
| 142 false /* Refreshing options is complete */); | 145 false /* Refreshing options is complete */); |
| 146 } |
| 143 break; | 147 break; |
| 144 } | 148 } |
| 145 } | 149 } |
| 146 | 150 |
| 147 void BluetoothChooserController::AddDevice(const std::string& device_id, | 151 void BluetoothChooserController::AddDevice(const std::string& device_id, |
| 148 const base::string16& device_name) { | 152 const base::string16& device_name) { |
| 149 device_names_and_ids_.push_back(std::make_pair(device_name, device_id)); | 153 device_names_and_ids_.push_back(std::make_pair(device_name, device_id)); |
| 150 ++device_name_map_[device_name]; | 154 ++device_name_map_[device_name]; |
| 151 if (observer()) | 155 if (view()) |
| 152 observer()->OnOptionAdded(device_names_and_ids_.size() - 1); | 156 view()->OnOptionAdded(device_names_and_ids_.size() - 1); |
| 153 } | 157 } |
| 154 | 158 |
| 155 void BluetoothChooserController::RemoveDevice(const std::string& device_id) { | 159 void BluetoothChooserController::RemoveDevice(const std::string& device_id) { |
| 156 for (auto it = device_names_and_ids_.begin(); | 160 for (auto it = device_names_and_ids_.begin(); |
| 157 it != device_names_and_ids_.end(); ++it) { | 161 it != device_names_and_ids_.end(); ++it) { |
| 158 if (it->second == device_id) { | 162 if (it->second == device_id) { |
| 159 size_t index = it - device_names_and_ids_.begin(); | 163 size_t index = it - device_names_and_ids_.begin(); |
| 160 DCHECK_GT(device_name_map_[it->first], 0); | 164 DCHECK_GT(device_name_map_[it->first], 0); |
| 161 if (--device_name_map_[it->first] == 0) | 165 if (--device_name_map_[it->first] == 0) |
| 162 device_name_map_.erase(it->first); | 166 device_name_map_.erase(it->first); |
| 163 device_names_and_ids_.erase(it); | 167 device_names_and_ids_.erase(it); |
| 164 if (observer()) | 168 if (view()) |
| 165 observer()->OnOptionRemoved(index); | 169 view()->OnOptionRemoved(index); |
| 166 return; | 170 return; |
| 167 } | 171 } |
| 168 } | 172 } |
| 169 } | 173 } |
| 170 | 174 |
| 171 void BluetoothChooserController::ClearAllDevices() { | 175 void BluetoothChooserController::ClearAllDevices() { |
| 172 device_names_and_ids_.clear(); | 176 device_names_and_ids_.clear(); |
| 173 device_name_map_.clear(); | 177 device_name_map_.clear(); |
| 174 } | 178 } |
| OLD | NEW |