| OLD | NEW |
| 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 <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 return adapter->weak_ptr_factory_.GetWeakPtr(); | 36 return adapter->weak_ptr_factory_.GetWeakPtr(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 BluetoothAdapterWin::BluetoothAdapterWin(const InitCallback& init_callback) | 39 BluetoothAdapterWin::BluetoothAdapterWin(const InitCallback& init_callback) |
| 40 : BluetoothAdapter(), | 40 : BluetoothAdapter(), |
| 41 init_callback_(init_callback), | 41 init_callback_(init_callback), |
| 42 initialized_(false), | 42 initialized_(false), |
| 43 powered_(false), | 43 powered_(false), |
| 44 discovery_status_(NOT_DISCOVERING), | 44 discovery_status_(NOT_DISCOVERING), |
| 45 num_discovery_listeners_(0), | 45 num_discovery_listeners_(0), |
| 46 weak_ptr_factory_(this) { | 46 force_update_device_for_test_(false), |
| 47 } | 47 weak_ptr_factory_(this) {} |
| 48 | 48 |
| 49 BluetoothAdapterWin::~BluetoothAdapterWin() { | 49 BluetoothAdapterWin::~BluetoothAdapterWin() { |
| 50 if (task_manager_.get()) { | 50 if (task_manager_.get()) { |
| 51 task_manager_->RemoveObserver(this); | 51 task_manager_->RemoveObserver(this); |
| 52 task_manager_->Shutdown(); | 52 task_manager_->Shutdown(); |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 std::string BluetoothAdapterWin::GetAddress() const { | 56 std::string BluetoothAdapterWin::GetAddress() const { |
| 57 return address_; | 57 return address_; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 observers_, | 277 observers_, |
| 278 DeviceAdded(this, device_win)); | 278 DeviceAdded(this, device_win)); |
| 279 } else if (changed_devices.find(device_state->address) != | 279 } else if (changed_devices.find(device_state->address) != |
| 280 changed_devices.end()) { | 280 changed_devices.end()) { |
| 281 DevicesMap::const_iterator iter = devices_.find(device_state->address); | 281 DevicesMap::const_iterator iter = devices_.find(device_state->address); |
| 282 DCHECK(iter != devices_.end()); | 282 DCHECK(iter != devices_.end()); |
| 283 BluetoothDeviceWin* device_win = | 283 BluetoothDeviceWin* device_win = |
| 284 static_cast<BluetoothDeviceWin*>(iter->second); | 284 static_cast<BluetoothDeviceWin*>(iter->second); |
| 285 if (!device_win->IsEqual(*device_state)) { | 285 if (!device_win->IsEqual(*device_state)) { |
| 286 device_win->Update(*device_state); | 286 device_win->Update(*device_state); |
| 287 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 287 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 288 observers_, | |
| 289 DeviceChanged(this, device_win)); | 288 DeviceChanged(this, device_win)); |
| 290 } | 289 } |
| 290 // Above IsEqual returns true if device name, address, status and services |
| 291 // (primary services of BLE device) are the same. However, in BLE tests, |
| 292 // we may simulate characteristic, descriptor and secondary GATT service |
| 293 // after device has been initialized. |
| 294 if (force_update_device_for_test_) |
| 295 device_win->Update(*device_state); |
| 291 } | 296 } |
| 292 } | 297 } |
| 293 } | 298 } |
| 294 | 299 |
| 295 // If the method is called when |discovery_status_| is DISCOVERY_STOPPING, | 300 // If the method is called when |discovery_status_| is DISCOVERY_STOPPING, |
| 296 // starting again is handled by BluetoothAdapterWin::DiscoveryStopped(). | 301 // starting again is handled by BluetoothAdapterWin::DiscoveryStopped(). |
| 297 void BluetoothAdapterWin::AddDiscoverySession( | 302 void BluetoothAdapterWin::AddDiscoverySession( |
| 298 BluetoothDiscoveryFilter* discovery_filter, | 303 BluetoothDiscoveryFilter* discovery_filter, |
| 299 const base::Closure& callback, | 304 const base::Closure& callback, |
| 300 const DiscoverySessionErrorCallback& error_callback) { | 305 const DiscoverySessionErrorCallback& error_callback) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 num_discovery_listeners_ -= on_stop_discovery_callbacks_.size(); | 374 num_discovery_listeners_ -= on_stop_discovery_callbacks_.size(); |
| 370 on_stop_discovery_callbacks_.clear(); | 375 on_stop_discovery_callbacks_.clear(); |
| 371 return; | 376 return; |
| 372 } | 377 } |
| 373 | 378 |
| 374 discovery_status_ = DISCOVERY_STOPPING; | 379 discovery_status_ = DISCOVERY_STOPPING; |
| 375 task_manager_->PostStopDiscoveryTask(); | 380 task_manager_->PostStopDiscoveryTask(); |
| 376 } | 381 } |
| 377 | 382 |
| 378 } // namespace device | 383 } // namespace device |
| OLD | NEW |