| 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 "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_event
_router.h" | 5 #include "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_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 "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 return error_status; | 180 return error_status; |
| 181 } | 181 } |
| 182 | 182 |
| 183 } // namespace | 183 } // namespace |
| 184 | 184 |
| 185 namespace extensions { | 185 namespace extensions { |
| 186 | 186 |
| 187 BluetoothLowEnergyEventRouter::BluetoothLowEnergyEventRouter( | 187 BluetoothLowEnergyEventRouter::BluetoothLowEnergyEventRouter( |
| 188 content::BrowserContext* context) | 188 content::BrowserContext* context) |
| 189 : adapter_(NULL), browser_context_(context), weak_ptr_factory_(this) { | 189 : adapter_(NULL), browser_context_(context), weak_ptr_factory_(this) { |
| 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 190 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 191 DCHECK(browser_context_); | 191 DCHECK(browser_context_); |
| 192 VLOG(1) << "Initializing BluetoothLowEnergyEventRouter."; | 192 VLOG(1) << "Initializing BluetoothLowEnergyEventRouter."; |
| 193 | 193 |
| 194 if (!IsBluetoothSupported()) { | 194 if (!IsBluetoothSupported()) { |
| 195 VLOG(1) << "Bluetooth not supported on the current platform."; | 195 VLOG(1) << "Bluetooth not supported on the current platform."; |
| 196 return; | 196 return; |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 | 199 |
| 200 BluetoothLowEnergyEventRouter::~BluetoothLowEnergyEventRouter() { | 200 BluetoothLowEnergyEventRouter::~BluetoothLowEnergyEventRouter() { |
| 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 201 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 202 if (!adapter_.get()) | 202 if (!adapter_.get()) |
| 203 return; | 203 return; |
| 204 | 204 |
| 205 adapter_->RemoveObserver(this); | 205 adapter_->RemoveObserver(this); |
| 206 adapter_ = NULL; | 206 adapter_ = NULL; |
| 207 } | 207 } |
| 208 | 208 |
| 209 bool BluetoothLowEnergyEventRouter::IsBluetoothSupported() const { | 209 bool BluetoothLowEnergyEventRouter::IsBluetoothSupported() const { |
| 210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 210 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 211 return adapter_.get() || | 211 return adapter_.get() || |
| 212 BluetoothAdapterFactory::IsBluetoothAdapterAvailable(); | 212 BluetoothAdapterFactory::IsBluetoothAdapterAvailable(); |
| 213 } | 213 } |
| 214 | 214 |
| 215 bool BluetoothLowEnergyEventRouter::InitializeAdapterAndInvokeCallback( | 215 bool BluetoothLowEnergyEventRouter::InitializeAdapterAndInvokeCallback( |
| 216 const base::Closure& callback) { | 216 const base::Closure& callback) { |
| 217 if (!IsBluetoothSupported()) | 217 if (!IsBluetoothSupported()) |
| 218 return false; | 218 return false; |
| 219 | 219 |
| 220 if (adapter_.get()) { | 220 if (adapter_.get()) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 232 bool BluetoothLowEnergyEventRouter::HasAdapter() const { | 232 bool BluetoothLowEnergyEventRouter::HasAdapter() const { |
| 233 return (adapter_.get() != NULL); | 233 return (adapter_.get() != NULL); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void BluetoothLowEnergyEventRouter::Connect( | 236 void BluetoothLowEnergyEventRouter::Connect( |
| 237 bool persistent, | 237 bool persistent, |
| 238 const Extension* extension, | 238 const Extension* extension, |
| 239 const std::string& device_address, | 239 const std::string& device_address, |
| 240 const base::Closure& callback, | 240 const base::Closure& callback, |
| 241 const ErrorCallback& error_callback) { | 241 const ErrorCallback& error_callback) { |
| 242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 242 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 243 if (!adapter_.get()) { | 243 if (!adapter_.get()) { |
| 244 VLOG(1) << "BluetoothAdapter not ready."; | 244 VLOG(1) << "BluetoothAdapter not ready."; |
| 245 error_callback.Run(kStatusErrorFailed); | 245 error_callback.Run(kStatusErrorFailed); |
| 246 return; | 246 return; |
| 247 } | 247 } |
| 248 | 248 |
| 249 const std::string extension_id = extension->id(); | 249 const std::string extension_id = extension->id(); |
| 250 const std::string connect_id = extension_id + device_address; | 250 const std::string connect_id = extension_id + device_address; |
| 251 | 251 |
| 252 if (connecting_devices_.count(connect_id) != 0) { | 252 if (connecting_devices_.count(connect_id) != 0) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 extension_id, | 287 extension_id, |
| 288 device_address, | 288 device_address, |
| 289 error_callback)); | 289 error_callback)); |
| 290 } | 290 } |
| 291 | 291 |
| 292 void BluetoothLowEnergyEventRouter::Disconnect( | 292 void BluetoothLowEnergyEventRouter::Disconnect( |
| 293 const Extension* extension, | 293 const Extension* extension, |
| 294 const std::string& device_address, | 294 const std::string& device_address, |
| 295 const base::Closure& callback, | 295 const base::Closure& callback, |
| 296 const ErrorCallback& error_callback) { | 296 const ErrorCallback& error_callback) { |
| 297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 297 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 298 if (!adapter_.get()) { | 298 if (!adapter_.get()) { |
| 299 VLOG(1) << "BluetoothAdapter not ready."; | 299 VLOG(1) << "BluetoothAdapter not ready."; |
| 300 error_callback.Run(kStatusErrorFailed); | 300 error_callback.Run(kStatusErrorFailed); |
| 301 return; | 301 return; |
| 302 } | 302 } |
| 303 | 303 |
| 304 const std::string extension_id = extension->id(); | 304 const std::string extension_id = extension->id(); |
| 305 const std::string disconnect_id = extension_id + device_address; | 305 const std::string disconnect_id = extension_id + device_address; |
| 306 | 306 |
| 307 if (disconnecting_devices_.count(disconnect_id) != 0) { | 307 if (disconnecting_devices_.count(disconnect_id) != 0) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 322 base::Bind(&BluetoothLowEnergyEventRouter::OnDisconnect, | 322 base::Bind(&BluetoothLowEnergyEventRouter::OnDisconnect, |
| 323 weak_ptr_factory_.GetWeakPtr(), | 323 weak_ptr_factory_.GetWeakPtr(), |
| 324 extension_id, | 324 extension_id, |
| 325 device_address, | 325 device_address, |
| 326 callback)); | 326 callback)); |
| 327 } | 327 } |
| 328 | 328 |
| 329 bool BluetoothLowEnergyEventRouter::GetServices( | 329 bool BluetoothLowEnergyEventRouter::GetServices( |
| 330 const std::string& device_address, | 330 const std::string& device_address, |
| 331 ServiceList* out_services) const { | 331 ServiceList* out_services) const { |
| 332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 332 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 333 DCHECK(out_services); | 333 DCHECK(out_services); |
| 334 if (!adapter_.get()) { | 334 if (!adapter_.get()) { |
| 335 VLOG(1) << "BluetoothAdapter not ready."; | 335 VLOG(1) << "BluetoothAdapter not ready."; |
| 336 return false; | 336 return false; |
| 337 } | 337 } |
| 338 | 338 |
| 339 BluetoothDevice* device = adapter_->GetDevice(device_address); | 339 BluetoothDevice* device = adapter_->GetDevice(device_address); |
| 340 if (!device) { | 340 if (!device) { |
| 341 VLOG(1) << "Bluetooth device not found: " << device_address; | 341 VLOG(1) << "Bluetooth device not found: " << device_address; |
| 342 return false; | 342 return false; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 357 | 357 |
| 358 out_services->push_back(api_service); | 358 out_services->push_back(api_service); |
| 359 } | 359 } |
| 360 | 360 |
| 361 return true; | 361 return true; |
| 362 } | 362 } |
| 363 | 363 |
| 364 BluetoothLowEnergyEventRouter::Status BluetoothLowEnergyEventRouter::GetService( | 364 BluetoothLowEnergyEventRouter::Status BluetoothLowEnergyEventRouter::GetService( |
| 365 const std::string& instance_id, | 365 const std::string& instance_id, |
| 366 apibtle::Service* out_service) const { | 366 apibtle::Service* out_service) const { |
| 367 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 367 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 368 DCHECK(out_service); | 368 DCHECK(out_service); |
| 369 if (!adapter_.get()) { | 369 if (!adapter_.get()) { |
| 370 VLOG(1) << "BluetoothAdapter not ready."; | 370 VLOG(1) << "BluetoothAdapter not ready."; |
| 371 return kStatusErrorFailed; | 371 return kStatusErrorFailed; |
| 372 } | 372 } |
| 373 | 373 |
| 374 BluetoothGattService* gatt_service = FindServiceById(instance_id); | 374 BluetoothGattService* gatt_service = FindServiceById(instance_id); |
| 375 if (!gatt_service) { | 375 if (!gatt_service) { |
| 376 VLOG(1) << "Service not found: " << instance_id; | 376 VLOG(1) << "Service not found: " << instance_id; |
| 377 return kStatusErrorNotFound; | 377 return kStatusErrorNotFound; |
| 378 } | 378 } |
| 379 | 379 |
| 380 PopulateService(gatt_service, out_service); | 380 PopulateService(gatt_service, out_service); |
| 381 return kStatusSuccess; | 381 return kStatusSuccess; |
| 382 } | 382 } |
| 383 | 383 |
| 384 BluetoothLowEnergyEventRouter::Status | 384 BluetoothLowEnergyEventRouter::Status |
| 385 BluetoothLowEnergyEventRouter::GetIncludedServices( | 385 BluetoothLowEnergyEventRouter::GetIncludedServices( |
| 386 const std::string& instance_id, | 386 const std::string& instance_id, |
| 387 ServiceList* out_services) const { | 387 ServiceList* out_services) const { |
| 388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 388 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 389 DCHECK(out_services); | 389 DCHECK(out_services); |
| 390 if (!adapter_.get()) { | 390 if (!adapter_.get()) { |
| 391 VLOG(1) << "BluetoothAdapter not ready."; | 391 VLOG(1) << "BluetoothAdapter not ready."; |
| 392 return kStatusErrorFailed; | 392 return kStatusErrorFailed; |
| 393 } | 393 } |
| 394 | 394 |
| 395 BluetoothGattService* service = FindServiceById(instance_id); | 395 BluetoothGattService* service = FindServiceById(instance_id); |
| 396 if (!service) { | 396 if (!service) { |
| 397 VLOG(1) << "Service not found: " << instance_id; | 397 VLOG(1) << "Service not found: " << instance_id; |
| 398 return kStatusErrorNotFound; | 398 return kStatusErrorNotFound; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 415 } | 415 } |
| 416 | 416 |
| 417 return kStatusSuccess; | 417 return kStatusSuccess; |
| 418 } | 418 } |
| 419 | 419 |
| 420 BluetoothLowEnergyEventRouter::Status | 420 BluetoothLowEnergyEventRouter::Status |
| 421 BluetoothLowEnergyEventRouter::GetCharacteristics( | 421 BluetoothLowEnergyEventRouter::GetCharacteristics( |
| 422 const Extension* extension, | 422 const Extension* extension, |
| 423 const std::string& instance_id, | 423 const std::string& instance_id, |
| 424 CharacteristicList* out_characteristics) const { | 424 CharacteristicList* out_characteristics) const { |
| 425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 425 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 426 DCHECK(extension); | 426 DCHECK(extension); |
| 427 DCHECK(out_characteristics); | 427 DCHECK(out_characteristics); |
| 428 if (!adapter_.get()) { | 428 if (!adapter_.get()) { |
| 429 VLOG(1) << "BlutoothAdapter not ready."; | 429 VLOG(1) << "BlutoothAdapter not ready."; |
| 430 return kStatusErrorFailed; | 430 return kStatusErrorFailed; |
| 431 } | 431 } |
| 432 | 432 |
| 433 BluetoothGattService* service = FindServiceById(instance_id); | 433 BluetoothGattService* service = FindServiceById(instance_id); |
| 434 if (!service) { | 434 if (!service) { |
| 435 VLOG(1) << "Service not found: " << instance_id; | 435 VLOG(1) << "Service not found: " << instance_id; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 461 } | 461 } |
| 462 | 462 |
| 463 return kStatusSuccess; | 463 return kStatusSuccess; |
| 464 } | 464 } |
| 465 | 465 |
| 466 BluetoothLowEnergyEventRouter::Status | 466 BluetoothLowEnergyEventRouter::Status |
| 467 BluetoothLowEnergyEventRouter::GetCharacteristic( | 467 BluetoothLowEnergyEventRouter::GetCharacteristic( |
| 468 const Extension* extension, | 468 const Extension* extension, |
| 469 const std::string& instance_id, | 469 const std::string& instance_id, |
| 470 apibtle::Characteristic* out_characteristic) const { | 470 apibtle::Characteristic* out_characteristic) const { |
| 471 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 471 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 472 DCHECK(extension); | 472 DCHECK(extension); |
| 473 DCHECK(out_characteristic); | 473 DCHECK(out_characteristic); |
| 474 if (!adapter_.get()) { | 474 if (!adapter_.get()) { |
| 475 VLOG(1) << "BluetoothAdapter not ready."; | 475 VLOG(1) << "BluetoothAdapter not ready."; |
| 476 return kStatusErrorFailed; | 476 return kStatusErrorFailed; |
| 477 } | 477 } |
| 478 | 478 |
| 479 BluetoothGattCharacteristic* characteristic = | 479 BluetoothGattCharacteristic* characteristic = |
| 480 FindCharacteristicById(instance_id); | 480 FindCharacteristicById(instance_id); |
| 481 if (!characteristic) { | 481 if (!characteristic) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 493 | 493 |
| 494 PopulateCharacteristic(characteristic, out_characteristic); | 494 PopulateCharacteristic(characteristic, out_characteristic); |
| 495 return kStatusSuccess; | 495 return kStatusSuccess; |
| 496 } | 496 } |
| 497 | 497 |
| 498 BluetoothLowEnergyEventRouter::Status | 498 BluetoothLowEnergyEventRouter::Status |
| 499 BluetoothLowEnergyEventRouter::GetDescriptors( | 499 BluetoothLowEnergyEventRouter::GetDescriptors( |
| 500 const Extension* extension, | 500 const Extension* extension, |
| 501 const std::string& instance_id, | 501 const std::string& instance_id, |
| 502 DescriptorList* out_descriptors) const { | 502 DescriptorList* out_descriptors) const { |
| 503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 503 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 504 DCHECK(extension); | 504 DCHECK(extension); |
| 505 DCHECK(out_descriptors); | 505 DCHECK(out_descriptors); |
| 506 if (!adapter_.get()) { | 506 if (!adapter_.get()) { |
| 507 VLOG(1) << "BlutoothAdapter not ready."; | 507 VLOG(1) << "BlutoothAdapter not ready."; |
| 508 return kStatusErrorFailed; | 508 return kStatusErrorFailed; |
| 509 } | 509 } |
| 510 | 510 |
| 511 BluetoothGattCharacteristic* characteristic = | 511 BluetoothGattCharacteristic* characteristic = |
| 512 FindCharacteristicById(instance_id); | 512 FindCharacteristicById(instance_id); |
| 513 if (!characteristic) { | 513 if (!characteristic) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 540 } | 540 } |
| 541 | 541 |
| 542 return kStatusSuccess; | 542 return kStatusSuccess; |
| 543 } | 543 } |
| 544 | 544 |
| 545 BluetoothLowEnergyEventRouter::Status | 545 BluetoothLowEnergyEventRouter::Status |
| 546 BluetoothLowEnergyEventRouter::GetDescriptor( | 546 BluetoothLowEnergyEventRouter::GetDescriptor( |
| 547 const Extension* extension, | 547 const Extension* extension, |
| 548 const std::string& instance_id, | 548 const std::string& instance_id, |
| 549 core_api::bluetooth_low_energy::Descriptor* out_descriptor) const { | 549 core_api::bluetooth_low_energy::Descriptor* out_descriptor) const { |
| 550 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 550 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 551 DCHECK(extension); | 551 DCHECK(extension); |
| 552 DCHECK(out_descriptor); | 552 DCHECK(out_descriptor); |
| 553 if (!adapter_.get()) { | 553 if (!adapter_.get()) { |
| 554 VLOG(1) << "BluetoothAdapter not ready."; | 554 VLOG(1) << "BluetoothAdapter not ready."; |
| 555 return kStatusErrorFailed; | 555 return kStatusErrorFailed; |
| 556 } | 556 } |
| 557 | 557 |
| 558 BluetoothGattDescriptor* descriptor = FindDescriptorById(instance_id); | 558 BluetoothGattDescriptor* descriptor = FindDescriptorById(instance_id); |
| 559 if (!descriptor) { | 559 if (!descriptor) { |
| 560 VLOG(1) << "Descriptor not found: " << instance_id; | 560 VLOG(1) << "Descriptor not found: " << instance_id; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 571 | 571 |
| 572 PopulateDescriptor(descriptor, out_descriptor); | 572 PopulateDescriptor(descriptor, out_descriptor); |
| 573 return kStatusSuccess; | 573 return kStatusSuccess; |
| 574 } | 574 } |
| 575 | 575 |
| 576 void BluetoothLowEnergyEventRouter::ReadCharacteristicValue( | 576 void BluetoothLowEnergyEventRouter::ReadCharacteristicValue( |
| 577 const Extension* extension, | 577 const Extension* extension, |
| 578 const std::string& instance_id, | 578 const std::string& instance_id, |
| 579 const base::Closure& callback, | 579 const base::Closure& callback, |
| 580 const ErrorCallback& error_callback) { | 580 const ErrorCallback& error_callback) { |
| 581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 581 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 582 DCHECK(extension); | 582 DCHECK(extension); |
| 583 if (!adapter_.get()) { | 583 if (!adapter_.get()) { |
| 584 VLOG(1) << "BluetoothAdapter not ready."; | 584 VLOG(1) << "BluetoothAdapter not ready."; |
| 585 error_callback.Run(kStatusErrorFailed); | 585 error_callback.Run(kStatusErrorFailed); |
| 586 return; | 586 return; |
| 587 } | 587 } |
| 588 | 588 |
| 589 BluetoothGattCharacteristic* characteristic = | 589 BluetoothGattCharacteristic* characteristic = |
| 590 FindCharacteristicById(instance_id); | 590 FindCharacteristicById(instance_id); |
| 591 if (!characteristic) { | 591 if (!characteristic) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 611 weak_ptr_factory_.GetWeakPtr(), | 611 weak_ptr_factory_.GetWeakPtr(), |
| 612 error_callback)); | 612 error_callback)); |
| 613 } | 613 } |
| 614 | 614 |
| 615 void BluetoothLowEnergyEventRouter::WriteCharacteristicValue( | 615 void BluetoothLowEnergyEventRouter::WriteCharacteristicValue( |
| 616 const Extension* extension, | 616 const Extension* extension, |
| 617 const std::string& instance_id, | 617 const std::string& instance_id, |
| 618 const std::vector<uint8>& value, | 618 const std::vector<uint8>& value, |
| 619 const base::Closure& callback, | 619 const base::Closure& callback, |
| 620 const ErrorCallback& error_callback) { | 620 const ErrorCallback& error_callback) { |
| 621 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 621 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 622 DCHECK(extension); | 622 DCHECK(extension); |
| 623 if (!adapter_.get()) { | 623 if (!adapter_.get()) { |
| 624 VLOG(1) << "BluetoothAdapter not ready."; | 624 VLOG(1) << "BluetoothAdapter not ready."; |
| 625 error_callback.Run(kStatusErrorFailed); | 625 error_callback.Run(kStatusErrorFailed); |
| 626 return; | 626 return; |
| 627 } | 627 } |
| 628 | 628 |
| 629 BluetoothGattCharacteristic* characteristic = | 629 BluetoothGattCharacteristic* characteristic = |
| 630 FindCharacteristicById(instance_id); | 630 FindCharacteristicById(instance_id); |
| 631 if (!characteristic) { | 631 if (!characteristic) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 650 weak_ptr_factory_.GetWeakPtr(), | 650 weak_ptr_factory_.GetWeakPtr(), |
| 651 error_callback)); | 651 error_callback)); |
| 652 } | 652 } |
| 653 | 653 |
| 654 void BluetoothLowEnergyEventRouter::StartCharacteristicNotifications( | 654 void BluetoothLowEnergyEventRouter::StartCharacteristicNotifications( |
| 655 bool persistent, | 655 bool persistent, |
| 656 const Extension* extension, | 656 const Extension* extension, |
| 657 const std::string& instance_id, | 657 const std::string& instance_id, |
| 658 const base::Closure& callback, | 658 const base::Closure& callback, |
| 659 const ErrorCallback& error_callback) { | 659 const ErrorCallback& error_callback) { |
| 660 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 660 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 661 if (!adapter_.get()) { | 661 if (!adapter_.get()) { |
| 662 VLOG(1) << "BluetoothAdapter not ready."; | 662 VLOG(1) << "BluetoothAdapter not ready."; |
| 663 error_callback.Run(kStatusErrorFailed); | 663 error_callback.Run(kStatusErrorFailed); |
| 664 return; | 664 return; |
| 665 } | 665 } |
| 666 | 666 |
| 667 const std::string extension_id = extension->id(); | 667 const std::string extension_id = extension->id(); |
| 668 const std::string session_id = extension_id + instance_id; | 668 const std::string session_id = extension_id + instance_id; |
| 669 | 669 |
| 670 if (pending_session_calls_.count(session_id) != 0) { | 670 if (pending_session_calls_.count(session_id) != 0) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 extension_id, | 715 extension_id, |
| 716 instance_id, | 716 instance_id, |
| 717 error_callback)); | 717 error_callback)); |
| 718 } | 718 } |
| 719 | 719 |
| 720 void BluetoothLowEnergyEventRouter::StopCharacteristicNotifications( | 720 void BluetoothLowEnergyEventRouter::StopCharacteristicNotifications( |
| 721 const Extension* extension, | 721 const Extension* extension, |
| 722 const std::string& instance_id, | 722 const std::string& instance_id, |
| 723 const base::Closure& callback, | 723 const base::Closure& callback, |
| 724 const ErrorCallback& error_callback) { | 724 const ErrorCallback& error_callback) { |
| 725 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 725 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 726 if (!adapter_.get()) { | 726 if (!adapter_.get()) { |
| 727 VLOG(1) << "BluetoothAdapter not ready."; | 727 VLOG(1) << "BluetoothAdapter not ready."; |
| 728 error_callback.Run(kStatusErrorFailed); | 728 error_callback.Run(kStatusErrorFailed); |
| 729 return; | 729 return; |
| 730 } | 730 } |
| 731 | 731 |
| 732 const std::string extension_id = extension->id(); | 732 const std::string extension_id = extension->id(); |
| 733 | 733 |
| 734 BluetoothLowEnergyNotifySession* session = | 734 BluetoothLowEnergyNotifySession* session = |
| 735 FindNotifySession(extension_id, instance_id); | 735 FindNotifySession(extension_id, instance_id); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 746 extension_id, | 746 extension_id, |
| 747 instance_id, | 747 instance_id, |
| 748 callback)); | 748 callback)); |
| 749 } | 749 } |
| 750 | 750 |
| 751 void BluetoothLowEnergyEventRouter::ReadDescriptorValue( | 751 void BluetoothLowEnergyEventRouter::ReadDescriptorValue( |
| 752 const Extension* extension, | 752 const Extension* extension, |
| 753 const std::string& instance_id, | 753 const std::string& instance_id, |
| 754 const base::Closure& callback, | 754 const base::Closure& callback, |
| 755 const ErrorCallback& error_callback) { | 755 const ErrorCallback& error_callback) { |
| 756 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 756 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 757 DCHECK(extension); | 757 DCHECK(extension); |
| 758 if (!adapter_.get()) { | 758 if (!adapter_.get()) { |
| 759 VLOG(1) << "BluetoothAdapter not ready."; | 759 VLOG(1) << "BluetoothAdapter not ready."; |
| 760 error_callback.Run(kStatusErrorFailed); | 760 error_callback.Run(kStatusErrorFailed); |
| 761 return; | 761 return; |
| 762 } | 762 } |
| 763 | 763 |
| 764 BluetoothGattDescriptor* descriptor = FindDescriptorById(instance_id); | 764 BluetoothGattDescriptor* descriptor = FindDescriptorById(instance_id); |
| 765 if (!descriptor) { | 765 if (!descriptor) { |
| 766 VLOG(1) << "Descriptor not found: " << instance_id; | 766 VLOG(1) << "Descriptor not found: " << instance_id; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 785 weak_ptr_factory_.GetWeakPtr(), | 785 weak_ptr_factory_.GetWeakPtr(), |
| 786 error_callback)); | 786 error_callback)); |
| 787 } | 787 } |
| 788 | 788 |
| 789 void BluetoothLowEnergyEventRouter::WriteDescriptorValue( | 789 void BluetoothLowEnergyEventRouter::WriteDescriptorValue( |
| 790 const Extension* extension, | 790 const Extension* extension, |
| 791 const std::string& instance_id, | 791 const std::string& instance_id, |
| 792 const std::vector<uint8>& value, | 792 const std::vector<uint8>& value, |
| 793 const base::Closure& callback, | 793 const base::Closure& callback, |
| 794 const ErrorCallback& error_callback) { | 794 const ErrorCallback& error_callback) { |
| 795 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 795 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 796 DCHECK(extension); | 796 DCHECK(extension); |
| 797 if (!adapter_.get()) { | 797 if (!adapter_.get()) { |
| 798 VLOG(1) << "BluetoothAdapter not ready."; | 798 VLOG(1) << "BluetoothAdapter not ready."; |
| 799 error_callback.Run(kStatusErrorFailed); | 799 error_callback.Run(kStatusErrorFailed); |
| 800 return; | 800 return; |
| 801 } | 801 } |
| 802 | 802 |
| 803 BluetoothGattDescriptor* descriptor = FindDescriptorById(instance_id); | 803 BluetoothGattDescriptor* descriptor = FindDescriptorById(instance_id); |
| 804 if (!descriptor) { | 804 if (!descriptor) { |
| 805 VLOG(1) << "Descriptor not found: " << instance_id; | 805 VLOG(1) << "Descriptor not found: " << instance_id; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 827 void BluetoothLowEnergyEventRouter::SetAdapterForTesting( | 827 void BluetoothLowEnergyEventRouter::SetAdapterForTesting( |
| 828 device::BluetoothAdapter* adapter) { | 828 device::BluetoothAdapter* adapter) { |
| 829 adapter_ = adapter; | 829 adapter_ = adapter; |
| 830 InitializeIdentifierMappings(); | 830 InitializeIdentifierMappings(); |
| 831 } | 831 } |
| 832 | 832 |
| 833 void BluetoothLowEnergyEventRouter::GattServiceAdded( | 833 void BluetoothLowEnergyEventRouter::GattServiceAdded( |
| 834 BluetoothAdapter* adapter, | 834 BluetoothAdapter* adapter, |
| 835 BluetoothDevice* device, | 835 BluetoothDevice* device, |
| 836 BluetoothGattService* service) { | 836 BluetoothGattService* service) { |
| 837 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 837 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 838 DCHECK_EQ(adapter, adapter_.get()); | 838 DCHECK_EQ(adapter, adapter_.get()); |
| 839 VLOG(2) << "GATT service added: " << service->GetIdentifier(); | 839 VLOG(2) << "GATT service added: " << service->GetIdentifier(); |
| 840 | 840 |
| 841 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) == | 841 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) == |
| 842 service_id_to_device_address_.end()); | 842 service_id_to_device_address_.end()); |
| 843 | 843 |
| 844 service_id_to_device_address_[service->GetIdentifier()] = | 844 service_id_to_device_address_[service->GetIdentifier()] = |
| 845 device->GetAddress(); | 845 device->GetAddress(); |
| 846 } | 846 } |
| 847 | 847 |
| 848 void BluetoothLowEnergyEventRouter::GattServiceRemoved( | 848 void BluetoothLowEnergyEventRouter::GattServiceRemoved( |
| 849 BluetoothAdapter* adapter, | 849 BluetoothAdapter* adapter, |
| 850 BluetoothDevice* device, | 850 BluetoothDevice* device, |
| 851 BluetoothGattService* service) { | 851 BluetoothGattService* service) { |
| 852 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 852 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 853 DCHECK_EQ(adapter, adapter_.get()); | 853 DCHECK_EQ(adapter, adapter_.get()); |
| 854 VLOG(2) << "GATT service removed: " << service->GetIdentifier(); | 854 VLOG(2) << "GATT service removed: " << service->GetIdentifier(); |
| 855 | 855 |
| 856 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != | 856 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != |
| 857 service_id_to_device_address_.end()); | 857 service_id_to_device_address_.end()); |
| 858 | 858 |
| 859 DCHECK(device->GetAddress() == | 859 DCHECK(device->GetAddress() == |
| 860 service_id_to_device_address_[service->GetIdentifier()]); | 860 service_id_to_device_address_[service->GetIdentifier()]); |
| 861 service_id_to_device_address_.erase(service->GetIdentifier()); | 861 service_id_to_device_address_.erase(service->GetIdentifier()); |
| 862 | 862 |
| 863 // Signal API event. | 863 // Signal API event. |
| 864 apibtle::Service api_service; | 864 apibtle::Service api_service; |
| 865 PopulateService(service, &api_service); | 865 PopulateService(service, &api_service); |
| 866 | 866 |
| 867 scoped_ptr<base::ListValue> args = | 867 scoped_ptr<base::ListValue> args = |
| 868 apibtle::OnServiceRemoved::Create(api_service); | 868 apibtle::OnServiceRemoved::Create(api_service); |
| 869 scoped_ptr<Event> event( | 869 scoped_ptr<Event> event( |
| 870 new Event(apibtle::OnServiceRemoved::kEventName, args.Pass())); | 870 new Event(apibtle::OnServiceRemoved::kEventName, args.Pass())); |
| 871 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); | 871 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); |
| 872 } | 872 } |
| 873 | 873 |
| 874 void BluetoothLowEnergyEventRouter::GattDiscoveryCompleteForService( | 874 void BluetoothLowEnergyEventRouter::GattDiscoveryCompleteForService( |
| 875 BluetoothAdapter* adapter, | 875 BluetoothAdapter* adapter, |
| 876 BluetoothGattService* service) { | 876 BluetoothGattService* service) { |
| 877 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 877 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 878 DCHECK_EQ(adapter, adapter_.get()); | 878 DCHECK_EQ(adapter, adapter_.get()); |
| 879 VLOG(2) << "GATT service discovery complete: " << service->GetIdentifier(); | 879 VLOG(2) << "GATT service discovery complete: " << service->GetIdentifier(); |
| 880 | 880 |
| 881 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != | 881 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != |
| 882 service_id_to_device_address_.end()); | 882 service_id_to_device_address_.end()); |
| 883 | 883 |
| 884 // Signal the service added event here. | 884 // Signal the service added event here. |
| 885 apibtle::Service api_service; | 885 apibtle::Service api_service; |
| 886 PopulateService(service, &api_service); | 886 PopulateService(service, &api_service); |
| 887 | 887 |
| 888 scoped_ptr<base::ListValue> args = | 888 scoped_ptr<base::ListValue> args = |
| 889 apibtle::OnServiceAdded::Create(api_service); | 889 apibtle::OnServiceAdded::Create(api_service); |
| 890 scoped_ptr<Event> event( | 890 scoped_ptr<Event> event( |
| 891 new Event(apibtle::OnServiceAdded::kEventName, args.Pass())); | 891 new Event(apibtle::OnServiceAdded::kEventName, args.Pass())); |
| 892 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); | 892 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); |
| 893 } | 893 } |
| 894 | 894 |
| 895 void BluetoothLowEnergyEventRouter::GattServiceChanged( | 895 void BluetoothLowEnergyEventRouter::GattServiceChanged( |
| 896 BluetoothAdapter* adapter, | 896 BluetoothAdapter* adapter, |
| 897 BluetoothGattService* service) { | 897 BluetoothGattService* service) { |
| 898 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 898 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 899 DCHECK_EQ(adapter, adapter_.get()); | 899 DCHECK_EQ(adapter, adapter_.get()); |
| 900 VLOG(2) << "GATT service changed: " << service->GetIdentifier(); | 900 VLOG(2) << "GATT service changed: " << service->GetIdentifier(); |
| 901 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != | 901 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != |
| 902 service_id_to_device_address_.end()); | 902 service_id_to_device_address_.end()); |
| 903 | 903 |
| 904 // Signal API event. | 904 // Signal API event. |
| 905 apibtle::Service api_service; | 905 apibtle::Service api_service; |
| 906 PopulateService(service, &api_service); | 906 PopulateService(service, &api_service); |
| 907 | 907 |
| 908 DispatchEventToExtensionsWithPermission( | 908 DispatchEventToExtensionsWithPermission( |
| 909 apibtle::OnServiceChanged::kEventName, | 909 apibtle::OnServiceChanged::kEventName, |
| 910 service->GetUUID(), | 910 service->GetUUID(), |
| 911 "" /* characteristic_id */, | 911 "" /* characteristic_id */, |
| 912 apibtle::OnServiceChanged::Create(api_service)); | 912 apibtle::OnServiceChanged::Create(api_service)); |
| 913 } | 913 } |
| 914 | 914 |
| 915 void BluetoothLowEnergyEventRouter::GattCharacteristicAdded( | 915 void BluetoothLowEnergyEventRouter::GattCharacteristicAdded( |
| 916 BluetoothAdapter* adapter, | 916 BluetoothAdapter* adapter, |
| 917 BluetoothGattCharacteristic* characteristic) { | 917 BluetoothGattCharacteristic* characteristic) { |
| 918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 918 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 919 DCHECK_EQ(adapter, adapter_.get()); | 919 DCHECK_EQ(adapter, adapter_.get()); |
| 920 VLOG(2) << "GATT characteristic added: " << characteristic->GetIdentifier(); | 920 VLOG(2) << "GATT characteristic added: " << characteristic->GetIdentifier(); |
| 921 | 921 |
| 922 BluetoothGattService* service = characteristic->GetService(); | 922 BluetoothGattService* service = characteristic->GetService(); |
| 923 DCHECK(service); | 923 DCHECK(service); |
| 924 | 924 |
| 925 DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) == | 925 DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) == |
| 926 chrc_id_to_service_id_.end()); | 926 chrc_id_to_service_id_.end()); |
| 927 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != | 927 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != |
| 928 service_id_to_device_address_.end()); | 928 service_id_to_device_address_.end()); |
| 929 | 929 |
| 930 chrc_id_to_service_id_[characteristic->GetIdentifier()] = | 930 chrc_id_to_service_id_[characteristic->GetIdentifier()] = |
| 931 service->GetIdentifier(); | 931 service->GetIdentifier(); |
| 932 } | 932 } |
| 933 | 933 |
| 934 void BluetoothLowEnergyEventRouter::GattCharacteristicRemoved( | 934 void BluetoothLowEnergyEventRouter::GattCharacteristicRemoved( |
| 935 BluetoothAdapter* adapter, | 935 BluetoothAdapter* adapter, |
| 936 BluetoothGattCharacteristic* characteristic) { | 936 BluetoothGattCharacteristic* characteristic) { |
| 937 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 937 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 938 DCHECK_EQ(adapter, adapter_.get()); | 938 DCHECK_EQ(adapter, adapter_.get()); |
| 939 VLOG(2) << "GATT characteristic removed: " << characteristic->GetIdentifier(); | 939 VLOG(2) << "GATT characteristic removed: " << characteristic->GetIdentifier(); |
| 940 | 940 |
| 941 BluetoothGattService* service = characteristic->GetService(); | 941 BluetoothGattService* service = characteristic->GetService(); |
| 942 DCHECK(service); | 942 DCHECK(service); |
| 943 | 943 |
| 944 DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) != | 944 DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) != |
| 945 chrc_id_to_service_id_.end()); | 945 chrc_id_to_service_id_.end()); |
| 946 DCHECK(service->GetIdentifier() == | 946 DCHECK(service->GetIdentifier() == |
| 947 chrc_id_to_service_id_[characteristic->GetIdentifier()]); | 947 chrc_id_to_service_id_[characteristic->GetIdentifier()]); |
| 948 | 948 |
| 949 chrc_id_to_service_id_.erase(characteristic->GetIdentifier()); | 949 chrc_id_to_service_id_.erase(characteristic->GetIdentifier()); |
| 950 } | 950 } |
| 951 | 951 |
| 952 void BluetoothLowEnergyEventRouter::GattDescriptorAdded( | 952 void BluetoothLowEnergyEventRouter::GattDescriptorAdded( |
| 953 BluetoothAdapter* adapter, | 953 BluetoothAdapter* adapter, |
| 954 BluetoothGattDescriptor* descriptor) { | 954 BluetoothGattDescriptor* descriptor) { |
| 955 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 955 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 956 DCHECK_EQ(adapter, adapter_.get()); | 956 DCHECK_EQ(adapter, adapter_.get()); |
| 957 VLOG(2) << "GATT descriptor added: " << descriptor->GetIdentifier(); | 957 VLOG(2) << "GATT descriptor added: " << descriptor->GetIdentifier(); |
| 958 | 958 |
| 959 BluetoothGattCharacteristic* characteristic = descriptor->GetCharacteristic(); | 959 BluetoothGattCharacteristic* characteristic = descriptor->GetCharacteristic(); |
| 960 DCHECK(characteristic); | 960 DCHECK(characteristic); |
| 961 | 961 |
| 962 DCHECK(desc_id_to_chrc_id_.find(descriptor->GetIdentifier()) == | 962 DCHECK(desc_id_to_chrc_id_.find(descriptor->GetIdentifier()) == |
| 963 desc_id_to_chrc_id_.end()); | 963 desc_id_to_chrc_id_.end()); |
| 964 DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) != | 964 DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) != |
| 965 chrc_id_to_service_id_.end()); | 965 chrc_id_to_service_id_.end()); |
| 966 | 966 |
| 967 desc_id_to_chrc_id_[descriptor->GetIdentifier()] = | 967 desc_id_to_chrc_id_[descriptor->GetIdentifier()] = |
| 968 characteristic->GetIdentifier(); | 968 characteristic->GetIdentifier(); |
| 969 } | 969 } |
| 970 | 970 |
| 971 void BluetoothLowEnergyEventRouter::GattDescriptorRemoved( | 971 void BluetoothLowEnergyEventRouter::GattDescriptorRemoved( |
| 972 BluetoothAdapter* adapter, | 972 BluetoothAdapter* adapter, |
| 973 BluetoothGattDescriptor* descriptor) { | 973 BluetoothGattDescriptor* descriptor) { |
| 974 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 974 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 975 DCHECK_EQ(adapter, adapter_.get()); | 975 DCHECK_EQ(adapter, adapter_.get()); |
| 976 VLOG(2) << "GATT descriptor removed: " << descriptor->GetIdentifier(); | 976 VLOG(2) << "GATT descriptor removed: " << descriptor->GetIdentifier(); |
| 977 | 977 |
| 978 BluetoothGattCharacteristic* characteristic = descriptor->GetCharacteristic(); | 978 BluetoothGattCharacteristic* characteristic = descriptor->GetCharacteristic(); |
| 979 DCHECK(characteristic); | 979 DCHECK(characteristic); |
| 980 | 980 |
| 981 DCHECK(desc_id_to_chrc_id_.find(descriptor->GetIdentifier()) != | 981 DCHECK(desc_id_to_chrc_id_.find(descriptor->GetIdentifier()) != |
| 982 desc_id_to_chrc_id_.end()); | 982 desc_id_to_chrc_id_.end()); |
| 983 DCHECK(characteristic->GetIdentifier() == | 983 DCHECK(characteristic->GetIdentifier() == |
| 984 desc_id_to_chrc_id_[descriptor->GetIdentifier()]); | 984 desc_id_to_chrc_id_[descriptor->GetIdentifier()]); |
| 985 | 985 |
| 986 desc_id_to_chrc_id_.erase(descriptor->GetIdentifier()); | 986 desc_id_to_chrc_id_.erase(descriptor->GetIdentifier()); |
| 987 } | 987 } |
| 988 | 988 |
| 989 void BluetoothLowEnergyEventRouter::GattCharacteristicValueChanged( | 989 void BluetoothLowEnergyEventRouter::GattCharacteristicValueChanged( |
| 990 BluetoothAdapter* adapter, | 990 BluetoothAdapter* adapter, |
| 991 BluetoothGattCharacteristic* characteristic, | 991 BluetoothGattCharacteristic* characteristic, |
| 992 const std::vector<uint8>& value) { | 992 const std::vector<uint8>& value) { |
| 993 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 993 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 994 DCHECK_EQ(adapter, adapter_.get()); | 994 DCHECK_EQ(adapter, adapter_.get()); |
| 995 VLOG(2) << "GATT characteristic value changed: " | 995 VLOG(2) << "GATT characteristic value changed: " |
| 996 << characteristic->GetIdentifier(); | 996 << characteristic->GetIdentifier(); |
| 997 | 997 |
| 998 BluetoothGattService* service = characteristic->GetService(); | 998 BluetoothGattService* service = characteristic->GetService(); |
| 999 DCHECK(service); | 999 DCHECK(service); |
| 1000 | 1000 |
| 1001 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != | 1001 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != |
| 1002 service_id_to_device_address_.end()); | 1002 service_id_to_device_address_.end()); |
| 1003 DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) != | 1003 DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) != |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1017 apibtle::OnCharacteristicValueChanged::kEventName, | 1017 apibtle::OnCharacteristicValueChanged::kEventName, |
| 1018 service->GetUUID(), | 1018 service->GetUUID(), |
| 1019 characteristic->GetIdentifier(), | 1019 characteristic->GetIdentifier(), |
| 1020 args.Pass()); | 1020 args.Pass()); |
| 1021 } | 1021 } |
| 1022 | 1022 |
| 1023 void BluetoothLowEnergyEventRouter::GattDescriptorValueChanged( | 1023 void BluetoothLowEnergyEventRouter::GattDescriptorValueChanged( |
| 1024 BluetoothAdapter* adapter, | 1024 BluetoothAdapter* adapter, |
| 1025 BluetoothGattDescriptor* descriptor, | 1025 BluetoothGattDescriptor* descriptor, |
| 1026 const std::vector<uint8>& value) { | 1026 const std::vector<uint8>& value) { |
| 1027 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1027 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1028 DCHECK_EQ(adapter, adapter_.get()); | 1028 DCHECK_EQ(adapter, adapter_.get()); |
| 1029 VLOG(2) << "GATT descriptor value changed: " << descriptor->GetIdentifier(); | 1029 VLOG(2) << "GATT descriptor value changed: " << descriptor->GetIdentifier(); |
| 1030 | 1030 |
| 1031 BluetoothGattCharacteristic* characteristic = descriptor->GetCharacteristic(); | 1031 BluetoothGattCharacteristic* characteristic = descriptor->GetCharacteristic(); |
| 1032 DCHECK(characteristic); | 1032 DCHECK(characteristic); |
| 1033 | 1033 |
| 1034 DCHECK(desc_id_to_chrc_id_.find(descriptor->GetIdentifier()) != | 1034 DCHECK(desc_id_to_chrc_id_.find(descriptor->GetIdentifier()) != |
| 1035 desc_id_to_chrc_id_.end()); | 1035 desc_id_to_chrc_id_.end()); |
| 1036 DCHECK(characteristic->GetIdentifier() == | 1036 DCHECK(characteristic->GetIdentifier() == |
| 1037 desc_id_to_chrc_id_[descriptor->GetIdentifier()]); | 1037 desc_id_to_chrc_id_[descriptor->GetIdentifier()]); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1058 | 1058 |
| 1059 // Initialize instance ID mappings for all discovered GATT objects and add | 1059 // Initialize instance ID mappings for all discovered GATT objects and add |
| 1060 // observers. | 1060 // observers. |
| 1061 InitializeIdentifierMappings(); | 1061 InitializeIdentifierMappings(); |
| 1062 adapter_->AddObserver(this); | 1062 adapter_->AddObserver(this); |
| 1063 | 1063 |
| 1064 callback.Run(); | 1064 callback.Run(); |
| 1065 } | 1065 } |
| 1066 | 1066 |
| 1067 void BluetoothLowEnergyEventRouter::InitializeIdentifierMappings() { | 1067 void BluetoothLowEnergyEventRouter::InitializeIdentifierMappings() { |
| 1068 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1068 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1069 DCHECK(service_id_to_device_address_.empty()); | 1069 DCHECK(service_id_to_device_address_.empty()); |
| 1070 DCHECK(chrc_id_to_service_id_.empty()); | 1070 DCHECK(chrc_id_to_service_id_.empty()); |
| 1071 | 1071 |
| 1072 // Devices | 1072 // Devices |
| 1073 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 1073 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 1074 for (BluetoothAdapter::DeviceList::iterator iter = devices.begin(); | 1074 for (BluetoothAdapter::DeviceList::iterator iter = devices.begin(); |
| 1075 iter != devices.end(); | 1075 iter != devices.end(); |
| 1076 ++iter) { | 1076 ++iter) { |
| 1077 BluetoothDevice* device = *iter; | 1077 BluetoothDevice* device = *iter; |
| 1078 | 1078 |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1488 continue; | 1488 continue; |
| 1489 | 1489 |
| 1490 manager->Remove(extension_id, *iter); | 1490 manager->Remove(extension_id, *iter); |
| 1491 return true; | 1491 return true; |
| 1492 } | 1492 } |
| 1493 | 1493 |
| 1494 return false; | 1494 return false; |
| 1495 } | 1495 } |
| 1496 | 1496 |
| 1497 } // namespace extensions | 1497 } // namespace extensions |
| OLD | NEW |