| 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_chromeos.h" | 5 #include "device/bluetooth/bluetooth_adapter_chromeos.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 void BluetoothAdapterChromeOS::PoweredChanged(bool powered) { | 227 void BluetoothAdapterChromeOS::PoweredChanged(bool powered) { |
| 228 if (powered == powered_) | 228 if (powered == powered_) |
| 229 return; | 229 return; |
| 230 | 230 |
| 231 powered_ = powered; | 231 powered_ = powered; |
| 232 | 232 |
| 233 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 233 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 234 AdapterPoweredChanged(this, powered_)); | 234 AdapterPoweredChanged(this, powered_)); |
| 235 } | 235 } |
| 236 | 236 |
| 237 void BluetoothAdapterChromeOS::NotifyDeviceChanged( |
| 238 BluetoothDeviceChromeOS* device) { |
| 239 DCHECK(device->adapter_ == this); |
| 240 |
| 241 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 242 DeviceChanged(this, device)); |
| 243 } |
| 244 |
| 237 void BluetoothAdapterChromeOS::OnStartDiscovery( | 245 void BluetoothAdapterChromeOS::OnStartDiscovery( |
| 238 const base::Closure& callback, | 246 const base::Closure& callback, |
| 239 const ErrorCallback& error_callback, | 247 const ErrorCallback& error_callback, |
| 240 const dbus::ObjectPath& adapter_path, | 248 const dbus::ObjectPath& adapter_path, |
| 241 bool success) { | 249 bool success) { |
| 242 if (success) { | 250 if (success) { |
| 243 if (discovering_count_++ == 0) { | 251 if (discovering_count_++ == 0) { |
| 244 VLOG(1) << object_path_.value() << ": started discovery."; | 252 VLOG(1) << object_path_.value() << ": started discovery."; |
| 245 | 253 |
| 246 // Clear devices found in previous discovery attempts | 254 // Clear devices found in previous discovery attempts |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 devices_[address] = device; | 367 devices_[address] = device; |
| 360 } | 368 } |
| 361 | 369 |
| 362 if (!device->HasObjectPath()) { | 370 if (!device->HasObjectPath()) { |
| 363 VLOG(1) << "Assigned object path " << device_path.value() << " to device " | 371 VLOG(1) << "Assigned object path " << device_path.value() << " to device " |
| 364 << address; | 372 << address; |
| 365 device->SetObjectPath(device_path); | 373 device->SetObjectPath(device_path); |
| 366 } | 374 } |
| 367 device->Update(properties, true); | 375 device->Update(properties, true); |
| 368 | 376 |
| 369 if (update_device) { | 377 if (update_device) |
| 370 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 378 NotifyDeviceChanged(device); |
| 371 DeviceChanged(this, device)); | 379 else { |
| 372 } else { | |
| 373 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 380 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 374 DeviceAdded(this, device)); | 381 DeviceAdded(this, device)); |
| 375 } | 382 } |
| 376 } | 383 } |
| 377 | 384 |
| 378 void BluetoothAdapterChromeOS::ClearDevices() { | 385 void BluetoothAdapterChromeOS::ClearDevices() { |
| 379 DevicesMap replace; | 386 DevicesMap replace; |
| 380 devices_.swap(replace); | 387 devices_.swap(replace); |
| 381 for (DevicesMap::iterator iter = replace.begin(); | 388 for (DevicesMap::iterator iter = replace.begin(); |
| 382 iter != replace.end(); ++iter) { | 389 iter != replace.end(); ++iter) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 DeviceRemoved(this, device)); | 428 DeviceRemoved(this, device)); |
| 422 | 429 |
| 423 VLOG(1) << "Removed device " << device->GetAddress(); | 430 VLOG(1) << "Removed device " << device->GetAddress(); |
| 424 | 431 |
| 425 delete device; | 432 delete device; |
| 426 devices_.erase(temp); | 433 devices_.erase(temp); |
| 427 } else { | 434 } else { |
| 428 VLOG(1) << "Removed object path from device " << device->GetAddress(); | 435 VLOG(1) << "Removed object path from device " << device->GetAddress(); |
| 429 device->RemoveObjectPath(); | 436 device->RemoveObjectPath(); |
| 430 | 437 |
| 431 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 438 NotifyDeviceChanged(device); |
| 432 DeviceChanged(this, device)); | |
| 433 } | 439 } |
| 434 } | 440 } |
| 435 } | 441 } |
| 436 | 442 |
| 437 void BluetoothAdapterChromeOS::DevicesChanged( | 443 void BluetoothAdapterChromeOS::DevicesChanged( |
| 438 const std::vector<dbus::ObjectPath>& devices) { | 444 const std::vector<dbus::ObjectPath>& devices) { |
| 439 for (std::vector<dbus::ObjectPath>::const_iterator iter = | 445 for (std::vector<dbus::ObjectPath>::const_iterator iter = |
| 440 devices.begin(); iter != devices.end(); ++iter) | 446 devices.begin(); iter != devices.end(); ++iter) |
| 441 UpdateDevice(*iter); | 447 UpdateDevice(*iter); |
| 442 } | 448 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 device = static_cast<BluetoothDeviceChromeOS*>(iter->second); | 484 device = static_cast<BluetoothDeviceChromeOS*>(iter->second); |
| 479 } else { | 485 } else { |
| 480 device = BluetoothDeviceChromeOS::Create(this); | 486 device = BluetoothDeviceChromeOS::Create(this); |
| 481 devices_[address] = device; | 487 devices_[address] = device; |
| 482 } | 488 } |
| 483 | 489 |
| 484 VLOG(1) << "Device " << address << " is visible to the adapter"; | 490 VLOG(1) << "Device " << address << " is visible to the adapter"; |
| 485 device->SetDiscovered(true); | 491 device->SetDiscovered(true); |
| 486 device->Update(&properties, false); | 492 device->Update(&properties, false); |
| 487 | 493 |
| 488 if (update_device) { | 494 if (update_device) |
| 489 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 495 NotifyDeviceChanged(device); |
| 490 DeviceChanged(this, device)); | 496 else { |
| 491 } else { | |
| 492 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 497 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 493 DeviceAdded(this, device)); | 498 DeviceAdded(this, device)); |
| 494 } | 499 } |
| 495 } | 500 } |
| 496 | 501 |
| 497 void BluetoothAdapterChromeOS::DeviceDisappeared( | 502 void BluetoothAdapterChromeOS::DeviceDisappeared( |
| 498 const dbus::ObjectPath& adapter_path, | 503 const dbus::ObjectPath& adapter_path, |
| 499 const std::string& address) { | 504 const std::string& address) { |
| 500 if (adapter_path != object_path_) | 505 if (adapter_path != object_path_) |
| 501 return; | 506 return; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 517 VLOG(1) << "Discovered device " << device->GetAddress() | 522 VLOG(1) << "Discovered device " << device->GetAddress() |
| 518 << " is no longer visible to the adapter"; | 523 << " is no longer visible to the adapter"; |
| 519 | 524 |
| 520 delete device; | 525 delete device; |
| 521 devices_.erase(iter); | 526 devices_.erase(iter); |
| 522 } else { | 527 } else { |
| 523 VLOG(1) << "Paired device " << device->GetAddress() | 528 VLOG(1) << "Paired device " << device->GetAddress() |
| 524 << " is no longer visible to the adapter"; | 529 << " is no longer visible to the adapter"; |
| 525 device->SetDiscovered(false); | 530 device->SetDiscovered(false); |
| 526 | 531 |
| 527 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 532 NotifyDeviceChanged(device); |
| 528 DeviceChanged(this, device)); | |
| 529 } | 533 } |
| 530 } | 534 } |
| 531 | 535 |
| 532 } // namespace chromeos | 536 } // namespace chromeos |
| OLD | NEW |