Chromium Code Reviews| Index: chrome/browser/chromeos/bluetooth/bluetooth_device.cc |
| diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_device.cc b/chrome/browser/chromeos/bluetooth/bluetooth_device.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f61aa6b438fb7c761886b0749d310342e38db441 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/bluetooth/bluetooth_device.cc |
| @@ -0,0 +1,120 @@ |
| +// 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_device.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/values.h" |
| +#include "third_party/cros_system_api/dbus/service_constants.h" |
| + |
| +namespace chromeos { |
| + |
| +class BluetoothDeviceImpl : public BluetoothDevice { |
| + public: |
| + BluetoothDeviceImpl(const std::string& address, |
| + uint32 bluetooth_class, |
| + const std::string& icon, |
| + const std::string& name, |
| + bool paired, |
| + const DictionaryValue& properties) |
|
satorux1
2011/10/26 19:26:55
base::DictionaryValue
Vince Laviano
2011/10/26 21:41:55
Done.
|
| + : address_(address), |
| + bluetooth_class_(bluetooth_class), |
| + icon_(icon), |
| + name_(name), |
|
satorux1
2011/10/26 19:26:55
device_name may be a bit clearer
Vince Laviano
2011/10/26 21:41:55
These are named identically to the underlying prop
|
| + paired_(paired), |
| + dictionary_rep_(properties.DeepCopy()) { |
| + DCHECK(dictionary_rep_); |
| + } |
| + |
| + virtual ~BluetoothDeviceImpl() { |
| + delete dictionary_rep_; |
| + } |
| + |
| + virtual const std::string& Address() const { |
| + return address_; |
| + } |
| + |
| + virtual uint32 BluetoothClass() const { |
| + return bluetooth_class_; |
| + } |
| + |
| + virtual const std::string& Icon() const { |
| + return icon_; |
| + } |
| + |
| + virtual const std::string& Name() const { |
| + return name_; |
| + } |
| + |
| + virtual bool Paired() const { |
| + return paired_; |
| + } |
| + |
| + virtual const DictionaryValue& DictionaryRep() const { |
| + DCHECK(dictionary_rep_); |
| + return *dictionary_rep_; |
| + } |
| + |
| + private: |
| + const std::string address_; |
| + uint32 bluetooth_class_; |
| + const std::string icon_; |
| + const std::string name_; |
| + bool paired_; |
| + DictionaryValue* dictionary_rep_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceImpl); |
| +}; |
| + |
| +BluetoothDevice::BluetoothDevice() { |
| +} |
| + |
| +BluetoothDevice::~BluetoothDevice() { |
| +} |
| + |
| +// static |
| +BluetoothDevice* BluetoothDevice::Create(const DictionaryValue& properties) { |
| + std::string address; |
| + uint32 bluetooth_class = 0; |
| + std::string icon; |
| + std::string name; |
| + bool paired = false; |
| + |
| + if (!properties.GetString(bluetooth_device::kAddressProperty, &address)) { |
| + LOG(ERROR) << "No address property"; |
| + return NULL; // mandatory |
| + } |
| + VLOG(1) << "address = " << address; |
| + |
| + // Note: DictionaryValue is Javascript-oriented and doesn't support unsigned |
| + // integers. |
| + if (!properties.GetInteger(bluetooth_device::kClassProperty, |
| + reinterpret_cast<int*>(&bluetooth_class))) { |
| + LOG(ERROR) << "No bluetooth_class property"; |
| + return NULL; // mandatory |
| + } |
| + VLOG(1) << "bluetooth_class = " << bluetooth_class; |
| + |
| + if (!properties.GetString(bluetooth_device::kIconProperty, &icon)) { |
| + LOG(WARNING) << "No icon property"; |
| + } |
| + VLOG(1) << "icon = " << icon; |
| + |
| + if (!properties.GetString(bluetooth_device::kNameProperty, &name)) { |
| + LOG(WARNING) << "No name property. Substituting MAC address."; |
| + // Populate name with mac address so that UI doesn't display a blank name. |
| + name = address; |
| + } |
| + VLOG(1) << "name = " << name; |
| + |
| + if (!properties.GetBoolean(bluetooth_device::kPairedProperty, &paired)) { |
| + LOG(ERROR) << "No paired property"; |
| + return NULL; // mandatory |
| + } |
| + |
| + return new BluetoothDeviceImpl(address, bluetooth_class, icon, name, paired, |
| + properties); |
| +} |
| + |
| +} // namespace chromeos |