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

Side by Side Diff: components/arc/bluetooth/arc_bluetooth_bridge.cc

Issue 2189183002: arc: bluetooth: Always acquire a NotifySession (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove IsNotifying since it's going to be private Created 4 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/arc/bluetooth/arc_bluetooth_bridge.h" 5 #include "components/arc/bluetooth/arc_bluetooth_bridge.h"
6 6
7 #include <bluetooth/bluetooth.h> 7 #include <bluetooth/bluetooth.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <sys/socket.h> 10 #include <sys/socket.h>
(...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 mojom::BluetoothGattIDPtr char_id, 1092 mojom::BluetoothGattIDPtr char_id,
1093 const RegisterForGattNotificationCallback& callback) { 1093 const RegisterForGattNotificationCallback& callback) {
1094 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( 1094 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic(
1095 std::move(remote_addr), std::move(service_id), std::move(char_id)); 1095 std::move(remote_addr), std::move(service_id), std::move(char_id));
1096 1096
1097 if (!characteristic) { 1097 if (!characteristic) {
1098 LOG(WARNING) << __func__ << " Characteristic is not existed."; 1098 LOG(WARNING) << __func__ << " Characteristic is not existed.";
1099 return; 1099 return;
1100 } 1100 }
1101 1101
1102 if (characteristic->IsNotifying()) {
1103 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS);
1104 return;
1105 }
1106
1107 characteristic->StartNotifySession( 1102 characteristic->StartNotifySession(
1108 base::Bind(&ArcBluetoothBridge::OnGattNotifyStartDone, 1103 base::Bind(&ArcBluetoothBridge::OnGattNotifyStartDone,
1109 weak_factory_.GetWeakPtr(), callback, 1104 weak_factory_.GetWeakPtr(), callback,
1110 characteristic->GetIdentifier()), 1105 characteristic->GetIdentifier()),
1111 base::Bind(&OnGattOperationError, callback)); 1106 base::Bind(&OnGattOperationError, callback));
1112 } 1107 }
1113 1108
1114 void ArcBluetoothBridge::DeregisterForGattNotification( 1109 void ArcBluetoothBridge::DeregisterForGattNotification(
1115 mojom::BluetoothAddressPtr remote_addr, 1110 mojom::BluetoothAddressPtr remote_addr,
1116 mojom::BluetoothGattServiceIDPtr service_id, 1111 mojom::BluetoothGattServiceIDPtr service_id,
1117 mojom::BluetoothGattIDPtr char_id, 1112 mojom::BluetoothGattIDPtr char_id,
1118 const DeregisterForGattNotificationCallback& callback) { 1113 const DeregisterForGattNotificationCallback& callback) {
1119 DCHECK(CalledOnValidThread()); 1114 DCHECK(CalledOnValidThread());
1120 1115
1121 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( 1116 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic(
1122 std::move(remote_addr), std::move(service_id), std::move(char_id)); 1117 std::move(remote_addr), std::move(service_id), std::move(char_id));
1123 1118
1124 if (!characteristic) { 1119 if (!characteristic) {
1125 LOG(WARNING) << __func__ << " Characteristic is not existed."; 1120 LOG(WARNING) << __func__ << " Characteristic is not existed.";
1126 return; 1121 return;
1127 } 1122 }
1128 1123
1129 if (!characteristic->IsNotifying()) {
1130 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS);
1131 return;
1132 }
1133
1134 std::string char_id_str = characteristic->GetIdentifier(); 1124 std::string char_id_str = characteristic->GetIdentifier();
1135 std::unique_ptr<BluetoothGattNotifySession> notify = 1125 std::unique_ptr<BluetoothGattNotifySession> notify =
1136 std::move(notification_session_[char_id_str]); 1126 std::move(notification_session_[char_id_str]);
1137 notification_session_.erase(char_id_str); 1127 notification_session_.erase(char_id_str);
1138 notify->Stop(base::Bind(&OnGattOperationDone, callback)); 1128 notify->Stop(base::Bind(&OnGattOperationDone, callback));
1139 } 1129 }
1140 1130
1141 void ArcBluetoothBridge::ReadRemoteRssi( 1131 void ArcBluetoothBridge::ReadRemoteRssi(
1142 mojom::BluetoothAddressPtr remote_addr, 1132 mojom::BluetoothAddressPtr remote_addr,
1143 const ReadRemoteRssiCallback& callback) { 1133 const ReadRemoteRssiCallback& callback) {
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 LOG(WARNING) << "Bluetooth instance is too old (version " << version 1642 LOG(WARNING) << "Bluetooth instance is too old (version " << version
1653 << ") need version " << version_need; 1643 << ") need version " << version_need;
1654 return false; 1644 return false;
1655 } 1645 }
1656 1646
1657 bool ArcBluetoothBridge::CalledOnValidThread() { 1647 bool ArcBluetoothBridge::CalledOnValidThread() {
1658 return thread_checker_.CalledOnValidThread(); 1648 return thread_checker_.CalledOnValidThread();
1659 } 1649 }
1660 1650
1661 } // namespace arc 1651 } // namespace arc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698