| 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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/observer_list.h" | 8 #include "base/observer_list.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" | 10 #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 observers_.RemoveObserver(observer); | 42 observers_.RemoveObserver(observer); |
| 43 } | 43 } |
| 44 | 44 |
| 45 virtual const std::string& Id() const { | 45 virtual const std::string& Id() const { |
| 46 return id_; | 46 return id_; |
| 47 } | 47 } |
| 48 | 48 |
| 49 virtual void StartDiscovery() { | 49 virtual void StartDiscovery() { |
| 50 VLOG(1) << id_ << ": StartDiscovery"; | 50 VLOG(1) << id_ << ": StartDiscovery"; |
| 51 DCHECK(bluetooth_adapter_client_); | 51 DCHECK(bluetooth_adapter_client_); |
| 52 bluetooth_adapter_client_->StartDiscovery(id_); | 52 bluetooth_adapter_client_->StartDiscovery(dbus::ObjectPath(id_)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 virtual void StopDiscovery() { | 55 virtual void StopDiscovery() { |
| 56 VLOG(1) << id_ << ": StopDiscovery"; | 56 VLOG(1) << id_ << ": StopDiscovery"; |
| 57 DCHECK(bluetooth_adapter_client_); | 57 DCHECK(bluetooth_adapter_client_); |
| 58 bluetooth_adapter_client_->StopDiscovery(id_); | 58 bluetooth_adapter_client_->StopDiscovery(dbus::ObjectPath(id_)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 // BluetoothAdapterClient::Observer override. | 61 // BluetoothAdapterClient::Observer override. |
| 62 virtual void DiscoveringPropertyChanged(const std::string& object_path, | 62 virtual void DiscoveringPropertyChanged(const dbus::ObjectPath& object_path, |
| 63 bool discovering) { | 63 bool discovering) { |
| 64 VLOG(1) << id_ << ": object_path = " << object_path << ", Discovering = " | 64 VLOG(1) << id_ << ": object_path = " << object_path.value() |
| 65 << discovering; | 65 << ", Discovering = " << discovering; |
| 66 if (object_path != id_) { | 66 if (object_path.value() != id_) { |
| 67 return; | 67 return; |
| 68 } | 68 } |
| 69 if (discovering) { | 69 if (discovering) { |
| 70 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 70 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 71 DiscoveryStarted(object_path)); | 71 DiscoveryStarted(object_path.value())); |
| 72 } else { | 72 } else { |
| 73 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 73 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 74 DiscoveryEnded(object_path)); | 74 DiscoveryEnded(object_path.value())); |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 // BluetoothAdapterClient::Observer override. | 78 // BluetoothAdapterClient::Observer override. |
| 79 virtual void DeviceFound(const std::string& object_path, | 79 virtual void DeviceFound(const dbus::ObjectPath& object_path, |
| 80 const std::string& address, | 80 const std::string& address, |
| 81 const base::DictionaryValue& device_properties) { | 81 const base::DictionaryValue& device_properties) { |
| 82 VLOG(1) << id_ << ": object_path = " << object_path << ", Device found: " | 82 VLOG(1) << id_ << ": object_path = " << object_path.value() |
| 83 << address << " (with " << device_properties.size() | 83 << ", Device found: " << address << " (with " |
| 84 << " properties)"; | 84 << device_properties.size() << " properties)"; |
| 85 if (object_path != id_) { | 85 if (object_path.value() != id_) { |
| 86 return; | 86 return; |
| 87 } | 87 } |
| 88 // TODO(vlaviano): later, we will want to persist the device. | 88 // TODO(vlaviano): later, we will want to persist the device. |
| 89 scoped_ptr<BluetoothDevice> device( | 89 scoped_ptr<BluetoothDevice> device( |
| 90 BluetoothDevice::Create(device_properties)); | 90 BluetoothDevice::Create(device_properties)); |
| 91 if (device.get() != NULL) { | 91 if (device.get() != NULL) { |
| 92 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 92 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 93 DeviceFound(object_path, device.get())); | 93 DeviceFound(object_path.value(), device.get())); |
| 94 } else { | 94 } else { |
| 95 LOG(WARNING) << "Could not create BluetoothDevice from properties."; | 95 LOG(WARNING) << "Could not create BluetoothDevice from properties."; |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 // BluetoothAdapterClient::Observer override. | 99 // BluetoothAdapterClient::Observer override. |
| 100 virtual void DeviceDisappeared(const std::string& object_path, | 100 virtual void DeviceDisappeared(const dbus::ObjectPath& object_path, |
| 101 const std::string& address) { | 101 const std::string& address) { |
| 102 VLOG(1) << id_ << ": object_path = " << object_path | 102 VLOG(1) << id_ << ": object_path = " << object_path.value() |
| 103 << ", Device disappeared: " << address; | 103 << ", Device disappeared: " << address; |
| 104 if (object_path != id_) { | 104 if (object_path.value() != id_) { |
| 105 return; | 105 return; |
| 106 } | 106 } |
| 107 // For now, we don't propagate this event to our observers. | 107 // For now, we don't propagate this event to our observers. |
| 108 } | 108 } |
| 109 | 109 |
| 110 private: | 110 private: |
| 111 // Owned by the dbus thread manager. | 111 // Owned by the dbus thread manager. |
| 112 BluetoothAdapterClient* bluetooth_adapter_client_; | 112 BluetoothAdapterClient* bluetooth_adapter_client_; |
| 113 | 113 |
| 114 ObserverList<BluetoothAdapter::Observer> observers_; | 114 ObserverList<BluetoothAdapter::Observer> observers_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 125 | 125 |
| 126 BluetoothAdapter::~BluetoothAdapter() { | 126 BluetoothAdapter::~BluetoothAdapter() { |
| 127 } | 127 } |
| 128 | 128 |
| 129 // static | 129 // static |
| 130 BluetoothAdapter* BluetoothAdapter::Create(const std::string& id) { | 130 BluetoothAdapter* BluetoothAdapter::Create(const std::string& id) { |
| 131 return new BluetoothAdapterImpl(id); | 131 return new BluetoothAdapterImpl(id); |
| 132 } | 132 } |
| 133 | 133 |
| 134 } // namespace chromeos | 134 } // namespace chromeos |
| OLD | NEW |