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

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

Issue 1389553002: bluetooth: Detect and fix incorrect thread usage of BluetoothDispatcherHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DCHECK_CURRENTLY_ON(BrowserThread::UI); Created 5 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // NETWORK_ERROR Note: 5 // NETWORK_ERROR Note:
6 // When a device can't be found in the BluetoothAdapter, that generally 6 // When a device can't be found in the BluetoothAdapter, that generally
7 // indicates that it's gone out of range. We reject with a NetworkError in that 7 // indicates that it's gone out of range. We reject with a NetworkError in that
8 // case. 8 // case.
9 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-conne ctgatt 9 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-conne ctgatt
10 10
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // TODO(jyasskin): Add a way for tests to control the dialog 164 // TODO(jyasskin): Add a way for tests to control the dialog
165 // directly, and change this to a reasonable discovery timeout. 165 // directly, and change this to a reasonable discovery timeout.
166 base::TimeDelta::FromSecondsD(current_delay_time_), 166 base::TimeDelta::FromSecondsD(current_delay_time_),
167 base::Bind(&BluetoothDispatcherHost::StopDeviceDiscovery, 167 base::Bind(&BluetoothDispatcherHost::StopDeviceDiscovery,
168 // base::Timer guarantees it won't call back after its 168 // base::Timer guarantees it won't call back after its
169 // destructor starts. 169 // destructor starts.
170 base::Unretained(this)), 170 base::Unretained(this)),
171 /*is_repeating=*/false), 171 /*is_repeating=*/false),
172 weak_ptr_factory_(this) { 172 weak_ptr_factory_(this) {
173 DCHECK_CURRENTLY_ON(BrowserThread::UI); 173 DCHECK_CURRENTLY_ON(BrowserThread::UI);
174
175 // Bind all future weak pointers to the UI thread.
176 weak_ptr_on_ui_thread_ = weak_ptr_factory_.GetWeakPtr();
177 weak_ptr_on_ui_thread_.get(); // Associates with UI thread.
178
174 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) 179 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable())
175 BluetoothAdapterFactory::GetAdapter( 180 BluetoothAdapterFactory::GetAdapter(
176 base::Bind(&BluetoothDispatcherHost::set_adapter, 181 base::Bind(&BluetoothDispatcherHost::set_adapter,
177 weak_ptr_factory_.GetWeakPtr())); 182 weak_ptr_factory_.GetWeakPtr()));
178 } 183 }
179 184
180 void BluetoothDispatcherHost::OnDestruct() const { 185 void BluetoothDispatcherHost::OnDestruct() const {
181 // See class comment: UI Thread Note. 186 // See class comment: UI Thread Note.
182 BrowserThread::DeleteOnUIThread::Destruct(this); 187 BrowserThread::DeleteOnUIThread::Destruct(this);
183 } 188 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 if (adapter_.get()) 276 if (adapter_.get())
272 adapter_->RemoveObserver(this); 277 adapter_->RemoveObserver(this);
273 adapter_ = adapter; 278 adapter_ = adapter;
274 if (adapter_.get()) 279 if (adapter_.get())
275 adapter_->AddObserver(this); 280 adapter_->AddObserver(this);
276 } 281 }
277 282
278 void BluetoothDispatcherHost::StartDeviceDiscovery( 283 void BluetoothDispatcherHost::StartDeviceDiscovery(
279 RequestDeviceSession* session, 284 RequestDeviceSession* session,
280 int chooser_id) { 285 int chooser_id) {
286 DCHECK_CURRENTLY_ON(BrowserThread::UI);
281 if (session->discovery_session) { 287 if (session->discovery_session) {
282 // Already running; just increase the timeout. 288 // Already running; just increase the timeout.
283 discovery_session_timer_.Reset(); 289 discovery_session_timer_.Reset();
284 } else { 290 } else {
285 session->chooser->ShowDiscoveryState( 291 session->chooser->ShowDiscoveryState(
286 BluetoothChooser::DiscoveryState::DISCOVERING); 292 BluetoothChooser::DiscoveryState::DISCOVERING);
287 adapter_->StartDiscoverySessionWithFilter( 293 adapter_->StartDiscoverySessionWithFilter(
288 session->ComputeScanFilter(), 294 session->ComputeScanFilter(),
289 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStarted, 295 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStarted,
290 weak_ptr_factory_.GetWeakPtr(), chooser_id), 296 weak_ptr_on_ui_thread_, chooser_id),
291 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStartedError, 297 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStartedError,
292 weak_ptr_factory_.GetWeakPtr(), chooser_id)); 298 weak_ptr_on_ui_thread_, chooser_id));
293 } 299 }
294 } 300 }
295 301
296 void BluetoothDispatcherHost::StopDeviceDiscovery() { 302 void BluetoothDispatcherHost::StopDeviceDiscovery() {
303 DCHECK_CURRENTLY_ON(BrowserThread::UI);
297 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter( 304 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter(
298 &request_device_sessions_); 305 &request_device_sessions_);
299 !iter.IsAtEnd(); iter.Advance()) { 306 !iter.IsAtEnd(); iter.Advance()) {
300 RequestDeviceSession* session = iter.GetCurrentValue(); 307 RequestDeviceSession* session = iter.GetCurrentValue();
301 if (session->discovery_session) { 308 if (session->discovery_session) {
302 StopDiscoverySession(session->discovery_session.Pass()); 309 StopDiscoverySession(session->discovery_session.Pass());
303 } 310 }
304 if (session->chooser) { 311 if (session->chooser) {
305 session->chooser->ShowDiscoveryState( 312 session->chooser->ShowDiscoveryState(
306 BluetoothChooser::DiscoveryState::IDLE); 313 BluetoothChooser::DiscoveryState::IDLE);
307 } 314 }
308 } 315 }
309 } 316 }
310 317
311 void BluetoothDispatcherHost::AdapterPoweredChanged( 318 void BluetoothDispatcherHost::AdapterPoweredChanged(
312 device::BluetoothAdapter* adapter, 319 device::BluetoothAdapter* adapter,
313 bool powered) { 320 bool powered) {
321 DCHECK_CURRENTLY_ON(BrowserThread::UI);
314 const BluetoothChooser::AdapterPresence presence = 322 const BluetoothChooser::AdapterPresence presence =
315 powered ? BluetoothChooser::AdapterPresence::POWERED_ON 323 powered ? BluetoothChooser::AdapterPresence::POWERED_ON
316 : BluetoothChooser::AdapterPresence::POWERED_OFF; 324 : BluetoothChooser::AdapterPresence::POWERED_OFF;
317 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter( 325 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter(
318 &request_device_sessions_); 326 &request_device_sessions_);
319 !iter.IsAtEnd(); iter.Advance()) { 327 !iter.IsAtEnd(); iter.Advance()) {
320 RequestDeviceSession* session = iter.GetCurrentValue(); 328 RequestDeviceSession* session = iter.GetCurrentValue();
321 if (session->chooser) 329 if (session->chooser)
322 session->chooser->SetAdapterPresence(presence); 330 session->chooser->SetAdapterPresence(presence);
323 } 331 }
324 } 332 }
325 333
326 void BluetoothDispatcherHost::DeviceAdded(device::BluetoothAdapter* adapter, 334 void BluetoothDispatcherHost::DeviceAdded(device::BluetoothAdapter* adapter,
327 device::BluetoothDevice* device) { 335 device::BluetoothDevice* device) {
336 DCHECK_CURRENTLY_ON(BrowserThread::UI);
328 VLOG(1) << "Adding device to all choosers: " << device->GetAddress(); 337 VLOG(1) << "Adding device to all choosers: " << device->GetAddress();
329 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter( 338 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter(
330 &request_device_sessions_); 339 &request_device_sessions_);
331 !iter.IsAtEnd(); iter.Advance()) { 340 !iter.IsAtEnd(); iter.Advance()) {
332 RequestDeviceSession* session = iter.GetCurrentValue(); 341 RequestDeviceSession* session = iter.GetCurrentValue();
333 session->AddFilteredDevice(*device); 342 session->AddFilteredDevice(*device);
334 } 343 }
335 } 344 }
336 345
337 void BluetoothDispatcherHost::DeviceRemoved(device::BluetoothAdapter* adapter, 346 void BluetoothDispatcherHost::DeviceRemoved(device::BluetoothAdapter* adapter,
338 device::BluetoothDevice* device) { 347 device::BluetoothDevice* device) {
348 DCHECK_CURRENTLY_ON(BrowserThread::UI);
339 VLOG(1) << "Marking device removed on all choosers: " << device->GetAddress(); 349 VLOG(1) << "Marking device removed on all choosers: " << device->GetAddress();
340 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter( 350 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter(
341 &request_device_sessions_); 351 &request_device_sessions_);
342 !iter.IsAtEnd(); iter.Advance()) { 352 !iter.IsAtEnd(); iter.Advance()) {
343 RequestDeviceSession* session = iter.GetCurrentValue(); 353 RequestDeviceSession* session = iter.GetCurrentValue();
344 if (session->chooser) { 354 if (session->chooser) {
345 session->chooser->RemoveDevice(device->GetAddress()); 355 session->chooser->RemoveDevice(device->GetAddress());
346 } 356 }
347 } 357 }
348 } 358 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 } 410 }
401 411
402 // Create storage for the information that backs the chooser, and show the 412 // Create storage for the information that backs the chooser, and show the
403 // chooser. 413 // chooser.
404 RequestDeviceSession* const session = new RequestDeviceSession( 414 RequestDeviceSession* const session = new RequestDeviceSession(
405 thread_id, request_id, filters, optional_services); 415 thread_id, request_id, filters, optional_services);
406 int chooser_id = request_device_sessions_.Add(session); 416 int chooser_id = request_device_sessions_.Add(session);
407 417
408 BluetoothChooser::EventHandler chooser_event_handler = 418 BluetoothChooser::EventHandler chooser_event_handler =
409 base::Bind(&BluetoothDispatcherHost::OnBluetoothChooserEvent, 419 base::Bind(&BluetoothDispatcherHost::OnBluetoothChooserEvent,
410 weak_ptr_factory_.GetWeakPtr(), chooser_id); 420 weak_ptr_on_ui_thread_, chooser_id);
411 if (WebContents* web_contents = 421 if (WebContents* web_contents =
412 WebContents::FromRenderFrameHost(render_frame_host)) { 422 WebContents::FromRenderFrameHost(render_frame_host)) {
413 if (WebContentsDelegate* delegate = web_contents->GetDelegate()) { 423 if (WebContentsDelegate* delegate = web_contents->GetDelegate()) {
414 session->chooser = delegate->RunBluetoothChooser( 424 session->chooser = delegate->RunBluetoothChooser(
415 web_contents, chooser_event_handler, 425 web_contents, chooser_event_handler,
416 render_frame_host->GetLastCommittedURL().GetOrigin()); 426 render_frame_host->GetLastCommittedURL().GetOrigin());
417 } 427 }
418 } 428 }
419 if (!session->chooser) { 429 if (!session->chooser) {
420 LOG(WARNING) 430 LOG(WARNING)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 // the device. https://crbug.com/484745 469 // the device. https://crbug.com/484745
460 device::BluetoothDevice* device = adapter_->GetDevice(device_instance_id); 470 device::BluetoothDevice* device = adapter_->GetDevice(device_instance_id);
461 if (device == nullptr) { // See "NETWORK_ERROR Note" above. 471 if (device == nullptr) { // See "NETWORK_ERROR Note" above.
462 RecordConnectGATTOutcome(UMAConnectGATTOutcome::NO_DEVICE); 472 RecordConnectGATTOutcome(UMAConnectGATTOutcome::NO_DEVICE);
463 Send(new BluetoothMsg_ConnectGATTError( 473 Send(new BluetoothMsg_ConnectGATTError(
464 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange)); 474 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange));
465 return; 475 return;
466 } 476 }
467 device->CreateGattConnection( 477 device->CreateGattConnection(
468 base::Bind(&BluetoothDispatcherHost::OnGATTConnectionCreated, 478 base::Bind(&BluetoothDispatcherHost::OnGATTConnectionCreated,
469 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, 479 weak_ptr_on_ui_thread_, thread_id, request_id,
470 device_instance_id, start_time), 480 device_instance_id, start_time),
471 base::Bind(&BluetoothDispatcherHost::OnCreateGATTConnectionError, 481 base::Bind(&BluetoothDispatcherHost::OnCreateGATTConnectionError,
472 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, 482 weak_ptr_on_ui_thread_, thread_id, request_id,
473 device_instance_id, start_time)); 483 device_instance_id, start_time));
474 } 484 }
475 485
476 void BluetoothDispatcherHost::OnGetPrimaryService( 486 void BluetoothDispatcherHost::OnGetPrimaryService(
477 int thread_id, 487 int thread_id,
478 int request_id, 488 int request_id,
479 const std::string& device_instance_id, 489 const std::string& device_instance_id,
480 const std::string& service_uuid) { 490 const std::string& service_uuid) {
481 DCHECK_CURRENTLY_ON(BrowserThread::UI); 491 DCHECK_CURRENTLY_ON(BrowserThread::UI);
482 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_PRIMARY_SERVICE); 492 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_PRIMARY_SERVICE);
483 RecordGetPrimaryServiceService(BluetoothUUID(service_uuid)); 493 RecordGetPrimaryServiceService(BluetoothUUID(service_uuid));
484 494
485 // TODO(ortuno): Check if device_instance_id is in "allowed devices" 495 // TODO(ortuno): Check if device_instance_id is in "allowed devices"
486 // https://crbug.com/493459 496 // https://crbug.com/493459
487 // TODO(ortuno): Check if service_uuid is in "allowed services" 497 // TODO(ortuno): Check if service_uuid is in "allowed services"
488 // https://crbug.com/493460 498 // https://crbug.com/493460
489 // For now just wait a fixed time and call OnServiceDiscovered. 499 // For now just wait a fixed time and call OnServiceDiscovered.
490 // TODO(ortuno): Use callback once it's implemented http://crbug.com/484504 500 // TODO(ortuno): Use callback once it's implemented http://crbug.com/484504
491 BrowserThread::PostDelayedTask( 501 BrowserThread::PostDelayedTask(
492 BrowserThread::UI, FROM_HERE, 502 BrowserThread::UI, FROM_HERE,
493 base::Bind(&BluetoothDispatcherHost::OnServicesDiscovered, 503 base::Bind(&BluetoothDispatcherHost::OnServicesDiscovered,
494 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, 504 weak_ptr_on_ui_thread_, thread_id, request_id,
495 device_instance_id, service_uuid), 505 device_instance_id, service_uuid),
496 base::TimeDelta::FromSeconds(current_delay_time_)); 506 base::TimeDelta::FromSeconds(current_delay_time_));
497 } 507 }
498 508
499 void BluetoothDispatcherHost::OnGetCharacteristic( 509 void BluetoothDispatcherHost::OnGetCharacteristic(
500 int thread_id, 510 int thread_id,
501 int request_id, 511 int request_id,
502 const std::string& service_instance_id, 512 const std::string& service_instance_id,
503 const std::string& characteristic_uuid) { 513 const std::string& characteristic_uuid) {
504 DCHECK_CURRENTLY_ON(BrowserThread::UI); 514 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 RecordCharacteristicReadValueOutcome( 622 RecordCharacteristicReadValueOutcome(
613 UMAGATTOperationOutcome::NO_CHARACTERISTIC); 623 UMAGATTOperationOutcome::NO_CHARACTERISTIC);
614 Send(new BluetoothMsg_ReadCharacteristicValueError( 624 Send(new BluetoothMsg_ReadCharacteristicValueError(
615 thread_id, request_id, 625 thread_id, request_id,
616 WebBluetoothError::CharacteristicNoLongerExists)); 626 WebBluetoothError::CharacteristicNoLongerExists));
617 return; 627 return;
618 } 628 }
619 629
620 characteristic->ReadRemoteCharacteristic( 630 characteristic->ReadRemoteCharacteristic(
621 base::Bind(&BluetoothDispatcherHost::OnCharacteristicValueRead, 631 base::Bind(&BluetoothDispatcherHost::OnCharacteristicValueRead,
622 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), 632 weak_ptr_on_ui_thread_, thread_id, request_id),
623 base::Bind(&BluetoothDispatcherHost::OnCharacteristicReadValueError, 633 base::Bind(&BluetoothDispatcherHost::OnCharacteristicReadValueError,
624 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); 634 weak_ptr_on_ui_thread_, thread_id, request_id));
625 } 635 }
626 636
627 void BluetoothDispatcherHost::OnWriteValue( 637 void BluetoothDispatcherHost::OnWriteValue(
628 int thread_id, 638 int thread_id,
629 int request_id, 639 int request_id,
630 const std::string& characteristic_instance_id, 640 const std::string& characteristic_instance_id,
631 const std::vector<uint8_t>& value) { 641 const std::vector<uint8_t>& value) {
632 DCHECK_CURRENTLY_ON(BrowserThread::UI); 642 DCHECK_CURRENTLY_ON(BrowserThread::UI);
633 RecordWebBluetoothFunctionCall( 643 RecordWebBluetoothFunctionCall(
634 UMAWebBluetoothFunction::CHARACTERISTIC_WRITE_VALUE); 644 UMAWebBluetoothFunction::CHARACTERISTIC_WRITE_VALUE);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 if (characteristic == nullptr) { 692 if (characteristic == nullptr) {
683 RecordCharacteristicWriteValueOutcome( 693 RecordCharacteristicWriteValueOutcome(
684 UMAGATTOperationOutcome::NO_CHARACTERISTIC); 694 UMAGATTOperationOutcome::NO_CHARACTERISTIC);
685 Send(new BluetoothMsg_WriteCharacteristicValueError( 695 Send(new BluetoothMsg_WriteCharacteristicValueError(
686 thread_id, request_id, 696 thread_id, request_id,
687 WebBluetoothError::CharacteristicNoLongerExists)); 697 WebBluetoothError::CharacteristicNoLongerExists));
688 return; 698 return;
689 } 699 }
690 characteristic->WriteRemoteCharacteristic( 700 characteristic->WriteRemoteCharacteristic(
691 value, base::Bind(&BluetoothDispatcherHost::OnWriteValueSuccess, 701 value, base::Bind(&BluetoothDispatcherHost::OnWriteValueSuccess,
692 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), 702 weak_ptr_on_ui_thread_, thread_id, request_id),
693 base::Bind(&BluetoothDispatcherHost::OnWriteValueFailed, 703 base::Bind(&BluetoothDispatcherHost::OnWriteValueFailed,
694 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); 704 weak_ptr_on_ui_thread_, thread_id, request_id));
695 } 705 }
696 706
697 void BluetoothDispatcherHost::OnDiscoverySessionStarted( 707 void BluetoothDispatcherHost::OnDiscoverySessionStarted(
698 int chooser_id, 708 int chooser_id,
699 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { 709 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) {
700 DCHECK_CURRENTLY_ON(BrowserThread::UI); 710 DCHECK_CURRENTLY_ON(BrowserThread::UI);
701 VLOG(1) << "Started discovery session for " << chooser_id; 711 VLOG(1) << "Started discovery session for " << chooser_id;
702 if (RequestDeviceSession* session = 712 if (RequestDeviceSession* session =
703 request_device_sessions_.Lookup(chooser_id)) { 713 request_device_sessions_.Lookup(chooser_id)) {
704 session->discovery_session = discovery_session.Pass(); 714 session->discovery_session = discovery_session.Pass();
(...skipping 18 matching lines...) Expand all
723 } 733 }
724 } 734 }
725 // Ignore discovery session start errors when the dialog was already closed by 735 // Ignore discovery session start errors when the dialog was already closed by
726 // the time they happen. 736 // the time they happen.
727 } 737 }
728 738
729 void BluetoothDispatcherHost::OnBluetoothChooserEvent( 739 void BluetoothDispatcherHost::OnBluetoothChooserEvent(
730 int chooser_id, 740 int chooser_id,
731 BluetoothChooser::Event event, 741 BluetoothChooser::Event event,
732 const std::string& device_id) { 742 const std::string& device_id) {
743 DCHECK_CURRENTLY_ON(BrowserThread::UI);
733 RequestDeviceSession* session = request_device_sessions_.Lookup(chooser_id); 744 RequestDeviceSession* session = request_device_sessions_.Lookup(chooser_id);
734 DCHECK(session) << "Shouldn't receive an event (" << static_cast<int>(event) 745 DCHECK(session) << "Shouldn't receive an event (" << static_cast<int>(event)
735 << ") from a closed chooser."; 746 << ") from a closed chooser.";
736 CHECK(session->chooser) << "Shouldn't receive an event (" 747 CHECK(session->chooser) << "Shouldn't receive an event ("
737 << static_cast<int>(event) 748 << static_cast<int>(event)
738 << ") from a closed chooser."; 749 << ") from a closed chooser.";
739 switch (event) { 750 switch (event) {
740 case BluetoothChooser::Event::RESCAN: 751 case BluetoothChooser::Event::RESCAN:
741 StartDeviceDiscovery(session, chooser_id); 752 StartDeviceDiscovery(session, chooser_id);
742 break; 753 break;
743 case BluetoothChooser::Event::CANCELLED: 754 case BluetoothChooser::Event::CANCELLED:
744 case BluetoothChooser::Event::SELECTED: { 755 case BluetoothChooser::Event::SELECTED: {
745 // Synchronously ensure nothing else calls into the chooser after it has 756 // Synchronously ensure nothing else calls into the chooser after it has
746 // asked to be closed. 757 // asked to be closed.
747 session->chooser.reset(); 758 session->chooser.reset();
748 759
749 // Yield to the event loop to make sure we don't destroy the session 760 // Yield to the event loop to make sure we don't destroy the session
750 // within a BluetoothDispatcherHost stack frame. 761 // within a BluetoothDispatcherHost stack frame.
751 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( 762 if (!base::ThreadTaskRunnerHandle::Get()->PostTask(
752 FROM_HERE, 763 FROM_HERE,
753 base::Bind(&BluetoothDispatcherHost::FinishClosingChooser, 764 base::Bind(&BluetoothDispatcherHost::FinishClosingChooser,
754 weak_ptr_factory_.GetWeakPtr(), chooser_id, event, 765 weak_ptr_on_ui_thread_, chooser_id, event,
755 device_id))) { 766 device_id))) {
756 LOG(WARNING) << "No TaskRunner; not closing requestDevice dialog."; 767 LOG(WARNING) << "No TaskRunner; not closing requestDevice dialog.";
757 } 768 }
758 break; 769 break;
759 } 770 }
760 case BluetoothChooser::Event::SHOW_OVERVIEW_HELP: 771 case BluetoothChooser::Event::SHOW_OVERVIEW_HELP:
761 ShowBluetoothOverviewLink(); 772 ShowBluetoothOverviewLink();
762 break; 773 break;
763 case BluetoothChooser::Event::SHOW_PAIRING_HELP: 774 case BluetoothChooser::Event::SHOW_PAIRING_HELP:
764 ShowBluetoothPairingLink(); 775 ShowBluetoothPairingLink();
765 break; 776 break;
766 case BluetoothChooser::Event::SHOW_ADAPTER_OFF_HELP: 777 case BluetoothChooser::Event::SHOW_ADAPTER_OFF_HELP:
767 ShowBluetoothAdapterOffLink(); 778 ShowBluetoothAdapterOffLink();
768 break; 779 break;
769 } 780 }
770 } 781 }
771 782
772 void BluetoothDispatcherHost::FinishClosingChooser( 783 void BluetoothDispatcherHost::FinishClosingChooser(
773 int chooser_id, 784 int chooser_id,
774 BluetoothChooser::Event event, 785 BluetoothChooser::Event event,
775 const std::string& device_id) { 786 const std::string& device_id) {
787 DCHECK_CURRENTLY_ON(BrowserThread::UI);
776 RequestDeviceSession* session = request_device_sessions_.Lookup(chooser_id); 788 RequestDeviceSession* session = request_device_sessions_.Lookup(chooser_id);
777 DCHECK(session) << "Session removed unexpectedly."; 789 DCHECK(session) << "Session removed unexpectedly.";
778 790
779 if (event == BluetoothChooser::Event::CANCELLED) { 791 if (event == BluetoothChooser::Event::CANCELLED) {
780 RecordRequestDeviceOutcome( 792 RecordRequestDeviceOutcome(
781 UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_CANCELLED); 793 UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_CANCELLED);
782 VLOG(1) << "Bluetooth chooser cancelled"; 794 VLOG(1) << "Bluetooth chooser cancelled";
783 Send(new BluetoothMsg_RequestDeviceError( 795 Send(new BluetoothMsg_RequestDeviceError(
784 session->thread_id, session->request_id, 796 session->thread_id, session->request_id,
785 WebBluetoothError::ChooserCancelled)); 797 WebBluetoothError::ChooserCancelled));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 session->request_id, device_ipc)); 833 session->request_id, device_ipc));
822 request_device_sessions_.Remove(chooser_id); 834 request_device_sessions_.Remove(chooser_id);
823 } 835 }
824 836
825 void BluetoothDispatcherHost::OnGATTConnectionCreated( 837 void BluetoothDispatcherHost::OnGATTConnectionCreated(
826 int thread_id, 838 int thread_id,
827 int request_id, 839 int request_id,
828 const std::string& device_instance_id, 840 const std::string& device_instance_id,
829 base::TimeTicks start_time, 841 base::TimeTicks start_time,
830 scoped_ptr<device::BluetoothGattConnection> connection) { 842 scoped_ptr<device::BluetoothGattConnection> connection) {
843 DCHECK_CURRENTLY_ON(BrowserThread::UI);
831 // TODO(ortuno): Save the BluetoothGattConnection so we can disconnect 844 // TODO(ortuno): Save the BluetoothGattConnection so we can disconnect
832 // from it. 845 // from it.
833 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time); 846 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time);
834 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS); 847 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS);
835 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, 848 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id,
836 device_instance_id)); 849 device_instance_id));
837 } 850 }
838 851
839 void BluetoothDispatcherHost::OnCreateGATTConnectionError( 852 void BluetoothDispatcherHost::OnCreateGATTConnectionError(
840 int thread_id, 853 int thread_id,
841 int request_id, 854 int request_id,
842 const std::string& device_instance_id, 855 const std::string& device_instance_id,
843 base::TimeTicks start_time, 856 base::TimeTicks start_time,
844 device::BluetoothDevice::ConnectErrorCode error_code) { 857 device::BluetoothDevice::ConnectErrorCode error_code) {
858 DCHECK_CURRENTLY_ON(BrowserThread::UI);
845 // There was an error creating the ATT Bearer so we reject with 859 // There was an error creating the ATT Bearer so we reject with
846 // NetworkError. 860 // NetworkError.
847 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-con nectgatt 861 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-con nectgatt
848 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); 862 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time);
849 // RecordConnectGATTOutcome is called by TranslateConnectError. 863 // RecordConnectGATTOutcome is called by TranslateConnectError.
850 Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id, 864 Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id,
851 TranslateConnectError(error_code))); 865 TranslateConnectError(error_code)));
852 } 866 }
853 867
854 void BluetoothDispatcherHost::OnServicesDiscovered( 868 void BluetoothDispatcherHost::OnServicesDiscovered(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 VLOG(1) << "No service found"; 904 VLOG(1) << "No service found";
891 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND); 905 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND);
892 Send(new BluetoothMsg_GetPrimaryServiceError( 906 Send(new BluetoothMsg_GetPrimaryServiceError(
893 thread_id, request_id, WebBluetoothError::ServiceNotFound)); 907 thread_id, request_id, WebBluetoothError::ServiceNotFound));
894 } 908 }
895 909
896 void BluetoothDispatcherHost::OnCharacteristicValueRead( 910 void BluetoothDispatcherHost::OnCharacteristicValueRead(
897 int thread_id, 911 int thread_id,
898 int request_id, 912 int request_id,
899 const std::vector<uint8>& value) { 913 const std::vector<uint8>& value) {
914 DCHECK_CURRENTLY_ON(BrowserThread::UI);
900 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::SUCCESS); 915 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::SUCCESS);
901 Send(new BluetoothMsg_ReadCharacteristicValueSuccess(thread_id, request_id, 916 Send(new BluetoothMsg_ReadCharacteristicValueSuccess(thread_id, request_id,
902 value)); 917 value));
903 } 918 }
904 919
905 void BluetoothDispatcherHost::OnCharacteristicReadValueError( 920 void BluetoothDispatcherHost::OnCharacteristicReadValueError(
906 int thread_id, 921 int thread_id,
907 int request_id, 922 int request_id,
908 device::BluetoothGattService::GattErrorCode error_code) { 923 device::BluetoothGattService::GattErrorCode error_code) {
924 DCHECK_CURRENTLY_ON(BrowserThread::UI);
909 // TranslateGATTError calls RecordGATTOperationOutcome. 925 // TranslateGATTError calls RecordGATTOperationOutcome.
910 Send(new BluetoothMsg_ReadCharacteristicValueError( 926 Send(new BluetoothMsg_ReadCharacteristicValueError(
911 thread_id, request_id, 927 thread_id, request_id,
912 TranslateGATTError(error_code, UMAGATTOperation::CHARACTERISTIC_READ))); 928 TranslateGATTError(error_code, UMAGATTOperation::CHARACTERISTIC_READ)));
913 } 929 }
914 930
915 void BluetoothDispatcherHost::OnWriteValueSuccess(int thread_id, 931 void BluetoothDispatcherHost::OnWriteValueSuccess(int thread_id,
916 int request_id) { 932 int request_id) {
933 DCHECK_CURRENTLY_ON(BrowserThread::UI);
917 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::SUCCESS); 934 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::SUCCESS);
918 Send(new BluetoothMsg_WriteCharacteristicValueSuccess(thread_id, request_id)); 935 Send(new BluetoothMsg_WriteCharacteristicValueSuccess(thread_id, request_id));
919 } 936 }
920 937
921 void BluetoothDispatcherHost::OnWriteValueFailed( 938 void BluetoothDispatcherHost::OnWriteValueFailed(
922 int thread_id, 939 int thread_id,
923 int request_id, 940 int request_id,
924 device::BluetoothGattService::GattErrorCode error_code) { 941 device::BluetoothGattService::GattErrorCode error_code) {
942 DCHECK_CURRENTLY_ON(BrowserThread::UI);
925 // TranslateGATTError calls RecordGATTOperationOutcome. 943 // TranslateGATTError calls RecordGATTOperationOutcome.
926 Send(new BluetoothMsg_WriteCharacteristicValueError( 944 Send(new BluetoothMsg_WriteCharacteristicValueError(
927 thread_id, request_id, 945 thread_id, request_id,
928 TranslateGATTError(error_code, UMAGATTOperation::CHARACTERISTIC_WRITE))); 946 TranslateGATTError(error_code, UMAGATTOperation::CHARACTERISTIC_WRITE)));
929 } 947 }
930 948
931 void BluetoothDispatcherHost::ShowBluetoothOverviewLink() { 949 void BluetoothDispatcherHost::ShowBluetoothOverviewLink() {
950 DCHECK_CURRENTLY_ON(BrowserThread::UI);
932 NOTIMPLEMENTED(); 951 NOTIMPLEMENTED();
933 } 952 }
934 953
935 void BluetoothDispatcherHost::ShowBluetoothPairingLink() { 954 void BluetoothDispatcherHost::ShowBluetoothPairingLink() {
955 DCHECK_CURRENTLY_ON(BrowserThread::UI);
936 NOTIMPLEMENTED(); 956 NOTIMPLEMENTED();
937 } 957 }
938 958
939 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() { 959 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() {
960 DCHECK_CURRENTLY_ON(BrowserThread::UI);
940 NOTIMPLEMENTED(); 961 NOTIMPLEMENTED();
941 } 962 }
942 963
943 } // namespace content 964 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698