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

Side by Side Diff: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc

Issue 1920353002: Implement create attribute API functions for BTLE. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@api_changes
Patch Set: Created 4 years, 7 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_event_router.h" 5 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_event_router.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
12 #include "base/containers/hash_tables.h" 12 #include "base/containers/hash_tables.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_connection.h" 17 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_connection.h"
18 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_notify_session.h" 18 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_notify_session.h"
19 #include "chrome/browser/extensions/api/bluetooth_low_energy/utils.h" 19 #include "chrome/browser/extensions/api/bluetooth_low_energy/utils.h"
20 #include "content/public/browser/browser_context.h" 20 #include "content/public/browser/browser_context.h"
21 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
22 #include "device/bluetooth/bluetooth_adapter_factory.h" 22 #include "device/bluetooth/bluetooth_adapter_factory.h"
23 #include "device/bluetooth/bluetooth_gatt_characteristic.h" 23 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
24 #include "device/bluetooth/bluetooth_gatt_connection.h" 24 #include "device/bluetooth/bluetooth_gatt_connection.h"
25 #include "device/bluetooth/bluetooth_gatt_notify_session.h" 25 #include "device/bluetooth/bluetooth_gatt_notify_session.h"
26 #include "device/bluetooth/bluetooth_gatt_service.h" 26 #include "device/bluetooth/bluetooth_gatt_service.h"
27 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h"
27 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" 28 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
28 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h" 29 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h"
29 #include "device/bluetooth/bluetooth_uuid.h" 30 #include "device/bluetooth/bluetooth_uuid.h"
30 #include "extensions/browser/api/api_resource_manager.h" 31 #include "extensions/browser/api/api_resource_manager.h"
31 #include "extensions/browser/event_listener_map.h" 32 #include "extensions/browser/event_listener_map.h"
32 #include "extensions/browser/event_router.h" 33 #include "extensions/browser/event_router.h"
33 #include "extensions/browser/extension_registry.h" 34 #include "extensions/browser/extension_registry.h"
34 #include "extensions/common/api/bluetooth/bluetooth_manifest_data.h" 35 #include "extensions/common/api/bluetooth/bluetooth_manifest_data.h"
35 #include "extensions/common/extension.h" 36 #include "extensions/common/extension.h"
36 37
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 std::unique_ptr<base::ListValue> args(new base::ListValue()); 1051 std::unique_ptr<base::ListValue> args(new base::ListValue());
1051 args->Append(apibtle::DescriptorToValue(&api_descriptor).release()); 1052 args->Append(apibtle::DescriptorToValue(&api_descriptor).release());
1052 1053
1053 DispatchEventToExtensionsWithPermission( 1054 DispatchEventToExtensionsWithPermission(
1054 events::BLUETOOTH_LOW_ENERGY_ON_DESCRIPTOR_VALUE_CHANGED, 1055 events::BLUETOOTH_LOW_ENERGY_ON_DESCRIPTOR_VALUE_CHANGED,
1055 apibtle::OnDescriptorValueChanged::kEventName, 1056 apibtle::OnDescriptorValueChanged::kEventName,
1056 characteristic->GetService()->GetUUID(), "" /* characteristic_id */, 1057 characteristic->GetService()->GetUUID(), "" /* characteristic_id */,
1057 std::move(args)); 1058 std::move(args));
1058 } 1059 }
1059 1060
1061 void BluetoothLowEnergyEventRouter::AddLocalCharacteristic(
1062 const std::string& id,
1063 const std::string& service_id) {
1064 if (chrc_id_to_service_id_.find(id) != chrc_id_to_service_id_.end())
1065 VLOG(1) << "Local characteristic with id " << id
scheib 2016/05/04 00:48:53 Consider DVLOG, as we don't expect to need to ask
rkc 2016/05/04 01:56:28 At an early stage of a feature, these VLOGs can be
1066 << " already exists. Replacing.";
1067 chrc_id_to_service_id_[id] = service_id;
1068 }
1069
1070 device::BluetoothLocalGattCharacteristic*
1071 BluetoothLowEnergyEventRouter::GetLocalCharacteristic(
1072 const std::string& id) const {
1073 if (chrc_id_to_service_id_.find(id) == chrc_id_to_service_id_.end()) {
1074 VLOG(1) << "Characteristic with id " << id << " not found.";
1075 return nullptr;
1076 }
1077 device::BluetoothLocalGattService* service =
1078 adapter_->GetGattService(chrc_id_to_service_id_.at(id));
1079 if (!service) {
1080 VLOG(1) << "Parent service of characteristic with id " << id
1081 << " not found.";
1082 return nullptr;
1083 }
1084
1085 return service->GetCharacteristic(id);
1086 }
1087
1060 void BluetoothLowEnergyEventRouter::OnGetAdapter( 1088 void BluetoothLowEnergyEventRouter::OnGetAdapter(
1061 const base::Closure& callback, 1089 const base::Closure& callback,
1062 scoped_refptr<device::BluetoothAdapter> adapter) { 1090 scoped_refptr<device::BluetoothAdapter> adapter) {
1063 adapter_ = adapter; 1091 adapter_ = adapter;
1064 1092
1065 // Initialize instance ID mappings for all discovered GATT objects and add 1093 // Initialize instance ID mappings for all discovered GATT objects and add
1066 // observers. 1094 // observers.
1067 InitializeIdentifierMappings(); 1095 InitializeIdentifierMappings();
1068 adapter_->AddObserver(this); 1096 adapter_->AddObserver(this);
1069 1097
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 continue; 1544 continue;
1517 1545
1518 manager->Remove(extension_id, *iter); 1546 manager->Remove(extension_id, *iter);
1519 return true; 1547 return true;
1520 } 1548 }
1521 1549
1522 return false; 1550 return false;
1523 } 1551 }
1524 1552
1525 } // namespace extensions 1553 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698