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