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_api.h" | 5 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_api.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 BrowserContext* context) { | 125 BrowserContext* context) { |
126 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 126 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
127 return extensions::BluetoothLowEnergyAPI::Get(context)->event_router(); | 127 return extensions::BluetoothLowEnergyAPI::Get(context)->event_router(); |
128 } | 128 } |
129 | 129 |
130 void DoWorkCallback(const base::Callback<bool()>& callback) { | 130 void DoWorkCallback(const base::Callback<bool()>& callback) { |
131 DCHECK(!callback.is_null()); | 131 DCHECK(!callback.is_null()); |
132 callback.Run(); | 132 callback.Run(); |
133 } | 133 } |
134 | 134 |
135 scoped_ptr<device::BluetoothAdvertisement::ManufacturerData> | 135 std::unique_ptr<device::BluetoothAdvertisement::ManufacturerData> |
136 CreateManufacturerData( | 136 CreateManufacturerData( |
137 std::vector<apibtle::ManufacturerData>* manufacturer_data) { | 137 std::vector<apibtle::ManufacturerData>* manufacturer_data) { |
138 scoped_ptr<device::BluetoothAdvertisement::ManufacturerData> created_data( | 138 std::unique_ptr<device::BluetoothAdvertisement::ManufacturerData> |
139 new device::BluetoothAdvertisement::ManufacturerData()); | 139 created_data(new device::BluetoothAdvertisement::ManufacturerData()); |
140 for (const auto& it : *manufacturer_data) { | 140 for (const auto& it : *manufacturer_data) { |
141 std::vector<uint8_t> data(it.data.size()); | 141 std::vector<uint8_t> data(it.data.size()); |
142 std::copy(it.data.begin(), it.data.end(), data.begin()); | 142 std::copy(it.data.begin(), it.data.end(), data.begin()); |
143 (*created_data)[it.id] = data; | 143 (*created_data)[it.id] = data; |
144 } | 144 } |
145 return created_data; | 145 return created_data; |
146 } | 146 } |
147 | 147 |
148 scoped_ptr<device::BluetoothAdvertisement::ServiceData> CreateServiceData( | 148 std::unique_ptr<device::BluetoothAdvertisement::ServiceData> CreateServiceData( |
149 std::vector<apibtle::ServiceData>* service_data) { | 149 std::vector<apibtle::ServiceData>* service_data) { |
150 scoped_ptr<device::BluetoothAdvertisement::ServiceData> created_data( | 150 std::unique_ptr<device::BluetoothAdvertisement::ServiceData> created_data( |
151 new device::BluetoothAdvertisement::ServiceData()); | 151 new device::BluetoothAdvertisement::ServiceData()); |
152 for (const auto& it : *service_data) { | 152 for (const auto& it : *service_data) { |
153 std::vector<uint8_t> data(it.data.size()); | 153 std::vector<uint8_t> data(it.data.size()); |
154 std::copy(it.data.begin(), it.data.end(), data.begin()); | 154 std::copy(it.data.begin(), it.data.end(), data.begin()); |
155 (*created_data)[it.uuid] = data; | 155 (*created_data)[it.uuid] = data; |
156 } | 156 } |
157 return created_data; | 157 return created_data; |
158 } | 158 } |
159 | 159 |
160 } // namespace | 160 } // namespace |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 GetEventRouter(browser_context()); | 228 GetEventRouter(browser_context()); |
229 | 229 |
230 // The adapter must be initialized at this point, but return an error instead | 230 // The adapter must be initialized at this point, but return an error instead |
231 // of asserting. | 231 // of asserting. |
232 if (!event_router->HasAdapter()) { | 232 if (!event_router->HasAdapter()) { |
233 SetError(kErrorAdapterNotInitialized); | 233 SetError(kErrorAdapterNotInitialized); |
234 SendResponse(false); | 234 SendResponse(false); |
235 return false; | 235 return false; |
236 } | 236 } |
237 | 237 |
238 scoped_ptr<apibtle::Connect::Params> params( | 238 std::unique_ptr<apibtle::Connect::Params> params( |
239 apibtle::Connect::Params::Create(*args_)); | 239 apibtle::Connect::Params::Create(*args_)); |
240 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 240 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
241 | 241 |
242 bool persistent = false; // Not persistent by default. | 242 bool persistent = false; // Not persistent by default. |
243 apibtle::ConnectProperties* properties = params.get()->properties.get(); | 243 apibtle::ConnectProperties* properties = params.get()->properties.get(); |
244 if (properties) | 244 if (properties) |
245 persistent = properties->persistent; | 245 persistent = properties->persistent; |
246 | 246 |
247 event_router->Connect( | 247 event_router->Connect( |
248 persistent, | 248 persistent, |
(...skipping 22 matching lines...) Expand all Loading... |
271 GetEventRouter(browser_context()); | 271 GetEventRouter(browser_context()); |
272 | 272 |
273 // The adapter must be initialized at this point, but return an error instead | 273 // The adapter must be initialized at this point, but return an error instead |
274 // of asserting. | 274 // of asserting. |
275 if (!event_router->HasAdapter()) { | 275 if (!event_router->HasAdapter()) { |
276 SetError(kErrorAdapterNotInitialized); | 276 SetError(kErrorAdapterNotInitialized); |
277 SendResponse(false); | 277 SendResponse(false); |
278 return false; | 278 return false; |
279 } | 279 } |
280 | 280 |
281 scoped_ptr<apibtle::Disconnect::Params> params( | 281 std::unique_ptr<apibtle::Disconnect::Params> params( |
282 apibtle::Disconnect::Params::Create(*args_)); | 282 apibtle::Disconnect::Params::Create(*args_)); |
283 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 283 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
284 | 284 |
285 event_router->Disconnect( | 285 event_router->Disconnect( |
286 extension(), | 286 extension(), |
287 params->device_address, | 287 params->device_address, |
288 base::Bind(&BluetoothLowEnergyDisconnectFunction::SuccessCallback, this), | 288 base::Bind(&BluetoothLowEnergyDisconnectFunction::SuccessCallback, this), |
289 base::Bind(&BluetoothLowEnergyDisconnectFunction::ErrorCallback, this)); | 289 base::Bind(&BluetoothLowEnergyDisconnectFunction::ErrorCallback, this)); |
290 | 290 |
291 return true; | 291 return true; |
(...skipping 16 matching lines...) Expand all Loading... |
308 GetEventRouter(browser_context()); | 308 GetEventRouter(browser_context()); |
309 | 309 |
310 // The adapter must be initialized at this point, but return an error instead | 310 // The adapter must be initialized at this point, but return an error instead |
311 // of asserting. | 311 // of asserting. |
312 if (!event_router->HasAdapter()) { | 312 if (!event_router->HasAdapter()) { |
313 SetError(kErrorAdapterNotInitialized); | 313 SetError(kErrorAdapterNotInitialized); |
314 SendResponse(false); | 314 SendResponse(false); |
315 return false; | 315 return false; |
316 } | 316 } |
317 | 317 |
318 scoped_ptr<apibtle::GetService::Params> params( | 318 std::unique_ptr<apibtle::GetService::Params> params( |
319 apibtle::GetService::Params::Create(*args_)); | 319 apibtle::GetService::Params::Create(*args_)); |
320 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 320 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
321 | 321 |
322 apibtle::Service service; | 322 apibtle::Service service; |
323 BluetoothLowEnergyEventRouter::Status status = | 323 BluetoothLowEnergyEventRouter::Status status = |
324 event_router->GetService(params->service_id, &service); | 324 event_router->GetService(params->service_id, &service); |
325 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { | 325 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { |
326 SetError(StatusToString(status)); | 326 SetError(StatusToString(status)); |
327 SendResponse(false); | 327 SendResponse(false); |
328 return false; | 328 return false; |
(...skipping 12 matching lines...) Expand all Loading... |
341 GetEventRouter(browser_context()); | 341 GetEventRouter(browser_context()); |
342 | 342 |
343 // The adapter must be initialized at this point, but return an error instead | 343 // The adapter must be initialized at this point, but return an error instead |
344 // of asserting. | 344 // of asserting. |
345 if (!event_router->HasAdapter()) { | 345 if (!event_router->HasAdapter()) { |
346 SetError(kErrorAdapterNotInitialized); | 346 SetError(kErrorAdapterNotInitialized); |
347 SendResponse(false); | 347 SendResponse(false); |
348 return false; | 348 return false; |
349 } | 349 } |
350 | 350 |
351 scoped_ptr<apibtle::GetServices::Params> params( | 351 std::unique_ptr<apibtle::GetServices::Params> params( |
352 apibtle::GetServices::Params::Create(*args_)); | 352 apibtle::GetServices::Params::Create(*args_)); |
353 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 353 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
354 | 354 |
355 BluetoothLowEnergyEventRouter::ServiceList service_list; | 355 BluetoothLowEnergyEventRouter::ServiceList service_list; |
356 if (!event_router->GetServices(params->device_address, &service_list)) { | 356 if (!event_router->GetServices(params->device_address, &service_list)) { |
357 SetError(kErrorNotFound); | 357 SetError(kErrorNotFound); |
358 SendResponse(false); | 358 SendResponse(false); |
359 return false; | 359 return false; |
360 } | 360 } |
361 | 361 |
(...skipping 10 matching lines...) Expand all Loading... |
372 GetEventRouter(browser_context()); | 372 GetEventRouter(browser_context()); |
373 | 373 |
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::GetCharacteristic::Params> params( | 382 std::unique_ptr<apibtle::GetCharacteristic::Params> params( |
383 apibtle::GetCharacteristic::Params::Create(*args_)); | 383 apibtle::GetCharacteristic::Params::Create(*args_)); |
384 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 384 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
385 | 385 |
386 apibtle::Characteristic characteristic; | 386 apibtle::Characteristic characteristic; |
387 BluetoothLowEnergyEventRouter::Status status = | 387 BluetoothLowEnergyEventRouter::Status status = |
388 event_router->GetCharacteristic( | 388 event_router->GetCharacteristic( |
389 extension(), params->characteristic_id, &characteristic); | 389 extension(), params->characteristic_id, &characteristic); |
390 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { | 390 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { |
391 SetError(StatusToString(status)); | 391 SetError(StatusToString(status)); |
392 SendResponse(false); | 392 SendResponse(false); |
(...skipping 16 matching lines...) Expand all Loading... |
409 GetEventRouter(browser_context()); | 409 GetEventRouter(browser_context()); |
410 | 410 |
411 // The adapter must be initialized at this point, but return an error instead | 411 // The adapter must be initialized at this point, but return an error instead |
412 // of asserting. | 412 // of asserting. |
413 if (!event_router->HasAdapter()) { | 413 if (!event_router->HasAdapter()) { |
414 SetError(kErrorAdapterNotInitialized); | 414 SetError(kErrorAdapterNotInitialized); |
415 SendResponse(false); | 415 SendResponse(false); |
416 return false; | 416 return false; |
417 } | 417 } |
418 | 418 |
419 scoped_ptr<apibtle::GetCharacteristics::Params> params( | 419 std::unique_ptr<apibtle::GetCharacteristics::Params> params( |
420 apibtle::GetCharacteristics::Params::Create(*args_)); | 420 apibtle::GetCharacteristics::Params::Create(*args_)); |
421 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 421 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
422 | 422 |
423 BluetoothLowEnergyEventRouter::CharacteristicList characteristic_list; | 423 BluetoothLowEnergyEventRouter::CharacteristicList characteristic_list; |
424 BluetoothLowEnergyEventRouter::Status status = | 424 BluetoothLowEnergyEventRouter::Status status = |
425 event_router->GetCharacteristics( | 425 event_router->GetCharacteristics( |
426 extension(), params->service_id, &characteristic_list); | 426 extension(), params->service_id, &characteristic_list); |
427 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { | 427 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { |
428 SetError(StatusToString(status)); | 428 SetError(StatusToString(status)); |
429 SendResponse(false); | 429 SendResponse(false); |
430 return false; | 430 return false; |
431 } | 431 } |
432 | 432 |
433 // Manually construct the result instead of using | 433 // Manually construct the result instead of using |
434 // apibtle::GetCharacteristics::Result::Create as it doesn't convert lists of | 434 // apibtle::GetCharacteristics::Result::Create as it doesn't convert lists of |
435 // enums correctly. | 435 // enums correctly. |
436 scoped_ptr<base::ListValue> result(new base::ListValue()); | 436 std::unique_ptr<base::ListValue> result(new base::ListValue()); |
437 for (apibtle::Characteristic& characteristic : characteristic_list) | 437 for (apibtle::Characteristic& characteristic : characteristic_list) |
438 result->Append(apibtle::CharacteristicToValue(&characteristic)); | 438 result->Append(apibtle::CharacteristicToValue(&characteristic)); |
439 | 439 |
440 SetResult(result.release()); | 440 SetResult(result.release()); |
441 SendResponse(true); | 441 SendResponse(true); |
442 | 442 |
443 return true; | 443 return true; |
444 } | 444 } |
445 | 445 |
446 bool BluetoothLowEnergyGetIncludedServicesFunction::DoWork() { | 446 bool BluetoothLowEnergyGetIncludedServicesFunction::DoWork() { |
447 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 447 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
448 | 448 |
449 BluetoothLowEnergyEventRouter* event_router = | 449 BluetoothLowEnergyEventRouter* event_router = |
450 GetEventRouter(browser_context()); | 450 GetEventRouter(browser_context()); |
451 | 451 |
452 // The adapter must be initialized at this point, but return an error instead | 452 // The adapter must be initialized at this point, but return an error instead |
453 // of asserting. | 453 // of asserting. |
454 if (!event_router->HasAdapter()) { | 454 if (!event_router->HasAdapter()) { |
455 SetError(kErrorAdapterNotInitialized); | 455 SetError(kErrorAdapterNotInitialized); |
456 SendResponse(false); | 456 SendResponse(false); |
457 return false; | 457 return false; |
458 } | 458 } |
459 | 459 |
460 scoped_ptr<apibtle::GetIncludedServices::Params> params( | 460 std::unique_ptr<apibtle::GetIncludedServices::Params> params( |
461 apibtle::GetIncludedServices::Params::Create(*args_)); | 461 apibtle::GetIncludedServices::Params::Create(*args_)); |
462 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 462 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
463 | 463 |
464 BluetoothLowEnergyEventRouter::ServiceList service_list; | 464 BluetoothLowEnergyEventRouter::ServiceList service_list; |
465 BluetoothLowEnergyEventRouter::Status status = | 465 BluetoothLowEnergyEventRouter::Status status = |
466 event_router->GetIncludedServices(params->service_id, &service_list); | 466 event_router->GetIncludedServices(params->service_id, &service_list); |
467 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { | 467 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { |
468 SetError(StatusToString(status)); | 468 SetError(StatusToString(status)); |
469 SendResponse(false); | 469 SendResponse(false); |
470 return false; | 470 return false; |
(...skipping 12 matching lines...) Expand all Loading... |
483 GetEventRouter(browser_context()); | 483 GetEventRouter(browser_context()); |
484 | 484 |
485 // The adapter must be initialized at this point, but return an error instead | 485 // The adapter must be initialized at this point, but return an error instead |
486 // of asserting. | 486 // of asserting. |
487 if (!event_router->HasAdapter()) { | 487 if (!event_router->HasAdapter()) { |
488 SetError(kErrorAdapterNotInitialized); | 488 SetError(kErrorAdapterNotInitialized); |
489 SendResponse(false); | 489 SendResponse(false); |
490 return false; | 490 return false; |
491 } | 491 } |
492 | 492 |
493 scoped_ptr<apibtle::GetDescriptor::Params> params( | 493 std::unique_ptr<apibtle::GetDescriptor::Params> params( |
494 apibtle::GetDescriptor::Params::Create(*args_)); | 494 apibtle::GetDescriptor::Params::Create(*args_)); |
495 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 495 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
496 | 496 |
497 apibtle::Descriptor descriptor; | 497 apibtle::Descriptor descriptor; |
498 BluetoothLowEnergyEventRouter::Status status = event_router->GetDescriptor( | 498 BluetoothLowEnergyEventRouter::Status status = event_router->GetDescriptor( |
499 extension(), params->descriptor_id, &descriptor); | 499 extension(), params->descriptor_id, &descriptor); |
500 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { | 500 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { |
501 SetError(StatusToString(status)); | 501 SetError(StatusToString(status)); |
502 SendResponse(false); | 502 SendResponse(false); |
503 return false; | 503 return false; |
(...skipping 15 matching lines...) Expand all Loading... |
519 GetEventRouter(browser_context()); | 519 GetEventRouter(browser_context()); |
520 | 520 |
521 // The adapter must be initialized at this point, but return an error instead | 521 // The adapter must be initialized at this point, but return an error instead |
522 // of asserting. | 522 // of asserting. |
523 if (!event_router->HasAdapter()) { | 523 if (!event_router->HasAdapter()) { |
524 SetError(kErrorAdapterNotInitialized); | 524 SetError(kErrorAdapterNotInitialized); |
525 SendResponse(false); | 525 SendResponse(false); |
526 return false; | 526 return false; |
527 } | 527 } |
528 | 528 |
529 scoped_ptr<apibtle::GetDescriptors::Params> params( | 529 std::unique_ptr<apibtle::GetDescriptors::Params> params( |
530 apibtle::GetDescriptors::Params::Create(*args_)); | 530 apibtle::GetDescriptors::Params::Create(*args_)); |
531 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 531 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
532 | 532 |
533 BluetoothLowEnergyEventRouter::DescriptorList descriptor_list; | 533 BluetoothLowEnergyEventRouter::DescriptorList descriptor_list; |
534 BluetoothLowEnergyEventRouter::Status status = event_router->GetDescriptors( | 534 BluetoothLowEnergyEventRouter::Status status = event_router->GetDescriptors( |
535 extension(), params->characteristic_id, &descriptor_list); | 535 extension(), params->characteristic_id, &descriptor_list); |
536 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { | 536 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { |
537 SetError(StatusToString(status)); | 537 SetError(StatusToString(status)); |
538 SendResponse(false); | 538 SendResponse(false); |
539 return false; | 539 return false; |
540 } | 540 } |
541 | 541 |
542 // Manually construct the result instead of using | 542 // Manually construct the result instead of using |
543 // apibtle::GetDescriptors::Result::Create as it doesn't convert lists of | 543 // apibtle::GetDescriptors::Result::Create as it doesn't convert lists of |
544 // enums correctly. | 544 // enums correctly. |
545 scoped_ptr<base::ListValue> result(new base::ListValue()); | 545 std::unique_ptr<base::ListValue> result(new base::ListValue()); |
546 for (apibtle::Descriptor& descriptor : descriptor_list) | 546 for (apibtle::Descriptor& descriptor : descriptor_list) |
547 result->Append(apibtle::DescriptorToValue(&descriptor)); | 547 result->Append(apibtle::DescriptorToValue(&descriptor)); |
548 | 548 |
549 SetResult(result.release()); | 549 SetResult(result.release()); |
550 SendResponse(true); | 550 SendResponse(true); |
551 | 551 |
552 return true; | 552 return true; |
553 } | 553 } |
554 | 554 |
555 bool BluetoothLowEnergyReadCharacteristicValueFunction::DoWork() { | 555 bool BluetoothLowEnergyReadCharacteristicValueFunction::DoWork() { |
556 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 556 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
557 | 557 |
558 BluetoothLowEnergyEventRouter* event_router = | 558 BluetoothLowEnergyEventRouter* event_router = |
559 GetEventRouter(browser_context()); | 559 GetEventRouter(browser_context()); |
560 | 560 |
561 // The adapter must be initialized at this point, but return an error instead | 561 // The adapter must be initialized at this point, but return an error instead |
562 // of asserting. | 562 // of asserting. |
563 if (!event_router->HasAdapter()) { | 563 if (!event_router->HasAdapter()) { |
564 SetError(kErrorAdapterNotInitialized); | 564 SetError(kErrorAdapterNotInitialized); |
565 SendResponse(false); | 565 SendResponse(false); |
566 return false; | 566 return false; |
567 } | 567 } |
568 | 568 |
569 scoped_ptr<apibtle::ReadCharacteristicValue::Params> params( | 569 std::unique_ptr<apibtle::ReadCharacteristicValue::Params> params( |
570 apibtle::ReadCharacteristicValue::Params::Create(*args_)); | 570 apibtle::ReadCharacteristicValue::Params::Create(*args_)); |
571 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 571 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
572 | 572 |
573 instance_id_ = params->characteristic_id; | 573 instance_id_ = params->characteristic_id; |
574 event_router->ReadCharacteristicValue( | 574 event_router->ReadCharacteristicValue( |
575 extension(), | 575 extension(), |
576 instance_id_, | 576 instance_id_, |
577 base::Bind( | 577 base::Bind( |
578 &BluetoothLowEnergyReadCharacteristicValueFunction::SuccessCallback, | 578 &BluetoothLowEnergyReadCharacteristicValueFunction::SuccessCallback, |
579 this), | 579 this), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 GetEventRouter(browser_context()); | 617 GetEventRouter(browser_context()); |
618 | 618 |
619 // The adapter must be initialized at this point, but return an error instead | 619 // The adapter must be initialized at this point, but return an error instead |
620 // of asserting. | 620 // of asserting. |
621 if (!event_router->HasAdapter()) { | 621 if (!event_router->HasAdapter()) { |
622 SetError(kErrorAdapterNotInitialized); | 622 SetError(kErrorAdapterNotInitialized); |
623 SendResponse(false); | 623 SendResponse(false); |
624 return false; | 624 return false; |
625 } | 625 } |
626 | 626 |
627 scoped_ptr<apibtle::WriteCharacteristicValue::Params> params( | 627 std::unique_ptr<apibtle::WriteCharacteristicValue::Params> params( |
628 apibtle::WriteCharacteristicValue::Params::Create(*args_)); | 628 apibtle::WriteCharacteristicValue::Params::Create(*args_)); |
629 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 629 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
630 | 630 |
631 std::vector<uint8_t> value(params->value.begin(), params->value.end()); | 631 std::vector<uint8_t> value(params->value.begin(), params->value.end()); |
632 event_router->WriteCharacteristicValue( | 632 event_router->WriteCharacteristicValue( |
633 extension(), | 633 extension(), |
634 params->characteristic_id, | 634 params->characteristic_id, |
635 value, | 635 value, |
636 base::Bind( | 636 base::Bind( |
637 &BluetoothLowEnergyWriteCharacteristicValueFunction::SuccessCallback, | 637 &BluetoothLowEnergyWriteCharacteristicValueFunction::SuccessCallback, |
(...skipping 23 matching lines...) Expand all Loading... |
661 GetEventRouter(browser_context()); | 661 GetEventRouter(browser_context()); |
662 | 662 |
663 // The adapter must be initialized at this point, but return an error instead | 663 // The adapter must be initialized at this point, but return an error instead |
664 // of asserting. | 664 // of asserting. |
665 if (!event_router->HasAdapter()) { | 665 if (!event_router->HasAdapter()) { |
666 SetError(kErrorAdapterNotInitialized); | 666 SetError(kErrorAdapterNotInitialized); |
667 SendResponse(false); | 667 SendResponse(false); |
668 return false; | 668 return false; |
669 } | 669 } |
670 | 670 |
671 scoped_ptr<apibtle::StartCharacteristicNotifications::Params> params( | 671 std::unique_ptr<apibtle::StartCharacteristicNotifications::Params> params( |
672 apibtle::StartCharacteristicNotifications::Params::Create(*args_)); | 672 apibtle::StartCharacteristicNotifications::Params::Create(*args_)); |
673 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 673 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
674 | 674 |
675 bool persistent = false; // Not persistent by default. | 675 bool persistent = false; // Not persistent by default. |
676 apibtle::NotificationProperties* properties = params.get()->properties.get(); | 676 apibtle::NotificationProperties* properties = params.get()->properties.get(); |
677 if (properties) | 677 if (properties) |
678 persistent = properties->persistent; | 678 persistent = properties->persistent; |
679 | 679 |
680 event_router->StartCharacteristicNotifications( | 680 event_router->StartCharacteristicNotifications( |
681 persistent, | 681 persistent, |
(...skipping 27 matching lines...) Expand all Loading... |
709 GetEventRouter(browser_context()); | 709 GetEventRouter(browser_context()); |
710 | 710 |
711 // The adapter must be initialized at this point, but return an error instead | 711 // The adapter must be initialized at this point, but return an error instead |
712 // of asserting. | 712 // of asserting. |
713 if (!event_router->HasAdapter()) { | 713 if (!event_router->HasAdapter()) { |
714 SetError(kErrorAdapterNotInitialized); | 714 SetError(kErrorAdapterNotInitialized); |
715 SendResponse(false); | 715 SendResponse(false); |
716 return false; | 716 return false; |
717 } | 717 } |
718 | 718 |
719 scoped_ptr<apibtle::StopCharacteristicNotifications::Params> params( | 719 std::unique_ptr<apibtle::StopCharacteristicNotifications::Params> params( |
720 apibtle::StopCharacteristicNotifications::Params::Create(*args_)); | 720 apibtle::StopCharacteristicNotifications::Params::Create(*args_)); |
721 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 721 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
722 | 722 |
723 event_router->StopCharacteristicNotifications( | 723 event_router->StopCharacteristicNotifications( |
724 extension(), | 724 extension(), |
725 params->characteristic_id, | 725 params->characteristic_id, |
726 base::Bind(&BluetoothLowEnergyStopCharacteristicNotificationsFunction:: | 726 base::Bind(&BluetoothLowEnergyStopCharacteristicNotificationsFunction:: |
727 SuccessCallback, | 727 SuccessCallback, |
728 this), | 728 this), |
729 base::Bind(&BluetoothLowEnergyStopCharacteristicNotificationsFunction:: | 729 base::Bind(&BluetoothLowEnergyStopCharacteristicNotificationsFunction:: |
(...skipping 21 matching lines...) Expand all Loading... |
751 GetEventRouter(browser_context()); | 751 GetEventRouter(browser_context()); |
752 | 752 |
753 // The adapter must be initialized at this point, but return an error instead | 753 // The adapter must be initialized at this point, but return an error instead |
754 // of asserting. | 754 // of asserting. |
755 if (!event_router->HasAdapter()) { | 755 if (!event_router->HasAdapter()) { |
756 SetError(kErrorAdapterNotInitialized); | 756 SetError(kErrorAdapterNotInitialized); |
757 SendResponse(false); | 757 SendResponse(false); |
758 return false; | 758 return false; |
759 } | 759 } |
760 | 760 |
761 scoped_ptr<apibtle::ReadDescriptorValue::Params> params( | 761 std::unique_ptr<apibtle::ReadDescriptorValue::Params> params( |
762 apibtle::ReadDescriptorValue::Params::Create(*args_)); | 762 apibtle::ReadDescriptorValue::Params::Create(*args_)); |
763 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 763 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
764 | 764 |
765 instance_id_ = params->descriptor_id; | 765 instance_id_ = params->descriptor_id; |
766 event_router->ReadDescriptorValue( | 766 event_router->ReadDescriptorValue( |
767 extension(), | 767 extension(), |
768 instance_id_, | 768 instance_id_, |
769 base::Bind( | 769 base::Bind( |
770 &BluetoothLowEnergyReadDescriptorValueFunction::SuccessCallback, | 770 &BluetoothLowEnergyReadDescriptorValueFunction::SuccessCallback, |
771 this), | 771 this), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 GetEventRouter(browser_context()); | 808 GetEventRouter(browser_context()); |
809 | 809 |
810 // The adapter must be initialized at this point, but return an error instead | 810 // The adapter must be initialized at this point, but return an error instead |
811 // of asserting. | 811 // of asserting. |
812 if (!event_router->HasAdapter()) { | 812 if (!event_router->HasAdapter()) { |
813 SetError(kErrorAdapterNotInitialized); | 813 SetError(kErrorAdapterNotInitialized); |
814 SendResponse(false); | 814 SendResponse(false); |
815 return false; | 815 return false; |
816 } | 816 } |
817 | 817 |
818 scoped_ptr<apibtle::WriteDescriptorValue::Params> params( | 818 std::unique_ptr<apibtle::WriteDescriptorValue::Params> params( |
819 apibtle::WriteDescriptorValue::Params::Create(*args_)); | 819 apibtle::WriteDescriptorValue::Params::Create(*args_)); |
820 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 820 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
821 | 821 |
822 std::vector<uint8_t> value(params->value.begin(), params->value.end()); | 822 std::vector<uint8_t> value(params->value.begin(), params->value.end()); |
823 event_router->WriteDescriptorValue( | 823 event_router->WriteDescriptorValue( |
824 extension(), | 824 extension(), |
825 params->descriptor_id, | 825 params->descriptor_id, |
826 value, | 826 value, |
827 base::Bind( | 827 base::Bind( |
828 &BluetoothLowEnergyWriteDescriptorValueFunction::SuccessCallback, | 828 &BluetoothLowEnergyWriteDescriptorValueFunction::SuccessCallback, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 GetEventRouter(browser_context()); | 923 GetEventRouter(browser_context()); |
924 | 924 |
925 // The adapter must be initialized at this point, but return an error instead | 925 // The adapter must be initialized at this point, but return an error instead |
926 // of asserting. | 926 // of asserting. |
927 if (!event_router->HasAdapter()) { | 927 if (!event_router->HasAdapter()) { |
928 SetError(kErrorAdapterNotInitialized); | 928 SetError(kErrorAdapterNotInitialized); |
929 SendResponse(false); | 929 SendResponse(false); |
930 return false; | 930 return false; |
931 } | 931 } |
932 | 932 |
933 scoped_ptr<apibtle::RegisterAdvertisement::Params> params( | 933 std::unique_ptr<apibtle::RegisterAdvertisement::Params> params( |
934 apibtle::RegisterAdvertisement::Params::Create(*args_)); | 934 apibtle::RegisterAdvertisement::Params::Create(*args_)); |
935 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 935 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
936 | 936 |
937 scoped_ptr<device::BluetoothAdvertisement::Data> advertisement_data( | 937 std::unique_ptr<device::BluetoothAdvertisement::Data> advertisement_data( |
938 new device::BluetoothAdvertisement::Data( | 938 new device::BluetoothAdvertisement::Data( |
939 params->advertisement.type == | 939 params->advertisement.type == |
940 apibtle::AdvertisementType::ADVERTISEMENT_TYPE_BROADCAST | 940 apibtle::AdvertisementType::ADVERTISEMENT_TYPE_BROADCAST |
941 ? device::BluetoothAdvertisement::AdvertisementType:: | 941 ? device::BluetoothAdvertisement::AdvertisementType:: |
942 ADVERTISEMENT_TYPE_BROADCAST | 942 ADVERTISEMENT_TYPE_BROADCAST |
943 : device::BluetoothAdvertisement::AdvertisementType:: | 943 : device::BluetoothAdvertisement::AdvertisementType:: |
944 ADVERTISEMENT_TYPE_PERIPHERAL)); | 944 ADVERTISEMENT_TYPE_PERIPHERAL)); |
945 | 945 |
946 advertisement_data->set_service_uuids( | 946 advertisement_data->set_service_uuids( |
947 std::move(params->advertisement.service_uuids)); | 947 std::move(params->advertisement.service_uuids)); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 return false; | 1014 return false; |
1015 } | 1015 } |
1016 | 1016 |
1017 BluetoothLowEnergyEventRouter* event_router = | 1017 BluetoothLowEnergyEventRouter* event_router = |
1018 GetEventRouter(browser_context()); | 1018 GetEventRouter(browser_context()); |
1019 | 1019 |
1020 // If we don't have an initialized adapter, unregistering is a no-op. | 1020 // If we don't have an initialized adapter, unregistering is a no-op. |
1021 if (!event_router->HasAdapter()) | 1021 if (!event_router->HasAdapter()) |
1022 return true; | 1022 return true; |
1023 | 1023 |
1024 scoped_ptr<apibtle::UnregisterAdvertisement::Params> params( | 1024 std::unique_ptr<apibtle::UnregisterAdvertisement::Params> params( |
1025 apibtle::UnregisterAdvertisement::Params::Create(*args_)); | 1025 apibtle::UnregisterAdvertisement::Params::Create(*args_)); |
1026 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 1026 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
1027 | 1027 |
1028 BluetoothApiAdvertisement* advertisement = | 1028 BluetoothApiAdvertisement* advertisement = |
1029 GetAdvertisement(params->advertisement_id); | 1029 GetAdvertisement(params->advertisement_id); |
1030 if (!advertisement) { | 1030 if (!advertisement) { |
1031 error_ = kStatusAdvertisementDoesNotExist; | 1031 error_ = kStatusAdvertisementDoesNotExist; |
1032 SendResponse(false); | 1032 SendResponse(false); |
1033 return false; | 1033 return false; |
1034 } | 1034 } |
(...skipping 25 matching lines...) Expand all Loading... |
1060 SetError(kStatusAdvertisementDoesNotExist); | 1060 SetError(kStatusAdvertisementDoesNotExist); |
1061 break; | 1061 break; |
1062 default: | 1062 default: |
1063 SetError(kErrorOperationFailed); | 1063 SetError(kErrorOperationFailed); |
1064 } | 1064 } |
1065 SendResponse(false); | 1065 SendResponse(false); |
1066 } | 1066 } |
1067 | 1067 |
1068 } // namespace api | 1068 } // namespace api |
1069 } // namespace extensions | 1069 } // namespace extensions |
OLD | NEW |