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

Side by Side Diff: components/arc/bluetooth/arc_bluetooth_bridge.h

Issue 2256003002: components/arc: implement multi advertising (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@plumb-incoming-connections
Patch Set: rickyz@ nits Created 4 years, 3 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
« no previous file with comments | « no previous file | components/arc/bluetooth/arc_bluetooth_bridge.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ 5 #ifndef COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_
6 #define COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ 6 #define COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 #include <unordered_map> 12 #include <unordered_map>
13 #include <unordered_set> 13 #include <unordered_set>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/callback.h" 16 #include "base/callback.h"
17 #include "base/timer/timer.h" 17 #include "base/timer/timer.h"
18 #include "components/arc/arc_bridge_service.h" 18 #include "components/arc/arc_bridge_service.h"
19 #include "components/arc/arc_service.h" 19 #include "components/arc/arc_service.h"
20 #include "components/arc/common/bluetooth.mojom.h" 20 #include "components/arc/common/bluetooth.mojom.h"
21 #include "components/arc/instance_holder.h" 21 #include "components/arc/instance_holder.h"
22 #include "device/bluetooth/bluetooth_adapter.h" 22 #include "device/bluetooth/bluetooth_adapter.h"
23 #include "device/bluetooth/bluetooth_adapter_factory.h" 23 #include "device/bluetooth/bluetooth_adapter_factory.h"
24 #include "device/bluetooth/bluetooth_advertisement.h"
24 #include "device/bluetooth/bluetooth_device.h" 25 #include "device/bluetooth/bluetooth_device.h"
25 #include "device/bluetooth/bluetooth_discovery_session.h" 26 #include "device/bluetooth/bluetooth_discovery_session.h"
26 #include "device/bluetooth/bluetooth_local_gatt_service.h" 27 #include "device/bluetooth/bluetooth_local_gatt_service.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_remote_gatt_service.h" 30 #include "device/bluetooth/bluetooth_remote_gatt_service.h"
30 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" 31 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h"
31 #include "mojo/public/cpp/bindings/binding.h" 32 #include "mojo/public/cpp/bindings/binding.h"
32 33
33 namespace arc { 34 namespace arc {
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 const SendIndicationCallback& callback) override; 270 const SendIndicationCallback& callback) override;
270 271
271 // Bluetooth Mojo host interface - Bluetooth SDP functions 272 // Bluetooth Mojo host interface - Bluetooth SDP functions
272 void GetSdpRecords(mojom::BluetoothAddressPtr remote_addr, 273 void GetSdpRecords(mojom::BluetoothAddressPtr remote_addr,
273 const device::BluetoothUUID& target_uuid) override; 274 const device::BluetoothUUID& target_uuid) override;
274 void CreateSdpRecord(mojom::BluetoothSdpRecordPtr record_mojo, 275 void CreateSdpRecord(mojom::BluetoothSdpRecordPtr record_mojo,
275 const CreateSdpRecordCallback& callback) override; 276 const CreateSdpRecordCallback& callback) override;
276 void RemoveSdpRecord(uint32_t service_handle, 277 void RemoveSdpRecord(uint32_t service_handle,
277 const RemoveSdpRecordCallback& callback) override; 278 const RemoveSdpRecordCallback& callback) override;
278 279
280 // Set up or disable multiple advertising.
281 void ReserveAdvertisementHandle(
282 const ReserveAdvertisementHandleCallback& callback) override;
283 void BroadcastAdvertisement(
284 int32_t adv_handle,
285 std::unique_ptr<device::BluetoothAdvertisement::Data> advertisement,
286 const BroadcastAdvertisementCallback& callback) override;
287 void ReleaseAdvertisementHandle(
288 int32_t adv_handle,
289 const ReleaseAdvertisementHandleCallback& callback) override;
290
279 // Chrome observer callbacks 291 // Chrome observer callbacks
280 void OnPoweredOn( 292 void OnPoweredOn(
281 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const; 293 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const;
282 void OnPoweredOff( 294 void OnPoweredOff(
283 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const; 295 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const;
284 void OnPoweredError( 296 void OnPoweredError(
285 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const; 297 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const;
286 void OnDiscoveryStarted( 298 void OnDiscoveryStarted(
287 std::unique_ptr<device::BluetoothDiscoverySession> session); 299 std::unique_ptr<device::BluetoothDiscoverySession> session);
288 void OnDiscoveryStopped(); 300 void OnDiscoveryStopped();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 387
376 void OnGetServiceRecordsDone( 388 void OnGetServiceRecordsDone(
377 mojom::BluetoothAddressPtr remote_addr, 389 mojom::BluetoothAddressPtr remote_addr,
378 const device::BluetoothUUID& target_uuid, 390 const device::BluetoothUUID& target_uuid,
379 const std::vector<bluez::BluetoothServiceRecordBlueZ>& records_bluez); 391 const std::vector<bluez::BluetoothServiceRecordBlueZ>& records_bluez);
380 void OnGetServiceRecordsError( 392 void OnGetServiceRecordsError(
381 mojom::BluetoothAddressPtr remote_addr, 393 mojom::BluetoothAddressPtr remote_addr,
382 const device::BluetoothUUID& target_uuid, 394 const device::BluetoothUUID& target_uuid,
383 bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code); 395 bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code);
384 396
397 // Callbacks for managing advertisements registered from the instance.
398
399 // Called when we have an open slot in the advertisement map and want to
400 // register the advertisement given by |data| for handle |adv_handle|.
401 void OnReadyToRegisterAdvertisement(
Rahul Chaturvedi 2016/09/16 22:37:22 Tests for these methods?
402 const BroadcastAdvertisementCallback& callback,
403 int32_t adv_handle,
404 std::unique_ptr<device::BluetoothAdvertisement::Data> data);
405 // Called when we've successfully registered a new advertisement for
406 // handle |adv_handle|.
407 void OnRegisterAdvertisementDone(
408 const BroadcastAdvertisementCallback& callback,
409 int32_t adv_handle,
410 scoped_refptr<device::BluetoothAdvertisement> advertisement);
411 // Called when the attempt to register an advertisement for handle
412 // |adv_handle| has failed. |adv_handle| remains reserved, but no
413 // advertisement is associated with it.
414 void OnRegisterAdvertisementError(
415 const BroadcastAdvertisementCallback& callback,
416 int32_t adv_handle,
417 device::BluetoothAdvertisement::ErrorCode error_code);
418 // Both of the following are called after we've tried to unregister
419 // the advertisement for |adv_handle|. Either way, we will no
420 // longer be broadcasting this advertisement, so in either case, the
421 // handle can be released.
422 void OnUnregisterAdvertisementDone(
423 const ReleaseAdvertisementHandleCallback& callback,
424 int32_t adv_handle);
425 void OnUnregisterAdvertisementError(
426 const ReleaseAdvertisementHandleCallback& callback,
427 int32_t adv_handle,
428 device::BluetoothAdvertisement::ErrorCode error_code);
429 // Find the next free advertisement handle and put it in *adv_handle,
430 // or return false if the advertisement map is full.
431 bool GetAdvertisementHandle(int32_t* adv_handle);
432
385 bool CalledOnValidThread(); 433 bool CalledOnValidThread();
386 434
387 mojo::Binding<mojom::BluetoothHost> binding_; 435 mojo::Binding<mojom::BluetoothHost> binding_;
388 436
389 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_; 437 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_;
390 scoped_refptr<device::BluetoothAdvertisement> advertisment_; 438 scoped_refptr<device::BluetoothAdvertisement> advertisment_;
391 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; 439 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_;
392 std::unordered_map<std::string, 440 std::unordered_map<std::string,
393 std::unique_ptr<device::BluetoothGattNotifySession>> 441 std::unique_ptr<device::BluetoothGattNotifySession>>
394 notification_session_; 442 notification_session_;
395 // Map from Android int handle to Chrome (BlueZ) string identifier. 443 // Map from Android int handle to Chrome (BlueZ) string identifier.
396 std::unordered_map<int32_t, std::string> gatt_identifier_; 444 std::unordered_map<int32_t, std::string> gatt_identifier_;
397 // Map from Chrome (BlueZ) string identifier to android int handle. 445 // Map from Chrome (BlueZ) string identifier to android int handle.
398 std::unordered_map<std::string, int32_t> gatt_handle_; 446 std::unordered_map<std::string, int32_t> gatt_handle_;
399 // Store last GattCharacteristic added to each GattService for GattServer. 447 // Store last GattCharacteristic added to each GattService for GattServer.
400 std::unordered_map<int32_t, int32_t> last_characteristic_; 448 std::unordered_map<int32_t, int32_t> last_characteristic_;
401 // Monotonically increasing value to use as handle to give to Android side. 449 // Monotonically increasing value to use as handle to give to Android side.
402 int32_t gatt_server_attribute_next_handle_ = 0; 450 int32_t gatt_server_attribute_next_handle_ = 0;
403 // Keeps track of all devices which initiated a GATT connection to us. 451 // Keeps track of all devices which initiated a GATT connection to us.
404 std::unordered_set<std::string> gatt_connection_cache_; 452 std::unordered_set<std::string> gatt_connection_cache_;
405 // Map of device address to GATT connection objects for connections we 453 // Map of device address to GATT connection objects for connections we
406 // have made. We need to hang on to these as long as the connection is 454 // have made. We need to hang on to these as long as the connection is
407 // active since their destructors will drop the connections otherwise. 455 // active since their destructors will drop the connections otherwise.
408 std::unordered_map<std::string, 456 std::unordered_map<std::string,
409 std::unique_ptr<device::BluetoothGattConnection>> 457 std::unique_ptr<device::BluetoothGattConnection>>
410 gatt_connections_; 458 gatt_connections_;
411 // Timer to turn adapter discoverable off. 459 // Timer to turn adapter discoverable off.
412 base::OneShotTimer discoverable_off_timer_; 460 base::OneShotTimer discoverable_off_timer_;
413 461
462 // Holds advertising data registered by the instance.
463 //
464 // When a handle is reserved, an entry is placed into the advertisements_
465 // map. This entry is not yet associated with a device::BluetoothAdvertisement
466 // because the instance hasn't sent us any advertising data yet, so its
467 // mapped value is nullptr until that happens. Thus we have three states for a
468 // handle:
469 // * unmapped -> free
470 // * mapped to nullptr -> reserved, awaiting data
471 // * mapped to a device::BluetoothAdvertisement -> in use, and the mapped
472 // BluetoothAdvertisement is currently registered with the adapter.
473 static constexpr uint16_t kMaxAdvertisements = 5;
Rahul Chaturvedi 2016/09/16 22:37:22 Is there a requirement for this to be 5? If not, l
Rahul Chaturvedi 2016/09/16 22:37:22 Don't use static constexpr's in classes for intege
474 std::map<int32_t, scoped_refptr<device::BluetoothAdvertisement>>
475 advertisements_;
476
414 base::ThreadChecker thread_checker_; 477 base::ThreadChecker thread_checker_;
415 478
416 // WeakPtrFactory to use for callbacks. 479 // WeakPtrFactory to use for callbacks.
417 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_; 480 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_;
418 481
419 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge); 482 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge);
420 }; 483 };
421 484
422 } // namespace arc 485 } // namespace arc
423 486
424 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ 487 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_
OLDNEW
« no previous file with comments | « no previous file | components/arc/bluetooth/arc_bluetooth_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698