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

Side by Side Diff: chromeos/components/tether/ble_advertiser.h

Issue 2972263002: [CrOS Tether] Do not register a new Bluetooth advertisement until any previous identical advertisem… (Closed)
Patch Set: Created 3 years, 5 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 CHROMEOS_COMPONENTS_TETHER_BLE_ADVERTISER_H_ 5 #ifndef CHROMEOS_COMPONENTS_TETHER_BLE_ADVERTISER_H_
6 #define CHROMEOS_COMPONENTS_TETHER_BLE_ADVERTISER_H_ 6 #define CHROMEOS_COMPONENTS_TETHER_BLE_ADVERTISER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <unordered_set>
9 10
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
12 #include "components/cryptauth/foreground_eid_generator.h" 13 #include "components/cryptauth/foreground_eid_generator.h"
13 #include "components/cryptauth/remote_device.h" 14 #include "components/cryptauth/remote_device.h"
14 #include "device/bluetooth/bluetooth_adapter.h" 15 #include "device/bluetooth/bluetooth_adapter.h"
15 #include "device/bluetooth/bluetooth_advertisement.h" 16 #include "device/bluetooth/bluetooth_advertisement.h"
16 17
17 namespace cryptauth { 18 namespace cryptauth {
18 class LocalDeviceDataProvider; 19 class LocalDeviceDataProvider;
(...skipping 18 matching lines...) Expand all
37 virtual ~BleAdvertiser(); 38 virtual ~BleAdvertiser();
38 39
39 virtual bool StartAdvertisingToDevice( 40 virtual bool StartAdvertisingToDevice(
40 const cryptauth::RemoteDevice& remote_device); 41 const cryptauth::RemoteDevice& remote_device);
41 virtual bool StopAdvertisingToDevice( 42 virtual bool StopAdvertisingToDevice(
42 const cryptauth::RemoteDevice& remote_device); 43 const cryptauth::RemoteDevice& remote_device);
43 44
44 private: 45 private:
45 friend class BleAdvertiserTest; 46 friend class BleAdvertiserTest;
46 47
48 // One IndividualAdvertisement is created for each device to which
49 // BleAdvertiser should be advertising. When an IndividualAdvertisement is
50 // created, it starts trying to advertise to its associated device ID;
51 // likewise, when it is destroyed, it stops advertising if necessary.
52 //
53 // However, because unregistering an advertisement is an asynchronous
54 // operation, it is possible that if an IndividualAdvertisement for one device
55 // is created just after another IndividualAdvertisement for the same device
56 // was destroyed, the previous advertisement was not fully unregistered.
57 // If that is the case, the newly-created IndividualAdvertisement must wait
Ryan Hansberry 2017/07/11 21:27:41 please explicitly mention OnPreviousAdvertisementU
Kyle Horimoto 2017/07/12 02:22:04 Done.
58 // until the previous advertisement was unregistered.
47 class IndividualAdvertisement 59 class IndividualAdvertisement
48 : public device::BluetoothAdapter::Observer, 60 : public device::BluetoothAdapter::Observer,
49 public device::BluetoothAdvertisement::Observer { 61 public device::BluetoothAdvertisement::Observer {
50 public: 62 public:
51 IndividualAdvertisement( 63 IndividualAdvertisement(
52 const std::string& device_id, 64 const std::string& device_id,
53 scoped_refptr<device::BluetoothAdapter> adapter, 65 scoped_refptr<device::BluetoothAdapter> adapter,
54 std::unique_ptr<cryptauth::DataWithTimestamp> advertisement_data); 66 std::unique_ptr<cryptauth::DataWithTimestamp> advertisement_data,
67 const base::Closure& on_advertisement_unregistered_callback,
68 std::unordered_set<std::string>* active_advertisement_device_ids_set);
55 ~IndividualAdvertisement() override; 69 ~IndividualAdvertisement() override;
56 70
71 // Callback for when a previously-registered advertisement corresponding to
72 // |device_id_| has been unregistered.
73 void OnPreviousAdvertisementUnregistered();
74
57 // device::BluetoothAdapter::Observer 75 // device::BluetoothAdapter::Observer
58 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, 76 void AdapterPoweredChanged(device::BluetoothAdapter* adapter,
59 bool powered) override; 77 bool powered) override;
60 78
61 // device::BluetoothAdvertisement::Observer 79 // device::BluetoothAdvertisement::Observer
62 void AdvertisementReleased( 80 void AdvertisementReleased(
63 device::BluetoothAdvertisement* advertisement) override; 81 device::BluetoothAdvertisement* advertisement) override;
64 82
65 private: 83 private:
66 friend class BleAdvertiserTest; 84 friend class BleAdvertiserTest;
(...skipping 11 matching lines...) Expand all
78 96
79 std::unique_ptr<device::BluetoothAdvertisement::ServiceData> 97 std::unique_ptr<device::BluetoothAdvertisement::ServiceData>
80 CreateServiceData() const; 98 CreateServiceData() const;
81 99
82 std::string device_id_; 100 std::string device_id_;
83 scoped_refptr<device::BluetoothAdapter> adapter_; 101 scoped_refptr<device::BluetoothAdapter> adapter_;
84 std::unique_ptr<cryptauth::DataWithTimestamp> advertisement_data_; 102 std::unique_ptr<cryptauth::DataWithTimestamp> advertisement_data_;
85 bool is_initializing_advertising_; 103 bool is_initializing_advertising_;
86 scoped_refptr<device::BluetoothAdvertisement> advertisement_; 104 scoped_refptr<device::BluetoothAdvertisement> advertisement_;
87 105
106 base::Closure on_advertisement_unregistered_callback_;
107 std::unordered_set<std::string>* active_advertisement_device_ids_set_;
108
88 base::WeakPtrFactory<IndividualAdvertisement> weak_ptr_factory_; 109 base::WeakPtrFactory<IndividualAdvertisement> weak_ptr_factory_;
89 110
90 DISALLOW_COPY_AND_ASSIGN(IndividualAdvertisement); 111 DISALLOW_COPY_AND_ASSIGN(IndividualAdvertisement);
91 }; 112 };
92 113
93 BleAdvertiser( 114 BleAdvertiser(
94 scoped_refptr<device::BluetoothAdapter> adapter, 115 scoped_refptr<device::BluetoothAdapter> adapter,
95 std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator, 116 std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator,
96 const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher, 117 const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher,
97 const cryptauth::LocalDeviceDataProvider* local_device_data_provider); 118 const cryptauth::LocalDeviceDataProvider* local_device_data_provider);
98 119
120 void OnAdvertisementUnregistered(const std::string& associated_device_id);
121
99 scoped_refptr<device::BluetoothAdapter> adapter_; 122 scoped_refptr<device::BluetoothAdapter> adapter_;
100 123
101 std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator_; 124 std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator_;
102 // Not owned by this instance and must outlive it. 125 // Not owned by this instance and must outlive it.
103 const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher_; 126 const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher_;
104 const cryptauth::LocalDeviceDataProvider* local_device_data_provider_; 127 const cryptauth::LocalDeviceDataProvider* local_device_data_provider_;
105 128
106 std::map<std::string, std::unique_ptr<IndividualAdvertisement>> 129 std::map<std::string, std::unique_ptr<IndividualAdvertisement>>
107 device_id_to_advertisement_map_; 130 device_id_to_advertisement_map_;
131 std::unordered_set<std::string> active_advertisement_device_ids_set_;
132
133 base::WeakPtrFactory<BleAdvertiser> weak_ptr_factory_;
108 134
109 DISALLOW_COPY_AND_ASSIGN(BleAdvertiser); 135 DISALLOW_COPY_AND_ASSIGN(BleAdvertiser);
110 }; 136 };
111 137
112 } // namespace tether 138 } // namespace tether
113 139
114 } // namespace chromeos 140 } // namespace chromeos
115 141
116 #endif // CHROMEOS_COMPONENTS_TETHER_BLE_ADVERTISER_H_ 142 #endif // CHROMEOS_COMPONENTS_TETHER_BLE_ADVERTISER_H_
OLDNEW
« no previous file with comments | « no previous file | chromeos/components/tether/ble_advertiser.cc » ('j') | chromeos/components/tether/ble_advertiser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698