| 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/location.h" | 10 #include "base/location.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
| 16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 17 #include "chromeos/dbus/bluetooth_adapter_client.h" | 17 #include "chromeos/dbus/bluetooth_adapter_client.h" |
| 18 #include "chromeos/dbus/bluetooth_agent_manager_client.h" | 18 #include "chromeos/dbus/bluetooth_agent_manager_client.h" |
| 19 #include "chromeos/dbus/bluetooth_agent_service_provider.h" | 19 #include "chromeos/dbus/bluetooth_agent_service_provider.h" |
| 20 #include "chromeos/dbus/bluetooth_device_client.h" | 20 #include "chromeos/dbus/bluetooth_device_client.h" |
| 21 #include "chromeos/dbus/bluetooth_input_client.h" | 21 #include "chromeos/dbus/bluetooth_input_client.h" |
| 22 #include "chromeos/dbus/dbus_thread_manager.h" | 22 #include "chromeos/dbus/dbus_thread_manager.h" |
| 23 #include "device/bluetooth/bluetooth_adapter_profile_chromeos.h" | |
| 24 #include "device/bluetooth/bluetooth_device.h" | 23 #include "device/bluetooth/bluetooth_device.h" |
| 25 #include "device/bluetooth/bluetooth_device_chromeos.h" | 24 #include "device/bluetooth/bluetooth_device_chromeos.h" |
| 26 #include "device/bluetooth/bluetooth_pairing_chromeos.h" | 25 #include "device/bluetooth/bluetooth_pairing_chromeos.h" |
| 27 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h" | 26 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h" |
| 28 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.h" | 27 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.h" |
| 29 #include "device/bluetooth/bluetooth_remote_gatt_service_chromeos.h" | 28 #include "device/bluetooth/bluetooth_remote_gatt_service_chromeos.h" |
| 30 #include "device/bluetooth/bluetooth_socket_chromeos.h" | 29 #include "device/bluetooth/bluetooth_socket_chromeos.h" |
| 31 #include "device/bluetooth/bluetooth_socket_thread.h" | 30 #include "device/bluetooth/bluetooth_socket_thread.h" |
| 32 #include "device/bluetooth/bluetooth_uuid.h" | 31 #include "device/bluetooth/bluetooth_uuid.h" |
| 33 #include "third_party/cros_system_api/dbus/service_constants.h" | 32 #include "third_party/cros_system_api/dbus/service_constants.h" |
| (...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 const std::vector<uint8>& value) { | 922 const std::vector<uint8>& value) { |
| 924 DCHECK_EQ(static_cast<BluetoothRemoteGattServiceChromeOS*>( | 923 DCHECK_EQ(static_cast<BluetoothRemoteGattServiceChromeOS*>( |
| 925 descriptor->GetCharacteristic()->GetService())->GetAdapter(), | 924 descriptor->GetCharacteristic()->GetService())->GetAdapter(), |
| 926 this); | 925 this); |
| 927 | 926 |
| 928 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 927 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, |
| 929 observers_, | 928 observers_, |
| 930 GattDescriptorValueChanged(this, descriptor, value)); | 929 GattDescriptorValueChanged(this, descriptor, value)); |
| 931 } | 930 } |
| 932 | 931 |
| 933 void BluetoothAdapterChromeOS::UseProfile( | |
| 934 const BluetoothUUID& uuid, | |
| 935 const dbus::ObjectPath& device_path, | |
| 936 const BluetoothProfileManagerClient::Options& options, | |
| 937 BluetoothProfileServiceProvider::Delegate* delegate, | |
| 938 const ProfileRegisteredCallback& success_callback, | |
| 939 const ErrorCompletionCallback& error_callback) { | |
| 940 DCHECK(delegate); | |
| 941 | |
| 942 if (profiles_.find(uuid) != profiles_.end()) { | |
| 943 // TODO(jamuraa) check that the options are the same and error when they are | |
| 944 // not. | |
| 945 SetProfileDelegate(uuid, device_path, delegate, success_callback, | |
| 946 error_callback); | |
| 947 return; | |
| 948 } | |
| 949 | |
| 950 profiles_[uuid] = BluetoothAdapterProfileChromeOS::Register( | |
| 951 this, uuid, options, | |
| 952 base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfile, this, uuid, | |
| 953 device_path, delegate, success_callback, error_callback), | |
| 954 base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfileError, this, uuid, | |
| 955 error_callback)); | |
| 956 } | |
| 957 | |
| 958 void BluetoothAdapterChromeOS::ReleaseProfile(const BluetoothUUID& uuid) { | |
| 959 if (profiles_.find(uuid) != profiles_.end()) { | |
| 960 delete profiles_[uuid]; | |
| 961 profiles_.erase(uuid); | |
| 962 } | |
| 963 } | |
| 964 | |
| 965 void BluetoothAdapterChromeOS::OnRegisterProfile( | |
| 966 const BluetoothUUID& uuid, | |
| 967 const dbus::ObjectPath& device_path, | |
| 968 BluetoothProfileServiceProvider::Delegate* delegate, | |
| 969 const ProfileRegisteredCallback& success_callback, | |
| 970 const ErrorCompletionCallback& error_callback) { | |
| 971 SetProfileDelegate(uuid, device_path, delegate, success_callback, | |
| 972 error_callback); | |
| 973 } | |
| 974 | |
| 975 bool BluetoothAdapterChromeOS::SetProfileDelegate( | |
| 976 const BluetoothUUID& uuid, | |
| 977 const dbus::ObjectPath& device_path, | |
| 978 BluetoothProfileServiceProvider::Delegate* delegate, | |
| 979 const ProfileRegisteredCallback& success_callback, | |
| 980 const ErrorCompletionCallback& error_callback) { | |
| 981 if (profiles_[uuid]->SetDelegate(device_path, delegate)) { | |
| 982 success_callback.Run(profiles_[uuid]); | |
| 983 return true; | |
| 984 } | |
| 985 // Already set | |
| 986 error_callback.Run(bluetooth_agent_manager::kErrorAlreadyExists); | |
| 987 return false; | |
| 988 } | |
| 989 | |
| 990 void BluetoothAdapterChromeOS::OnRegisterProfileError( | |
| 991 const BluetoothUUID& uuid, | |
| 992 const ErrorCompletionCallback& error_callback, | |
| 993 const std::string& error_name, | |
| 994 const std::string& error_message) { | |
| 995 LOG(WARNING) << object_path_.value() | |
| 996 << ": Failed to register profile: " << error_name << ": " | |
| 997 << error_message; | |
| 998 error_callback.Run(error_message); | |
| 999 delete profiles_[uuid]; | |
| 1000 profiles_.erase(uuid); | |
| 1001 } | |
| 1002 | |
| 1003 void BluetoothAdapterChromeOS::OnSetDiscoverable( | 932 void BluetoothAdapterChromeOS::OnSetDiscoverable( |
| 1004 const base::Closure& callback, | 933 const base::Closure& callback, |
| 1005 const ErrorCallback& error_callback, | 934 const ErrorCallback& error_callback, |
| 1006 bool success) { | 935 bool success) { |
| 1007 DCHECK(IsPresent()); | 936 DCHECK(IsPresent()); |
| 1008 // Set the discoverable_timeout property to zero so the adapter remains | 937 // Set the discoverable_timeout property to zero so the adapter remains |
| 1009 // discoverable forever. | 938 // discoverable forever. |
| 1010 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 939 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> |
| 1011 GetProperties(object_path_)->discoverable_timeout.Set( | 940 GetProperties(object_path_)->discoverable_timeout.Set( |
| 1012 0, | 941 0, |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1202 | 1131 |
| 1203 // If the queued request resulted in a pending call, then let it | 1132 // If the queued request resulted in a pending call, then let it |
| 1204 // asynchonously process the remaining queued requests once the pending | 1133 // asynchonously process the remaining queued requests once the pending |
| 1205 // call returns. | 1134 // call returns. |
| 1206 if (discovery_request_pending_) | 1135 if (discovery_request_pending_) |
| 1207 return; | 1136 return; |
| 1208 } | 1137 } |
| 1209 } | 1138 } |
| 1210 | 1139 |
| 1211 } // namespace chromeos | 1140 } // namespace chromeos |
| OLD | NEW |