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

Side by Side Diff: extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_api.cc

Issue 2370373002: Move chrome.bluetoothLowEnergy out of //chrome. (Closed)
Patch Set: build fix Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_api.h" 5 #include "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_api.h "
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <iterator> 9 #include <iterator>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/callback_forward.h" 15 #include "base/callback_forward.h"
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/lazy_instance.h" 17 #include "base/lazy_instance.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/memory/weak_ptr.h" 19 #include "base/memory/weak_ptr.h"
20 #include "base/values.h" 20 #include "base/values.h"
21 #include "chrome/browser/extensions/api/bluetooth_low_energy/utils.h"
22 #include "chrome/common/extensions/api/bluetooth_low_energy.h"
23 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
24 #include "device/bluetooth/bluetooth_adapter.h" 22 #include "device/bluetooth/bluetooth_adapter.h"
25 #include "device/bluetooth/bluetooth_gatt_characteristic.h" 23 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
26 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h" 24 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h"
27 #include "device/bluetooth/bluetooth_local_gatt_descriptor.h" 25 #include "device/bluetooth/bluetooth_local_gatt_descriptor.h"
28 #include "device/bluetooth/bluetooth_local_gatt_service.h" 26 #include "device/bluetooth/bluetooth_local_gatt_service.h"
29 #include "device/bluetooth/bluetooth_uuid.h" 27 #include "device/bluetooth/bluetooth_uuid.h"
28 #include "extensions/browser/api/bluetooth_low_energy/utils.h"
29 #include "extensions/browser/api/extensions_api_client.h"
30 #include "extensions/browser/kiosk/kiosk_delegate.h"
30 #include "extensions/common/api/bluetooth/bluetooth_manifest_data.h" 31 #include "extensions/common/api/bluetooth/bluetooth_manifest_data.h"
32 #include "extensions/common/api/bluetooth_low_energy.h"
31 #include "extensions/common/extension.h" 33 #include "extensions/common/extension.h"
34 #include "extensions/common/extension_id.h"
32 #include "extensions/common/switches.h" 35 #include "extensions/common/switches.h"
33 36
34 #if defined(OS_CHROMEOS)
35 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
36 #endif
37
38 using content::BrowserContext; 37 using content::BrowserContext;
39 using content::BrowserThread; 38 using content::BrowserThread;
40 39
41 namespace apibtle = extensions::api::bluetooth_low_energy; 40 namespace apibtle = extensions::api::bluetooth_low_energy;
42 41
43 namespace extensions { 42 namespace extensions {
44 43
45 namespace { 44 namespace {
46 45
47 const char kErrorAdapterNotInitialized[] = 46 const char kErrorAdapterNotInitialized[] =
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 api_permissions, 321 api_permissions,
323 apibtle::DESCRIPTOR_PERMISSION_ENCRYPTEDAUTHENTICATEDWRITE)) { 322 apibtle::DESCRIPTOR_PERMISSION_ENCRYPTEDAUTHENTICATEDWRITE)) {
324 permissions |= device::BluetoothGattCharacteristic:: 323 permissions |= device::BluetoothGattCharacteristic::
325 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED; 324 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED;
326 } 325 }
327 326
328 return permissions; 327 return permissions;
329 } 328 }
330 329
331 bool IsAutoLaunchedKioskApp(const ExtensionId& id) { 330 bool IsAutoLaunchedKioskApp(const ExtensionId& id) {
332 #if defined(OS_CHROMEOS) 331 KioskDelegate* delegate = ExtensionsBrowserClient::Get()->GetKioskDelegate();
333 chromeos::KioskAppManager::App app_info; 332 DCHECK(delegate);
334 return chromeos::KioskAppManager::Get()->GetApp(id, &app_info) && 333 return delegate->IsAutoLaunchedKioskApp(id);
335 app_info.was_auto_launched_with_zero_delay;
336 #else
337 return false;
338 #endif
339 } 334 }
340 335
341 bool IsPeripheralFlagEnabled() { 336 bool IsPeripheralFlagEnabled() {
342 return base::CommandLine::ForCurrentProcess()->HasSwitch( 337 return base::CommandLine::ForCurrentProcess()->HasSwitch(
343 switches::kEnableBLEAdvertising); 338 switches::kEnableBLEAdvertising);
344 } 339 }
345 340
346 } // namespace 341 } // namespace
347 342
348 343 static base::LazyInstance<BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI>>
349 static base::LazyInstance<BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI> >
350 g_factory = LAZY_INSTANCE_INITIALIZER; 344 g_factory = LAZY_INSTANCE_INITIALIZER;
351 345
352 // static 346 // static
353 BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI>* 347 BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI>*
354 BluetoothLowEnergyAPI::GetFactoryInstance() { 348 BluetoothLowEnergyAPI::GetFactoryInstance() {
355 return g_factory.Pointer(); 349 return g_factory.Pointer();
356 } 350 }
357 351
358 // static 352 // static
359 BluetoothLowEnergyAPI* BluetoothLowEnergyAPI::Get(BrowserContext* context) { 353 BluetoothLowEnergyAPI* BluetoothLowEnergyAPI::Get(BrowserContext* context) {
360 DCHECK_CURRENTLY_ON(BrowserThread::UI); 354 DCHECK_CURRENTLY_ON(BrowserThread::UI);
361 return GetFactoryInstance()->Get(context); 355 return GetFactoryInstance()->Get(context);
362 } 356 }
363 357
364 BluetoothLowEnergyAPI::BluetoothLowEnergyAPI(BrowserContext* context) 358 BluetoothLowEnergyAPI::BluetoothLowEnergyAPI(BrowserContext* context)
365 : event_router_(new BluetoothLowEnergyEventRouter(context)) { 359 : event_router_(new BluetoothLowEnergyEventRouter(context)) {
366 DCHECK_CURRENTLY_ON(BrowserThread::UI); 360 DCHECK_CURRENTLY_ON(BrowserThread::UI);
367 } 361 }
368 362
369 BluetoothLowEnergyAPI::~BluetoothLowEnergyAPI() { 363 BluetoothLowEnergyAPI::~BluetoothLowEnergyAPI() {}
370 }
371 364
372 void BluetoothLowEnergyAPI::Shutdown() { 365 void BluetoothLowEnergyAPI::Shutdown() {
373 DCHECK_CURRENTLY_ON(BrowserThread::UI); 366 DCHECK_CURRENTLY_ON(BrowserThread::UI);
374 } 367 }
375 368
376 namespace api { 369 namespace api {
377 370
378 BluetoothLowEnergyExtensionFunctionDeprecated:: 371 BluetoothLowEnergyExtensionFunctionDeprecated::
379 BluetoothLowEnergyExtensionFunctionDeprecated() {} 372 BluetoothLowEnergyExtensionFunctionDeprecated() {}
380 373
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 std::unique_ptr<apibtle::Connect::Params> params( 483 std::unique_ptr<apibtle::Connect::Params> params(
491 apibtle::Connect::Params::Create(*args_)); 484 apibtle::Connect::Params::Create(*args_));
492 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); 485 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
493 486
494 bool persistent = false; // Not persistent by default. 487 bool persistent = false; // Not persistent by default.
495 apibtle::ConnectProperties* properties = params->properties.get(); 488 apibtle::ConnectProperties* properties = params->properties.get();
496 if (properties) 489 if (properties)
497 persistent = properties->persistent; 490 persistent = properties->persistent;
498 491
499 event_router->Connect( 492 event_router->Connect(
500 persistent, 493 persistent, extension(), params->device_address,
501 extension(),
502 params->device_address,
503 base::Bind(&BluetoothLowEnergyConnectFunction::SuccessCallback, this), 494 base::Bind(&BluetoothLowEnergyConnectFunction::SuccessCallback, this),
504 base::Bind(&BluetoothLowEnergyConnectFunction::ErrorCallback, this)); 495 base::Bind(&BluetoothLowEnergyConnectFunction::ErrorCallback, this));
505 496
506 return true; 497 return true;
507 } 498 }
508 499
509 void BluetoothLowEnergyConnectFunction::SuccessCallback() { 500 void BluetoothLowEnergyConnectFunction::SuccessCallback() {
510 SendResponse(true); 501 SendResponse(true);
511 } 502 }
512 503
(...skipping 15 matching lines...) Expand all
528 SetError(kErrorAdapterNotInitialized); 519 SetError(kErrorAdapterNotInitialized);
529 SendResponse(false); 520 SendResponse(false);
530 return false; 521 return false;
531 } 522 }
532 523
533 std::unique_ptr<apibtle::Disconnect::Params> params( 524 std::unique_ptr<apibtle::Disconnect::Params> params(
534 apibtle::Disconnect::Params::Create(*args_)); 525 apibtle::Disconnect::Params::Create(*args_));
535 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); 526 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
536 527
537 event_router->Disconnect( 528 event_router->Disconnect(
538 extension(), 529 extension(), params->device_address,
539 params->device_address,
540 base::Bind(&BluetoothLowEnergyDisconnectFunction::SuccessCallback, this), 530 base::Bind(&BluetoothLowEnergyDisconnectFunction::SuccessCallback, this),
541 base::Bind(&BluetoothLowEnergyDisconnectFunction::ErrorCallback, this)); 531 base::Bind(&BluetoothLowEnergyDisconnectFunction::ErrorCallback, this));
542 532
543 return true; 533 return true;
544 } 534 }
545 535
546 void BluetoothLowEnergyDisconnectFunction::SuccessCallback() { 536 void BluetoothLowEnergyDisconnectFunction::SuccessCallback() {
547 SendResponse(true); 537 SendResponse(true);
548 } 538 }
549 539
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 SendResponse(false); 620 SendResponse(false);
631 return false; 621 return false;
632 } 622 }
633 623
634 std::unique_ptr<apibtle::GetCharacteristic::Params> params( 624 std::unique_ptr<apibtle::GetCharacteristic::Params> params(
635 apibtle::GetCharacteristic::Params::Create(*args_)); 625 apibtle::GetCharacteristic::Params::Create(*args_));
636 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); 626 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
637 627
638 apibtle::Characteristic characteristic; 628 apibtle::Characteristic characteristic;
639 BluetoothLowEnergyEventRouter::Status status = 629 BluetoothLowEnergyEventRouter::Status status =
640 event_router->GetCharacteristic( 630 event_router->GetCharacteristic(extension(), params->characteristic_id,
641 extension(), params->characteristic_id, &characteristic); 631 &characteristic);
642 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { 632 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) {
643 SetError(StatusToString(status)); 633 SetError(StatusToString(status));
644 SendResponse(false); 634 SendResponse(false);
645 return false; 635 return false;
646 } 636 }
647 637
648 // Manually construct the result instead of using 638 // Manually construct the result instead of using
649 // apibtle::GetCharacteristic::Result::Create as it doesn't convert lists of 639 // apibtle::GetCharacteristic::Result::Create as it doesn't convert lists of
650 // enums correctly. 640 // enums correctly.
651 SetResult(apibtle::CharacteristicToValue(&characteristic)); 641 SetResult(apibtle::CharacteristicToValue(&characteristic));
(...skipping 15 matching lines...) Expand all
667 SendResponse(false); 657 SendResponse(false);
668 return false; 658 return false;
669 } 659 }
670 660
671 std::unique_ptr<apibtle::GetCharacteristics::Params> params( 661 std::unique_ptr<apibtle::GetCharacteristics::Params> params(
672 apibtle::GetCharacteristics::Params::Create(*args_)); 662 apibtle::GetCharacteristics::Params::Create(*args_));
673 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); 663 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
674 664
675 BluetoothLowEnergyEventRouter::CharacteristicList characteristic_list; 665 BluetoothLowEnergyEventRouter::CharacteristicList characteristic_list;
676 BluetoothLowEnergyEventRouter::Status status = 666 BluetoothLowEnergyEventRouter::Status status =
677 event_router->GetCharacteristics( 667 event_router->GetCharacteristics(extension(), params->service_id,
678 extension(), params->service_id, &characteristic_list); 668 &characteristic_list);
679 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) { 669 if (status != BluetoothLowEnergyEventRouter::kStatusSuccess) {
680 SetError(StatusToString(status)); 670 SetError(StatusToString(status));
681 SendResponse(false); 671 SendResponse(false);
682 return false; 672 return false;
683 } 673 }
684 674
685 // Manually construct the result instead of using 675 // Manually construct the result instead of using
686 // apibtle::GetCharacteristics::Result::Create as it doesn't convert lists of 676 // apibtle::GetCharacteristics::Result::Create as it doesn't convert lists of
687 // enums correctly. 677 // enums correctly.
688 std::unique_ptr<base::ListValue> result(new base::ListValue()); 678 std::unique_ptr<base::ListValue> result(new base::ListValue());
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 SendResponse(false); 807 SendResponse(false);
818 return false; 808 return false;
819 } 809 }
820 810
821 std::unique_ptr<apibtle::ReadCharacteristicValue::Params> params( 811 std::unique_ptr<apibtle::ReadCharacteristicValue::Params> params(
822 apibtle::ReadCharacteristicValue::Params::Create(*args_)); 812 apibtle::ReadCharacteristicValue::Params::Create(*args_));
823 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); 813 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
824 814
825 instance_id_ = params->characteristic_id; 815 instance_id_ = params->characteristic_id;
826 event_router->ReadCharacteristicValue( 816 event_router->ReadCharacteristicValue(
827 extension(), 817 extension(), instance_id_,
828 instance_id_,
829 base::Bind( 818 base::Bind(
830 &BluetoothLowEnergyReadCharacteristicValueFunction::SuccessCallback, 819 &BluetoothLowEnergyReadCharacteristicValueFunction::SuccessCallback,
831 this), 820 this),
832 base::Bind( 821 base::Bind(
833 &BluetoothLowEnergyReadCharacteristicValueFunction::ErrorCallback, 822 &BluetoothLowEnergyReadCharacteristicValueFunction::ErrorCallback,
834 this)); 823 this));
835 824
836 return true; 825 return true;
837 } 826 }
838 827
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 SendResponse(false); 864 SendResponse(false);
876 return false; 865 return false;
877 } 866 }
878 867
879 std::unique_ptr<apibtle::WriteCharacteristicValue::Params> params( 868 std::unique_ptr<apibtle::WriteCharacteristicValue::Params> params(
880 apibtle::WriteCharacteristicValue::Params::Create(*args_)); 869 apibtle::WriteCharacteristicValue::Params::Create(*args_));
881 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); 870 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
882 871
883 std::vector<uint8_t> value(params->value.begin(), params->value.end()); 872 std::vector<uint8_t> value(params->value.begin(), params->value.end());
884 event_router->WriteCharacteristicValue( 873 event_router->WriteCharacteristicValue(
885 extension(), 874 extension(), params->characteristic_id, value,
886 params->characteristic_id,
887 value,
888 base::Bind( 875 base::Bind(
889 &BluetoothLowEnergyWriteCharacteristicValueFunction::SuccessCallback, 876 &BluetoothLowEnergyWriteCharacteristicValueFunction::SuccessCallback,
890 this), 877 this),
891 base::Bind( 878 base::Bind(
892 &BluetoothLowEnergyWriteCharacteristicValueFunction::ErrorCallback, 879 &BluetoothLowEnergyWriteCharacteristicValueFunction::ErrorCallback,
893 this)); 880 this));
894 881
895 return true; 882 return true;
896 } 883 }
897 884
(...skipping 25 matching lines...) Expand all
923 std::unique_ptr<apibtle::StartCharacteristicNotifications::Params> params( 910 std::unique_ptr<apibtle::StartCharacteristicNotifications::Params> params(
924 apibtle::StartCharacteristicNotifications::Params::Create(*args_)); 911 apibtle::StartCharacteristicNotifications::Params::Create(*args_));
925 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); 912 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
926 913
927 bool persistent = false; // Not persistent by default. 914 bool persistent = false; // Not persistent by default.
928 apibtle::NotificationProperties* properties = params->properties.get(); 915 apibtle::NotificationProperties* properties = params->properties.get();
929 if (properties) 916 if (properties)
930 persistent = properties->persistent; 917 persistent = properties->persistent;
931 918
932 event_router->StartCharacteristicNotifications( 919 event_router->StartCharacteristicNotifications(
933 persistent, 920 persistent, extension(), params->characteristic_id,
934 extension(),
935 params->characteristic_id,
936 base::Bind(&BluetoothLowEnergyStartCharacteristicNotificationsFunction:: 921 base::Bind(&BluetoothLowEnergyStartCharacteristicNotificationsFunction::
937 SuccessCallback, 922 SuccessCallback,
938 this), 923 this),
939 base::Bind(&BluetoothLowEnergyStartCharacteristicNotificationsFunction:: 924 base::Bind(&BluetoothLowEnergyStartCharacteristicNotificationsFunction::
940 ErrorCallback, 925 ErrorCallback,
941 this)); 926 this));
942 927
943 return true; 928 return true;
944 } 929 }
945 930
946 void 931 void BluetoothLowEnergyStartCharacteristicNotificationsFunction::
947 BluetoothLowEnergyStartCharacteristicNotificationsFunction::SuccessCallback() { 932 SuccessCallback() {
948 SendResponse(true); 933 SendResponse(true);
949 } 934 }
950 935
951 void BluetoothLowEnergyStartCharacteristicNotificationsFunction::ErrorCallback( 936 void BluetoothLowEnergyStartCharacteristicNotificationsFunction::ErrorCallback(
952 BluetoothLowEnergyEventRouter::Status status) { 937 BluetoothLowEnergyEventRouter::Status status) {
953 SetError(StatusToString(status)); 938 SetError(StatusToString(status));
954 SendResponse(false); 939 SendResponse(false);
955 } 940 }
956 941
957 bool BluetoothLowEnergyStopCharacteristicNotificationsFunction::DoWork() { 942 bool BluetoothLowEnergyStopCharacteristicNotificationsFunction::DoWork() {
958 DCHECK_CURRENTLY_ON(BrowserThread::UI); 943 DCHECK_CURRENTLY_ON(BrowserThread::UI);
959 944
960 BluetoothLowEnergyEventRouter* event_router = 945 BluetoothLowEnergyEventRouter* event_router =
961 GetEventRouter(browser_context()); 946 GetEventRouter(browser_context());
962 947
963 // The adapter must be initialized at this point, but return an error instead 948 // The adapter must be initialized at this point, but return an error instead
964 // of asserting. 949 // of asserting.
965 if (!event_router->HasAdapter()) { 950 if (!event_router->HasAdapter()) {
966 SetError(kErrorAdapterNotInitialized); 951 SetError(kErrorAdapterNotInitialized);
967 SendResponse(false); 952 SendResponse(false);
968 return false; 953 return false;
969 } 954 }
970 955
971 std::unique_ptr<apibtle::StopCharacteristicNotifications::Params> params( 956 std::unique_ptr<apibtle::StopCharacteristicNotifications::Params> params(
972 apibtle::StopCharacteristicNotifications::Params::Create(*args_)); 957 apibtle::StopCharacteristicNotifications::Params::Create(*args_));
973 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); 958 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
974 959
975 event_router->StopCharacteristicNotifications( 960 event_router->StopCharacteristicNotifications(
976 extension(), 961 extension(), params->characteristic_id,
977 params->characteristic_id,
978 base::Bind(&BluetoothLowEnergyStopCharacteristicNotificationsFunction:: 962 base::Bind(&BluetoothLowEnergyStopCharacteristicNotificationsFunction::
979 SuccessCallback, 963 SuccessCallback,
980 this), 964 this),
981 base::Bind(&BluetoothLowEnergyStopCharacteristicNotificationsFunction:: 965 base::Bind(&BluetoothLowEnergyStopCharacteristicNotificationsFunction::
982 ErrorCallback, 966 ErrorCallback,
983 this)); 967 this));
984 968
985 return true; 969 return true;
986 } 970 }
987 971
988 void 972 void BluetoothLowEnergyStopCharacteristicNotificationsFunction::
989 BluetoothLowEnergyStopCharacteristicNotificationsFunction::SuccessCallback() { 973 SuccessCallback() {
990 SendResponse(true); 974 SendResponse(true);
991 } 975 }
992 976
993 void BluetoothLowEnergyStopCharacteristicNotificationsFunction::ErrorCallback( 977 void BluetoothLowEnergyStopCharacteristicNotificationsFunction::ErrorCallback(
994 BluetoothLowEnergyEventRouter::Status status) { 978 BluetoothLowEnergyEventRouter::Status status) {
995 SetError(StatusToString(status)); 979 SetError(StatusToString(status));
996 SendResponse(false); 980 SendResponse(false);
997 } 981 }
998 982
999 bool BluetoothLowEnergyReadDescriptorValueFunction::DoWork() { 983 bool BluetoothLowEnergyReadDescriptorValueFunction::DoWork() {
1000 DCHECK_CURRENTLY_ON(BrowserThread::UI); 984 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1001 985
1002 BluetoothLowEnergyEventRouter* event_router = 986 BluetoothLowEnergyEventRouter* event_router =
1003 GetEventRouter(browser_context()); 987 GetEventRouter(browser_context());
1004 988
1005 // The adapter must be initialized at this point, but return an error instead 989 // The adapter must be initialized at this point, but return an error instead
1006 // of asserting. 990 // of asserting.
1007 if (!event_router->HasAdapter()) { 991 if (!event_router->HasAdapter()) {
1008 SetError(kErrorAdapterNotInitialized); 992 SetError(kErrorAdapterNotInitialized);
1009 SendResponse(false); 993 SendResponse(false);
1010 return false; 994 return false;
1011 } 995 }
1012 996
1013 std::unique_ptr<apibtle::ReadDescriptorValue::Params> params( 997 std::unique_ptr<apibtle::ReadDescriptorValue::Params> params(
1014 apibtle::ReadDescriptorValue::Params::Create(*args_)); 998 apibtle::ReadDescriptorValue::Params::Create(*args_));
1015 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); 999 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
1016 1000
1017 instance_id_ = params->descriptor_id; 1001 instance_id_ = params->descriptor_id;
1018 event_router->ReadDescriptorValue( 1002 event_router->ReadDescriptorValue(
1019 extension(), 1003 extension(), instance_id_,
1020 instance_id_,
1021 base::Bind( 1004 base::Bind(
1022 &BluetoothLowEnergyReadDescriptorValueFunction::SuccessCallback, 1005 &BluetoothLowEnergyReadDescriptorValueFunction::SuccessCallback,
1023 this), 1006 this),
1024 base::Bind(&BluetoothLowEnergyReadDescriptorValueFunction::ErrorCallback, 1007 base::Bind(&BluetoothLowEnergyReadDescriptorValueFunction::ErrorCallback,
1025 this)); 1008 this));
1026 1009
1027 return true; 1010 return true;
1028 } 1011 }
1029 1012
1030 void BluetoothLowEnergyReadDescriptorValueFunction::SuccessCallback() { 1013 void BluetoothLowEnergyReadDescriptorValueFunction::SuccessCallback() {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 SendResponse(false); 1049 SendResponse(false);
1067 return false; 1050 return false;
1068 } 1051 }
1069 1052
1070 std::unique_ptr<apibtle::WriteDescriptorValue::Params> params( 1053 std::unique_ptr<apibtle::WriteDescriptorValue::Params> params(
1071 apibtle::WriteDescriptorValue::Params::Create(*args_)); 1054 apibtle::WriteDescriptorValue::Params::Create(*args_));
1072 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); 1055 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
1073 1056
1074 std::vector<uint8_t> value(params->value.begin(), params->value.end()); 1057 std::vector<uint8_t> value(params->value.begin(), params->value.end());
1075 event_router->WriteDescriptorValue( 1058 event_router->WriteDescriptorValue(
1076 extension(), 1059 extension(), params->descriptor_id, value,
1077 params->descriptor_id,
1078 value,
1079 base::Bind( 1060 base::Bind(
1080 &BluetoothLowEnergyWriteDescriptorValueFunction::SuccessCallback, 1061 &BluetoothLowEnergyWriteDescriptorValueFunction::SuccessCallback,
1081 this), 1062 this),
1082 base::Bind(&BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback, 1063 base::Bind(&BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback,
1083 this)); 1064 this));
1084 1065
1085 return true; 1066 return true;
1086 } 1067 }
1087 1068
1088 void BluetoothLowEnergyWriteDescriptorValueFunction::SuccessCallback() { 1069 void BluetoothLowEnergyWriteDescriptorValueFunction::SuccessCallback() {
1089 results_ = apibtle::WriteDescriptorValue::Results::Create(); 1070 results_ = apibtle::WriteDescriptorValue::Results::Create();
1090 SendResponse(true); 1071 SendResponse(true);
1091 } 1072 }
1092 1073
1093 void BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback( 1074 void BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback(
1094 BluetoothLowEnergyEventRouter::Status status) { 1075 BluetoothLowEnergyEventRouter::Status status) {
1095 SetError(StatusToString(status)); 1076 SetError(StatusToString(status));
1096 SendResponse(false); 1077 SendResponse(false);
1097 } 1078 }
1098 1079
1099 BluetoothLowEnergyAdvertisementFunction:: 1080 BluetoothLowEnergyAdvertisementFunction::
1100 BluetoothLowEnergyAdvertisementFunction() 1081 BluetoothLowEnergyAdvertisementFunction()
1101 : advertisements_manager_(nullptr) { 1082 : advertisements_manager_(nullptr) {}
1102 }
1103 1083
1104 BluetoothLowEnergyAdvertisementFunction:: 1084 BluetoothLowEnergyAdvertisementFunction::
1105 ~BluetoothLowEnergyAdvertisementFunction() { 1085 ~BluetoothLowEnergyAdvertisementFunction() {}
1106 }
1107 1086
1108 int BluetoothLowEnergyAdvertisementFunction::AddAdvertisement( 1087 int BluetoothLowEnergyAdvertisementFunction::AddAdvertisement(
1109 BluetoothApiAdvertisement* advertisement) { 1088 BluetoothApiAdvertisement* advertisement) {
1110 DCHECK(advertisements_manager_); 1089 DCHECK(advertisements_manager_);
1111 return advertisements_manager_->Add(advertisement); 1090 return advertisements_manager_->Add(advertisement);
1112 } 1091 }
1113 1092
1114 BluetoothApiAdvertisement* 1093 BluetoothApiAdvertisement*
1115 BluetoothLowEnergyAdvertisementFunction::GetAdvertisement( 1094 BluetoothLowEnergyAdvertisementFunction::GetAdvertisement(
1116 int advertisement_id) { 1095 int advertisement_id) {
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 params_->response.value->end()); 1510 params_->response.value->end());
1532 } 1511 }
1533 event_router_->HandleRequestResponse( 1512 event_router_->HandleRequestResponse(
1534 extension(), params_->response.request_id, params_->response.is_error, 1513 extension(), params_->response.request_id, params_->response.is_error,
1535 uint8_vector); 1514 uint8_vector);
1536 Respond(NoArguments()); 1515 Respond(NoArguments());
1537 } 1516 }
1538 1517
1539 } // namespace api 1518 } // namespace api
1540 } // namespace extensions 1519 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698