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

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

Issue 1382743002: bluetooth: Add characteristicvaluechanged event (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-notifications-1
Patch Set: Final clean up Created 5 years, 2 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 // NETWORK_ERROR Note: 5 // NETWORK_ERROR Note:
6 // When a device can't be found in the BluetoothAdapter, that generally 6 // When a device can't be found in the BluetoothAdapter, that generally
7 // indicates that it's gone out of range. We reject with a NetworkError in that 7 // indicates that it's gone out of range. We reject with a NetworkError in that
8 // case. 8 // case.
9 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-conne ctgatt 9 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-conne ctgatt
10 10
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 bool handled = true; 206 bool handled = true;
207 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcherHost, message) 207 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcherHost, message)
208 IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice) 208 IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice)
209 IPC_MESSAGE_HANDLER(BluetoothHostMsg_ConnectGATT, OnConnectGATT) 209 IPC_MESSAGE_HANDLER(BluetoothHostMsg_ConnectGATT, OnConnectGATT)
210 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetPrimaryService, OnGetPrimaryService) 210 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetPrimaryService, OnGetPrimaryService)
211 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristic, OnGetCharacteristic) 211 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristic, OnGetCharacteristic)
212 IPC_MESSAGE_HANDLER(BluetoothHostMsg_ReadValue, OnReadValue) 212 IPC_MESSAGE_HANDLER(BluetoothHostMsg_ReadValue, OnReadValue)
213 IPC_MESSAGE_HANDLER(BluetoothHostMsg_WriteValue, OnWriteValue) 213 IPC_MESSAGE_HANDLER(BluetoothHostMsg_WriteValue, OnWriteValue)
214 IPC_MESSAGE_HANDLER(BluetoothHostMsg_StartNotifications, OnStartNotifications) 214 IPC_MESSAGE_HANDLER(BluetoothHostMsg_StartNotifications, OnStartNotifications)
215 IPC_MESSAGE_HANDLER(BluetoothHostMsg_StopNotifications, OnStopNotifications) 215 IPC_MESSAGE_HANDLER(BluetoothHostMsg_StopNotifications, OnStopNotifications)
216 IPC_MESSAGE_HANDLER(BluetoothHostMsg_RegisterCharacteristic,
217 OnRegisterCharacteristicObject);
218 IPC_MESSAGE_HANDLER(BluetoothHostMsg_UnregisterCharacteristic,
219 OnUnregisterCharacteristicObject);
216 IPC_MESSAGE_UNHANDLED(handled = false) 220 IPC_MESSAGE_UNHANDLED(handled = false)
217 IPC_END_MESSAGE_MAP() 221 IPC_END_MESSAGE_MAP()
218 return handled; 222 return handled;
219 } 223 }
220 224
221 void BluetoothDispatcherHost::SetBluetoothAdapterForTesting( 225 void BluetoothDispatcherHost::SetBluetoothAdapterForTesting(
222 scoped_refptr<device::BluetoothAdapter> mock_adapter) { 226 scoped_refptr<device::BluetoothAdapter> mock_adapter) {
223 DCHECK_CURRENTLY_ON(BrowserThread::UI); 227 DCHECK_CURRENTLY_ON(BrowserThread::UI);
224 current_delay_time_ = kTestingDelayTime; 228 current_delay_time_ = kTestingDelayTime;
225 // Reset the discovery session timer to use the new delay time. 229 // Reset the discovery session timer to use the new delay time.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 if (session->chooser) { 368 if (session->chooser) {
365 session->chooser->RemoveDevice(device->GetAddress()); 369 session->chooser->RemoveDevice(device->GetAddress());
366 } 370 }
367 } 371 }
368 } 372 }
369 373
370 void BluetoothDispatcherHost::GattCharacteristicValueChanged( 374 void BluetoothDispatcherHost::GattCharacteristicValueChanged(
371 device::BluetoothAdapter* adapter, 375 device::BluetoothAdapter* adapter,
372 device::BluetoothGattCharacteristic* characteristic, 376 device::BluetoothGattCharacteristic* characteristic,
373 const std::vector<uint8>& value) { 377 const std::vector<uint8>& value) {
374 // TODO(ortuno): Notify renderer the characteristic changed. 378 VLOG(1) << "Characteristic updated: " << characteristic->GetIdentifier();
375 // http://crbug.com/529560 379 auto iter =
376 VLOG(1) << "Characteristic updated."; 380 active_characteristic_threads_.find(characteristic->GetIdentifier());
381
382 if (iter == active_characteristic_threads_.end()) {
383 return;
384 }
385
386 for (int thread_id : iter->second) {
387 // Yield to the event loop so that the event gets dispatched after the
Jeffrey Yasskin 2015/10/15 23:00:51 I've filed https://github.com/WebBluetoothCG/web-b
ortuno 2015/10/16 01:24:21 It's possible to miss a notification if the charac
Jeffrey Yasskin 2015/10/16 01:40:17 Heh, argh. I'm suspicious we'll need to send event
ortuno 2015/10/16 19:40:59 Yup. That's probably going to be the solution.
388 // readValue promise resolves.
389 if (!base::ThreadTaskRunnerHandle::Get()->PostTask(
390 FROM_HERE,
391 base::Bind(&BluetoothDispatcherHost::NotifyActiveCharacteristic,
392 weak_ptr_on_ui_thread_, thread_id,
393 characteristic->GetIdentifier(), value))) {
394 LOG(WARNING) << "No TaskRunner.";
395 }
396 }
397 }
398
399 void BluetoothDispatcherHost::NotifyActiveCharacteristic(
400 int thread_id,
401 const std::string characteristic_instance_id,
402 const std::vector<uint8> value) {
403 Send(new BluetoothMsg_CharacteristicValueChanged(
404 thread_id, characteristic_instance_id, value));
377 } 405 }
378 406
379 void BluetoothDispatcherHost::OnRequestDevice( 407 void BluetoothDispatcherHost::OnRequestDevice(
380 int thread_id, 408 int thread_id,
381 int request_id, 409 int request_id,
382 int frame_routing_id, 410 int frame_routing_id,
383 const std::vector<BluetoothScanFilter>& filters, 411 const std::vector<BluetoothScanFilter>& filters,
384 const std::vector<BluetoothUUID>& optional_services) { 412 const std::vector<BluetoothUUID>& optional_services) {
385 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 413 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
386 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); 414 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE);
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 if (notify_session_iter == characteristic_id_to_notify_session_.end()) { 826 if (notify_session_iter == characteristic_id_to_notify_session_.end()) {
799 Send(new BluetoothMsg_StopNotificationsSuccess(thread_id, request_id)); 827 Send(new BluetoothMsg_StopNotificationsSuccess(thread_id, request_id));
800 return; 828 return;
801 } 829 }
802 notify_session_iter->second->Stop( 830 notify_session_iter->second->Stop(
803 base::Bind(&BluetoothDispatcherHost::OnStopNotifySession, 831 base::Bind(&BluetoothDispatcherHost::OnStopNotifySession,
804 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, 832 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id,
805 characteristic_instance_id)); 833 characteristic_instance_id));
806 } 834 }
807 835
836 void BluetoothDispatcherHost::OnRegisterCharacteristicObject(
837 int thread_id,
838 const std::string& characteristic_instance_id) {
839 DCHECK_CURRENTLY_ON(BrowserThread::UI);
840 active_characteristic_threads_[characteristic_instance_id].insert(thread_id);
841 }
842
843 void BluetoothDispatcherHost::OnUnregisterCharacteristicObject(
844 int thread_id,
845 const std::string& characteristic_instance_id) {
846 DCHECK_CURRENTLY_ON(BrowserThread::UI);
847 auto active_iter =
848 active_characteristic_threads_.find(characteristic_instance_id);
849 if (active_iter != active_characteristic_threads_.end()) {
850 std::set<int>& thread_ids_set = active_iter->second;
851 thread_ids_set.erase(thread_id);
852 if (thread_ids_set.empty()) {
853 active_characteristic_threads_.erase(active_iter);
854 }
855 }
856 }
857
808 void BluetoothDispatcherHost::OnDiscoverySessionStarted( 858 void BluetoothDispatcherHost::OnDiscoverySessionStarted(
809 int chooser_id, 859 int chooser_id,
810 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { 860 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) {
811 DCHECK_CURRENTLY_ON(BrowserThread::UI); 861 DCHECK_CURRENTLY_ON(BrowserThread::UI);
812 VLOG(1) << "Started discovery session for " << chooser_id; 862 VLOG(1) << "Started discovery session for " << chooser_id;
813 if (RequestDeviceSession* session = 863 if (RequestDeviceSession* session =
814 request_device_sessions_.Lookup(chooser_id)) { 864 request_device_sessions_.Lookup(chooser_id)) {
815 session->discovery_session = discovery_session.Pass(); 865 session->discovery_session = discovery_session.Pass();
816 866
817 // Arrange to stop discovery later. 867 // Arrange to stop discovery later.
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1134 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1085 NOTIMPLEMENTED(); 1135 NOTIMPLEMENTED();
1086 } 1136 }
1087 1137
1088 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() { 1138 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() {
1089 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1139 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1090 NOTIMPLEMENTED(); 1140 NOTIMPLEMENTED();
1091 } 1141 }
1092 1142
1093 } // namespace content 1143 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698