OLD | NEW |
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 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_event_router.h" | 5 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_event_router.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_connection.h" | 10 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_connection.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 return (adapter_.get() != NULL); | 204 return (adapter_.get() != NULL); |
205 } | 205 } |
206 | 206 |
207 void BluetoothLowEnergyEventRouter::Connect( | 207 void BluetoothLowEnergyEventRouter::Connect( |
208 bool persistent, | 208 bool persistent, |
209 const Extension* extension, | 209 const Extension* extension, |
210 const std::string& device_address, | 210 const std::string& device_address, |
211 const base::Closure& callback, | 211 const base::Closure& callback, |
212 const ErrorCallback& error_callback) { | 212 const ErrorCallback& error_callback) { |
213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
214 if (!adapter_) { | 214 if (!adapter_.get()) { |
215 VLOG(1) << "BluetoothAdapter not ready."; | 215 VLOG(1) << "BluetoothAdapter not ready."; |
216 error_callback.Run(kStatusErrorFailed); | 216 error_callback.Run(kStatusErrorFailed); |
217 return; | 217 return; |
218 } | 218 } |
219 | 219 |
220 const std::string extension_id = extension->id(); | 220 const std::string extension_id = extension->id(); |
221 const std::string connect_id = extension_id + device_address; | 221 const std::string connect_id = extension_id + device_address; |
222 | 222 |
223 if (connecting_devices_.count(connect_id) != 0) { | 223 if (connecting_devices_.count(connect_id) != 0) { |
224 error_callback.Run(kStatusErrorInProgress); | 224 error_callback.Run(kStatusErrorInProgress); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 device_address, | 259 device_address, |
260 error_callback)); | 260 error_callback)); |
261 } | 261 } |
262 | 262 |
263 void BluetoothLowEnergyEventRouter::Disconnect( | 263 void BluetoothLowEnergyEventRouter::Disconnect( |
264 const Extension* extension, | 264 const Extension* extension, |
265 const std::string& device_address, | 265 const std::string& device_address, |
266 const base::Closure& callback, | 266 const base::Closure& callback, |
267 const ErrorCallback& error_callback) { | 267 const ErrorCallback& error_callback) { |
268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
269 if (!adapter_) { | 269 if (!adapter_.get()) { |
270 VLOG(1) << "BluetoothAdapter not ready."; | 270 VLOG(1) << "BluetoothAdapter not ready."; |
271 error_callback.Run(kStatusErrorFailed); | 271 error_callback.Run(kStatusErrorFailed); |
272 return; | 272 return; |
273 } | 273 } |
274 | 274 |
275 const std::string extension_id = extension->id(); | 275 const std::string extension_id = extension->id(); |
276 const std::string disconnect_id = extension_id + device_address; | 276 const std::string disconnect_id = extension_id + device_address; |
277 | 277 |
278 if (disconnecting_devices_.count(disconnect_id) != 0) { | 278 if (disconnecting_devices_.count(disconnect_id) != 0) { |
279 error_callback.Run(kStatusErrorInProgress); | 279 error_callback.Run(kStatusErrorInProgress); |
(...skipping 15 matching lines...) Expand all Loading... |
295 extension_id, | 295 extension_id, |
296 device_address, | 296 device_address, |
297 callback)); | 297 callback)); |
298 } | 298 } |
299 | 299 |
300 bool BluetoothLowEnergyEventRouter::GetServices( | 300 bool BluetoothLowEnergyEventRouter::GetServices( |
301 const std::string& device_address, | 301 const std::string& device_address, |
302 ServiceList* out_services) const { | 302 ServiceList* out_services) const { |
303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
304 DCHECK(out_services); | 304 DCHECK(out_services); |
305 if (!adapter_) { | 305 if (!adapter_.get()) { |
306 VLOG(1) << "BluetoothAdapter not ready."; | 306 VLOG(1) << "BluetoothAdapter not ready."; |
307 return false; | 307 return false; |
308 } | 308 } |
309 | 309 |
310 BluetoothDevice* device = adapter_->GetDevice(device_address); | 310 BluetoothDevice* device = adapter_->GetDevice(device_address); |
311 if (!device) { | 311 if (!device) { |
312 VLOG(1) << "Bluetooth device not found: " << device_address; | 312 VLOG(1) << "Bluetooth device not found: " << device_address; |
313 return false; | 313 return false; |
314 } | 314 } |
315 | 315 |
(...skipping 14 matching lines...) Expand all Loading... |
330 } | 330 } |
331 | 331 |
332 return true; | 332 return true; |
333 } | 333 } |
334 | 334 |
335 BluetoothLowEnergyEventRouter::Status BluetoothLowEnergyEventRouter::GetService( | 335 BluetoothLowEnergyEventRouter::Status BluetoothLowEnergyEventRouter::GetService( |
336 const std::string& instance_id, | 336 const std::string& instance_id, |
337 apibtle::Service* out_service) const { | 337 apibtle::Service* out_service) const { |
338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
339 DCHECK(out_service); | 339 DCHECK(out_service); |
340 if (!adapter_) { | 340 if (!adapter_.get()) { |
341 VLOG(1) << "BluetoothAdapter not ready."; | 341 VLOG(1) << "BluetoothAdapter not ready."; |
342 return kStatusErrorFailed; | 342 return kStatusErrorFailed; |
343 } | 343 } |
344 | 344 |
345 BluetoothGattService* gatt_service = FindServiceById(instance_id); | 345 BluetoothGattService* gatt_service = FindServiceById(instance_id); |
346 if (!gatt_service) { | 346 if (!gatt_service) { |
347 VLOG(1) << "Service not found: " << instance_id; | 347 VLOG(1) << "Service not found: " << instance_id; |
348 return kStatusErrorNotFound; | 348 return kStatusErrorNotFound; |
349 } | 349 } |
350 | 350 |
351 PopulateService(gatt_service, out_service); | 351 PopulateService(gatt_service, out_service); |
352 return kStatusSuccess; | 352 return kStatusSuccess; |
353 } | 353 } |
354 | 354 |
355 BluetoothLowEnergyEventRouter::Status | 355 BluetoothLowEnergyEventRouter::Status |
356 BluetoothLowEnergyEventRouter::GetIncludedServices( | 356 BluetoothLowEnergyEventRouter::GetIncludedServices( |
357 const std::string& instance_id, | 357 const std::string& instance_id, |
358 ServiceList* out_services) const { | 358 ServiceList* out_services) const { |
359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
360 DCHECK(out_services); | 360 DCHECK(out_services); |
361 if (!adapter_) { | 361 if (!adapter_.get()) { |
362 VLOG(1) << "BluetoothAdapter not ready."; | 362 VLOG(1) << "BluetoothAdapter not ready."; |
363 return kStatusErrorFailed; | 363 return kStatusErrorFailed; |
364 } | 364 } |
365 | 365 |
366 BluetoothGattService* service = FindServiceById(instance_id); | 366 BluetoothGattService* service = FindServiceById(instance_id); |
367 if (!service) { | 367 if (!service) { |
368 VLOG(1) << "Service not found: " << instance_id; | 368 VLOG(1) << "Service not found: " << instance_id; |
369 return kStatusErrorNotFound; | 369 return kStatusErrorNotFound; |
370 } | 370 } |
371 | 371 |
(...skipping 17 matching lines...) Expand all Loading... |
389 } | 389 } |
390 | 390 |
391 BluetoothLowEnergyEventRouter::Status | 391 BluetoothLowEnergyEventRouter::Status |
392 BluetoothLowEnergyEventRouter::GetCharacteristics( | 392 BluetoothLowEnergyEventRouter::GetCharacteristics( |
393 const Extension* extension, | 393 const Extension* extension, |
394 const std::string& instance_id, | 394 const std::string& instance_id, |
395 CharacteristicList* out_characteristics) const { | 395 CharacteristicList* out_characteristics) const { |
396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
397 DCHECK(extension); | 397 DCHECK(extension); |
398 DCHECK(out_characteristics); | 398 DCHECK(out_characteristics); |
399 if (!adapter_) { | 399 if (!adapter_.get()) { |
400 VLOG(1) << "BlutoothAdapter not ready."; | 400 VLOG(1) << "BlutoothAdapter not ready."; |
401 return kStatusErrorFailed; | 401 return kStatusErrorFailed; |
402 } | 402 } |
403 | 403 |
404 BluetoothGattService* service = FindServiceById(instance_id); | 404 BluetoothGattService* service = FindServiceById(instance_id); |
405 if (!service) { | 405 if (!service) { |
406 VLOG(1) << "Service not found: " << instance_id; | 406 VLOG(1) << "Service not found: " << instance_id; |
407 return kStatusErrorNotFound; | 407 return kStatusErrorNotFound; |
408 } | 408 } |
409 | 409 |
(...skipping 25 matching lines...) Expand all Loading... |
435 } | 435 } |
436 | 436 |
437 BluetoothLowEnergyEventRouter::Status | 437 BluetoothLowEnergyEventRouter::Status |
438 BluetoothLowEnergyEventRouter::GetCharacteristic( | 438 BluetoothLowEnergyEventRouter::GetCharacteristic( |
439 const Extension* extension, | 439 const Extension* extension, |
440 const std::string& instance_id, | 440 const std::string& instance_id, |
441 apibtle::Characteristic* out_characteristic) const { | 441 apibtle::Characteristic* out_characteristic) const { |
442 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 442 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
443 DCHECK(extension); | 443 DCHECK(extension); |
444 DCHECK(out_characteristic); | 444 DCHECK(out_characteristic); |
445 if (!adapter_) { | 445 if (!adapter_.get()) { |
446 VLOG(1) << "BluetoothAdapter not ready."; | 446 VLOG(1) << "BluetoothAdapter not ready."; |
447 return kStatusErrorFailed; | 447 return kStatusErrorFailed; |
448 } | 448 } |
449 | 449 |
450 BluetoothGattCharacteristic* characteristic = | 450 BluetoothGattCharacteristic* characteristic = |
451 FindCharacteristicById(instance_id); | 451 FindCharacteristicById(instance_id); |
452 if (!characteristic) { | 452 if (!characteristic) { |
453 VLOG(1) << "Characteristic not found: " << instance_id; | 453 VLOG(1) << "Characteristic not found: " << instance_id; |
454 return kStatusErrorNotFound; | 454 return kStatusErrorNotFound; |
455 } | 455 } |
(...skipping 11 matching lines...) Expand all Loading... |
467 } | 467 } |
468 | 468 |
469 BluetoothLowEnergyEventRouter::Status | 469 BluetoothLowEnergyEventRouter::Status |
470 BluetoothLowEnergyEventRouter::GetDescriptors( | 470 BluetoothLowEnergyEventRouter::GetDescriptors( |
471 const Extension* extension, | 471 const Extension* extension, |
472 const std::string& instance_id, | 472 const std::string& instance_id, |
473 DescriptorList* out_descriptors) const { | 473 DescriptorList* out_descriptors) const { |
474 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 474 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
475 DCHECK(extension); | 475 DCHECK(extension); |
476 DCHECK(out_descriptors); | 476 DCHECK(out_descriptors); |
477 if (!adapter_) { | 477 if (!adapter_.get()) { |
478 VLOG(1) << "BlutoothAdapter not ready."; | 478 VLOG(1) << "BlutoothAdapter not ready."; |
479 return kStatusErrorFailed; | 479 return kStatusErrorFailed; |
480 } | 480 } |
481 | 481 |
482 BluetoothGattCharacteristic* characteristic = | 482 BluetoothGattCharacteristic* characteristic = |
483 FindCharacteristicById(instance_id); | 483 FindCharacteristicById(instance_id); |
484 if (!characteristic) { | 484 if (!characteristic) { |
485 VLOG(1) << "Characteristic not found: " << instance_id; | 485 VLOG(1) << "Characteristic not found: " << instance_id; |
486 return kStatusErrorNotFound; | 486 return kStatusErrorNotFound; |
487 } | 487 } |
(...skipping 26 matching lines...) Expand all Loading... |
514 } | 514 } |
515 | 515 |
516 BluetoothLowEnergyEventRouter::Status | 516 BluetoothLowEnergyEventRouter::Status |
517 BluetoothLowEnergyEventRouter::GetDescriptor( | 517 BluetoothLowEnergyEventRouter::GetDescriptor( |
518 const Extension* extension, | 518 const Extension* extension, |
519 const std::string& instance_id, | 519 const std::string& instance_id, |
520 api::bluetooth_low_energy::Descriptor* out_descriptor) const { | 520 api::bluetooth_low_energy::Descriptor* out_descriptor) const { |
521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
522 DCHECK(extension); | 522 DCHECK(extension); |
523 DCHECK(out_descriptor); | 523 DCHECK(out_descriptor); |
524 if (!adapter_) { | 524 if (!adapter_.get()) { |
525 VLOG(1) << "BluetoothAdapter not ready."; | 525 VLOG(1) << "BluetoothAdapter not ready."; |
526 return kStatusErrorFailed; | 526 return kStatusErrorFailed; |
527 } | 527 } |
528 | 528 |
529 BluetoothGattDescriptor* descriptor = FindDescriptorById(instance_id); | 529 BluetoothGattDescriptor* descriptor = FindDescriptorById(instance_id); |
530 if (!descriptor) { | 530 if (!descriptor) { |
531 VLOG(1) << "Descriptor not found: " << instance_id; | 531 VLOG(1) << "Descriptor not found: " << instance_id; |
532 return kStatusErrorNotFound; | 532 return kStatusErrorNotFound; |
533 } | 533 } |
534 | 534 |
535 BluetoothPermissionRequest request( | 535 BluetoothPermissionRequest request( |
536 descriptor->GetCharacteristic()->GetService()->GetUUID().value()); | 536 descriptor->GetCharacteristic()->GetService()->GetUUID().value()); |
537 if (!BluetoothManifestData::CheckRequest(extension, request)) { | 537 if (!BluetoothManifestData::CheckRequest(extension, request)) { |
538 VLOG(1) << "App has no permission to access this descriptor: " | 538 VLOG(1) << "App has no permission to access this descriptor: " |
539 << instance_id; | 539 << instance_id; |
540 return kStatusErrorPermissionDenied; | 540 return kStatusErrorPermissionDenied; |
541 } | 541 } |
542 | 542 |
543 PopulateDescriptor(descriptor, out_descriptor); | 543 PopulateDescriptor(descriptor, out_descriptor); |
544 return kStatusSuccess; | 544 return kStatusSuccess; |
545 } | 545 } |
546 | 546 |
547 void BluetoothLowEnergyEventRouter::ReadCharacteristicValue( | 547 void BluetoothLowEnergyEventRouter::ReadCharacteristicValue( |
548 const Extension* extension, | 548 const Extension* extension, |
549 const std::string& instance_id, | 549 const std::string& instance_id, |
550 const base::Closure& callback, | 550 const base::Closure& callback, |
551 const ErrorCallback& error_callback) { | 551 const ErrorCallback& error_callback) { |
552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
553 DCHECK(extension); | 553 DCHECK(extension); |
554 if (!adapter_) { | 554 if (!adapter_.get()) { |
555 VLOG(1) << "BluetoothAdapter not ready."; | 555 VLOG(1) << "BluetoothAdapter not ready."; |
556 error_callback.Run(kStatusErrorFailed); | 556 error_callback.Run(kStatusErrorFailed); |
557 return; | 557 return; |
558 } | 558 } |
559 | 559 |
560 BluetoothGattCharacteristic* characteristic = | 560 BluetoothGattCharacteristic* characteristic = |
561 FindCharacteristicById(instance_id); | 561 FindCharacteristicById(instance_id); |
562 if (!characteristic) { | 562 if (!characteristic) { |
563 VLOG(1) << "Characteristic not found: " << instance_id; | 563 VLOG(1) << "Characteristic not found: " << instance_id; |
564 error_callback.Run(kStatusErrorNotFound); | 564 error_callback.Run(kStatusErrorNotFound); |
(...skipping 19 matching lines...) Expand all Loading... |
584 } | 584 } |
585 | 585 |
586 void BluetoothLowEnergyEventRouter::WriteCharacteristicValue( | 586 void BluetoothLowEnergyEventRouter::WriteCharacteristicValue( |
587 const Extension* extension, | 587 const Extension* extension, |
588 const std::string& instance_id, | 588 const std::string& instance_id, |
589 const std::vector<uint8>& value, | 589 const std::vector<uint8>& value, |
590 const base::Closure& callback, | 590 const base::Closure& callback, |
591 const ErrorCallback& error_callback) { | 591 const ErrorCallback& error_callback) { |
592 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 592 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
593 DCHECK(extension); | 593 DCHECK(extension); |
594 if (!adapter_) { | 594 if (!adapter_.get()) { |
595 VLOG(1) << "BluetoothAdapter not ready."; | 595 VLOG(1) << "BluetoothAdapter not ready."; |
596 error_callback.Run(kStatusErrorFailed); | 596 error_callback.Run(kStatusErrorFailed); |
597 return; | 597 return; |
598 } | 598 } |
599 | 599 |
600 BluetoothGattCharacteristic* characteristic = | 600 BluetoothGattCharacteristic* characteristic = |
601 FindCharacteristicById(instance_id); | 601 FindCharacteristicById(instance_id); |
602 if (!characteristic) { | 602 if (!characteristic) { |
603 VLOG(1) << "Characteristic not found: " << instance_id; | 603 VLOG(1) << "Characteristic not found: " << instance_id; |
604 error_callback.Run(kStatusErrorNotFound); | 604 error_callback.Run(kStatusErrorNotFound); |
(...skipping 17 matching lines...) Expand all Loading... |
622 error_callback)); | 622 error_callback)); |
623 } | 623 } |
624 | 624 |
625 void BluetoothLowEnergyEventRouter::StartCharacteristicNotifications( | 625 void BluetoothLowEnergyEventRouter::StartCharacteristicNotifications( |
626 bool persistent, | 626 bool persistent, |
627 const Extension* extension, | 627 const Extension* extension, |
628 const std::string& instance_id, | 628 const std::string& instance_id, |
629 const base::Closure& callback, | 629 const base::Closure& callback, |
630 const ErrorCallback& error_callback) { | 630 const ErrorCallback& error_callback) { |
631 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 631 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
632 if (!adapter_) { | 632 if (!adapter_.get()) { |
633 VLOG(1) << "BluetoothAdapter not ready."; | 633 VLOG(1) << "BluetoothAdapter not ready."; |
634 error_callback.Run(kStatusErrorFailed); | 634 error_callback.Run(kStatusErrorFailed); |
635 return; | 635 return; |
636 } | 636 } |
637 | 637 |
638 const std::string extension_id = extension->id(); | 638 const std::string extension_id = extension->id(); |
639 const std::string session_id = extension_id + instance_id; | 639 const std::string session_id = extension_id + instance_id; |
640 | 640 |
641 if (pending_session_calls_.count(session_id) != 0) { | 641 if (pending_session_calls_.count(session_id) != 0) { |
642 error_callback.Run(kStatusErrorInProgress); | 642 error_callback.Run(kStatusErrorInProgress); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 instance_id, | 687 instance_id, |
688 error_callback)); | 688 error_callback)); |
689 } | 689 } |
690 | 690 |
691 void BluetoothLowEnergyEventRouter::StopCharacteristicNotifications( | 691 void BluetoothLowEnergyEventRouter::StopCharacteristicNotifications( |
692 const Extension* extension, | 692 const Extension* extension, |
693 const std::string& instance_id, | 693 const std::string& instance_id, |
694 const base::Closure& callback, | 694 const base::Closure& callback, |
695 const ErrorCallback& error_callback) { | 695 const ErrorCallback& error_callback) { |
696 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 696 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
697 if (!adapter_) { | 697 if (!adapter_.get()) { |
698 VLOG(1) << "BluetoothAdapter not ready."; | 698 VLOG(1) << "BluetoothAdapter not ready."; |
699 error_callback.Run(kStatusErrorFailed); | 699 error_callback.Run(kStatusErrorFailed); |
700 return; | 700 return; |
701 } | 701 } |
702 | 702 |
703 const std::string extension_id = extension->id(); | 703 const std::string extension_id = extension->id(); |
704 | 704 |
705 BluetoothLowEnergyNotifySession* session = | 705 BluetoothLowEnergyNotifySession* session = |
706 FindNotifySession(extension_id, instance_id); | 706 FindNotifySession(extension_id, instance_id); |
707 if (!session || !session->GetSession()->IsActive()) { | 707 if (!session || !session->GetSession()->IsActive()) { |
(...skipping 11 matching lines...) Expand all Loading... |
719 callback)); | 719 callback)); |
720 } | 720 } |
721 | 721 |
722 void BluetoothLowEnergyEventRouter::ReadDescriptorValue( | 722 void BluetoothLowEnergyEventRouter::ReadDescriptorValue( |
723 const Extension* extension, | 723 const Extension* extension, |
724 const std::string& instance_id, | 724 const std::string& instance_id, |
725 const base::Closure& callback, | 725 const base::Closure& callback, |
726 const ErrorCallback& error_callback) { | 726 const ErrorCallback& error_callback) { |
727 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 727 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
728 DCHECK(extension); | 728 DCHECK(extension); |
729 if (!adapter_) { | 729 if (!adapter_.get()) { |
730 VLOG(1) << "BluetoothAdapter not ready."; | 730 VLOG(1) << "BluetoothAdapter not ready."; |
731 error_callback.Run(kStatusErrorFailed); | 731 error_callback.Run(kStatusErrorFailed); |
732 return; | 732 return; |
733 } | 733 } |
734 | 734 |
735 BluetoothGattDescriptor* descriptor = FindDescriptorById(instance_id); | 735 BluetoothGattDescriptor* descriptor = FindDescriptorById(instance_id); |
736 if (!descriptor) { | 736 if (!descriptor) { |
737 VLOG(1) << "Descriptor not found: " << instance_id; | 737 VLOG(1) << "Descriptor not found: " << instance_id; |
738 error_callback.Run(kStatusErrorNotFound); | 738 error_callback.Run(kStatusErrorNotFound); |
739 return; | 739 return; |
(...skipping 18 matching lines...) Expand all Loading... |
758 } | 758 } |
759 | 759 |
760 void BluetoothLowEnergyEventRouter::WriteDescriptorValue( | 760 void BluetoothLowEnergyEventRouter::WriteDescriptorValue( |
761 const Extension* extension, | 761 const Extension* extension, |
762 const std::string& instance_id, | 762 const std::string& instance_id, |
763 const std::vector<uint8>& value, | 763 const std::vector<uint8>& value, |
764 const base::Closure& callback, | 764 const base::Closure& callback, |
765 const ErrorCallback& error_callback) { | 765 const ErrorCallback& error_callback) { |
766 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 766 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
767 DCHECK(extension); | 767 DCHECK(extension); |
768 if (!adapter_) { | 768 if (!adapter_.get()) { |
769 VLOG(1) << "BluetoothAdapter not ready."; | 769 VLOG(1) << "BluetoothAdapter not ready."; |
770 error_callback.Run(kStatusErrorFailed); | 770 error_callback.Run(kStatusErrorFailed); |
771 return; | 771 return; |
772 } | 772 } |
773 | 773 |
774 BluetoothGattDescriptor* descriptor = FindDescriptorById(instance_id); | 774 BluetoothGattDescriptor* descriptor = FindDescriptorById(instance_id); |
775 if (!descriptor) { | 775 if (!descriptor) { |
776 VLOG(1) << "Descriptor not found: " << instance_id; | 776 VLOG(1) << "Descriptor not found: " << instance_id; |
777 error_callback.Run(kStatusErrorNotFound); | 777 error_callback.Run(kStatusErrorNotFound); |
778 return; | 778 return; |
(...skipping 20 matching lines...) Expand all Loading... |
799 device::BluetoothAdapter* adapter) { | 799 device::BluetoothAdapter* adapter) { |
800 adapter_ = adapter; | 800 adapter_ = adapter; |
801 InitializeIdentifierMappings(); | 801 InitializeIdentifierMappings(); |
802 } | 802 } |
803 | 803 |
804 void BluetoothLowEnergyEventRouter::GattServiceAdded( | 804 void BluetoothLowEnergyEventRouter::GattServiceAdded( |
805 BluetoothAdapter* adapter, | 805 BluetoothAdapter* adapter, |
806 BluetoothDevice* device, | 806 BluetoothDevice* device, |
807 BluetoothGattService* service) { | 807 BluetoothGattService* service) { |
808 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 808 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
809 DCHECK_EQ(adapter, adapter_); | 809 DCHECK_EQ(adapter, adapter_.get()); |
810 VLOG(2) << "GATT service added: " << service->GetIdentifier(); | 810 VLOG(2) << "GATT service added: " << service->GetIdentifier(); |
811 | 811 |
812 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) == | 812 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) == |
813 service_id_to_device_address_.end()); | 813 service_id_to_device_address_.end()); |
814 | 814 |
815 service_id_to_device_address_[service->GetIdentifier()] = | 815 service_id_to_device_address_[service->GetIdentifier()] = |
816 device->GetAddress(); | 816 device->GetAddress(); |
817 } | 817 } |
818 | 818 |
819 void BluetoothLowEnergyEventRouter::GattServiceRemoved( | 819 void BluetoothLowEnergyEventRouter::GattServiceRemoved( |
820 BluetoothAdapter* adapter, | 820 BluetoothAdapter* adapter, |
821 BluetoothDevice* device, | 821 BluetoothDevice* device, |
822 BluetoothGattService* service) { | 822 BluetoothGattService* service) { |
823 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 823 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
824 DCHECK_EQ(adapter, adapter_); | 824 DCHECK_EQ(adapter, adapter_.get()); |
825 VLOG(2) << "GATT service removed: " << service->GetIdentifier(); | 825 VLOG(2) << "GATT service removed: " << service->GetIdentifier(); |
826 | 826 |
827 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != | 827 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != |
828 service_id_to_device_address_.end()); | 828 service_id_to_device_address_.end()); |
829 | 829 |
830 DCHECK(device->GetAddress() == | 830 DCHECK(device->GetAddress() == |
831 service_id_to_device_address_[service->GetIdentifier()]); | 831 service_id_to_device_address_[service->GetIdentifier()]); |
832 service_id_to_device_address_.erase(service->GetIdentifier()); | 832 service_id_to_device_address_.erase(service->GetIdentifier()); |
833 | 833 |
834 // Signal API event. | 834 // Signal API event. |
835 apibtle::Service api_service; | 835 apibtle::Service api_service; |
836 PopulateService(service, &api_service); | 836 PopulateService(service, &api_service); |
837 | 837 |
838 scoped_ptr<base::ListValue> args = | 838 scoped_ptr<base::ListValue> args = |
839 apibtle::OnServiceRemoved::Create(api_service); | 839 apibtle::OnServiceRemoved::Create(api_service); |
840 scoped_ptr<Event> event( | 840 scoped_ptr<Event> event( |
841 new Event(apibtle::OnServiceRemoved::kEventName, args.Pass())); | 841 new Event(apibtle::OnServiceRemoved::kEventName, args.Pass())); |
842 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); | 842 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); |
843 } | 843 } |
844 | 844 |
845 void BluetoothLowEnergyEventRouter::GattDiscoveryCompleteForService( | 845 void BluetoothLowEnergyEventRouter::GattDiscoveryCompleteForService( |
846 BluetoothAdapter* adapter, | 846 BluetoothAdapter* adapter, |
847 BluetoothGattService* service) { | 847 BluetoothGattService* service) { |
848 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 848 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
849 DCHECK_EQ(adapter, adapter_); | 849 DCHECK_EQ(adapter, adapter_.get()); |
850 VLOG(2) << "GATT service discovery complete: " << service->GetIdentifier(); | 850 VLOG(2) << "GATT service discovery complete: " << service->GetIdentifier(); |
851 | 851 |
852 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != | 852 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != |
853 service_id_to_device_address_.end()); | 853 service_id_to_device_address_.end()); |
854 | 854 |
855 // Signal the service added event here. | 855 // Signal the service added event here. |
856 apibtle::Service api_service; | 856 apibtle::Service api_service; |
857 PopulateService(service, &api_service); | 857 PopulateService(service, &api_service); |
858 | 858 |
859 scoped_ptr<base::ListValue> args = | 859 scoped_ptr<base::ListValue> args = |
860 apibtle::OnServiceAdded::Create(api_service); | 860 apibtle::OnServiceAdded::Create(api_service); |
861 scoped_ptr<Event> event( | 861 scoped_ptr<Event> event( |
862 new Event(apibtle::OnServiceAdded::kEventName, args.Pass())); | 862 new Event(apibtle::OnServiceAdded::kEventName, args.Pass())); |
863 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); | 863 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); |
864 } | 864 } |
865 | 865 |
866 void BluetoothLowEnergyEventRouter::GattServiceChanged( | 866 void BluetoothLowEnergyEventRouter::GattServiceChanged( |
867 BluetoothAdapter* adapter, | 867 BluetoothAdapter* adapter, |
868 BluetoothGattService* service) { | 868 BluetoothGattService* service) { |
869 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 869 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
870 DCHECK_EQ(adapter, adapter_); | 870 DCHECK_EQ(adapter, adapter_.get()); |
871 VLOG(2) << "GATT service changed: " << service->GetIdentifier(); | 871 VLOG(2) << "GATT service changed: " << service->GetIdentifier(); |
872 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != | 872 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != |
873 service_id_to_device_address_.end()); | 873 service_id_to_device_address_.end()); |
874 | 874 |
875 // Signal API event. | 875 // Signal API event. |
876 apibtle::Service api_service; | 876 apibtle::Service api_service; |
877 PopulateService(service, &api_service); | 877 PopulateService(service, &api_service); |
878 | 878 |
879 DispatchEventToExtensionsWithPermission( | 879 DispatchEventToExtensionsWithPermission( |
880 apibtle::OnServiceChanged::kEventName, | 880 apibtle::OnServiceChanged::kEventName, |
881 service->GetUUID(), | 881 service->GetUUID(), |
882 "" /* characteristic_id */, | 882 "" /* characteristic_id */, |
883 apibtle::OnServiceChanged::Create(api_service)); | 883 apibtle::OnServiceChanged::Create(api_service)); |
884 } | 884 } |
885 | 885 |
886 void BluetoothLowEnergyEventRouter::GattCharacteristicAdded( | 886 void BluetoothLowEnergyEventRouter::GattCharacteristicAdded( |
887 BluetoothAdapter* adapter, | 887 BluetoothAdapter* adapter, |
888 BluetoothGattCharacteristic* characteristic) { | 888 BluetoothGattCharacteristic* characteristic) { |
889 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 889 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
890 DCHECK_EQ(adapter, adapter_); | 890 DCHECK_EQ(adapter, adapter_.get()); |
891 VLOG(2) << "GATT characteristic added: " << characteristic->GetIdentifier(); | 891 VLOG(2) << "GATT characteristic added: " << characteristic->GetIdentifier(); |
892 | 892 |
893 BluetoothGattService* service = characteristic->GetService(); | 893 BluetoothGattService* service = characteristic->GetService(); |
894 DCHECK(service); | 894 DCHECK(service); |
895 | 895 |
896 DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) == | 896 DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) == |
897 chrc_id_to_service_id_.end()); | 897 chrc_id_to_service_id_.end()); |
898 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != | 898 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != |
899 service_id_to_device_address_.end()); | 899 service_id_to_device_address_.end()); |
900 | 900 |
901 chrc_id_to_service_id_[characteristic->GetIdentifier()] = | 901 chrc_id_to_service_id_[characteristic->GetIdentifier()] = |
902 service->GetIdentifier(); | 902 service->GetIdentifier(); |
903 } | 903 } |
904 | 904 |
905 void BluetoothLowEnergyEventRouter::GattCharacteristicRemoved( | 905 void BluetoothLowEnergyEventRouter::GattCharacteristicRemoved( |
906 BluetoothAdapter* adapter, | 906 BluetoothAdapter* adapter, |
907 BluetoothGattCharacteristic* characteristic) { | 907 BluetoothGattCharacteristic* characteristic) { |
908 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 908 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
909 DCHECK_EQ(adapter, adapter_); | 909 DCHECK_EQ(adapter, adapter_.get()); |
910 VLOG(2) << "GATT characteristic removed: " << characteristic->GetIdentifier(); | 910 VLOG(2) << "GATT characteristic removed: " << characteristic->GetIdentifier(); |
911 | 911 |
912 BluetoothGattService* service = characteristic->GetService(); | 912 BluetoothGattService* service = characteristic->GetService(); |
913 DCHECK(service); | 913 DCHECK(service); |
914 | 914 |
915 DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) != | 915 DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) != |
916 chrc_id_to_service_id_.end()); | 916 chrc_id_to_service_id_.end()); |
917 DCHECK(service->GetIdentifier() == | 917 DCHECK(service->GetIdentifier() == |
918 chrc_id_to_service_id_[characteristic->GetIdentifier()]); | 918 chrc_id_to_service_id_[characteristic->GetIdentifier()]); |
919 | 919 |
920 chrc_id_to_service_id_.erase(characteristic->GetIdentifier()); | 920 chrc_id_to_service_id_.erase(characteristic->GetIdentifier()); |
921 } | 921 } |
922 | 922 |
923 void BluetoothLowEnergyEventRouter::GattDescriptorAdded( | 923 void BluetoothLowEnergyEventRouter::GattDescriptorAdded( |
924 BluetoothAdapter* adapter, | 924 BluetoothAdapter* adapter, |
925 BluetoothGattDescriptor* descriptor) { | 925 BluetoothGattDescriptor* descriptor) { |
926 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 926 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
927 DCHECK_EQ(adapter, adapter_); | 927 DCHECK_EQ(adapter, adapter_.get()); |
928 VLOG(2) << "GATT descriptor added: " << descriptor->GetIdentifier(); | 928 VLOG(2) << "GATT descriptor added: " << descriptor->GetIdentifier(); |
929 | 929 |
930 BluetoothGattCharacteristic* characteristic = descriptor->GetCharacteristic(); | 930 BluetoothGattCharacteristic* characteristic = descriptor->GetCharacteristic(); |
931 DCHECK(characteristic); | 931 DCHECK(characteristic); |
932 | 932 |
933 DCHECK(desc_id_to_chrc_id_.find(descriptor->GetIdentifier()) == | 933 DCHECK(desc_id_to_chrc_id_.find(descriptor->GetIdentifier()) == |
934 desc_id_to_chrc_id_.end()); | 934 desc_id_to_chrc_id_.end()); |
935 DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) != | 935 DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) != |
936 chrc_id_to_service_id_.end()); | 936 chrc_id_to_service_id_.end()); |
937 | 937 |
938 desc_id_to_chrc_id_[descriptor->GetIdentifier()] = | 938 desc_id_to_chrc_id_[descriptor->GetIdentifier()] = |
939 characteristic->GetIdentifier(); | 939 characteristic->GetIdentifier(); |
940 } | 940 } |
941 | 941 |
942 void BluetoothLowEnergyEventRouter::GattDescriptorRemoved( | 942 void BluetoothLowEnergyEventRouter::GattDescriptorRemoved( |
943 BluetoothAdapter* adapter, | 943 BluetoothAdapter* adapter, |
944 BluetoothGattDescriptor* descriptor) { | 944 BluetoothGattDescriptor* descriptor) { |
945 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 945 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
946 DCHECK_EQ(adapter, adapter_); | 946 DCHECK_EQ(adapter, adapter_.get()); |
947 VLOG(2) << "GATT descriptor removed: " << descriptor->GetIdentifier(); | 947 VLOG(2) << "GATT descriptor removed: " << descriptor->GetIdentifier(); |
948 | 948 |
949 BluetoothGattCharacteristic* characteristic = descriptor->GetCharacteristic(); | 949 BluetoothGattCharacteristic* characteristic = descriptor->GetCharacteristic(); |
950 DCHECK(characteristic); | 950 DCHECK(characteristic); |
951 | 951 |
952 DCHECK(desc_id_to_chrc_id_.find(descriptor->GetIdentifier()) != | 952 DCHECK(desc_id_to_chrc_id_.find(descriptor->GetIdentifier()) != |
953 desc_id_to_chrc_id_.end()); | 953 desc_id_to_chrc_id_.end()); |
954 DCHECK(characteristic->GetIdentifier() == | 954 DCHECK(characteristic->GetIdentifier() == |
955 desc_id_to_chrc_id_[descriptor->GetIdentifier()]); | 955 desc_id_to_chrc_id_[descriptor->GetIdentifier()]); |
956 | 956 |
957 desc_id_to_chrc_id_.erase(descriptor->GetIdentifier()); | 957 desc_id_to_chrc_id_.erase(descriptor->GetIdentifier()); |
958 } | 958 } |
959 | 959 |
960 void BluetoothLowEnergyEventRouter::GattCharacteristicValueChanged( | 960 void BluetoothLowEnergyEventRouter::GattCharacteristicValueChanged( |
961 BluetoothAdapter* adapter, | 961 BluetoothAdapter* adapter, |
962 BluetoothGattCharacteristic* characteristic, | 962 BluetoothGattCharacteristic* characteristic, |
963 const std::vector<uint8>& value) { | 963 const std::vector<uint8>& value) { |
964 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 964 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
965 DCHECK_EQ(adapter, adapter_); | 965 DCHECK_EQ(adapter, adapter_.get()); |
966 VLOG(2) << "GATT characteristic value changed: " | 966 VLOG(2) << "GATT characteristic value changed: " |
967 << characteristic->GetIdentifier(); | 967 << characteristic->GetIdentifier(); |
968 | 968 |
969 BluetoothGattService* service = characteristic->GetService(); | 969 BluetoothGattService* service = characteristic->GetService(); |
970 DCHECK(service); | 970 DCHECK(service); |
971 | 971 |
972 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != | 972 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != |
973 service_id_to_device_address_.end()); | 973 service_id_to_device_address_.end()); |
974 DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) != | 974 DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) != |
975 chrc_id_to_service_id_.end()); | 975 chrc_id_to_service_id_.end()); |
(...skipping 13 matching lines...) Expand all Loading... |
989 service->GetUUID(), | 989 service->GetUUID(), |
990 characteristic->GetIdentifier(), | 990 characteristic->GetIdentifier(), |
991 args.Pass()); | 991 args.Pass()); |
992 } | 992 } |
993 | 993 |
994 void BluetoothLowEnergyEventRouter::GattDescriptorValueChanged( | 994 void BluetoothLowEnergyEventRouter::GattDescriptorValueChanged( |
995 BluetoothAdapter* adapter, | 995 BluetoothAdapter* adapter, |
996 BluetoothGattDescriptor* descriptor, | 996 BluetoothGattDescriptor* descriptor, |
997 const std::vector<uint8>& value) { | 997 const std::vector<uint8>& value) { |
998 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 998 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
999 DCHECK_EQ(adapter, adapter_); | 999 DCHECK_EQ(adapter, adapter_.get()); |
1000 VLOG(2) << "GATT descriptor value changed: " << descriptor->GetIdentifier(); | 1000 VLOG(2) << "GATT descriptor value changed: " << descriptor->GetIdentifier(); |
1001 | 1001 |
1002 BluetoothGattCharacteristic* characteristic = descriptor->GetCharacteristic(); | 1002 BluetoothGattCharacteristic* characteristic = descriptor->GetCharacteristic(); |
1003 DCHECK(characteristic); | 1003 DCHECK(characteristic); |
1004 | 1004 |
1005 DCHECK(desc_id_to_chrc_id_.find(descriptor->GetIdentifier()) != | 1005 DCHECK(desc_id_to_chrc_id_.find(descriptor->GetIdentifier()) != |
1006 desc_id_to_chrc_id_.end()); | 1006 desc_id_to_chrc_id_.end()); |
1007 DCHECK(characteristic->GetIdentifier() == | 1007 DCHECK(characteristic->GetIdentifier() == |
1008 desc_id_to_chrc_id_[descriptor->GetIdentifier()]); | 1008 desc_id_to_chrc_id_[descriptor->GetIdentifier()]); |
1009 | 1009 |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1441 continue; | 1441 continue; |
1442 | 1442 |
1443 manager->Remove(extension_id, *iter); | 1443 manager->Remove(extension_id, *iter); |
1444 return true; | 1444 return true; |
1445 } | 1445 } |
1446 | 1446 |
1447 return false; | 1447 return false; |
1448 } | 1448 } |
1449 | 1449 |
1450 } // namespace extensions | 1450 } // namespace extensions |
OLD | NEW |