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

Unified 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: hansberry@ comment. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chromeos/components/tether/ble_advertiser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/components/tether/ble_advertiser.h
diff --git a/chromeos/components/tether/ble_advertiser.h b/chromeos/components/tether/ble_advertiser.h
index 590b86e15bbe7b294d41ce7cebfb222bb9db78ca..a1211b2eb155f88e4cd02fb2c1e5b544ec20f27b 100644
--- a/chromeos/components/tether/ble_advertiser.h
+++ b/chromeos/components/tether/ble_advertiser.h
@@ -6,7 +6,9 @@
#define CHROMEOS_COMPONENTS_TETHER_BLE_ADVERTISER_H_
#include <map>
+#include <unordered_set>
+#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "components/cryptauth/foreground_eid_generator.h"
@@ -44,6 +46,17 @@ class BleAdvertiser {
private:
friend class BleAdvertiserTest;
+ // One IndividualAdvertisement is created for each device to which
+ // BleAdvertiser should be advertising. When an IndividualAdvertisement is
+ // created, it starts trying to advertise to its associated device ID;
+ // likewise, when it is destroyed, it stops advertising if necessary.
+ //
+ // However, because unregistering an advertisement is an asynchronous
+ // operation, it is possible that if an IndividualAdvertisement for one device
+ // is created just after another IndividualAdvertisement for the same device
+ // was destroyed, the previous advertisement was not fully unregistered.
+ // If that is the case, the newly-created IndividualAdvertisement must wait
+ // until OnPreviousAdvertisementUnregistered() is called.
class IndividualAdvertisement
: public device::BluetoothAdapter::Observer,
public device::BluetoothAdvertisement::Observer {
@@ -51,9 +64,17 @@ class BleAdvertiser {
IndividualAdvertisement(
const std::string& device_id,
scoped_refptr<device::BluetoothAdapter> adapter,
- std::unique_ptr<cryptauth::DataWithTimestamp> advertisement_data);
+ std::unique_ptr<cryptauth::DataWithTimestamp> advertisement_data,
+ const base::Closure& on_unregister_advertisement_success_callback,
+ const base::Callback<void(device::BluetoothAdvertisement::ErrorCode)>&
+ on_unregister_advertisement_error_callback,
+ std::unordered_set<std::string>* active_advertisement_device_ids_set);
~IndividualAdvertisement() override;
+ // Callback for when a previously-registered advertisement corresponding to
+ // |device_id_| has been unregistered.
+ void OnPreviousAdvertisementUnregistered();
+
// device::BluetoothAdapter::Observer
void AdapterPoweredChanged(device::BluetoothAdapter* adapter,
bool powered) override;
@@ -85,6 +106,11 @@ class BleAdvertiser {
bool is_initializing_advertising_;
scoped_refptr<device::BluetoothAdvertisement> advertisement_;
+ base::Closure on_unregister_advertisement_success_callback_;
+ base::Callback<void(device::BluetoothAdvertisement::ErrorCode)>
+ on_unregister_advertisement_error_callback_;
+ std::unordered_set<std::string>* active_advertisement_device_ids_set_;
+
base::WeakPtrFactory<IndividualAdvertisement> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(IndividualAdvertisement);
@@ -96,6 +122,13 @@ class BleAdvertiser {
const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher,
const cryptauth::LocalDeviceDataProvider* local_device_data_provider);
+ void OnUnregisterAdvertisementSuccess(
+ const std::string& associated_device_id);
+ void OnUnregisterAdvertisementError(
+ const std::string& associated_device_id,
+ device::BluetoothAdvertisement::ErrorCode error_code);
+ void RemoveAdvertisingDeviceIdAndRetry(const std::string& device_id);
+
scoped_refptr<device::BluetoothAdapter> adapter_;
std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator_;
@@ -104,7 +137,10 @@ class BleAdvertiser {
const cryptauth::LocalDeviceDataProvider* local_device_data_provider_;
std::map<std::string, std::unique_ptr<IndividualAdvertisement>>
- device_id_to_advertisement_map_;
+ device_id_to_individual_advertisement_map_;
+ std::unordered_set<std::string> active_advertisement_device_ids_set_;
+
+ base::WeakPtrFactory<BleAdvertiser> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(BleAdvertiser);
};
« no previous file with comments | « no previous file | chromeos/components/tether/ble_advertiser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698