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 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()) |
|
msw
2016/07/20 20:37:07
nit: for each of these multi-line conditional bloc
juncai
2016/07/20 22:37:45
Done.
| |
| 111 observer()->OnAdapterEnabledChanged( | 111 view()->OnAdapterEnabledChanged( |
| 112 false /* Bluetooth adapter is turned off */); | 112 false /* Bluetooth adapter is turned off */); |
| 113 break; | 113 break; |
| 114 case content::BluetoothChooser::AdapterPresence::POWERED_ON: | 114 case content::BluetoothChooser::AdapterPresence::POWERED_ON: |
| 115 no_devices_text_ = | 115 no_devices_text_ = |
| 116 l10n_util::GetStringUTF16(IDS_DEVICE_CHOOSER_NO_DEVICES_FOUND_PROMPT); | 116 l10n_util::GetStringUTF16(IDS_DEVICE_CHOOSER_NO_DEVICES_FOUND_PROMPT); |
| 117 status_text_ = | 117 status_text_ = |
| 118 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN); | 118 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN); |
| 119 if (observer()) | 119 if (view()) |
| 120 observer()->OnAdapterEnabledChanged( | 120 view()->OnAdapterEnabledChanged( |
| 121 true /* Bluetooth adapter is turned on */); | 121 true /* Bluetooth adapter is turned on */); |
| 122 break; | 122 break; |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 | 125 |
| 126 void BluetoothChooserController::OnDiscoveryStateChanged( | 126 void BluetoothChooserController::OnDiscoveryStateChanged( |
| 127 content::BluetoothChooser::DiscoveryState state) { | 127 content::BluetoothChooser::DiscoveryState state) { |
| 128 switch (state) { | 128 switch (state) { |
| 129 case content::BluetoothChooser::DiscoveryState::DISCOVERING: | 129 case content::BluetoothChooser::DiscoveryState::DISCOVERING: |
| 130 status_text_ = | 130 status_text_ = |
| 131 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING); | 131 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING); |
| 132 if (observer()) | 132 if (view()) |
| 133 observer()->OnRefreshStateChanged( | 133 view()->OnRefreshStateChanged( |
| 134 true /* Refreshing options is in progress */); | 134 true /* Refreshing options is in progress */); |
| 135 break; | 135 break; |
| 136 case content::BluetoothChooser::DiscoveryState::IDLE: | 136 case content::BluetoothChooser::DiscoveryState::IDLE: |
| 137 case content::BluetoothChooser::DiscoveryState::FAILED_TO_START: | 137 case content::BluetoothChooser::DiscoveryState::FAILED_TO_START: |
| 138 status_text_ = | 138 status_text_ = |
| 139 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN); | 139 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN); |
| 140 if (observer()) | 140 if (view()) |
| 141 observer()->OnRefreshStateChanged( | 141 view()->OnRefreshStateChanged( |
| 142 false /* Refreshing options is complete */); | 142 false /* Refreshing options is complete */); |
| 143 break; | 143 break; |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 | 146 |
| 147 void BluetoothChooserController::AddDevice(const std::string& device_id, | 147 void BluetoothChooserController::AddDevice(const std::string& device_id, |
| 148 const base::string16& device_name) { | 148 const base::string16& device_name) { |
| 149 device_names_and_ids_.push_back(std::make_pair(device_name, device_id)); | 149 device_names_and_ids_.push_back(std::make_pair(device_name, device_id)); |
| 150 ++device_name_map_[device_name]; | 150 ++device_name_map_[device_name]; |
| 151 if (observer()) | 151 if (view()) |
| 152 observer()->OnOptionAdded(device_names_and_ids_.size() - 1); | 152 view()->OnOptionAdded(device_names_and_ids_.size() - 1); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void BluetoothChooserController::RemoveDevice(const std::string& device_id) { | 155 void BluetoothChooserController::RemoveDevice(const std::string& device_id) { |
| 156 for (auto it = device_names_and_ids_.begin(); | 156 for (auto it = device_names_and_ids_.begin(); |
| 157 it != device_names_and_ids_.end(); ++it) { | 157 it != device_names_and_ids_.end(); ++it) { |
| 158 if (it->second == device_id) { | 158 if (it->second == device_id) { |
| 159 size_t index = it - device_names_and_ids_.begin(); | 159 size_t index = it - device_names_and_ids_.begin(); |
| 160 DCHECK_GT(device_name_map_[it->first], 0); | 160 DCHECK_GT(device_name_map_[it->first], 0); |
| 161 if (--device_name_map_[it->first] == 0) | 161 if (--device_name_map_[it->first] == 0) |
| 162 device_name_map_.erase(it->first); | 162 device_name_map_.erase(it->first); |
| 163 device_names_and_ids_.erase(it); | 163 device_names_and_ids_.erase(it); |
| 164 if (observer()) | 164 if (view()) |
| 165 observer()->OnOptionRemoved(index); | 165 view()->OnOptionRemoved(index); |
| 166 return; | 166 return; |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 | 170 |
| 171 void BluetoothChooserController::ClearAllDevices() { | 171 void BluetoothChooserController::ClearAllDevices() { |
| 172 device_names_and_ids_.clear(); | 172 device_names_and_ids_.clear(); |
| 173 device_name_map_.clear(); | 173 device_name_map_.clear(); |
| 174 } | 174 } |
| OLD | NEW |