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

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

Issue 851123002: Manage profiles in BluetoothAdapter on ChromeOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments, slight refactor Created 5 years, 11 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
OLDNEW
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"
23 #include "device/bluetooth/bluetooth_device.h" 24 #include "device/bluetooth/bluetooth_device.h"
24 #include "device/bluetooth/bluetooth_device_chromeos.h" 25 #include "device/bluetooth/bluetooth_device_chromeos.h"
25 #include "device/bluetooth/bluetooth_pairing_chromeos.h" 26 #include "device/bluetooth/bluetooth_pairing_chromeos.h"
26 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h" 27 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h"
27 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.h" 28 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.h"
28 #include "device/bluetooth/bluetooth_remote_gatt_service_chromeos.h" 29 #include "device/bluetooth/bluetooth_remote_gatt_service_chromeos.h"
29 #include "device/bluetooth/bluetooth_socket_chromeos.h" 30 #include "device/bluetooth/bluetooth_socket_chromeos.h"
30 #include "device/bluetooth/bluetooth_socket_thread.h" 31 #include "device/bluetooth/bluetooth_socket_thread.h"
31 #include "device/bluetooth/bluetooth_uuid.h" 32 #include "device/bluetooth/bluetooth_uuid.h"
32 #include "third_party/cros_system_api/dbus/service_constants.h" 33 #include "third_party/cros_system_api/dbus/service_constants.h"
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 const std::vector<uint8>& value) { 871 const std::vector<uint8>& value) {
871 DCHECK_EQ(static_cast<BluetoothRemoteGattServiceChromeOS*>( 872 DCHECK_EQ(static_cast<BluetoothRemoteGattServiceChromeOS*>(
872 descriptor->GetCharacteristic()->GetService())->GetAdapter(), 873 descriptor->GetCharacteristic()->GetService())->GetAdapter(),
873 this); 874 this);
874 875
875 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, 876 FOR_EACH_OBSERVER(BluetoothAdapter::Observer,
876 observers_, 877 observers_,
877 GattDescriptorValueChanged(this, descriptor, value)); 878 GattDescriptorValueChanged(this, descriptor, value));
878 } 879 }
879 880
881 void BluetoothAdapterChromeOS::UseProfile(
882 const BluetoothUUID& uuid,
883 const dbus::ObjectPath& device_path,
884 const BluetoothProfileManagerClient::Options& options,
885 BluetoothProfileServiceProvider::Delegate* delegate,
886 const ProfileRegisteredCallback& success_callback,
887 const ErrorCompletionCallback& error_callback) {
888 DCHECK(delegate);
889
890 if (profiles_.find(uuid) != profiles_.end()) {
891 // TODO(jamuraa) check that the options are the same and error when they are
892 // not.
893 SetProfileDelegate(uuid, device_path, delegate, success_callback,
894 error_callback);
895 return;
896 }
897
898 profiles_[uuid] = BluetoothAdapterProfileChromeOS::Register(
899 this, uuid, options,
900 base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfile, this, uuid,
901 device_path, delegate, success_callback, error_callback),
902 base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfileError, this, uuid,
903 error_callback));
904 }
905
906 void BluetoothAdapterChromeOS::ReleaseProfile(const BluetoothUUID& uuid) {
907 if (profiles_.find(uuid) != profiles_.end()) {
908 delete profiles_[uuid];
909 profiles_.erase(uuid);
910 }
911 }
912
913 void BluetoothAdapterChromeOS::OnRegisterProfile(
914 const BluetoothUUID& uuid,
915 const dbus::ObjectPath& device_path,
916 BluetoothProfileServiceProvider::Delegate* delegate,
917 const ProfileRegisteredCallback& success_callback,
918 const ErrorCompletionCallback& error_callback) {
919 SetProfileDelegate(uuid, device_path, delegate, success_callback,
920 error_callback);
921 }
922
923 bool BluetoothAdapterChromeOS::SetProfileDelegate(
924 const BluetoothUUID& uuid,
925 const dbus::ObjectPath& device_path,
926 BluetoothProfileServiceProvider::Delegate* delegate,
927 const ProfileRegisteredCallback& success_callback,
928 const ErrorCompletionCallback& error_callback) {
929 if (profiles_[uuid]->SetDelegate(device_path, delegate)) {
930 success_callback.Run(profiles_[uuid]);
931 return true;
932 }
933 // Already set
934 error_callback.Run(bluetooth_agent_manager::kErrorAlreadyExists);
935 return false;
936 }
937
938 void BluetoothAdapterChromeOS::OnRegisterProfileError(
939 const BluetoothUUID& uuid,
940 const ErrorCompletionCallback& error_callback,
941 const std::string& error_name,
942 const std::string& error_message) {
943 LOG(WARNING) << object_path_.value()
944 << ": Failed to register profile: " << error_name << ": "
945 << error_message;
946 error_callback.Run(error_message);
947 delete profiles_[uuid];
948 profiles_.erase(uuid);
949 }
950
880 void BluetoothAdapterChromeOS::OnSetDiscoverable( 951 void BluetoothAdapterChromeOS::OnSetDiscoverable(
881 const base::Closure& callback, 952 const base::Closure& callback,
882 const ErrorCallback& error_callback, 953 const ErrorCallback& error_callback,
883 bool success) { 954 bool success) {
884 // Set the discoverable_timeout property to zero so the adapter remains 955 // Set the discoverable_timeout property to zero so the adapter remains
885 // discoverable forever. 956 // discoverable forever.
886 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> 957 DBusThreadManager::Get()->GetBluetoothAdapterClient()->
887 GetProperties(object_path_)->discoverable_timeout.Set( 958 GetProperties(object_path_)->discoverable_timeout.Set(
888 0, 959 0,
889 base::Bind(&BluetoothAdapterChromeOS::OnPropertyChangeCompleted, 960 base::Bind(&BluetoothAdapterChromeOS::OnPropertyChangeCompleted,
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 1139
1069 // If the queued request resulted in a pending call, then let it 1140 // If the queued request resulted in a pending call, then let it
1070 // asynchonously process the remaining queued requests once the pending 1141 // asynchonously process the remaining queued requests once the pending
1071 // call returns. 1142 // call returns.
1072 if (discovery_request_pending_) 1143 if (discovery_request_pending_)
1073 return; 1144 return;
1074 } 1145 }
1075 } 1146 }
1076 1147
1077 } // namespace chromeos 1148 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698