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

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: more testing 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 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 const SendIndicationCallback& callback) override; 267 const SendIndicationCallback& callback) override;
267 268
268 // Bluetooth Mojo host interface - Bluetooth SDP functions 269 // Bluetooth Mojo host interface - Bluetooth SDP functions
269 void GetSdpRecords(mojom::BluetoothAddressPtr remote_addr, 270 void GetSdpRecords(mojom::BluetoothAddressPtr remote_addr,
270 const device::BluetoothUUID& target_uuid) override; 271 const device::BluetoothUUID& target_uuid) override;
271 void CreateSdpRecord(mojom::BluetoothSdpRecordPtr record_mojo, 272 void CreateSdpRecord(mojom::BluetoothSdpRecordPtr record_mojo,
272 const CreateSdpRecordCallback& callback) override; 273 const CreateSdpRecordCallback& callback) override;
273 void RemoveSdpRecord(uint32_t service_handle, 274 void RemoveSdpRecord(uint32_t service_handle,
274 const RemoveSdpRecordCallback& callback) override; 275 const RemoveSdpRecordCallback& callback) override;
275 276
277 // Set up or disable multiple advertising.
278 void ReserveAdvertisementHandle(
279 const ReserveAdvertisementHandleCallback& callback) override;
280 void BroadcastAdvertisement(
281 int32_t adv_handle,
282 std::unique_ptr<device::BluetoothAdvertisement::Data> advertisement,
283 const BroadcastAdvertisementCallback& callback) override;
284 void ReleaseAdvertisementHandle(
285 int32_t adv_handle,
286 const ReleaseAdvertisementHandleCallback& callback) override;
287
276 // Chrome observer callbacks 288 // Chrome observer callbacks
277 void OnPoweredOn( 289 void OnPoweredOn(
278 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const; 290 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const;
279 void OnPoweredOff( 291 void OnPoweredOff(
280 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const; 292 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const;
281 void OnPoweredError( 293 void OnPoweredError(
282 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const; 294 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const;
283 void OnDiscoveryStarted( 295 void OnDiscoveryStarted(
284 std::unique_ptr<device::BluetoothDiscoverySession> session); 296 std::unique_ptr<device::BluetoothDiscoverySession> session);
285 void OnDiscoveryStopped(); 297 void OnDiscoveryStopped();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 382
371 void OnGetServiceRecordsDone( 383 void OnGetServiceRecordsDone(
372 mojom::BluetoothAddressPtr remote_addr, 384 mojom::BluetoothAddressPtr remote_addr,
373 const device::BluetoothUUID& target_uuid, 385 const device::BluetoothUUID& target_uuid,
374 const std::vector<bluez::BluetoothServiceRecordBlueZ>& records_bluez); 386 const std::vector<bluez::BluetoothServiceRecordBlueZ>& records_bluez);
375 void OnGetServiceRecordsError( 387 void OnGetServiceRecordsError(
376 mojom::BluetoothAddressPtr remote_addr, 388 mojom::BluetoothAddressPtr remote_addr,
377 const device::BluetoothUUID& target_uuid, 389 const device::BluetoothUUID& target_uuid,
378 bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code); 390 bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code);
379 391
392 // Callbacks for managing advertisements registered from the instance.
393
394 // Called when we have an open slot in the advertisement map and want to
395 // register the advertisement given by |data| for handle |adv_handle|.
396 void OnReadyToRegisterAdvertisement(
397 const BroadcastAdvertisementCallback& callback,
398 int32_t adv_handle,
399 std::unique_ptr<device::BluetoothAdvertisement::Data> data);
400 // Called when we've successfully registered a new advertisement for
401 // handle |adv_handle|.
402 void OnRegisterAdvertisementDone(
403 const BroadcastAdvertisementCallback& callback,
404 int32_t adv_handle,
405 scoped_refptr<device::BluetoothAdvertisement> advertisement);
406 // Called when the attempt to register an advertisement for handle
407 // |adv_handle| has failed. |adv_handle| remains reserved, but no
408 // advertisement is associated with it.
409 void OnRegisterAdvertisementError(
410 const BroadcastAdvertisementCallback& callback,
411 int32_t adv_handle,
412 device::BluetoothAdvertisement::ErrorCode error_code);
413 // Both of the following are called after we've tried to unregister
414 // the advertisement for |adv_handle|. Either way, we will no
415 // longer be broadcasting this advertisement, so in either case, the
416 // handle can be released.
417 void OnUnregisterAdvertisementDone(
418 const ReleaseAdvertisementHandleCallback& callback,
419 int32_t adv_handle);
420 void OnUnregisterAdvertisementError(
421 const ReleaseAdvertisementHandleCallback& callback,
422 int32_t adv_handle,
423 device::BluetoothAdvertisement::ErrorCode error_code);
424 // Find the next free advertisement handle and put it in *adv_handle,
425 // or return false if the advertisement map is full.
426 bool GetAdvertisementHandle(int32_t* adv_handle);
427
380 bool CalledOnValidThread(); 428 bool CalledOnValidThread();
381 429
382 mojo::Binding<mojom::BluetoothHost> binding_; 430 mojo::Binding<mojom::BluetoothHost> binding_;
383 431
384 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_; 432 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_;
385 scoped_refptr<device::BluetoothAdvertisement> advertisment_; 433 scoped_refptr<device::BluetoothAdvertisement> advertisment_;
386 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; 434 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_;
387 std::unordered_map<std::string, 435 std::unordered_map<std::string,
388 std::unique_ptr<device::BluetoothGattNotifySession>> 436 std::unique_ptr<device::BluetoothGattNotifySession>>
389 notification_session_; 437 notification_session_;
(...skipping 11 matching lines...) Expand all
401 // have made. We need to hang on to these as long as the connection is 449 // have made. We need to hang on to these as long as the connection is
402 // active since their destructors will drop the connections otherwise. 450 // active since their destructors will drop the connections otherwise.
403 std::unordered_map<std::string, 451 std::unordered_map<std::string,
404 std::unique_ptr<device::BluetoothGattConnection>> 452 std::unique_ptr<device::BluetoothGattConnection>>
405 gatt_connections_; 453 gatt_connections_;
406 // Timer to turn discovery off. 454 // Timer to turn discovery off.
407 base::OneShotTimer discovery_off_timer_; 455 base::OneShotTimer discovery_off_timer_;
408 // Timer to turn adapter discoverable off. 456 // Timer to turn adapter discoverable off.
409 base::OneShotTimer discoverable_off_timer_; 457 base::OneShotTimer discoverable_off_timer_;
410 458
459 // Holds advertising data registered by the instance.
460 //
461 // When a handle is reserved, an entry is placed into the advertisements_
462 // map. This entry is not yet associated with a device::BluetoothAdvertisement
463 // because the instance hasn't sent us any advertising data yet, so its
464 // mapped value is nullptr until that happens. Thus we have three states for a
465 // handle:
466 // * unmapped -> free
467 // * mapped to nullptr -> reserved, awaiting data
468 // * mapped to a device::BluetoothAdvertisement -> in use, and the mapped
469 // BluetoothAdvertisement is currently registered with the adapter.
470 enum { kMaxAdvertisements = 5 };
471 std::map<int32_t, scoped_refptr<device::BluetoothAdvertisement>>
472 advertisements_;
473
411 base::ThreadChecker thread_checker_; 474 base::ThreadChecker thread_checker_;
412 475
413 // WeakPtrFactory to use for callbacks. 476 // WeakPtrFactory to use for callbacks.
414 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_; 477 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_;
415 478
416 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge); 479 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge);
417 }; 480 };
418 481
419 } // namespace arc 482 } // namespace arc
420 483
421 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ 484 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698