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

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

Issue 180163009: chrome.bluetooth API improvements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address code review feedback. Created 6 years, 9 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 <hash_set> 7 #include <hash_set>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 178
179 void BluetoothAdapterWin::DevicesDiscovered( 179 void BluetoothAdapterWin::DevicesDiscovered(
180 const ScopedVector<BluetoothTaskManagerWin::DeviceState>& devices) { 180 const ScopedVector<BluetoothTaskManagerWin::DeviceState>& devices) {
181 DCHECK(thread_checker_.CalledOnValidThread()); 181 DCHECK(thread_checker_.CalledOnValidThread());
182 for (ScopedVector<BluetoothTaskManagerWin::DeviceState>::const_iterator iter = 182 for (ScopedVector<BluetoothTaskManagerWin::DeviceState>::const_iterator iter =
183 devices.begin(); 183 devices.begin();
184 iter != devices.end(); 184 iter != devices.end();
185 ++iter) { 185 ++iter) {
186 if (discovered_devices_.find((*iter)->address) == 186 if (discovered_devices_.find((*iter)->address) ==
187 discovered_devices_.end()) { 187 discovered_devices_.end()) {
188 BluetoothDeviceWin device_win(**iter); 188 BluetoothDeviceWin device_win(**iter,
189 ui_task_runner_,
190 file_task_runner_,
191 net_log_,
192 net_log_source_);
189 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 193 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
190 DeviceAdded(this, &device_win)); 194 DeviceAdded(this, &device_win));
191 discovered_devices_.insert((*iter)->address); 195 discovered_devices_.insert((*iter)->address);
192 } 196 }
193 } 197 }
194 } 198 }
195 199
196 void BluetoothAdapterWin::DevicesUpdated( 200 void BluetoothAdapterWin::DevicesUpdated(
197 const ScopedVector<BluetoothTaskManagerWin::DeviceState>& devices) { 201 const ScopedVector<BluetoothTaskManagerWin::DeviceState>& devices) {
198 STLDeleteValues(&devices_); 202 STLDeleteValues(&devices_);
199 for (ScopedVector<BluetoothTaskManagerWin::DeviceState>::const_iterator iter = 203 for (ScopedVector<BluetoothTaskManagerWin::DeviceState>::const_iterator iter =
200 devices.begin(); 204 devices.begin();
201 iter != devices.end(); 205 iter != devices.end();
202 ++iter) { 206 ++iter) {
203 devices_[(*iter)->address] = new BluetoothDeviceWin(**iter); 207 devices_[(*iter)->address] = new BluetoothDeviceWin(
208 **iter, ui_task_runner_, file_task_runner_, net_log_, net_log_source_);
204 } 209 }
205 } 210 }
206 211
207 // If the method is called when |discovery_status_| is DISCOVERY_STOPPING, 212 // If the method is called when |discovery_status_| is DISCOVERY_STOPPING,
208 // starting again is handled by BluetoothAdapterWin::DiscoveryStopped(). 213 // starting again is handled by BluetoothAdapterWin::DiscoveryStopped().
209 void BluetoothAdapterWin::AddDiscoverySession( 214 void BluetoothAdapterWin::AddDiscoverySession(
210 const base::Closure& callback, 215 const base::Closure& callback,
211 const ErrorCallback& error_callback) { 216 const ErrorCallback& error_callback) {
212 if (discovery_status_ == DISCOVERING) { 217 if (discovery_status_ == DISCOVERING) {
213 num_discovery_listeners_++; 218 num_discovery_listeners_++;
(...skipping 27 matching lines...) Expand all
241 void BluetoothAdapterWin::InitForTest( 246 void BluetoothAdapterWin::InitForTest(
242 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, 247 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
243 scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner) { 248 scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner) {
244 ui_task_runner_ = ui_task_runner; 249 ui_task_runner_ = ui_task_runner;
245 task_manager_ = 250 task_manager_ =
246 new BluetoothTaskManagerWin(ui_task_runner_); 251 new BluetoothTaskManagerWin(ui_task_runner_);
247 task_manager_->AddObserver(this); 252 task_manager_->AddObserver(this);
248 task_manager_->InitializeWithBluetoothTaskRunner(bluetooth_task_runner); 253 task_manager_->InitializeWithBluetoothTaskRunner(bluetooth_task_runner);
249 } 254 }
250 255
256 void BluetoothAdapterWin::PostInit(
257 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
258 scoped_refptr<base::SequencedTaskRunner> file_task_runner,
259 net::NetLog* net_log,
260 const net::NetLog::Source& net_log_source) {
261 ui_task_runner_ = ui_task_runner;
262 file_task_runner_ = file_task_runner;
263 net_log_ = net_log;
264 net_log_source_ = net_log_source;
265 }
266
251 void BluetoothAdapterWin::MaybePostStartDiscoveryTask() { 267 void BluetoothAdapterWin::MaybePostStartDiscoveryTask() {
252 if (discovery_status_ == NOT_DISCOVERING && 268 if (discovery_status_ == NOT_DISCOVERING &&
253 !on_start_discovery_callbacks_.empty()) { 269 !on_start_discovery_callbacks_.empty()) {
254 discovery_status_ = DISCOVERY_STARTING; 270 discovery_status_ = DISCOVERY_STARTING;
255 task_manager_->PostStartDiscoveryTask(); 271 task_manager_->PostStartDiscoveryTask();
256 } 272 }
257 } 273 }
258 274
259 void BluetoothAdapterWin::MaybePostStopDiscoveryTask() { 275 void BluetoothAdapterWin::MaybePostStopDiscoveryTask() {
260 if (discovery_status_ != DISCOVERING) 276 if (discovery_status_ != DISCOVERING)
261 return; 277 return;
262 278
263 if (on_stop_discovery_callbacks_.size() < num_discovery_listeners_) { 279 if (on_stop_discovery_callbacks_.size() < num_discovery_listeners_) {
264 for (std::vector<base::Closure>::const_iterator iter = 280 for (std::vector<base::Closure>::const_iterator iter =
265 on_stop_discovery_callbacks_.begin(); 281 on_stop_discovery_callbacks_.begin();
266 iter != on_stop_discovery_callbacks_.end(); 282 iter != on_stop_discovery_callbacks_.end();
267 ++iter) { 283 ++iter) {
268 ui_task_runner_->PostTask(FROM_HERE, *iter); 284 ui_task_runner_->PostTask(FROM_HERE, *iter);
269 } 285 }
270 num_discovery_listeners_ -= on_stop_discovery_callbacks_.size(); 286 num_discovery_listeners_ -= on_stop_discovery_callbacks_.size();
271 on_stop_discovery_callbacks_.clear(); 287 on_stop_discovery_callbacks_.clear();
272 return; 288 return;
273 } 289 }
274 290
275 discovery_status_ = DISCOVERY_STOPPING; 291 discovery_status_ = DISCOVERY_STOPPING;
276 task_manager_->PostStopDiscoveryTask(); 292 task_manager_->PostStopDiscoveryTask();
277 } 293 }
278 294
279 } // namespace device 295 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698