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

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: fix profile memory leaks when adapter is gone Created 5 years, 10 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 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 const std::vector<uint8>& value) { 923 const std::vector<uint8>& value) {
923 DCHECK_EQ(static_cast<BluetoothRemoteGattServiceChromeOS*>( 924 DCHECK_EQ(static_cast<BluetoothRemoteGattServiceChromeOS*>(
924 descriptor->GetCharacteristic()->GetService())->GetAdapter(), 925 descriptor->GetCharacteristic()->GetService())->GetAdapter(),
925 this); 926 this);
926 927
927 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, 928 FOR_EACH_OBSERVER(BluetoothAdapter::Observer,
928 observers_, 929 observers_,
929 GattDescriptorValueChanged(this, descriptor, value)); 930 GattDescriptorValueChanged(this, descriptor, value));
930 } 931 }
931 932
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
932 void BluetoothAdapterChromeOS::OnSetDiscoverable( 1003 void BluetoothAdapterChromeOS::OnSetDiscoverable(
933 const base::Closure& callback, 1004 const base::Closure& callback,
934 const ErrorCallback& error_callback, 1005 const ErrorCallback& error_callback,
935 bool success) { 1006 bool success) {
936 DCHECK(IsPresent()); 1007 DCHECK(IsPresent());
937 // Set the discoverable_timeout property to zero so the adapter remains 1008 // Set the discoverable_timeout property to zero so the adapter remains
938 // discoverable forever. 1009 // discoverable forever.
939 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> 1010 DBusThreadManager::Get()->GetBluetoothAdapterClient()->
940 GetProperties(object_path_)->discoverable_timeout.Set( 1011 GetProperties(object_path_)->discoverable_timeout.Set(
941 0, 1012 0,
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 1202
1132 // If the queued request resulted in a pending call, then let it 1203 // If the queued request resulted in a pending call, then let it
1133 // asynchonously process the remaining queued requests once the pending 1204 // asynchonously process the remaining queued requests once the pending
1134 // call returns. 1205 // call returns.
1135 if (discovery_request_pending_) 1206 if (discovery_request_pending_)
1136 return; 1207 return;
1137 } 1208 }
1138 } 1209 }
1139 1210
1140 } // namespace chromeos 1211 } // namespace chromeos
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_chromeos.h ('k') | device/bluetooth/bluetooth_adapter_profile_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698