| 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_api.h
" | 5 #include "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_api.h
" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 // The adapter must be initialized at this point, but return an error instead | 149 // The adapter must be initialized at this point, but return an error instead |
| 150 // of asserting. | 150 // of asserting. |
| 151 if (!event_router->HasAdapter()) { | 151 if (!event_router->HasAdapter()) { |
| 152 SetError(kErrorAdapterNotInitialized); | 152 SetError(kErrorAdapterNotInitialized); |
| 153 SendResponse(false); | 153 SendResponse(false); |
| 154 return false; | 154 return false; |
| 155 } | 155 } |
| 156 | 156 |
| 157 scoped_ptr<apibtle::Connect::Params> params( | 157 scoped_ptr<apibtle::Connect::Params> params( |
| 158 apibtle::Connect::Params::Create(*args_)); | 158 apibtle::Connect::Params::Create(*args_)); |
| 159 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 159 EXTENSION_FUNCTION_VALIDATE(params.get() != nullptr); |
| 160 | 160 |
| 161 bool persistent = false; // Not persistent by default. | 161 bool persistent = false; // Not persistent by default. |
| 162 apibtle::ConnectProperties* properties = params.get()->properties.get(); | 162 apibtle::ConnectProperties* properties = params.get()->properties.get(); |
| 163 if (properties) | 163 if (properties) |
| 164 persistent = properties->persistent; | 164 persistent = properties->persistent; |
| 165 | 165 |
| 166 event_router->Connect( | 166 event_router->Connect( |
| 167 persistent, | 167 persistent, |
| 168 extension(), | 168 extension(), |
| 169 params->device_address, | 169 params->device_address, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 192 // The adapter must be initialized at this point, but return an error instead | 192 // The adapter must be initialized at this point, but return an error instead |
| 193 // of asserting. | 193 // of asserting. |
| 194 if (!event_router->HasAdapter()) { | 194 if (!event_router->HasAdapter()) { |
| 195 SetError(kErrorAdapterNotInitialized); | 195 SetError(kErrorAdapterNotInitialized); |
| 196 SendResponse(false); | 196 SendResponse(false); |
| 197 return false; | 197 return false; |
| 198 } | 198 } |
| 199 | 199 |
| 200 scoped_ptr<apibtle::Disconnect::Params> params( | 200 scoped_ptr<apibtle::Disconnect::Params> params( |
| 201 apibtle::Disconnect::Params::Create(*args_)); | 201 apibtle::Disconnect::Params::Create(*args_)); |
| 202 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 202 EXTENSION_FUNCTION_VALIDATE(params.get() != nullptr); |
| 203 | 203 |
| 204 event_router->Disconnect( | 204 event_router->Disconnect( |
| 205 extension(), | 205 extension(), |
| 206 params->device_address, | 206 params->device_address, |
| 207 base::Bind(&BluetoothLowEnergyDisconnectFunction::SuccessCallback, this), | 207 base::Bind(&BluetoothLowEnergyDisconnectFunction::SuccessCallback, this), |
| 208 base::Bind(&BluetoothLowEnergyDisconnectFunction::ErrorCallback, this)); | 208 base::Bind(&BluetoothLowEnergyDisconnectFunction::ErrorCallback, this)); |
| 209 | 209 |
| 210 return true; | 210 return true; |
| 211 } | 211 } |
| 212 | 212 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 229 // The adapter must be initialized at this point, but return an error instead | 229 // The adapter must be initialized at this point, but return an error instead |
| 230 // of asserting. | 230 // of asserting. |
| 231 if (!event_router->HasAdapter()) { | 231 if (!event_router->HasAdapter()) { |
| 232 SetError(kErrorAdapterNotInitialized); | 232 SetError(kErrorAdapterNotInitialized); |
| 233 SendResponse(false); | 233 SendResponse(false); |
| 234 return false; | 234 return false; |
| 235 } | 235 } |
| 236 | 236 |
| 237 scoped_ptr<apibtle::GetService::Params> params( | 237 scoped_ptr<apibtle::GetService::Params> params( |
| 238 apibtle::GetService::Params::Create(*args_)); | 238 apibtle::GetService::Params::Create(*args_)); |
| 239 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 239 EXTENSION_FUNCTION_VALIDATE(params.get() != nullptr); |
| 240 | 240 |
| 241 apibtle::Service service; | 241 apibtle::Service service; |
| 242 BluetoothLowEnergyEventRouter::Status status = | 242 BluetoothLowEnergyEventRouter::Status status = |
| 243 event_router->GetService(params->service_id, &service); | 243 event_router->GetService(params->service_id, &service); |
| 244 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { | 244 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { |
| 245 SetError(StatusToString(status)); | 245 SetError(StatusToString(status)); |
| 246 SendResponse(false); | 246 SendResponse(false); |
| 247 return false; | 247 return false; |
| 248 } | 248 } |
| 249 | 249 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 262 // The adapter must be initialized at this point, but return an error instead | 262 // The adapter must be initialized at this point, but return an error instead |
| 263 // of asserting. | 263 // of asserting. |
| 264 if (!event_router->HasAdapter()) { | 264 if (!event_router->HasAdapter()) { |
| 265 SetError(kErrorAdapterNotInitialized); | 265 SetError(kErrorAdapterNotInitialized); |
| 266 SendResponse(false); | 266 SendResponse(false); |
| 267 return false; | 267 return false; |
| 268 } | 268 } |
| 269 | 269 |
| 270 scoped_ptr<apibtle::GetServices::Params> params( | 270 scoped_ptr<apibtle::GetServices::Params> params( |
| 271 apibtle::GetServices::Params::Create(*args_)); | 271 apibtle::GetServices::Params::Create(*args_)); |
| 272 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 272 EXTENSION_FUNCTION_VALIDATE(params.get() != nullptr); |
| 273 | 273 |
| 274 BluetoothLowEnergyEventRouter::ServiceList service_list; | 274 BluetoothLowEnergyEventRouter::ServiceList service_list; |
| 275 if (!event_router->GetServices(params->device_address, &service_list)) { | 275 if (!event_router->GetServices(params->device_address, &service_list)) { |
| 276 SetError(kErrorNotFound); | 276 SetError(kErrorNotFound); |
| 277 SendResponse(false); | 277 SendResponse(false); |
| 278 return false; | 278 return false; |
| 279 } | 279 } |
| 280 | 280 |
| 281 results_ = apibtle::GetServices::Results::Create(service_list); | 281 results_ = apibtle::GetServices::Results::Create(service_list); |
| 282 SendResponse(true); | 282 SendResponse(true); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 293 // The adapter must be initialized at this point, but return an error instead | 293 // The adapter must be initialized at this point, but return an error instead |
| 294 // of asserting. | 294 // of asserting. |
| 295 if (!event_router->HasAdapter()) { | 295 if (!event_router->HasAdapter()) { |
| 296 SetError(kErrorAdapterNotInitialized); | 296 SetError(kErrorAdapterNotInitialized); |
| 297 SendResponse(false); | 297 SendResponse(false); |
| 298 return false; | 298 return false; |
| 299 } | 299 } |
| 300 | 300 |
| 301 scoped_ptr<apibtle::GetCharacteristic::Params> params( | 301 scoped_ptr<apibtle::GetCharacteristic::Params> params( |
| 302 apibtle::GetCharacteristic::Params::Create(*args_)); | 302 apibtle::GetCharacteristic::Params::Create(*args_)); |
| 303 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 303 EXTENSION_FUNCTION_VALIDATE(params.get() != nullptr); |
| 304 | 304 |
| 305 apibtle::Characteristic characteristic; | 305 apibtle::Characteristic characteristic; |
| 306 BluetoothLowEnergyEventRouter::Status status = | 306 BluetoothLowEnergyEventRouter::Status status = |
| 307 event_router->GetCharacteristic( | 307 event_router->GetCharacteristic( |
| 308 extension(), params->characteristic_id, &characteristic); | 308 extension(), params->characteristic_id, &characteristic); |
| 309 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { | 309 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { |
| 310 SetError(StatusToString(status)); | 310 SetError(StatusToString(status)); |
| 311 SendResponse(false); | 311 SendResponse(false); |
| 312 return false; | 312 return false; |
| 313 } | 313 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 330 // The adapter must be initialized at this point, but return an error instead | 330 // The adapter must be initialized at this point, but return an error instead |
| 331 // of asserting. | 331 // of asserting. |
| 332 if (!event_router->HasAdapter()) { | 332 if (!event_router->HasAdapter()) { |
| 333 SetError(kErrorAdapterNotInitialized); | 333 SetError(kErrorAdapterNotInitialized); |
| 334 SendResponse(false); | 334 SendResponse(false); |
| 335 return false; | 335 return false; |
| 336 } | 336 } |
| 337 | 337 |
| 338 scoped_ptr<apibtle::GetCharacteristics::Params> params( | 338 scoped_ptr<apibtle::GetCharacteristics::Params> params( |
| 339 apibtle::GetCharacteristics::Params::Create(*args_)); | 339 apibtle::GetCharacteristics::Params::Create(*args_)); |
| 340 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 340 EXTENSION_FUNCTION_VALIDATE(params.get() != nullptr); |
| 341 | 341 |
| 342 BluetoothLowEnergyEventRouter::CharacteristicList characteristic_list; | 342 BluetoothLowEnergyEventRouter::CharacteristicList characteristic_list; |
| 343 BluetoothLowEnergyEventRouter::Status status = | 343 BluetoothLowEnergyEventRouter::Status status = |
| 344 event_router->GetCharacteristics( | 344 event_router->GetCharacteristics( |
| 345 extension(), params->service_id, &characteristic_list); | 345 extension(), params->service_id, &characteristic_list); |
| 346 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { | 346 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { |
| 347 SetError(StatusToString(status)); | 347 SetError(StatusToString(status)); |
| 348 SendResponse(false); | 348 SendResponse(false); |
| 349 return false; | 349 return false; |
| 350 } | 350 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 374 // The adapter must be initialized at this point, but return an error instead | 374 // The adapter must be initialized at this point, but return an error instead |
| 375 // of asserting. | 375 // of asserting. |
| 376 if (!event_router->HasAdapter()) { | 376 if (!event_router->HasAdapter()) { |
| 377 SetError(kErrorAdapterNotInitialized); | 377 SetError(kErrorAdapterNotInitialized); |
| 378 SendResponse(false); | 378 SendResponse(false); |
| 379 return false; | 379 return false; |
| 380 } | 380 } |
| 381 | 381 |
| 382 scoped_ptr<apibtle::GetIncludedServices::Params> params( | 382 scoped_ptr<apibtle::GetIncludedServices::Params> params( |
| 383 apibtle::GetIncludedServices::Params::Create(*args_)); | 383 apibtle::GetIncludedServices::Params::Create(*args_)); |
| 384 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 384 EXTENSION_FUNCTION_VALIDATE(params.get() != nullptr); |
| 385 | 385 |
| 386 BluetoothLowEnergyEventRouter::ServiceList service_list; | 386 BluetoothLowEnergyEventRouter::ServiceList service_list; |
| 387 BluetoothLowEnergyEventRouter::Status status = | 387 BluetoothLowEnergyEventRouter::Status status = |
| 388 event_router->GetIncludedServices(params->service_id, &service_list); | 388 event_router->GetIncludedServices(params->service_id, &service_list); |
| 389 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { | 389 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { |
| 390 SetError(StatusToString(status)); | 390 SetError(StatusToString(status)); |
| 391 SendResponse(false); | 391 SendResponse(false); |
| 392 return false; | 392 return false; |
| 393 } | 393 } |
| 394 | 394 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 407 // The adapter must be initialized at this point, but return an error instead | 407 // The adapter must be initialized at this point, but return an error instead |
| 408 // of asserting. | 408 // of asserting. |
| 409 if (!event_router->HasAdapter()) { | 409 if (!event_router->HasAdapter()) { |
| 410 SetError(kErrorAdapterNotInitialized); | 410 SetError(kErrorAdapterNotInitialized); |
| 411 SendResponse(false); | 411 SendResponse(false); |
| 412 return false; | 412 return false; |
| 413 } | 413 } |
| 414 | 414 |
| 415 scoped_ptr<apibtle::GetDescriptor::Params> params( | 415 scoped_ptr<apibtle::GetDescriptor::Params> params( |
| 416 apibtle::GetDescriptor::Params::Create(*args_)); | 416 apibtle::GetDescriptor::Params::Create(*args_)); |
| 417 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 417 EXTENSION_FUNCTION_VALIDATE(params.get() != nullptr); |
| 418 | 418 |
| 419 apibtle::Descriptor descriptor; | 419 apibtle::Descriptor descriptor; |
| 420 BluetoothLowEnergyEventRouter::Status status = event_router->GetDescriptor( | 420 BluetoothLowEnergyEventRouter::Status status = event_router->GetDescriptor( |
| 421 extension(), params->descriptor_id, &descriptor); | 421 extension(), params->descriptor_id, &descriptor); |
| 422 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { | 422 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { |
| 423 SetError(StatusToString(status)); | 423 SetError(StatusToString(status)); |
| 424 SendResponse(false); | 424 SendResponse(false); |
| 425 return false; | 425 return false; |
| 426 } | 426 } |
| 427 | 427 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 443 // The adapter must be initialized at this point, but return an error instead | 443 // The adapter must be initialized at this point, but return an error instead |
| 444 // of asserting. | 444 // of asserting. |
| 445 if (!event_router->HasAdapter()) { | 445 if (!event_router->HasAdapter()) { |
| 446 SetError(kErrorAdapterNotInitialized); | 446 SetError(kErrorAdapterNotInitialized); |
| 447 SendResponse(false); | 447 SendResponse(false); |
| 448 return false; | 448 return false; |
| 449 } | 449 } |
| 450 | 450 |
| 451 scoped_ptr<apibtle::GetDescriptors::Params> params( | 451 scoped_ptr<apibtle::GetDescriptors::Params> params( |
| 452 apibtle::GetDescriptors::Params::Create(*args_)); | 452 apibtle::GetDescriptors::Params::Create(*args_)); |
| 453 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 453 EXTENSION_FUNCTION_VALIDATE(params.get() != nullptr); |
| 454 | 454 |
| 455 BluetoothLowEnergyEventRouter::DescriptorList descriptor_list; | 455 BluetoothLowEnergyEventRouter::DescriptorList descriptor_list; |
| 456 BluetoothLowEnergyEventRouter::Status status = event_router->GetDescriptors( | 456 BluetoothLowEnergyEventRouter::Status status = event_router->GetDescriptors( |
| 457 extension(), params->characteristic_id, &descriptor_list); | 457 extension(), params->characteristic_id, &descriptor_list); |
| 458 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { | 458 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { |
| 459 SetError(StatusToString(status)); | 459 SetError(StatusToString(status)); |
| 460 SendResponse(false); | 460 SendResponse(false); |
| 461 return false; | 461 return false; |
| 462 } | 462 } |
| 463 | 463 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 486 // The adapter must be initialized at this point, but return an error instead | 486 // The adapter must be initialized at this point, but return an error instead |
| 487 // of asserting. | 487 // of asserting. |
| 488 if (!event_router->HasAdapter()) { | 488 if (!event_router->HasAdapter()) { |
| 489 SetError(kErrorAdapterNotInitialized); | 489 SetError(kErrorAdapterNotInitialized); |
| 490 SendResponse(false); | 490 SendResponse(false); |
| 491 return false; | 491 return false; |
| 492 } | 492 } |
| 493 | 493 |
| 494 scoped_ptr<apibtle::ReadCharacteristicValue::Params> params( | 494 scoped_ptr<apibtle::ReadCharacteristicValue::Params> params( |
| 495 apibtle::ReadCharacteristicValue::Params::Create(*args_)); | 495 apibtle::ReadCharacteristicValue::Params::Create(*args_)); |
| 496 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 496 EXTENSION_FUNCTION_VALIDATE(params.get() != nullptr); |
| 497 | 497 |
| 498 instance_id_ = params->characteristic_id; | 498 instance_id_ = params->characteristic_id; |
| 499 event_router->ReadCharacteristicValue( | 499 event_router->ReadCharacteristicValue( |
| 500 extension(), | 500 extension(), |
| 501 instance_id_, | 501 instance_id_, |
| 502 base::Bind( | 502 base::Bind( |
| 503 &BluetoothLowEnergyReadCharacteristicValueFunction::SuccessCallback, | 503 &BluetoothLowEnergyReadCharacteristicValueFunction::SuccessCallback, |
| 504 this), | 504 this), |
| 505 base::Bind( | 505 base::Bind( |
| 506 &BluetoothLowEnergyReadCharacteristicValueFunction::ErrorCallback, | 506 &BluetoothLowEnergyReadCharacteristicValueFunction::ErrorCallback, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 // The adapter must be initialized at this point, but return an error instead | 544 // The adapter must be initialized at this point, but return an error instead |
| 545 // of asserting. | 545 // of asserting. |
| 546 if (!event_router->HasAdapter()) { | 546 if (!event_router->HasAdapter()) { |
| 547 SetError(kErrorAdapterNotInitialized); | 547 SetError(kErrorAdapterNotInitialized); |
| 548 SendResponse(false); | 548 SendResponse(false); |
| 549 return false; | 549 return false; |
| 550 } | 550 } |
| 551 | 551 |
| 552 scoped_ptr<apibtle::WriteCharacteristicValue::Params> params( | 552 scoped_ptr<apibtle::WriteCharacteristicValue::Params> params( |
| 553 apibtle::WriteCharacteristicValue::Params::Create(*args_)); | 553 apibtle::WriteCharacteristicValue::Params::Create(*args_)); |
| 554 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 554 EXTENSION_FUNCTION_VALIDATE(params.get() != nullptr); |
| 555 | 555 |
| 556 std::vector<uint8> value(params->value.begin(), params->value.end()); | 556 std::vector<uint8> value(params->value.begin(), params->value.end()); |
| 557 event_router->WriteCharacteristicValue( | 557 event_router->WriteCharacteristicValue( |
| 558 extension(), | 558 extension(), |
| 559 params->characteristic_id, | 559 params->characteristic_id, |
| 560 value, | 560 value, |
| 561 base::Bind( | 561 base::Bind( |
| 562 &BluetoothLowEnergyWriteCharacteristicValueFunction::SuccessCallback, | 562 &BluetoothLowEnergyWriteCharacteristicValueFunction::SuccessCallback, |
| 563 this), | 563 this), |
| 564 base::Bind( | 564 base::Bind( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 588 // The adapter must be initialized at this point, but return an error instead | 588 // The adapter must be initialized at this point, but return an error instead |
| 589 // of asserting. | 589 // of asserting. |
| 590 if (!event_router->HasAdapter()) { | 590 if (!event_router->HasAdapter()) { |
| 591 SetError(kErrorAdapterNotInitialized); | 591 SetError(kErrorAdapterNotInitialized); |
| 592 SendResponse(false); | 592 SendResponse(false); |
| 593 return false; | 593 return false; |
| 594 } | 594 } |
| 595 | 595 |
| 596 scoped_ptr<apibtle::StartCharacteristicNotifications::Params> params( | 596 scoped_ptr<apibtle::StartCharacteristicNotifications::Params> params( |
| 597 apibtle::StartCharacteristicNotifications::Params::Create(*args_)); | 597 apibtle::StartCharacteristicNotifications::Params::Create(*args_)); |
| 598 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 598 EXTENSION_FUNCTION_VALIDATE(params.get() != nullptr); |
| 599 | 599 |
| 600 bool persistent = false; // Not persistent by default. | 600 bool persistent = false; // Not persistent by default. |
| 601 apibtle::NotificationProperties* properties = params.get()->properties.get(); | 601 apibtle::NotificationProperties* properties = params.get()->properties.get(); |
| 602 if (properties) | 602 if (properties) |
| 603 persistent = properties->persistent; | 603 persistent = properties->persistent; |
| 604 | 604 |
| 605 event_router->StartCharacteristicNotifications( | 605 event_router->StartCharacteristicNotifications( |
| 606 persistent, | 606 persistent, |
| 607 extension(), | 607 extension(), |
| 608 params->characteristic_id, | 608 params->characteristic_id, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 636 // The adapter must be initialized at this point, but return an error instead | 636 // The adapter must be initialized at this point, but return an error instead |
| 637 // of asserting. | 637 // of asserting. |
| 638 if (!event_router->HasAdapter()) { | 638 if (!event_router->HasAdapter()) { |
| 639 SetError(kErrorAdapterNotInitialized); | 639 SetError(kErrorAdapterNotInitialized); |
| 640 SendResponse(false); | 640 SendResponse(false); |
| 641 return false; | 641 return false; |
| 642 } | 642 } |
| 643 | 643 |
| 644 scoped_ptr<apibtle::StopCharacteristicNotifications::Params> params( | 644 scoped_ptr<apibtle::StopCharacteristicNotifications::Params> params( |
| 645 apibtle::StopCharacteristicNotifications::Params::Create(*args_)); | 645 apibtle::StopCharacteristicNotifications::Params::Create(*args_)); |
| 646 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 646 EXTENSION_FUNCTION_VALIDATE(params.get() != nullptr); |
| 647 | 647 |
| 648 event_router->StopCharacteristicNotifications( | 648 event_router->StopCharacteristicNotifications( |
| 649 extension(), | 649 extension(), |
| 650 params->characteristic_id, | 650 params->characteristic_id, |
| 651 base::Bind(&BluetoothLowEnergyStopCharacteristicNotificationsFunction:: | 651 base::Bind(&BluetoothLowEnergyStopCharacteristicNotificationsFunction:: |
| 652 SuccessCallback, | 652 SuccessCallback, |
| 653 this), | 653 this), |
| 654 base::Bind(&BluetoothLowEnergyStopCharacteristicNotificationsFunction:: | 654 base::Bind(&BluetoothLowEnergyStopCharacteristicNotificationsFunction:: |
| 655 ErrorCallback, | 655 ErrorCallback, |
| 656 this)); | 656 this)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 678 // The adapter must be initialized at this point, but return an error instead | 678 // The adapter must be initialized at this point, but return an error instead |
| 679 // of asserting. | 679 // of asserting. |
| 680 if (!event_router->HasAdapter()) { | 680 if (!event_router->HasAdapter()) { |
| 681 SetError(kErrorAdapterNotInitialized); | 681 SetError(kErrorAdapterNotInitialized); |
| 682 SendResponse(false); | 682 SendResponse(false); |
| 683 return false; | 683 return false; |
| 684 } | 684 } |
| 685 | 685 |
| 686 scoped_ptr<apibtle::ReadDescriptorValue::Params> params( | 686 scoped_ptr<apibtle::ReadDescriptorValue::Params> params( |
| 687 apibtle::ReadDescriptorValue::Params::Create(*args_)); | 687 apibtle::ReadDescriptorValue::Params::Create(*args_)); |
| 688 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 688 EXTENSION_FUNCTION_VALIDATE(params.get() != nullptr); |
| 689 | 689 |
| 690 instance_id_ = params->descriptor_id; | 690 instance_id_ = params->descriptor_id; |
| 691 event_router->ReadDescriptorValue( | 691 event_router->ReadDescriptorValue( |
| 692 extension(), | 692 extension(), |
| 693 instance_id_, | 693 instance_id_, |
| 694 base::Bind( | 694 base::Bind( |
| 695 &BluetoothLowEnergyReadDescriptorValueFunction::SuccessCallback, | 695 &BluetoothLowEnergyReadDescriptorValueFunction::SuccessCallback, |
| 696 this), | 696 this), |
| 697 base::Bind(&BluetoothLowEnergyReadDescriptorValueFunction::ErrorCallback, | 697 base::Bind(&BluetoothLowEnergyReadDescriptorValueFunction::ErrorCallback, |
| 698 this)); | 698 this)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 // The adapter must be initialized at this point, but return an error instead | 735 // The adapter must be initialized at this point, but return an error instead |
| 736 // of asserting. | 736 // of asserting. |
| 737 if (!event_router->HasAdapter()) { | 737 if (!event_router->HasAdapter()) { |
| 738 SetError(kErrorAdapterNotInitialized); | 738 SetError(kErrorAdapterNotInitialized); |
| 739 SendResponse(false); | 739 SendResponse(false); |
| 740 return false; | 740 return false; |
| 741 } | 741 } |
| 742 | 742 |
| 743 scoped_ptr<apibtle::WriteDescriptorValue::Params> params( | 743 scoped_ptr<apibtle::WriteDescriptorValue::Params> params( |
| 744 apibtle::WriteDescriptorValue::Params::Create(*args_)); | 744 apibtle::WriteDescriptorValue::Params::Create(*args_)); |
| 745 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 745 EXTENSION_FUNCTION_VALIDATE(params.get() != nullptr); |
| 746 | 746 |
| 747 std::vector<uint8> value(params->value.begin(), params->value.end()); | 747 std::vector<uint8> value(params->value.begin(), params->value.end()); |
| 748 event_router->WriteDescriptorValue( | 748 event_router->WriteDescriptorValue( |
| 749 extension(), | 749 extension(), |
| 750 params->descriptor_id, | 750 params->descriptor_id, |
| 751 value, | 751 value, |
| 752 base::Bind( | 752 base::Bind( |
| 753 &BluetoothLowEnergyWriteDescriptorValueFunction::SuccessCallback, | 753 &BluetoothLowEnergyWriteDescriptorValueFunction::SuccessCallback, |
| 754 this), | 754 this), |
| 755 base::Bind(&BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback, | 755 base::Bind(&BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback, |
| 756 this)); | 756 this)); |
| 757 | 757 |
| 758 return true; | 758 return true; |
| 759 } | 759 } |
| 760 | 760 |
| 761 void BluetoothLowEnergyWriteDescriptorValueFunction::SuccessCallback() { | 761 void BluetoothLowEnergyWriteDescriptorValueFunction::SuccessCallback() { |
| 762 results_ = apibtle::WriteDescriptorValue::Results::Create(); | 762 results_ = apibtle::WriteDescriptorValue::Results::Create(); |
| 763 SendResponse(true); | 763 SendResponse(true); |
| 764 } | 764 } |
| 765 | 765 |
| 766 void BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback( | 766 void BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback( |
| 767 BluetoothLowEnergyEventRouter::Status status) { | 767 BluetoothLowEnergyEventRouter::Status status) { |
| 768 SetError(StatusToString(status)); | 768 SetError(StatusToString(status)); |
| 769 SendResponse(false); | 769 SendResponse(false); |
| 770 } | 770 } |
| 771 | 771 |
| 772 } // namespace core_api | 772 } // namespace core_api |
| 773 } // namespace extensions | 773 } // namespace extensions |
| OLD | NEW |