Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: device/bluetooth/bluetooth_adapter_experimental_chromeos.cc

Issue 14898004: Bluetooth: set a name for the adapter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_experimental_chromeos.h" 5 #include "device/bluetooth/bluetooth_adapter_experimental_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/command_line.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "chromeos/chromeos_switches.h"
12 #include "chromeos/dbus/dbus_thread_manager.h" 14 #include "chromeos/dbus/dbus_thread_manager.h"
13 #include "chromeos/dbus/experimental_bluetooth_adapter_client.h" 15 #include "chromeos/dbus/experimental_bluetooth_adapter_client.h"
14 #include "chromeos/dbus/experimental_bluetooth_device_client.h" 16 #include "chromeos/dbus/experimental_bluetooth_device_client.h"
15 #include "chromeos/dbus/experimental_bluetooth_input_client.h" 17 #include "chromeos/dbus/experimental_bluetooth_input_client.h"
16 #include "device/bluetooth/bluetooth_device.h" 18 #include "device/bluetooth/bluetooth_device.h"
17 #include "device/bluetooth/bluetooth_device_experimental_chromeos.h" 19 #include "device/bluetooth/bluetooth_device_experimental_chromeos.h"
18 20
19 using device::BluetoothAdapter; 21 using device::BluetoothAdapter;
20 using device::BluetoothDevice; 22 using device::BluetoothDevice;
21 23
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 return NULL; 305 return NULL;
304 } 306 }
305 307
306 void BluetoothAdapterExperimentalChromeOS::SetAdapter( 308 void BluetoothAdapterExperimentalChromeOS::SetAdapter(
307 const dbus::ObjectPath& object_path) { 309 const dbus::ObjectPath& object_path) {
308 DCHECK(!IsPresent()); 310 DCHECK(!IsPresent());
309 object_path_ = object_path; 311 object_path_ = object_path;
310 312
311 VLOG(1) << object_path_.value() << ": using adapter."; 313 VLOG(1) << object_path_.value() << ": using adapter.";
312 314
315 SetAdapterName();
316
313 ExperimentalBluetoothAdapterClient::Properties* properties = 317 ExperimentalBluetoothAdapterClient::Properties* properties =
314 DBusThreadManager::Get()->GetExperimentalBluetoothAdapterClient()-> 318 DBusThreadManager::Get()->GetExperimentalBluetoothAdapterClient()->
315 GetProperties(object_path_); 319 GetProperties(object_path_);
316 320
317 PresentChanged(true); 321 PresentChanged(true);
318 322
319 if (properties->powered.value()) 323 if (properties->powered.value())
320 PoweredChanged(true); 324 PoweredChanged(true);
321 if (properties->discovering.value()) 325 if (properties->discovering.value())
322 DiscoveringChanged(true); 326 DiscoveringChanged(true);
323 327
324 std::vector<dbus::ObjectPath> device_paths = 328 std::vector<dbus::ObjectPath> device_paths =
325 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> 329 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()->
326 GetDevicesForAdapter(object_path_); 330 GetDevicesForAdapter(object_path_);
327 331
328 for (std::vector<dbus::ObjectPath>::iterator iter = device_paths.begin(); 332 for (std::vector<dbus::ObjectPath>::iterator iter = device_paths.begin();
329 iter != device_paths.end(); ++iter) { 333 iter != device_paths.end(); ++iter) {
330 BluetoothDeviceExperimentalChromeOS* device_chromeos = 334 BluetoothDeviceExperimentalChromeOS* device_chromeos =
331 new BluetoothDeviceExperimentalChromeOS(this, *iter); 335 new BluetoothDeviceExperimentalChromeOS(this, *iter);
332 336
333 devices_[device_chromeos->GetAddress()] = device_chromeos; 337 devices_[device_chromeos->GetAddress()] = device_chromeos;
334 338
335 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 339 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
336 DeviceAdded(this, device_chromeos)); 340 DeviceAdded(this, device_chromeos));
337 } 341 }
338 } 342 }
339 343
344 void BluetoothAdapterExperimentalChromeOS::SetAdapterName() {
345 // Set a better name for the adapter than "BlueZ 5.x"; this isn't an ideal
346 // way to do this but it'll do for now. See http://crbug.com/126732 and
347 // http://crbug.com/126802.
348 std::string board;
349 const CommandLine* command_line = CommandLine::ForCurrentProcess();
350 if (command_line->HasSwitch(chromeos::switches::kChromeOSReleaseBoard)) {
351 board = command_line->
352 GetSwitchValueASCII(chromeos::switches::kChromeOSReleaseBoard);
353 }
354
355 std::string alias;
356 if (board.substr(0, 6) == "stumpy") {
357 alias = "Chromebox";
358 } else if (board.substr(0, 4) == "link") {
359 alias = "Chromebook Pixel";
360 } else {
361 alias = "Chromebook";
362 }
363
364 DBusThreadManager::Get()->GetExperimentalBluetoothAdapterClient()->
365 GetProperties(object_path_)->alias.Set(
366 alias,
367 base::Bind(&BluetoothAdapterExperimentalChromeOS::OnSetAlias,
368 weak_ptr_factory_.GetWeakPtr()));
369 }
370
371 void BluetoothAdapterExperimentalChromeOS::OnSetAlias(bool success) {
372 LOG_IF(WARNING, !success) << object_path_.value()
373 << ": Failed to set adapter alias";
374 }
375
340 void BluetoothAdapterExperimentalChromeOS::RemoveAdapter() { 376 void BluetoothAdapterExperimentalChromeOS::RemoveAdapter() {
341 DCHECK(IsPresent()); 377 DCHECK(IsPresent());
342 VLOG(1) << object_path_.value() << ": adapter removed."; 378 VLOG(1) << object_path_.value() << ": adapter removed.";
343 379
344 ExperimentalBluetoothAdapterClient::Properties* properties = 380 ExperimentalBluetoothAdapterClient::Properties* properties =
345 DBusThreadManager::Get()->GetExperimentalBluetoothAdapterClient()-> 381 DBusThreadManager::Get()->GetExperimentalBluetoothAdapterClient()->
346 GetProperties(object_path_); 382 GetProperties(object_path_);
347 383
348 object_path_ = dbus::ObjectPath(""); 384 object_path_ = dbus::ObjectPath("");
349 385
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 void BluetoothAdapterExperimentalChromeOS::OnStopDiscoveryError( 459 void BluetoothAdapterExperimentalChromeOS::OnStopDiscoveryError(
424 const ErrorCallback& error_callback, 460 const ErrorCallback& error_callback,
425 const std::string& error_name, 461 const std::string& error_name,
426 const std::string& error_message) { 462 const std::string& error_message) {
427 LOG(WARNING) << object_path_.value() << ": Failed to stop discovery: " 463 LOG(WARNING) << object_path_.value() << ": Failed to stop discovery: "
428 << error_name << ": " << error_message; 464 << error_name << ": " << error_message;
429 error_callback.Run(); 465 error_callback.Run();
430 } 466 }
431 467
432 } // namespace chromeos 468 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698