Index: chrome/browser/chromeos/bluetooth/bluetooth_adapter.cc |
diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_adapter.cc b/chrome/browser/chromeos/bluetooth/bluetooth_adapter.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..826e8226795851244f3b880ac1ca4e30e4285b82 |
--- /dev/null |
+++ b/chrome/browser/chromeos/bluetooth/bluetooth_adapter.cc |
@@ -0,0 +1,136 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" |
+ |
+#include "base/observer_list.h" |
+#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" |
+#include "chrome/browser/chromeos/dbus/bluetooth_adapter_client.h" |
+#include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
+ |
+namespace base { |
+class DictionaryValue; |
+} // namespace base |
satorux1
2011/10/26 19:26:55
In .cc file, we usually don't forward like this, a
Vince Laviano
2011/10/26 21:41:55
Done.
|
+ |
+using base::DictionaryValue; |
satorux1
2011/10/26 19:26:55
Let's not do this. saving 6 bytes don't help much.
Vince Laviano
2011/10/26 21:41:55
Done.
|
+ |
+namespace chromeos { |
+ |
+class BluetoothAdapterImpl : public BluetoothAdapter, |
+ public BluetoothAdapterClient::Observer { |
+ public: |
+ explicit BluetoothAdapterImpl(const std::string& id) : id_(id) { |
+ DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get(); |
+ DCHECK(dbus_thread_manager); |
+ bluetooth_adapter_client_ = dbus_thread_manager->bluetooth_adapter_client(); |
+ DCHECK(bluetooth_adapter_client_); |
+ bluetooth_adapter_client_->AddObserver(this, id_); |
+ } |
+ |
+ virtual ~BluetoothAdapterImpl() { |
+ DCHECK(bluetooth_adapter_client_); |
+ bluetooth_adapter_client_->RemoveObserver(this, id_); |
+ } |
+ |
+ virtual void AddObserver(BluetoothAdapter::Observer* observer) { |
+ VLOG(1) << id_ << ": AddObserver"; |
+ DCHECK(observer); |
+ observers_.AddObserver(observer); |
+ } |
+ |
+ virtual void RemoveObserver(BluetoothAdapter::Observer* observer) { |
+ VLOG(1) << id_ << ": RemoveObserver"; |
+ DCHECK(observer); |
+ observers_.RemoveObserver(observer); |
+ } |
+ |
+ virtual const std::string& Id() const { |
+ return id_; |
+ } |
+ |
+ virtual void StartDiscovery() { |
+ VLOG(1) << id_ << ": StartDiscovery"; |
+ DCHECK(bluetooth_adapter_client_); |
+ bluetooth_adapter_client_->StartDiscovery(id_); |
+ } |
+ |
+ virtual void StopDiscovery() { |
+ VLOG(1) << id_ << ": StopDiscovery"; |
+ DCHECK(bluetooth_adapter_client_); |
+ bluetooth_adapter_client_->StopDiscovery(id_); |
+ } |
+ |
+ // BluetoothAdapterClient::Observer override. |
+ virtual void DiscoveringPropertyChanged(const std::string& object_path, |
+ bool discovering) { |
+ VLOG(1) << id_ << ": object_path = " << object_path << ", Discovering = " |
+ << discovering; |
+ if (object_path != id_) { |
+ return; |
+ } |
+ if (discovering) { |
+ FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
+ DiscoveryStarted(object_path)); |
+ } else { |
+ FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
+ DiscoveryEnded(object_path)); |
+ } |
+ } |
+ |
+ // BluetoothAdapterClient::Observer override. |
+ virtual void DeviceFound(const std::string& object_path, |
+ const std::string& address, |
+ const DictionaryValue& device_properties) { |
+ VLOG(1) << id_ << ": object_path = " << object_path << ", Device found: " |
+ << address << " (with " << device_properties.size() << " properties)"; |
satorux1
2011/10/26 19:26:55
<< for logging should be vertically aligned like:
Vince Laviano
2011/10/26 21:41:55
Done.
|
+ if (object_path != id_) { |
+ return; |
+ } |
+ BluetoothDevice *device = BluetoothDevice::Create(device_properties); |
satorux1
2011/10/26 19:26:55
Move * to left.
Vince Laviano
2011/10/26 21:41:55
Done.
|
+ if (device != NULL) { |
+ FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
+ DeviceFound(object_path, device)); |
+ } else { |
+ LOG(WARNING) << "Could not create BluetoothDevice from properties."; |
+ } |
+ // TODO(vlaviano): later, we will want to persist the device. |
+ delete device; |
satorux1
2011/10/26 19:26:55
You might want to use scoped_ptr<> instead
Vince Laviano
2011/10/26 21:41:55
Done.
|
+ } |
+ |
+ // BluetoothAdapterClient::Observer override. |
+ virtual void DeviceDisappeared(const std::string& object_path, |
+ const std::string& address) { |
+ VLOG(1) << id_ << ": object_path = " << object_path |
+ << ", Device disappeared: " << address; |
+ if (object_path != id_) { |
+ return; |
+ } |
+ // For now, we don't propagate this event to our observers. |
+ } |
+ |
+ private: |
+ // Owned by the dbus thread manager. |
+ BluetoothAdapterClient* bluetooth_adapter_client_; |
+ |
+ ObserverList<BluetoothAdapter::Observer> observers_; |
+ |
+ // An opaque identifier that we provide to clients. |
+ // We use the dbus object path for the adapter as the id. |
+ const std::string id_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterImpl); |
+}; |
+ |
+BluetoothAdapter::BluetoothAdapter() { |
+} |
+ |
+BluetoothAdapter::~BluetoothAdapter() { |
+} |
+ |
+// static |
+BluetoothAdapter* BluetoothAdapter::Create(const std::string& id) { |
+ return new BluetoothAdapterImpl(id); |
satorux1
2011/10/26 19:26:55
It's totally fine to hide Impl class in .cc file,
Vince Laviano
2011/10/26 21:41:55
Yes, I'd prefer to keep the separation.
|
+} |
+ |
+} // namespace chromeos |