| 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 <hash_set> | 7 #include <hash_set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 16 #include "device/bluetooth/bluetooth_device_win.h" | 16 #include "device/bluetooth/bluetooth_device_win.h" |
| 17 #include "device/bluetooth/bluetooth_socket_thread_win.h" | |
| 18 #include "device/bluetooth/bluetooth_task_manager_win.h" | 17 #include "device/bluetooth/bluetooth_task_manager_win.h" |
| 19 | 18 |
| 20 namespace device { | 19 namespace device { |
| 21 | 20 |
| 22 BluetoothAdapterWin::BluetoothAdapterWin(const InitCallback& init_callback) | 21 BluetoothAdapterWin::BluetoothAdapterWin(const InitCallback& init_callback) |
| 23 : BluetoothAdapter(), | 22 : BluetoothAdapter(), |
| 24 init_callback_(init_callback), | 23 init_callback_(init_callback), |
| 25 initialized_(false), | 24 initialized_(false), |
| 26 powered_(false), | 25 powered_(false), |
| 27 discovery_status_(NOT_DISCOVERING), | 26 discovery_status_(NOT_DISCOVERING), |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 | 178 |
| 180 void BluetoothAdapterWin::DevicesDiscovered( | 179 void BluetoothAdapterWin::DevicesDiscovered( |
| 181 const ScopedVector<BluetoothTaskManagerWin::DeviceState>& devices) { | 180 const ScopedVector<BluetoothTaskManagerWin::DeviceState>& devices) { |
| 182 DCHECK(thread_checker_.CalledOnValidThread()); | 181 DCHECK(thread_checker_.CalledOnValidThread()); |
| 183 for (ScopedVector<BluetoothTaskManagerWin::DeviceState>::const_iterator iter = | 182 for (ScopedVector<BluetoothTaskManagerWin::DeviceState>::const_iterator iter = |
| 184 devices.begin(); | 183 devices.begin(); |
| 185 iter != devices.end(); | 184 iter != devices.end(); |
| 186 ++iter) { | 185 ++iter) { |
| 187 if (discovered_devices_.find((*iter)->address) == | 186 if (discovered_devices_.find((*iter)->address) == |
| 188 discovered_devices_.end()) { | 187 discovered_devices_.end()) { |
| 189 BluetoothDeviceWin device_win( | 188 BluetoothDeviceWin device_win(**iter); |
| 190 **iter, ui_task_runner_, socket_thread_, NULL, net::NetLog::Source()); | |
| 191 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 189 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 192 DeviceAdded(this, &device_win)); | 190 DeviceAdded(this, &device_win)); |
| 193 discovered_devices_.insert((*iter)->address); | 191 discovered_devices_.insert((*iter)->address); |
| 194 } | 192 } |
| 195 } | 193 } |
| 196 } | 194 } |
| 197 | 195 |
| 198 void BluetoothAdapterWin::DevicesUpdated( | 196 void BluetoothAdapterWin::DevicesUpdated( |
| 199 const ScopedVector<BluetoothTaskManagerWin::DeviceState>& devices) { | 197 const ScopedVector<BluetoothTaskManagerWin::DeviceState>& devices) { |
| 200 STLDeleteValues(&devices_); | 198 STLDeleteValues(&devices_); |
| 201 for (ScopedVector<BluetoothTaskManagerWin::DeviceState>::const_iterator iter = | 199 for (ScopedVector<BluetoothTaskManagerWin::DeviceState>::const_iterator iter = |
| 202 devices.begin(); | 200 devices.begin(); |
| 203 iter != devices.end(); | 201 iter != devices.end(); |
| 204 ++iter) { | 202 ++iter) { |
| 205 devices_[(*iter)->address] = new BluetoothDeviceWin( | 203 devices_[(*iter)->address] = new BluetoothDeviceWin(**iter); |
| 206 **iter, ui_task_runner_, socket_thread_, NULL, net::NetLog::Source()); | |
| 207 } | 204 } |
| 208 } | 205 } |
| 209 | 206 |
| 210 // If the method is called when |discovery_status_| is DISCOVERY_STOPPING, | 207 // If the method is called when |discovery_status_| is DISCOVERY_STOPPING, |
| 211 // starting again is handled by BluetoothAdapterWin::DiscoveryStopped(). | 208 // starting again is handled by BluetoothAdapterWin::DiscoveryStopped(). |
| 212 void BluetoothAdapterWin::AddDiscoverySession( | 209 void BluetoothAdapterWin::AddDiscoverySession( |
| 213 const base::Closure& callback, | 210 const base::Closure& callback, |
| 214 const ErrorCallback& error_callback) { | 211 const ErrorCallback& error_callback) { |
| 215 if (discovery_status_ == DISCOVERING) { | 212 if (discovery_status_ == DISCOVERING) { |
| 216 num_discovery_listeners_++; | 213 num_discovery_listeners_++; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 228 if (discovery_status_ == NOT_DISCOVERING) { | 225 if (discovery_status_ == NOT_DISCOVERING) { |
| 229 error_callback.Run(); | 226 error_callback.Run(); |
| 230 return; | 227 return; |
| 231 } | 228 } |
| 232 on_stop_discovery_callbacks_.push_back(callback); | 229 on_stop_discovery_callbacks_.push_back(callback); |
| 233 MaybePostStopDiscoveryTask(); | 230 MaybePostStopDiscoveryTask(); |
| 234 } | 231 } |
| 235 | 232 |
| 236 void BluetoothAdapterWin::Init() { | 233 void BluetoothAdapterWin::Init() { |
| 237 ui_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 234 ui_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 238 socket_thread_ = BluetoothSocketThreadWin::Get(); | |
| 239 task_manager_ = | 235 task_manager_ = |
| 240 new BluetoothTaskManagerWin(ui_task_runner_); | 236 new BluetoothTaskManagerWin(ui_task_runner_); |
| 241 task_manager_->AddObserver(this); | 237 task_manager_->AddObserver(this); |
| 242 task_manager_->Initialize(); | 238 task_manager_->Initialize(); |
| 243 } | 239 } |
| 244 | 240 |
| 245 void BluetoothAdapterWin::InitForTest( | 241 void BluetoothAdapterWin::InitForTest( |
| 246 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 242 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 247 scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner) { | 243 scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner) { |
| 248 ui_task_runner_ = ui_task_runner; | 244 ui_task_runner_ = ui_task_runner; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 274 num_discovery_listeners_ -= on_stop_discovery_callbacks_.size(); | 270 num_discovery_listeners_ -= on_stop_discovery_callbacks_.size(); |
| 275 on_stop_discovery_callbacks_.clear(); | 271 on_stop_discovery_callbacks_.clear(); |
| 276 return; | 272 return; |
| 277 } | 273 } |
| 278 | 274 |
| 279 discovery_status_ = DISCOVERY_STOPPING; | 275 discovery_status_ = DISCOVERY_STOPPING; |
| 280 task_manager_->PostStopDiscoveryTask(); | 276 task_manager_->PostStopDiscoveryTask(); |
| 281 } | 277 } |
| 282 | 278 |
| 283 } // namespace device | 279 } // namespace device |
| OLD | NEW |