From b6283774ed9c61fed60fd38f7df675499f497d2b Mon Sep 17 00:00:00 2001 From: "keybuk@chromium.org" Date: Mon, 6 May 2013 21:38:16 +0000 Subject: Bluetooth: set a name for the adapter BUG=220820 TEST=bt_console, show R=youngki@chromium.org Review URL: https://chromiumcodereview.appspot.com/14898004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198544 0039d316-1c4b-4281-b951-d872f2087c98 --- .../bluetooth_adapter_experimental_chromeos.cc | 36 ++++++++++++++++++++++ .../bluetooth_adapter_experimental_chromeos.h | 5 +++ .../bluetooth_experimental_chromeos_unittest.cc | 1 - 3 files changed, 41 insertions(+), 1 deletion(-) (limited to 'device') diff --git a/device/bluetooth/bluetooth_adapter_experimental_chromeos.cc b/device/bluetooth/bluetooth_adapter_experimental_chromeos.cc index 6f3a185c..579dbb5 100644 --- a/device/bluetooth/bluetooth_adapter_experimental_chromeos.cc +++ b/device/bluetooth/bluetooth_adapter_experimental_chromeos.cc @@ -7,8 +7,10 @@ #include #include "base/bind.h" +#include "base/command_line.h" #include "base/logging.h" #include "base/metrics/histogram.h" +#include "chromeos/chromeos_switches.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/experimental_bluetooth_adapter_client.h" #include "chromeos/dbus/experimental_bluetooth_device_client.h" @@ -310,6 +312,8 @@ void BluetoothAdapterExperimentalChromeOS::SetAdapter( VLOG(1) << object_path_.value() << ": using adapter."; + SetAdapterName(); + ExperimentalBluetoothAdapterClient::Properties* properties = DBusThreadManager::Get()->GetExperimentalBluetoothAdapterClient()-> GetProperties(object_path_); @@ -337,6 +341,38 @@ void BluetoothAdapterExperimentalChromeOS::SetAdapter( } } +void BluetoothAdapterExperimentalChromeOS::SetAdapterName() { + // Set a better name for the adapter than "BlueZ 5.x"; this isn't an ideal + // way to do this but it'll do for now. See http://crbug.com/126732 and + // http://crbug.com/126802. + std::string board; + const CommandLine* command_line = CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(chromeos::switches::kChromeOSReleaseBoard)) { + board = command_line-> + GetSwitchValueASCII(chromeos::switches::kChromeOSReleaseBoard); + } + + std::string alias; + if (board.substr(0, 6) == "stumpy") { + alias = "Chromebox"; + } else if (board.substr(0, 4) == "link") { + alias = "Chromebook Pixel"; + } else { + alias = "Chromebook"; + } + + DBusThreadManager::Get()->GetExperimentalBluetoothAdapterClient()-> + GetProperties(object_path_)->alias.Set( + alias, + base::Bind(&BluetoothAdapterExperimentalChromeOS::OnSetAlias, + weak_ptr_factory_.GetWeakPtr())); +} + +void BluetoothAdapterExperimentalChromeOS::OnSetAlias(bool success) { + LOG_IF(WARNING, !success) << object_path_.value() + << ": Failed to set adapter alias"; +} + void BluetoothAdapterExperimentalChromeOS::RemoveAdapter() { DCHECK(IsPresent()); VLOG(1) << object_path_.value() << ": adapter removed."; diff --git a/device/bluetooth/bluetooth_adapter_experimental_chromeos.h b/device/bluetooth/bluetooth_adapter_experimental_chromeos.h index e761a86..a3a0655 100644 --- a/device/bluetooth/bluetooth_adapter_experimental_chromeos.h +++ b/device/bluetooth/bluetooth_adapter_experimental_chromeos.h @@ -95,6 +95,11 @@ class BluetoothAdapterExperimentalChromeOS // subsequently operate on that adapter until it is removed. void SetAdapter(const dbus::ObjectPath& object_path); + // Set the adapter name to one chosen from the system information, and method + // called by dbus:: on completion of the alias property change. + void SetAdapterName(); + void OnSetAlias(bool success); + // Remove the currently tracked adapter. IsPresent() will return false after // this is called. void RemoveAdapter(); diff --git a/device/bluetooth/bluetooth_experimental_chromeos_unittest.cc b/device/bluetooth/bluetooth_experimental_chromeos_unittest.cc index 3b8f997..1c6f5b6 100644 --- a/device/bluetooth/bluetooth_experimental_chromeos_unittest.cc +++ b/device/bluetooth/bluetooth_experimental_chromeos_unittest.cc @@ -338,7 +338,6 @@ TEST_F(BluetoothExperimentalChromeOSTest, AlreadyPresent) { EXPECT_FALSE(adapter_->IsPowered()); EXPECT_EQ(FakeBluetoothAdapterClient::kAdapterAddress, adapter_->GetAddress()); - EXPECT_EQ(FakeBluetoothAdapterClient::kAdapterName, adapter_->GetName()); EXPECT_FALSE(adapter_->IsDiscovering()); // There should be a device -- cgit v1.1