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 <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/metrics/histogram_macros.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 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) { | 31 void RecordInteractionWithChooser(bool has_null_handler) { |
| 32 UMA_HISTOGRAM_BOOLEAN("Bluetooth.Web.ChooserInteraction", has_null_handler); | 32 UMA_HISTOGRAM_BOOLEAN("Bluetooth.Web.ChooserInteraction", has_null_handler); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void RecordScanningDuration(const base::TimeDelta& duration) { | |
| 36 UMA_HISTOGRAM_MEDIUM_TIMES("Bluetooth.Web.RequestDevice.ScanningDuration", | |
|
scheib
2016/11/17 05:19:59
"UMA_HISTOGRAM_LONG_TIMES" instead I think. We've
juncai
2016/11/17 21:15:30
Done.
| |
| 37 duration); | |
| 38 } | |
| 39 | |
| 35 } // namespace | 40 } // namespace |
| 36 | 41 |
| 37 BluetoothChooserController::BluetoothChooserController( | 42 BluetoothChooserController::BluetoothChooserController( |
| 38 content::RenderFrameHost* owner, | 43 content::RenderFrameHost* owner, |
| 39 const content::BluetoothChooser::EventHandler& event_handler) | 44 const content::BluetoothChooser::EventHandler& event_handler) |
| 40 : ChooserController(owner, | 45 : ChooserController(owner, |
| 41 IDS_BLUETOOTH_DEVICE_CHOOSER_PROMPT_ORIGIN, | 46 IDS_BLUETOOTH_DEVICE_CHOOSER_PROMPT_ORIGIN, |
| 42 IDS_BLUETOOTH_DEVICE_CHOOSER_PROMPT_EXTENSION_NAME), | 47 IDS_BLUETOOTH_DEVICE_CHOOSER_PROMPT_EXTENSION_NAME), |
| 43 event_handler_(event_handler) {} | 48 event_handler_(event_handler) {} |
| 44 | 49 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 true /* Bluetooth adapter is turned on */); | 167 true /* Bluetooth adapter is turned on */); |
| 163 } | 168 } |
| 164 break; | 169 break; |
| 165 } | 170 } |
| 166 } | 171 } |
| 167 | 172 |
| 168 void BluetoothChooserController::OnDiscoveryStateChanged( | 173 void BluetoothChooserController::OnDiscoveryStateChanged( |
| 169 content::BluetoothChooser::DiscoveryState state) { | 174 content::BluetoothChooser::DiscoveryState state) { |
| 170 switch (state) { | 175 switch (state) { |
| 171 case content::BluetoothChooser::DiscoveryState::DISCOVERING: | 176 case content::BluetoothChooser::DiscoveryState::DISCOVERING: |
| 177 scanning_start_time_ = base::TimeTicks::Now(); | |
| 172 status_text_ = | 178 status_text_ = |
| 173 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING); | 179 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING); |
| 174 if (view()) { | 180 if (view()) { |
| 175 view()->OnRefreshStateChanged( | 181 view()->OnRefreshStateChanged( |
| 176 true /* Refreshing options is in progress */); | 182 true /* Refreshing options is in progress */); |
| 177 } | 183 } |
| 178 break; | 184 break; |
| 179 case content::BluetoothChooser::DiscoveryState::IDLE: | 185 case content::BluetoothChooser::DiscoveryState::IDLE: |
| 180 case content::BluetoothChooser::DiscoveryState::FAILED_TO_START: | 186 case content::BluetoothChooser::DiscoveryState::FAILED_TO_START: |
| 181 status_text_ = | 187 status_text_ = |
| 182 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN); | 188 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN); |
| 183 if (view()) { | 189 if (view()) { |
| 184 view()->OnRefreshStateChanged( | 190 view()->OnRefreshStateChanged( |
| 185 false /* Refreshing options is complete */); | 191 false /* Refreshing options is complete */); |
| 186 } | 192 } |
| 187 break; | 193 break; |
| 188 } | 194 } |
| 189 } | 195 } |
| 190 | 196 |
| 191 void BluetoothChooserController::AddOrUpdateDevice( | 197 void BluetoothChooserController::AddOrUpdateDevice( |
| 192 const std::string& device_id, | 198 const std::string& device_id, |
| 193 bool should_update_name, | 199 bool should_update_name, |
| 194 const base::string16& device_name, | 200 const base::string16& device_name, |
| 195 bool is_gatt_connected, | 201 bool is_gatt_connected, |
| 196 bool is_paired, | 202 bool is_paired, |
| 197 int signal_strength_level) { | 203 int signal_strength_level) { |
| 204 if (scanning_start_time_) { | |
|
scheib
2016/11/17 05:19:59
Why is the scanning start time reset when a new de
juncai
2016/11/17 21:15:30
Done.
| |
| 205 RecordScanningDuration(base::TimeTicks::Now() - | |
| 206 scanning_start_time_.value()); | |
| 207 scanning_start_time_.reset(); | |
| 208 } | |
| 198 auto name_it = device_id_to_name_map_.find(device_id); | 209 auto name_it = device_id_to_name_map_.find(device_id); |
| 199 if (name_it != device_id_to_name_map_.end()) { | 210 if (name_it != device_id_to_name_map_.end()) { |
| 200 if (should_update_name) { | 211 if (should_update_name) { |
| 201 base::string16 previous_device_name = name_it->second; | 212 base::string16 previous_device_name = name_it->second; |
| 202 name_it->second = device_name; | 213 name_it->second = device_name; |
| 203 | 214 |
| 204 const auto& it = device_name_counts_.find(previous_device_name); | 215 const auto& it = device_name_counts_.find(previous_device_name); |
| 205 DCHECK(it != device_name_counts_.end()); | 216 DCHECK(it != device_name_counts_.end()); |
| 206 DCHECK_GT(it->second, 0); | 217 DCHECK_GT(it->second, 0); |
| 207 | 218 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 | 280 |
| 270 void BluetoothChooserController::ResetEventHandler() { | 281 void BluetoothChooserController::ResetEventHandler() { |
| 271 event_handler_.Reset(); | 282 event_handler_.Reset(); |
| 272 } | 283 } |
| 273 | 284 |
| 274 void BluetoothChooserController::ClearAllDevices() { | 285 void BluetoothChooserController::ClearAllDevices() { |
| 275 devices_.clear(); | 286 devices_.clear(); |
| 276 device_id_to_name_map_.clear(); | 287 device_id_to_name_map_.clear(); |
| 277 device_name_counts_.clear(); | 288 device_name_counts_.clear(); |
| 278 } | 289 } |
| OLD | NEW |