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

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: 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 BluetoothAdapterProfileChromeOS* BluetoothAdapterChromeOS::UseProfile(
882 const BluetoothUUID& uuid,
883 const dbus::ObjectPath& device_path,
884 const BluetoothProfileManagerClient::Options* options,
885 BluetoothProfileServiceProvider::Delegate* delegate,
886 const base::Closure& success_callback,
887 const ErrorCompletionCallback& error_callback) {
armansito 2015/01/21 01:44:47 Add a DCHECK for delegate.
Marie Janssen 2015/01/22 21:55:32 Done.
888 if (profiles_.find(uuid) != profiles_.end()) {
889 // TODO(jamuraa) check that the options are the same and error when they are
890 // not.
891 if (SetProfileDelegate(uuid, device_path, delegate, success_callback,
892 error_callback)) {
893 return profiles_[uuid];
894 } else {
armansito 2015/01/21 01:44:47 No need for else since you have an early return al
Marie Janssen 2015/01/22 21:55:32 Done.
895 return NULL;
896 }
897 }
898
899 profiles_[uuid] = BluetoothAdapterProfileChromeOS::Register(
900 this, uuid, options,
901 base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfile, this, uuid,
902 device_path, delegate, success_callback, error_callback),
armansito 2015/01/21 01:44:47 I don't think it's safe to pass a raw pointer to |
Marie Janssen 2015/01/22 21:55:32 This is consistent with the passing of |delegate|
903 base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfileError, this,
904 error_callback));
905
906 return profiles_[uuid];
907 }
908
909 void BluetoothAdapterChromeOS::ReleaseProfile(const BluetoothUUID& uuid) {
910 if (profiles_.find(uuid) != profiles_.end()) {
911 delete profiles_[uuid];
912 profiles_.erase(uuid);
913 }
914 }
915
916 void BluetoothAdapterChromeOS::OnRegisterProfile(
917 const BluetoothUUID& uuid,
918 const dbus::ObjectPath& device_path,
919 BluetoothProfileServiceProvider::Delegate* delegate,
920 const base::Closure& success_callback,
921 const ErrorCompletionCallback& error_callback) {
922 SetProfileDelegate(uuid, device_path, delegate, success_callback,
923 error_callback);
924 }
925
926 bool BluetoothAdapterChromeOS::SetProfileDelegate(
927 const BluetoothUUID& uuid,
928 const dbus::ObjectPath& device_path,
929 BluetoothProfileServiceProvider::Delegate* delegate,
930 const base::Closure& success_callback,
931 const ErrorCompletionCallback& error_callback) {
932 if (profiles_[uuid]->SetDelegate(device_path, delegate)) {
933 success_callback.Run();
934 return true;
935 } else {
armansito 2015/01/21 01:44:47 No need for else, since you have an early return a
Marie Janssen 2015/01/22 21:55:32 Done.
936 // Already set
937 error_callback.Run(bluetooth_agent_manager::kErrorAlreadyExists);
938 return false;
939 }
940 }
941
942 void BluetoothAdapterChromeOS::OnRegisterProfileError(
943 const ErrorCompletionCallback& error_callback,
944 const std::string& error_name,
945 const std::string& error_message) {
armansito 2015/01/21 01:44:47 Since registering the profile failed, should it be
Marie Janssen 2015/01/22 21:55:32 Done.
946 LOG(WARNING) << object_path_.value()
947 << ": Failed to register profile: " << error_name << ": "
948 << error_message;
949 error_callback.Run(error_message);
950 }
951
880 void BluetoothAdapterChromeOS::OnSetDiscoverable( 952 void BluetoothAdapterChromeOS::OnSetDiscoverable(
881 const base::Closure& callback, 953 const base::Closure& callback,
882 const ErrorCallback& error_callback, 954 const ErrorCallback& error_callback,
883 bool success) { 955 bool success) {
884 // Set the discoverable_timeout property to zero so the adapter remains 956 // Set the discoverable_timeout property to zero so the adapter remains
885 // discoverable forever. 957 // discoverable forever.
886 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> 958 DBusThreadManager::Get()->GetBluetoothAdapterClient()->
887 GetProperties(object_path_)->discoverable_timeout.Set( 959 GetProperties(object_path_)->discoverable_timeout.Set(
888 0, 960 0,
889 base::Bind(&BluetoothAdapterChromeOS::OnPropertyChangeCompleted, 961 base::Bind(&BluetoothAdapterChromeOS::OnPropertyChangeCompleted,
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 1140
1069 // If the queued request resulted in a pending call, then let it 1141 // If the queued request resulted in a pending call, then let it
1070 // asynchonously process the remaining queued requests once the pending 1142 // asynchonously process the remaining queued requests once the pending
1071 // call returns. 1143 // call returns.
1072 if (discovery_request_pending_) 1144 if (discovery_request_pending_)
1073 return; 1145 return;
1074 } 1146 }
1075 } 1147 }
1076 1148
1077 } // namespace chromeos 1149 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698