| 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 "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" | 5 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 device->SetObjectPath(device_path); | 280 device->SetObjectPath(device_path); |
| 281 device->Update(properties, true); | 281 device->Update(properties, true); |
| 282 | 282 |
| 283 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 283 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 284 DeviceChanged(this, device)); | 284 DeviceChanged(this, device)); |
| 285 return; | 285 return; |
| 286 } | 286 } |
| 287 | 287 |
| 288 // Device has an address and was not previously known, add to the map | 288 // Device has an address and was not previously known, add to the map |
| 289 // and notify observers. | 289 // and notify observers. |
| 290 BluetoothDevice* device = BluetoothDevice::CreateBound(device_path, | 290 BluetoothDevice* device = BluetoothDevice::CreateBound(this, device_path, |
| 291 properties); | 291 properties); |
| 292 devices_[address] = device; | 292 devices_[address] = device; |
| 293 | 293 |
| 294 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 294 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 295 DeviceAdded(this, device)); | 295 DeviceAdded(this, device)); |
| 296 } | 296 } |
| 297 | 297 |
| 298 BluetoothAdapter::DeviceList BluetoothAdapter::GetDevices() { | 298 BluetoothAdapter::DeviceList BluetoothAdapter::GetDevices() { |
| 299 DeviceList devices; | 299 DeviceList devices; |
| 300 for (DevicesMap::iterator iter = devices_.begin(); | 300 for (DevicesMap::iterator iter = devices_.begin(); |
| 301 iter != devices_.end(); ++iter) | 301 iter != devices_.end(); ++iter) |
| 302 devices.push_back(iter->second); | 302 devices.push_back(iter->second); |
| 303 | 303 |
| 304 return devices; | 304 return devices; |
| 305 } | 305 } |
| 306 | 306 |
| 307 BluetoothDevice* BluetoothAdapter::GetDevice(const std::string& address) { |
| 308 DevicesMap::iterator iter = devices_.find(address); |
| 309 if (iter != devices_.end()) |
| 310 return iter->second; |
| 311 |
| 312 return NULL; |
| 313 } |
| 314 |
| 307 void BluetoothAdapter::ClearDevices() { | 315 void BluetoothAdapter::ClearDevices() { |
| 308 for (DevicesMap::iterator iter = devices_.begin(); | 316 for (DevicesMap::iterator iter = devices_.begin(); |
| 309 iter != devices_.end(); ++iter) { | 317 iter != devices_.end(); ++iter) { |
| 310 BluetoothDevice* device = iter->second; | 318 BluetoothDevice* device = iter->second; |
| 311 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 319 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 312 DeviceRemoved(this, device)); | 320 DeviceRemoved(this, device)); |
| 313 | 321 |
| 314 delete device; | 322 delete device; |
| 315 } | 323 } |
| 316 devices_.clear(); | 324 devices_.clear(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 const BluetoothDeviceClient::Properties& properties) { | 382 const BluetoothDeviceClient::Properties& properties) { |
| 375 if (adapter_path != object_path_) | 383 if (adapter_path != object_path_) |
| 376 return; | 384 return; |
| 377 | 385 |
| 378 // DeviceFound can also be called to indicate that a device we've | 386 // DeviceFound can also be called to indicate that a device we've |
| 379 // paired with or previously connected to is now visible to the adapter, | 387 // paired with or previously connected to is now visible to the adapter, |
| 380 // so check it's not already in the list and just update if it is. | 388 // so check it's not already in the list and just update if it is. |
| 381 BluetoothDevice* device; | 389 BluetoothDevice* device; |
| 382 DevicesMap::iterator iter = devices_.find(address); | 390 DevicesMap::iterator iter = devices_.find(address); |
| 383 if (iter == devices_.end()) { | 391 if (iter == devices_.end()) { |
| 384 device = BluetoothDevice::CreateUnbound(&properties); | 392 device = BluetoothDevice::CreateUnbound(this, &properties); |
| 385 devices_[address] = device; | 393 devices_[address] = device; |
| 386 | 394 |
| 387 if (device->IsSupported()) | 395 if (device->IsSupported()) |
| 388 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 396 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 389 DeviceAdded(this, device)); | 397 DeviceAdded(this, device)); |
| 390 } else { | 398 } else { |
| 391 device = iter->second; | 399 device = iter->second; |
| 392 device->Update(&properties, false); | 400 device->Update(&properties, false); |
| 393 | 401 |
| 394 if (device->IsSupported() || !device->WasDiscovered()) | 402 if (device->IsSupported() || !device->WasDiscovered()) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 } | 440 } |
| 433 | 441 |
| 434 // static | 442 // static |
| 435 BluetoothAdapter* BluetoothAdapter::Create(const std::string& address) { | 443 BluetoothAdapter* BluetoothAdapter::Create(const std::string& address) { |
| 436 BluetoothAdapter* adapter = new BluetoothAdapter; | 444 BluetoothAdapter* adapter = new BluetoothAdapter; |
| 437 adapter->FindAdapter(address); | 445 adapter->FindAdapter(address); |
| 438 return adapter; | 446 return adapter; |
| 439 } | 447 } |
| 440 | 448 |
| 441 } // namespace chromeos | 449 } // namespace chromeos |
| OLD | NEW |