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

Side by Side Diff: device/bluetooth/bluetooth_adapter_win.cc

Issue 2423793002: Remove usage of FOR_EACH_OBSERVER macro in device/ (Closed)
Patch Set: rebase 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "device/bluetooth/bluetooth_adapter_win.h" 5 #include "device/bluetooth/bluetooth_adapter_win.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 else 121 else
122 ui_task_runner_->PostTask( 122 ui_task_runner_->PostTask(
123 FROM_HERE, 123 FROM_HERE,
124 base::Bind(&RunDiscoverySessionErrorCallback, callbacks.second, 124 base::Bind(&RunDiscoverySessionErrorCallback, callbacks.second,
125 UMABluetoothDiscoverySessionOutcome::UNKNOWN)); 125 UMABluetoothDiscoverySessionOutcome::UNKNOWN));
126 } 126 }
127 num_discovery_listeners_ = on_start_discovery_callbacks_.size(); 127 num_discovery_listeners_ = on_start_discovery_callbacks_.size();
128 on_start_discovery_callbacks_.clear(); 128 on_start_discovery_callbacks_.clear();
129 129
130 if (success) { 130 if (success) {
131 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 131 for (auto& observer : observers_)
132 AdapterDiscoveringChanged(this, true)); 132 observer.AdapterDiscoveringChanged(this, true);
133 133
134 // If there are stop discovery requests, post the stop discovery again. 134 // If there are stop discovery requests, post the stop discovery again.
135 MaybePostStopDiscoveryTask(); 135 MaybePostStopDiscoveryTask();
136 } else if (!on_stop_discovery_callbacks_.empty()) { 136 } else if (!on_stop_discovery_callbacks_.empty()) {
137 // If there are stop discovery requests but start discovery has failed, 137 // If there are stop discovery requests but start discovery has failed,
138 // notify that stop discovery has been complete. 138 // notify that stop discovery has been complete.
139 DiscoveryStopped(); 139 DiscoveryStopped();
140 } 140 }
141 } 141 }
142 142
143 void BluetoothAdapterWin::DiscoveryStopped() { 143 void BluetoothAdapterWin::DiscoveryStopped() {
144 discovered_devices_.clear(); 144 discovered_devices_.clear();
145 bool was_discovering = IsDiscovering(); 145 bool was_discovering = IsDiscovering();
146 discovery_status_ = NOT_DISCOVERING; 146 discovery_status_ = NOT_DISCOVERING;
147 for (std::vector<base::Closure>::const_iterator iter = 147 for (std::vector<base::Closure>::const_iterator iter =
148 on_stop_discovery_callbacks_.begin(); 148 on_stop_discovery_callbacks_.begin();
149 iter != on_stop_discovery_callbacks_.end(); 149 iter != on_stop_discovery_callbacks_.end();
150 ++iter) { 150 ++iter) {
151 ui_task_runner_->PostTask(FROM_HERE, *iter); 151 ui_task_runner_->PostTask(FROM_HERE, *iter);
152 } 152 }
153 num_discovery_listeners_ = 0; 153 num_discovery_listeners_ = 0;
154 on_stop_discovery_callbacks_.clear(); 154 on_stop_discovery_callbacks_.clear();
155 if (was_discovering) 155 if (was_discovering)
156 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 156 for (auto& observer : observers_)
157 AdapterDiscoveringChanged(this, false)); 157 observer.AdapterDiscoveringChanged(this, false);
158 158
159 // If there are start discovery requests, post the start discovery again. 159 // If there are start discovery requests, post the start discovery again.
160 MaybePostStartDiscoveryTask(); 160 MaybePostStartDiscoveryTask();
161 } 161 }
162 162
163 BluetoothAdapter::UUIDList BluetoothAdapterWin::GetUUIDs() const { 163 BluetoothAdapter::UUIDList BluetoothAdapterWin::GetUUIDs() const {
164 NOTIMPLEMENTED(); 164 NOTIMPLEMENTED();
165 return UUIDList(); 165 return UUIDList();
166 } 166 }
167 167
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 205 }
206 206
207 void BluetoothAdapterWin::AdapterStateChanged( 207 void BluetoothAdapterWin::AdapterStateChanged(
208 const BluetoothTaskManagerWin::AdapterState& state) { 208 const BluetoothTaskManagerWin::AdapterState& state) {
209 DCHECK(thread_checker_.CalledOnValidThread()); 209 DCHECK(thread_checker_.CalledOnValidThread());
210 name_ = state.name; 210 name_ = state.name;
211 bool was_present = IsPresent(); 211 bool was_present = IsPresent();
212 bool is_present = !state.address.empty(); 212 bool is_present = !state.address.empty();
213 address_ = BluetoothDevice::CanonicalizeAddress(state.address); 213 address_ = BluetoothDevice::CanonicalizeAddress(state.address);
214 if (was_present != is_present) { 214 if (was_present != is_present) {
215 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 215 for (auto& observer : observers_)
216 AdapterPresentChanged(this, is_present)); 216 observer.AdapterPresentChanged(this, is_present);
217 } 217 }
218 if (powered_ != state.powered) { 218 if (powered_ != state.powered) {
219 powered_ = state.powered; 219 powered_ = state.powered;
220 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 220 for (auto& observer : observers_)
221 AdapterPoweredChanged(this, powered_)); 221 observer.AdapterPoweredChanged(this, powered_);
222 } 222 }
223 if (!initialized_) { 223 if (!initialized_) {
224 initialized_ = true; 224 initialized_ = true;
225 init_callback_.Run(); 225 init_callback_.Run();
226 } 226 }
227 } 227 }
228 228
229 void BluetoothAdapterWin::DevicesPolled( 229 void BluetoothAdapterWin::DevicesPolled(
230 const ScopedVector<BluetoothTaskManagerWin::DeviceState>& devices) { 230 const ScopedVector<BluetoothTaskManagerWin::DeviceState>& devices) {
231 DCHECK(thread_checker_.CalledOnValidThread()); 231 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 19 matching lines...) Expand all
251 } 251 }
252 252
253 // Process device removal first 253 // Process device removal first
254 DeviceAddressSet removed_devices = 254 DeviceAddressSet removed_devices =
255 base::STLSetDifference<DeviceAddressSet>(known_devices, new_devices); 255 base::STLSetDifference<DeviceAddressSet>(known_devices, new_devices);
256 for (DeviceAddressSet::const_iterator iter = removed_devices.begin(); 256 for (DeviceAddressSet::const_iterator iter = removed_devices.begin();
257 iter != removed_devices.end(); 257 iter != removed_devices.end();
258 ++iter) { 258 ++iter) {
259 std::unique_ptr<BluetoothDevice> device_win = 259 std::unique_ptr<BluetoothDevice> device_win =
260 devices_.take_and_erase(*iter); 260 devices_.take_and_erase(*iter);
261 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 261 for (auto& observer : observers_)
262 DeviceRemoved(this, device_win.get())); 262 observer.DeviceRemoved(this, device_win.get());
263 } 263 }
264 264
265 // Process added and (maybe) changed devices in one pass 265 // Process added and (maybe) changed devices in one pass
266 DeviceAddressSet added_devices = 266 DeviceAddressSet added_devices =
267 base::STLSetDifference<DeviceAddressSet>(new_devices, known_devices); 267 base::STLSetDifference<DeviceAddressSet>(new_devices, known_devices);
268 DeviceAddressSet changed_devices = 268 DeviceAddressSet changed_devices =
269 base::STLSetIntersection<DeviceAddressSet>(known_devices, new_devices); 269 base::STLSetIntersection<DeviceAddressSet>(known_devices, new_devices);
270 for (ScopedVector<BluetoothTaskManagerWin::DeviceState>::const_iterator iter = 270 for (ScopedVector<BluetoothTaskManagerWin::DeviceState>::const_iterator iter =
271 devices.begin(); 271 devices.begin();
272 iter != devices.end(); 272 iter != devices.end();
273 ++iter) { 273 ++iter) {
274 BluetoothTaskManagerWin::DeviceState* device_state = (*iter); 274 BluetoothTaskManagerWin::DeviceState* device_state = (*iter);
275 if (added_devices.find(device_state->address) != added_devices.end()) { 275 if (added_devices.find(device_state->address) != added_devices.end()) {
276 BluetoothDeviceWin* device_win = 276 BluetoothDeviceWin* device_win =
277 new BluetoothDeviceWin(this, *device_state, ui_task_runner_, 277 new BluetoothDeviceWin(this, *device_state, ui_task_runner_,
278 socket_thread_, NULL, net::NetLogSource()); 278 socket_thread_, NULL, net::NetLogSource());
279 devices_.set(device_state->address, 279 devices_.set(device_state->address,
280 std::unique_ptr<BluetoothDevice>(device_win)); 280 std::unique_ptr<BluetoothDevice>(device_win));
281 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, 281 for (auto& observer : observers_)
282 observers_, 282 observer.DeviceAdded(this, device_win);
283 DeviceAdded(this, device_win));
284 } else if (changed_devices.find(device_state->address) != 283 } else if (changed_devices.find(device_state->address) !=
285 changed_devices.end()) { 284 changed_devices.end()) {
286 DevicesMap::const_iterator iter = devices_.find(device_state->address); 285 DevicesMap::const_iterator iter = devices_.find(device_state->address);
287 DCHECK(iter != devices_.end()); 286 DCHECK(iter != devices_.end());
288 BluetoothDeviceWin* device_win = 287 BluetoothDeviceWin* device_win =
289 static_cast<BluetoothDeviceWin*>(iter->second); 288 static_cast<BluetoothDeviceWin*>(iter->second);
290 if (!device_win->IsEqual(*device_state)) { 289 if (!device_win->IsEqual(*device_state)) {
291 device_win->Update(*device_state); 290 device_win->Update(*device_state);
292 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 291 for (auto& observer : observers_)
293 DeviceChanged(this, device_win)); 292 observer.DeviceChanged(this, device_win);
294 } 293 }
295 // Above IsEqual returns true if device name, address, status and services 294 // Above IsEqual returns true if device name, address, status and services
296 // (primary services of BLE device) are the same. However, in BLE tests, 295 // (primary services of BLE device) are the same. However, in BLE tests,
297 // we may simulate characteristic, descriptor and secondary GATT service 296 // we may simulate characteristic, descriptor and secondary GATT service
298 // after device has been initialized. 297 // after device has been initialized.
299 if (force_update_device_for_test_) 298 if (force_update_device_for_test_)
300 device_win->Update(*device_state); 299 device_win->Update(*device_state);
301 } 300 }
302 } 301 }
303 } 302 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 num_discovery_listeners_ -= on_stop_discovery_callbacks_.size(); 380 num_discovery_listeners_ -= on_stop_discovery_callbacks_.size();
382 on_stop_discovery_callbacks_.clear(); 381 on_stop_discovery_callbacks_.clear();
383 return; 382 return;
384 } 383 }
385 384
386 discovery_status_ = DISCOVERY_STOPPING; 385 discovery_status_ = DISCOVERY_STOPPING;
387 task_manager_->PostStopDiscoveryTask(); 386 task_manager_->PostStopDiscoveryTask();
388 } 387 }
389 388
390 } // namespace device 389 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_mac.mm ('k') | device/bluetooth/bluetooth_task_manager_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698