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

Side by Side Diff: content/browser/bluetooth/bluetooth_dispatcher_host.cc

Issue 1120373004: bluetooth: Browser-side implementation of connectGATT. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-request-device-implementation
Patch Set: Address jyasskin's comments Created 5 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/bluetooth/bluetooth_dispatcher_host.h" 5 #include "content/browser/bluetooth/bluetooth_dispatcher_host.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "content/common/bluetooth/bluetooth_messages.h" 8 #include "content/common/bluetooth/bluetooth_messages.h"
9 #include "device/bluetooth/bluetooth_adapter.h" 9 #include "device/bluetooth/bluetooth_adapter.h"
10 #include "device/bluetooth/bluetooth_adapter_factory.h" 10 #include "device/bluetooth/bluetooth_adapter_factory.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 BluetoothError::NOT_FOUND)); 93 BluetoothError::NOT_FOUND));
94 } 94 }
95 return; 95 return;
96 } 96 }
97 97
98 void BluetoothDispatcherHost::OnConnectGATT( 98 void BluetoothDispatcherHost::OnConnectGATT(
99 int thread_id, 99 int thread_id,
100 int request_id, 100 int request_id,
101 const std::string& device_instance_id) { 101 const std::string& device_instance_id) {
102 DCHECK_CURRENTLY_ON(BrowserThread::UI); 102 DCHECK_CURRENTLY_ON(BrowserThread::UI);
103 // TODO(ortuno): Add actual implementation of connectGATT. This needs to be 103 // TODO(ortuno): Right now it's pointless to check if the domain has access to
104 // done after the "allowed devices map" is implemented. 104 // the device, because any domain can connect to any device. But once
105 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, 105 // permissions are implemented we should check that the domain has access to
106 device_instance_id)); 106 // the device. https://crbug.com/484745
107 device::BluetoothDevice* device = adapter_->GetDevice(device_instance_id);
108 if (device == NULL) {
109 // Device could have gone out of range so it's no longer in
110 // BluetoothAdapter. Since we can't create a ATT Bearer without a device we
111 // reject with NetworkError.
112 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-conne ctgatt
113 Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id,
114 BluetoothError::NETWORK_ERROR));
115 return;
116 }
117 device->CreateGattConnection(
118 base::Bind(&BluetoothDispatcherHost::OnGATTConnectionCreated,
119 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id,
120 device_instance_id),
121 base::Bind(&BluetoothDispatcherHost::OnCreateGATTConnectionError,
122 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id,
123 device_instance_id));
107 } 124 }
108 125
109 void BluetoothDispatcherHost::OnDiscoverySessionStarted( 126 void BluetoothDispatcherHost::OnDiscoverySessionStarted(
110 int thread_id, 127 int thread_id,
111 int request_id, 128 int request_id,
112 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { 129 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) {
113 DCHECK_CURRENTLY_ON(BrowserThread::UI); 130 DCHECK_CURRENTLY_ON(BrowserThread::UI);
114 BrowserThread::PostDelayedTask( 131 BrowserThread::PostDelayedTask(
115 BrowserThread::UI, FROM_HERE, 132 BrowserThread::UI, FROM_HERE,
116 base::Bind(&BluetoothDispatcherHost::StopDiscoverySession, 133 base::Bind(&BluetoothDispatcherHost::StopDiscoverySession,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 182 }
166 183
167 void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id, 184 void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id,
168 int request_id) { 185 int request_id) {
169 DCHECK_CURRENTLY_ON(BrowserThread::UI); 186 DCHECK_CURRENTLY_ON(BrowserThread::UI);
170 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStoppedError"; 187 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStoppedError";
171 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, 188 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id,
172 BluetoothError::NOT_FOUND)); 189 BluetoothError::NOT_FOUND));
173 } 190 }
174 191
192 void BluetoothDispatcherHost::OnGATTConnectionCreated(
193 int thread_id,
194 int request_id,
195 const std::string& device_instance_id,
196 scoped_ptr<device::BluetoothGattConnection> connection) {
197 // TODO(ortuno): Save the BluetoothGattConnection so we can disconnect
198 // from it.
199 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id,
200 device_instance_id));
201 }
202
203 void BluetoothDispatcherHost::OnCreateGATTConnectionError(
204 int thread_id,
205 int request_id,
206 const std::string& device_instance_id,
207 device::BluetoothDevice::ConnectErrorCode error_code) {
208 // There was an error creating the ATT Bearer so we reject with
209 // NetworkError.
210 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-connect gatt
211 Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id,
212 BluetoothError::NETWORK_ERROR));
213 }
214
175 } // namespace content 215 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/bluetooth/bluetooth_dispatcher_host.h ('k') | content/child/bluetooth/bluetooth_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698