Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: content/browser/bluetooth/bluetooth_device_chooser_controller.cc

Issue 2304213002: Show device connection and paired status in chooser on Mac (Closed)
Patch Set: updated variable name Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/browser/bluetooth/bluetooth_device_chooser_controller.h" 5 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <unordered_set> 9 #include <unordered_set>
10 10
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 191 }
192 NOTREACHED(); 192 NOTREACHED();
193 return UMARequestDeviceOutcome::SUCCESS; 193 return UMARequestDeviceOutcome::SUCCESS;
194 } 194 }
195 195
196 } // namespace 196 } // namespace
197 197
198 BluetoothDeviceChooserController::BluetoothDeviceChooserController( 198 BluetoothDeviceChooserController::BluetoothDeviceChooserController(
199 WebBluetoothServiceImpl* web_bluetooth_service, 199 WebBluetoothServiceImpl* web_bluetooth_service,
200 RenderFrameHost* render_frame_host, 200 RenderFrameHost* render_frame_host,
201 device::BluetoothAdapter* adapter) 201 device::BluetoothAdapter* adapter,
202 BluetoothAllowedDevicesMap* bluetooth_allowed_devices_map,
203 const url::Origin& origin)
202 : adapter_(adapter), 204 : adapter_(adapter),
203 web_bluetooth_service_(web_bluetooth_service), 205 web_bluetooth_service_(web_bluetooth_service),
204 render_frame_host_(render_frame_host), 206 render_frame_host_(render_frame_host),
205 web_contents_(WebContents::FromRenderFrameHost(render_frame_host_)), 207 web_contents_(WebContents::FromRenderFrameHost(render_frame_host_)),
206 discovery_session_timer_( 208 discovery_session_timer_(
207 FROM_HERE, 209 FROM_HERE,
208 // TODO(jyasskin): Add a way for tests to control the dialog 210 // TODO(jyasskin): Add a way for tests to control the dialog
209 // directly, and change this to a reasonable discovery timeout. 211 // directly, and change this to a reasonable discovery timeout.
210 base::TimeDelta::FromSeconds( 212 base::TimeDelta::FromSeconds(
211 use_test_scan_duration_ ? kTestScanDuration : kScanDuration), 213 use_test_scan_duration_ ? kTestScanDuration : kScanDuration),
212 base::Bind(&BluetoothDeviceChooserController::StopDeviceDiscovery, 214 base::Bind(&BluetoothDeviceChooserController::StopDeviceDiscovery,
213 // base::Timer guarantees it won't call back after its 215 // base::Timer guarantees it won't call back after its
214 // destructor starts. 216 // destructor starts.
215 base::Unretained(this)), 217 base::Unretained(this)),
216 /*is_repeating=*/false), 218 /*is_repeating=*/false),
219 bluetooth_allowed_devices_map_(bluetooth_allowed_devices_map),
220 origin_(origin),
217 weak_ptr_factory_(this) { 221 weak_ptr_factory_(this) {
218 CHECK(adapter_); 222 CHECK(adapter_);
219 } 223 }
220 224
221 BluetoothDeviceChooserController::~BluetoothDeviceChooserController() { 225 BluetoothDeviceChooserController::~BluetoothDeviceChooserController() {
222 if (chooser_) { 226 if (chooser_) {
223 DCHECK(!error_callback_.is_null()); 227 DCHECK(!error_callback_.is_null());
224 error_callback_.Run(blink::mojom::WebBluetoothError::CHOOSER_CANCELLED); 228 error_callback_.Run(blink::mojom::WebBluetoothError::CHOOSER_CANCELLED);
225 } 229 }
226 } 230 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 return; 347 return;
344 } 348 }
345 349
346 StartDeviceDiscovery(); 350 StartDeviceDiscovery();
347 } 351 }
348 352
349 void BluetoothDeviceChooserController::AddFilteredDevice( 353 void BluetoothDeviceChooserController::AddFilteredDevice(
350 const device::BluetoothDevice& device) { 354 const device::BluetoothDevice& device) {
351 if (chooser_.get() && MatchesFilters(device, options_->filters)) { 355 if (chooser_.get() && MatchesFilters(device, options_->filters)) {
352 base::Optional<int8_t> rssi = device.GetInquiryRSSI(); 356 base::Optional<int8_t> rssi = device.GetInquiryRSSI();
357 bool is_paired = false;
358 const WebBluetoothDeviceId* device_id_ptr =
359 bluetooth_allowed_devices_map_->GetDeviceId(origin_,
360 device.GetAddress());
361 if (device_id_ptr) {
ortuno 2016/09/12 03:45:22 As long as the user has paired with the device in
juncai 2016/09/12 20:37:12 Done.
362 device::BluetoothDevice::UUIDSet uuids = device.GetUUIDs();
363 for (const auto& uuid : uuids) {
364 if (bluetooth_allowed_devices_map_->IsOriginAllowedToAccessService(
365 origin_, *device_id_ptr, uuid)) {
366 is_paired = true;
367 break;
368 }
369 }
370 }
371
353 chooser_->AddOrUpdateDevice( 372 chooser_->AddOrUpdateDevice(
354 device.GetAddress(), !!device.GetName() /* should_update_name */, 373 device.GetAddress(), !!device.GetName() /* should_update_name */,
355 device.GetNameForDisplay(), 374 device.GetNameForDisplay(),
356 // TODO(http://crbug.com/543466): Show connection and paired status. 375 device.IsGattConnected() /* is_gatt_connected */,
ortuno 2016/09/12 03:45:22 I don't think you need the comments anymore. It's
juncai 2016/09/12 20:37:12 Done.
357 false /* is_gatt_connected */, false /* is_paired */, 376 is_paired /* is_paired */,
358 rssi ? CalculateSignalStrengthLevel(rssi.value()) : -1); 377 rssi ? CalculateSignalStrengthLevel(rssi.value()) : -1);
359 } 378 }
360 } 379 }
361 380
362 void BluetoothDeviceChooserController::AdapterPoweredChanged(bool powered) { 381 void BluetoothDeviceChooserController::AdapterPoweredChanged(bool powered) {
363 if (!powered && discovery_session_.get()) { 382 if (!powered && discovery_session_.get()) {
364 StopDiscoverySession(std::move(discovery_session_)); 383 StopDiscoverySession(std::move(discovery_session_));
365 } 384 }
366 385
367 if (chooser_.get()) { 386 if (chooser_.get()) {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 528
510 void BluetoothDeviceChooserController::PostErrorCallback( 529 void BluetoothDeviceChooserController::PostErrorCallback(
511 blink::mojom::WebBluetoothError error) { 530 blink::mojom::WebBluetoothError error) {
512 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( 531 if (!base::ThreadTaskRunnerHandle::Get()->PostTask(
513 FROM_HERE, base::Bind(error_callback_, error))) { 532 FROM_HERE, base::Bind(error_callback_, error))) {
514 LOG(WARNING) << "No TaskRunner."; 533 LOG(WARNING) << "No TaskRunner.";
515 } 534 }
516 } 535 }
517 536
518 } // namespace content 537 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698