| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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_chromeos.h" | 5 #include "device/bluetooth/bluetooth_adapter_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/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/sequenced_task_runner.h" |
| 13 #include "base/single_thread_task_runner.h" |
| 12 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
| 15 #include "base/thread_task_runner_handle.h" |
| 13 #include "chromeos/dbus/bluetooth_adapter_client.h" | 16 #include "chromeos/dbus/bluetooth_adapter_client.h" |
| 14 #include "chromeos/dbus/bluetooth_agent_manager_client.h" | 17 #include "chromeos/dbus/bluetooth_agent_manager_client.h" |
| 15 #include "chromeos/dbus/bluetooth_agent_service_provider.h" | 18 #include "chromeos/dbus/bluetooth_agent_service_provider.h" |
| 16 #include "chromeos/dbus/bluetooth_device_client.h" | 19 #include "chromeos/dbus/bluetooth_device_client.h" |
| 17 #include "chromeos/dbus/bluetooth_input_client.h" | 20 #include "chromeos/dbus/bluetooth_input_client.h" |
| 18 #include "chromeos/dbus/dbus_thread_manager.h" | 21 #include "chromeos/dbus/dbus_thread_manager.h" |
| 19 #include "device/bluetooth/bluetooth_device.h" | 22 #include "device/bluetooth/bluetooth_device.h" |
| 20 #include "device/bluetooth/bluetooth_device_chromeos.h" | 23 #include "device/bluetooth/bluetooth_device_chromeos.h" |
| 21 #include "device/bluetooth/bluetooth_pairing_chromeos.h" | 24 #include "device/bluetooth/bluetooth_pairing_chromeos.h" |
| 25 #include "device/bluetooth/bluetooth_socket_thread.h" |
| 22 #include "third_party/cros_system_api/dbus/service_constants.h" | 26 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 23 | 27 |
| 24 using device::BluetoothAdapter; | 28 using device::BluetoothAdapter; |
| 25 using device::BluetoothDevice; | 29 using device::BluetoothDevice; |
| 26 | 30 |
| 27 namespace { | 31 namespace { |
| 28 | 32 |
| 29 // The agent path is relatively meaningless since BlueZ only permits one to | 33 // The agent path is relatively meaningless since BlueZ only permits one to |
| 30 // exist per D-Bus connection, it just has to be unique within Chromium. | 34 // exist per D-Bus connection, it just has to be unique within Chromium. |
| 31 const char kAgentPath[] = "/org/chromium/bluetooth_agent"; | 35 const char kAgentPath[] = "/org/chromium/bluetooth_agent"; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 57 // static | 61 // static |
| 58 base::WeakPtr<BluetoothAdapter> BluetoothAdapterChromeOS::CreateAdapter() { | 62 base::WeakPtr<BluetoothAdapter> BluetoothAdapterChromeOS::CreateAdapter() { |
| 59 BluetoothAdapterChromeOS* adapter = new BluetoothAdapterChromeOS(); | 63 BluetoothAdapterChromeOS* adapter = new BluetoothAdapterChromeOS(); |
| 60 return adapter->weak_ptr_factory_.GetWeakPtr(); | 64 return adapter->weak_ptr_factory_.GetWeakPtr(); |
| 61 } | 65 } |
| 62 | 66 |
| 63 BluetoothAdapterChromeOS::BluetoothAdapterChromeOS() | 67 BluetoothAdapterChromeOS::BluetoothAdapterChromeOS() |
| 64 : num_discovery_sessions_(0), | 68 : num_discovery_sessions_(0), |
| 65 discovery_request_pending_(false), | 69 discovery_request_pending_(false), |
| 66 weak_ptr_factory_(this) { | 70 weak_ptr_factory_(this) { |
| 71 ui_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 72 socket_thread_ = device::BluetoothSocketThread::Get(); |
| 73 |
| 67 DBusThreadManager::Get()->GetBluetoothAdapterClient()->AddObserver(this); | 74 DBusThreadManager::Get()->GetBluetoothAdapterClient()->AddObserver(this); |
| 68 DBusThreadManager::Get()->GetBluetoothDeviceClient()->AddObserver(this); | 75 DBusThreadManager::Get()->GetBluetoothDeviceClient()->AddObserver(this); |
| 69 DBusThreadManager::Get()->GetBluetoothInputClient()->AddObserver(this); | 76 DBusThreadManager::Get()->GetBluetoothInputClient()->AddObserver(this); |
| 70 | 77 |
| 71 // Register the pairing agent. | 78 // Register the pairing agent. |
| 72 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); | 79 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); |
| 73 agent_.reset(BluetoothAgentServiceProvider::Create( | 80 agent_.reset(BluetoothAgentServiceProvider::Create( |
| 74 system_bus, dbus::ObjectPath(kAgentPath), this)); | 81 system_bus, dbus::ObjectPath(kAgentPath), this)); |
| 75 DCHECK(agent_.get()); | 82 DCHECK(agent_.get()); |
| 76 | 83 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 | 273 |
| 267 void BluetoothAdapterChromeOS::DeviceAdded( | 274 void BluetoothAdapterChromeOS::DeviceAdded( |
| 268 const dbus::ObjectPath& object_path) { | 275 const dbus::ObjectPath& object_path) { |
| 269 BluetoothDeviceClient::Properties* properties = | 276 BluetoothDeviceClient::Properties* properties = |
| 270 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 277 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> |
| 271 GetProperties(object_path); | 278 GetProperties(object_path); |
| 272 if (properties->adapter.value() != object_path_) | 279 if (properties->adapter.value() != object_path_) |
| 273 return; | 280 return; |
| 274 | 281 |
| 275 BluetoothDeviceChromeOS* device_chromeos = | 282 BluetoothDeviceChromeOS* device_chromeos = |
| 276 new BluetoothDeviceChromeOS(this, object_path); | 283 new BluetoothDeviceChromeOS(this, |
| 284 object_path, |
| 285 ui_task_runner_, |
| 286 socket_thread_); |
| 277 DCHECK(devices_.find(device_chromeos->GetAddress()) == devices_.end()); | 287 DCHECK(devices_.find(device_chromeos->GetAddress()) == devices_.end()); |
| 278 | 288 |
| 279 devices_[device_chromeos->GetAddress()] = device_chromeos; | 289 devices_[device_chromeos->GetAddress()] = device_chromeos; |
| 280 | 290 |
| 281 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 291 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 282 DeviceAdded(this, device_chromeos)); | 292 DeviceAdded(this, device_chromeos)); |
| 283 } | 293 } |
| 284 | 294 |
| 285 void BluetoothAdapterChromeOS::DeviceRemoved( | 295 void BluetoothAdapterChromeOS::DeviceRemoved( |
| 286 const dbus::ObjectPath& object_path) { | 296 const dbus::ObjectPath& object_path) { |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 DiscoverableChanged(true); | 586 DiscoverableChanged(true); |
| 577 if (properties->discovering.value()) | 587 if (properties->discovering.value()) |
| 578 DiscoveringChanged(true); | 588 DiscoveringChanged(true); |
| 579 | 589 |
| 580 std::vector<dbus::ObjectPath> device_paths = | 590 std::vector<dbus::ObjectPath> device_paths = |
| 581 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 591 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> |
| 582 GetDevicesForAdapter(object_path_); | 592 GetDevicesForAdapter(object_path_); |
| 583 | 593 |
| 584 for (std::vector<dbus::ObjectPath>::iterator iter = device_paths.begin(); | 594 for (std::vector<dbus::ObjectPath>::iterator iter = device_paths.begin(); |
| 585 iter != device_paths.end(); ++iter) { | 595 iter != device_paths.end(); ++iter) { |
| 586 BluetoothDeviceChromeOS* device_chromeos = | 596 DeviceAdded(*iter); |
| 587 new BluetoothDeviceChromeOS(this, *iter); | |
| 588 | |
| 589 devices_[device_chromeos->GetAddress()] = device_chromeos; | |
| 590 | |
| 591 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | |
| 592 DeviceAdded(this, device_chromeos)); | |
| 593 } | 597 } |
| 594 } | 598 } |
| 595 | 599 |
| 596 void BluetoothAdapterChromeOS::SetDefaultAdapterName() { | 600 void BluetoothAdapterChromeOS::SetDefaultAdapterName() { |
| 597 std::string board = base::SysInfo::GetLsbReleaseBoard(); | 601 std::string board = base::SysInfo::GetLsbReleaseBoard(); |
| 598 std::string alias; | 602 std::string alias; |
| 599 if (board.substr(0, 6) == "stumpy") { | 603 if (board.substr(0, 6) == "stumpy") { |
| 600 alias = "Chromebox"; | 604 alias = "Chromebox"; |
| 601 } else if (board.substr(0, 4) == "link") { | 605 } else if (board.substr(0, 4) == "link") { |
| 602 alias = "Chromebook Pixel"; | 606 alias = "Chromebook Pixel"; |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 | 872 |
| 869 // If the queued request resulted in a pending call, then let it | 873 // If the queued request resulted in a pending call, then let it |
| 870 // asynchonously process the remaining queued requests once the pending | 874 // asynchonously process the remaining queued requests once the pending |
| 871 // call returns. | 875 // call returns. |
| 872 if (discovery_request_pending_) | 876 if (discovery_request_pending_) |
| 873 return; | 877 return; |
| 874 } | 878 } |
| 875 } | 879 } |
| 876 | 880 |
| 877 } // namespace chromeos | 881 } // namespace chromeos |
| OLD | NEW |