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

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: 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 unified diff | Download patch
« no previous file with comments | « no previous file | chromeos/components/tether/ble_advertiser.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 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
11 #include "base/callback_forward.h"
10 #include "base/macros.h" 12 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
12 #include "components/cryptauth/foreground_eid_generator.h" 14 #include "components/cryptauth/foreground_eid_generator.h"
13 #include "components/cryptauth/remote_device.h" 15 #include "components/cryptauth/remote_device.h"
14 #include "device/bluetooth/bluetooth_adapter.h" 16 #include "device/bluetooth/bluetooth_adapter.h"
15 #include "device/bluetooth/bluetooth_advertisement.h" 17 #include "device/bluetooth/bluetooth_advertisement.h"
16 18
17 namespace cryptauth { 19 namespace cryptauth {
18 class LocalDeviceDataProvider; 20 class LocalDeviceDataProvider;
19 class RemoteBeaconSeedFetcher; 21 class RemoteBeaconSeedFetcher;
(...skipping 17 matching lines...) Expand all
37 virtual ~BleAdvertiser(); 39 virtual ~BleAdvertiser();
38 40
39 virtual bool StartAdvertisingToDevice( 41 virtual bool StartAdvertisingToDevice(
40 const cryptauth::RemoteDevice& remote_device); 42 const cryptauth::RemoteDevice& remote_device);
41 virtual bool StopAdvertisingToDevice( 43 virtual bool StopAdvertisingToDevice(
42 const cryptauth::RemoteDevice& remote_device); 44 const cryptauth::RemoteDevice& remote_device);
43 45
44 private: 46 private:
45 friend class BleAdvertiserTest; 47 friend class BleAdvertiserTest;
46 48
49 // One IndividualAdvertisement is created for each device to which
50 // BleAdvertiser should be advertising. When an IndividualAdvertisement is
51 // created, it starts trying to advertise to its associated device ID;
52 // likewise, when it is destroyed, it stops advertising if necessary.
53 //
54 // However, because unregistering an advertisement is an asynchronous
55 // operation, it is possible that if an IndividualAdvertisement for one device
56 // is created just after another IndividualAdvertisement for the same device
57 // was destroyed, the previous advertisement was not fully unregistered.
58 // If that is the case, the newly-created IndividualAdvertisement must wait
59 // until OnPreviousAdvertisementUnregistered() is called.
47 class IndividualAdvertisement 60 class IndividualAdvertisement
48 : public device::BluetoothAdapter::Observer, 61 : public device::BluetoothAdapter::Observer,
49 public device::BluetoothAdvertisement::Observer { 62 public device::BluetoothAdvertisement::Observer {
50 public: 63 public:
51 IndividualAdvertisement( 64 IndividualAdvertisement(
52 const std::string& device_id, 65 const std::string& device_id,
53 scoped_refptr<device::BluetoothAdapter> adapter, 66 scoped_refptr<device::BluetoothAdapter> adapter,
54 std::unique_ptr<cryptauth::DataWithTimestamp> advertisement_data); 67 std::unique_ptr<cryptauth::DataWithTimestamp> advertisement_data,
68 const base::Closure& on_unregister_advertisement_success_callback,
69 const base::Callback<void(device::BluetoothAdvertisement::ErrorCode)>&
70 on_unregister_advertisement_error_callback,
71 std::unordered_set<std::string>* active_advertisement_device_ids_set);
55 ~IndividualAdvertisement() override; 72 ~IndividualAdvertisement() override;
56 73
74 // Callback for when a previously-registered advertisement corresponding to
75 // |device_id_| has been unregistered.
76 void OnPreviousAdvertisementUnregistered();
77
57 // device::BluetoothAdapter::Observer 78 // device::BluetoothAdapter::Observer
58 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, 79 void AdapterPoweredChanged(device::BluetoothAdapter* adapter,
59 bool powered) override; 80 bool powered) override;
60 81
61 // device::BluetoothAdvertisement::Observer 82 // device::BluetoothAdvertisement::Observer
62 void AdvertisementReleased( 83 void AdvertisementReleased(
63 device::BluetoothAdvertisement* advertisement) override; 84 device::BluetoothAdvertisement* advertisement) override;
64 85
65 private: 86 private:
66 friend class BleAdvertiserTest; 87 friend class BleAdvertiserTest;
(...skipping 11 matching lines...) Expand all
78 99
79 std::unique_ptr<device::BluetoothAdvertisement::ServiceData> 100 std::unique_ptr<device::BluetoothAdvertisement::ServiceData>
80 CreateServiceData() const; 101 CreateServiceData() const;
81 102
82 std::string device_id_; 103 std::string device_id_;
83 scoped_refptr<device::BluetoothAdapter> adapter_; 104 scoped_refptr<device::BluetoothAdapter> adapter_;
84 std::unique_ptr<cryptauth::DataWithTimestamp> advertisement_data_; 105 std::unique_ptr<cryptauth::DataWithTimestamp> advertisement_data_;
85 bool is_initializing_advertising_; 106 bool is_initializing_advertising_;
86 scoped_refptr<device::BluetoothAdvertisement> advertisement_; 107 scoped_refptr<device::BluetoothAdvertisement> advertisement_;
87 108
109 base::Closure on_unregister_advertisement_success_callback_;
110 base::Callback<void(device::BluetoothAdvertisement::ErrorCode)>
111 on_unregister_advertisement_error_callback_;
112 std::unordered_set<std::string>* active_advertisement_device_ids_set_;
113
88 base::WeakPtrFactory<IndividualAdvertisement> weak_ptr_factory_; 114 base::WeakPtrFactory<IndividualAdvertisement> weak_ptr_factory_;
89 115
90 DISALLOW_COPY_AND_ASSIGN(IndividualAdvertisement); 116 DISALLOW_COPY_AND_ASSIGN(IndividualAdvertisement);
91 }; 117 };
92 118
93 BleAdvertiser( 119 BleAdvertiser(
94 scoped_refptr<device::BluetoothAdapter> adapter, 120 scoped_refptr<device::BluetoothAdapter> adapter,
95 std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator, 121 std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator,
96 const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher, 122 const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher,
97 const cryptauth::LocalDeviceDataProvider* local_device_data_provider); 123 const cryptauth::LocalDeviceDataProvider* local_device_data_provider);
98 124
125 void OnUnregisterAdvertisementSuccess(
126 const std::string& associated_device_id);
127 void OnUnregisterAdvertisementError(
128 const std::string& associated_device_id,
129 device::BluetoothAdvertisement::ErrorCode error_code);
130 void RemoveAdvertisingDeviceIdAndRetry(const std::string& device_id);
131
99 scoped_refptr<device::BluetoothAdapter> adapter_; 132 scoped_refptr<device::BluetoothAdapter> adapter_;
100 133
101 std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator_; 134 std::unique_ptr<cryptauth::ForegroundEidGenerator> eid_generator_;
102 // Not owned by this instance and must outlive it. 135 // Not owned by this instance and must outlive it.
103 const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher_; 136 const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher_;
104 const cryptauth::LocalDeviceDataProvider* local_device_data_provider_; 137 const cryptauth::LocalDeviceDataProvider* local_device_data_provider_;
105 138
106 std::map<std::string, std::unique_ptr<IndividualAdvertisement>> 139 std::map<std::string, std::unique_ptr<IndividualAdvertisement>>
107 device_id_to_advertisement_map_; 140 device_id_to_individual_advertisement_map_;
141 std::unordered_set<std::string> active_advertisement_device_ids_set_;
142
143 base::WeakPtrFactory<BleAdvertiser> weak_ptr_factory_;
108 144
109 DISALLOW_COPY_AND_ASSIGN(BleAdvertiser); 145 DISALLOW_COPY_AND_ASSIGN(BleAdvertiser);
110 }; 146 };
111 147
112 } // namespace tether 148 } // namespace tether
113 149
114 } // namespace chromeos 150 } // namespace chromeos
115 151
116 #endif // CHROMEOS_COMPONENTS_TETHER_BLE_ADVERTISER_H_ 152 #endif // CHROMEOS_COMPONENTS_TETHER_BLE_ADVERTISER_H_
OLDNEW
« 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