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

Side by Side Diff: content/renderer/bluetooth/bluetooth_dispatcher.cc

Issue 1502663003: bluetooth: Implement allowed devices map (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Address jyasskin's comments Created 4 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 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/renderer/bluetooth/bluetooth_dispatcher.h" 5 #include "content/renderer/bluetooth/bluetooth_dispatcher.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 ~BluetoothCharacteristicRequest() {} 63 ~BluetoothCharacteristicRequest() {}
64 64
65 blink::WebString service_instance_id; 65 blink::WebString service_instance_id;
66 blink::WebString characteristic_uuid; 66 blink::WebString characteristic_uuid;
67 scoped_ptr<blink::WebBluetoothGetCharacteristicCallbacks> callbacks; 67 scoped_ptr<blink::WebBluetoothGetCharacteristicCallbacks> callbacks;
68 }; 68 };
69 69
70 // Struct that holds a pending Start/StopNotifications request. 70 // Struct that holds a pending Start/StopNotifications request.
71 struct BluetoothNotificationsRequest { 71 struct BluetoothNotificationsRequest {
72 BluetoothNotificationsRequest( 72 BluetoothNotificationsRequest(
73 int frame_routing_id,
73 const std::string characteristic_instance_id, 74 const std::string characteristic_instance_id,
74 blink::WebBluetoothGATTCharacteristic* characteristic, 75 blink::WebBluetoothGATTCharacteristic* characteristic,
75 blink::WebBluetoothNotificationsCallbacks* callbacks, 76 blink::WebBluetoothNotificationsCallbacks* callbacks,
76 NotificationsRequestType type) 77 NotificationsRequestType type)
77 : characteristic_instance_id(characteristic_instance_id), 78 : frame_routing_id(frame_routing_id),
79 characteristic_instance_id(characteristic_instance_id),
78 characteristic(characteristic), 80 characteristic(characteristic),
79 callbacks(callbacks), 81 callbacks(callbacks),
80 type(type) {} 82 type(type) {}
81 ~BluetoothNotificationsRequest() {} 83 ~BluetoothNotificationsRequest() {}
82 84
85 const int frame_routing_id;
83 const std::string characteristic_instance_id; 86 const std::string characteristic_instance_id;
84 // The characteristic object is owned by the execution context on 87 // The characteristic object is owned by the execution context on
85 // the blink side which can destroy the object at any point. Since the 88 // the blink side which can destroy the object at any point. Since the
86 // object implements ActiveDOMObject, the object calls Stop when is getting 89 // object implements ActiveDOMObject, the object calls Stop when is getting
87 // destroyed, which in turn calls characteristicObjectRemoved. 90 // destroyed, which in turn calls characteristicObjectRemoved.
88 // characteristicObjectRemoved will null any pointers to the object 91 // characteristicObjectRemoved will null any pointers to the object
89 // and queue a stop notifications request if necessary. 92 // and queue a stop notifications request if necessary.
90 blink::WebBluetoothGATTCharacteristic* characteristic; 93 blink::WebBluetoothGATTCharacteristic* characteristic;
91 scoped_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks; 94 scoped_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks;
92 NotificationsRequestType type; 95 NotificationsRequestType type;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 for (const WebString& optional_service : options.optionalServices) { 212 for (const WebString& optional_service : options.optionalServices) {
210 optional_services.push_back(device::BluetoothUUID(optional_service.utf8())); 213 optional_services.push_back(device::BluetoothUUID(optional_service.utf8()));
211 } 214 }
212 215
213 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id, 216 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id,
214 frame_routing_id, filters, 217 frame_routing_id, filters,
215 optional_services)); 218 optional_services));
216 } 219 }
217 220
218 void BluetoothDispatcher::connectGATT( 221 void BluetoothDispatcher::connectGATT(
222 int frame_routing_id,
219 const blink::WebString& device_id, 223 const blink::WebString& device_id,
220 blink::WebBluetoothConnectGATTCallbacks* callbacks) { 224 blink::WebBluetoothConnectGATTCallbacks* callbacks) {
221 int request_id = pending_connect_requests_.Add(callbacks); 225 int request_id = pending_connect_requests_.Add(callbacks);
222 Send(new BluetoothHostMsg_ConnectGATT(CurrentWorkerId(), request_id, 226 Send(new BluetoothHostMsg_ConnectGATT(CurrentWorkerId(), request_id,
223 device_id.utf8())); 227 frame_routing_id, device_id.utf8()));
224 } 228 }
225 229
226 void BluetoothDispatcher::getPrimaryService( 230 void BluetoothDispatcher::getPrimaryService(
231 int frame_routing_id,
227 const blink::WebString& device_id, 232 const blink::WebString& device_id,
228 const blink::WebString& service_uuid, 233 const blink::WebString& service_uuid,
229 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) { 234 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) {
230 int request_id = pending_primary_service_requests_.Add( 235 int request_id = pending_primary_service_requests_.Add(
231 new BluetoothPrimaryServiceRequest(device_id, service_uuid, callbacks)); 236 new BluetoothPrimaryServiceRequest(device_id, service_uuid, callbacks));
232 Send(new BluetoothHostMsg_GetPrimaryService( 237 Send(new BluetoothHostMsg_GetPrimaryService(
233 CurrentWorkerId(), request_id, device_id.utf8(), service_uuid.utf8())); 238 CurrentWorkerId(), request_id, frame_routing_id, device_id.utf8(),
239 service_uuid.utf8()));
234 } 240 }
235 241
236 void BluetoothDispatcher::getCharacteristic( 242 void BluetoothDispatcher::getCharacteristic(
243 int frame_routing_id,
237 const blink::WebString& service_instance_id, 244 const blink::WebString& service_instance_id,
238 const blink::WebString& characteristic_uuid, 245 const blink::WebString& characteristic_uuid,
239 blink::WebBluetoothGetCharacteristicCallbacks* callbacks) { 246 blink::WebBluetoothGetCharacteristicCallbacks* callbacks) {
240 int request_id = 247 int request_id =
241 pending_characteristic_requests_.Add(new BluetoothCharacteristicRequest( 248 pending_characteristic_requests_.Add(new BluetoothCharacteristicRequest(
242 service_instance_id, characteristic_uuid, callbacks)); 249 service_instance_id, characteristic_uuid, callbacks));
243 Send(new BluetoothHostMsg_GetCharacteristic(CurrentWorkerId(), request_id, 250 Send(new BluetoothHostMsg_GetCharacteristic(
244 service_instance_id.utf8(), 251 CurrentWorkerId(), request_id, frame_routing_id,
Jeffrey Yasskin 2016/01/13 19:25:34 I wish we had different types for routing IDs, req
ortuno 2016/01/13 21:34:31 I feel you. Hopefully with mojo we can get rid of
245 characteristic_uuid.utf8())); 252 service_instance_id.utf8(), characteristic_uuid.utf8()));
246 } 253 }
247 254
248 void BluetoothDispatcher::readValue( 255 void BluetoothDispatcher::readValue(
256 int frame_routing_id,
249 const blink::WebString& characteristic_instance_id, 257 const blink::WebString& characteristic_instance_id,
250 blink::WebBluetoothReadValueCallbacks* callbacks) { 258 blink::WebBluetoothReadValueCallbacks* callbacks) {
251 int request_id = pending_read_value_requests_.Add(callbacks); 259 int request_id = pending_read_value_requests_.Add(callbacks);
252 Send(new BluetoothHostMsg_ReadValue(CurrentWorkerId(), request_id, 260 Send(new BluetoothHostMsg_ReadValue(CurrentWorkerId(), request_id,
261 frame_routing_id,
253 characteristic_instance_id.utf8())); 262 characteristic_instance_id.utf8()));
254 } 263 }
255 264
256 void BluetoothDispatcher::writeValue( 265 void BluetoothDispatcher::writeValue(
266 int frame_routing_id,
257 const blink::WebString& characteristic_instance_id, 267 const blink::WebString& characteristic_instance_id,
258 const blink::WebVector<uint8_t>& value, 268 const blink::WebVector<uint8_t>& value,
259 blink::WebBluetoothWriteValueCallbacks* callbacks) { 269 blink::WebBluetoothWriteValueCallbacks* callbacks) {
260 int request_id = pending_write_value_requests_.Add(callbacks); 270 int request_id = pending_write_value_requests_.Add(callbacks);
261 271
262 Send(new BluetoothHostMsg_WriteValue( 272 Send(new BluetoothHostMsg_WriteValue(
263 CurrentWorkerId(), request_id, characteristic_instance_id.utf8(), 273 CurrentWorkerId(), request_id, frame_routing_id,
274 characteristic_instance_id.utf8(),
264 std::vector<uint8_t>(value.begin(), value.end()))); 275 std::vector<uint8_t>(value.begin(), value.end())));
265 } 276 }
266 277
267 void BluetoothDispatcher::startNotifications( 278 void BluetoothDispatcher::startNotifications(
279 int frame_routing_id,
268 const blink::WebString& characteristic_instance_id, 280 const blink::WebString& characteristic_instance_id,
269 blink::WebBluetoothGATTCharacteristic* characteristic, 281 blink::WebBluetoothGATTCharacteristic* characteristic,
270 blink::WebBluetoothNotificationsCallbacks* callbacks) { 282 blink::WebBluetoothNotificationsCallbacks* callbacks) {
271 int request_id = QueueNotificationRequest(characteristic_instance_id.utf8(), 283 int request_id = QueueNotificationRequest(
272 characteristic, callbacks, 284 frame_routing_id, characteristic_instance_id.utf8(), characteristic,
273 NotificationsRequestType::START); 285 callbacks, NotificationsRequestType::START);
274 // The Notification subscription's state can change after a request 286 // The Notification subscription's state can change after a request
275 // finishes. To avoid resolving with a soon-to-be-invalid state we queue 287 // finishes. To avoid resolving with a soon-to-be-invalid state we queue
276 // requests. 288 // requests.
277 if (HasNotificationRequestResponsePending( 289 if (HasNotificationRequestResponsePending(
278 characteristic_instance_id.utf8())) { 290 characteristic_instance_id.utf8())) {
279 return; 291 return;
280 } 292 }
281 293
282 ResolveOrSendStartNotificationRequest(request_id); 294 ResolveOrSendStartNotificationRequest(request_id);
283 } 295 }
284 296
285 void BluetoothDispatcher::stopNotifications( 297 void BluetoothDispatcher::stopNotifications(
298 int frame_routing_id,
286 const blink::WebString& characteristic_instance_id, 299 const blink::WebString& characteristic_instance_id,
287 blink::WebBluetoothGATTCharacteristic* characteristic, 300 blink::WebBluetoothGATTCharacteristic* characteristic,
288 blink::WebBluetoothNotificationsCallbacks* callbacks) { 301 blink::WebBluetoothNotificationsCallbacks* callbacks) {
289 int request_id = QueueNotificationRequest(characteristic_instance_id.utf8(), 302 int request_id = QueueNotificationRequest(
290 characteristic, callbacks, 303 frame_routing_id, characteristic_instance_id.utf8(), characteristic,
291 NotificationsRequestType::STOP); 304 callbacks, NotificationsRequestType::STOP);
292 if (HasNotificationRequestResponsePending( 305 if (HasNotificationRequestResponsePending(
293 characteristic_instance_id.utf8())) { 306 characteristic_instance_id.utf8())) {
294 return; 307 return;
295 } 308 }
296 309
297 ResolveOrSendStopNotificationsRequest(request_id); 310 ResolveOrSendStopNotificationsRequest(request_id);
298 } 311 }
299 312
300 void BluetoothDispatcher::characteristicObjectRemoved( 313 void BluetoothDispatcher::characteristicObjectRemoved(
314 int frame_routing_id,
301 const blink::WebString& characteristic_instance_id, 315 const blink::WebString& characteristic_instance_id,
302 blink::WebBluetoothGATTCharacteristic* characteristic) { 316 blink::WebBluetoothGATTCharacteristic* characteristic) {
303 // We need to remove references to the object from the following: 317 // We need to remove references to the object from the following:
304 // 1) The set of active characteristics 318 // 1) The set of active characteristics
305 // 2) The queue waiting for a response 319 // 2) The queue waiting for a response
306 // 3) The set of active notifications 320 // 3) The set of active notifications
307 321
308 // 1 322 // 1
309 // TODO(ortuno): We should only unregister a characteristic once 323 // TODO(ortuno): We should only unregister a characteristic once
310 // there are no characteristic objects that have listeners attached. 324 // there are no characteristic objects that have listeners attached.
311 // https://crbug.com/541388 325 // https://crbug.com/541388
312 UnregisterCharacteristicObject(characteristic_instance_id); 326 UnregisterCharacteristicObject(frame_routing_id, characteristic_instance_id);
313 327
314 // 2 328 // 2
315 // If the object is in the queue we null the characteristic. If this is the 329 // If the object is in the queue we null the characteristic. If this is the
316 // first object waiting for a response OnStartNotificationsSuccess will make 330 // first object waiting for a response OnStartNotificationsSuccess will make
317 // sure not to add the characteristic to the map and it will queue a Stop 331 // sure not to add the characteristic to the map and it will queue a Stop
318 // request. Otherwise ResolveOrSendStartNotificationRequest will make sure not 332 // request. Otherwise ResolveOrSendStartNotificationRequest will make sure not
319 // to add it to active notification subscriptions. 333 // to add it to active notification subscriptions.
320 bool found = false; 334 bool found = false;
321 for (IDMap<BluetoothNotificationsRequest, IDMapOwnPointer>::iterator iter( 335 for (IDMap<BluetoothNotificationsRequest, IDMapOwnPointer>::iterator iter(
322 &pending_notifications_requests_); 336 &pending_notifications_requests_);
(...skipping 26 matching lines...) Expand all
349 363
350 if (!HasActiveNotificationSubscription(characteristic_instance_id.utf8())) { 364 if (!HasActiveNotificationSubscription(characteristic_instance_id.utf8())) {
351 return; 365 return;
352 } 366 }
353 367
354 // For 2 and 3 calling ResolveOrSendStopNotificationsRequest ensures the 368 // For 2 and 3 calling ResolveOrSendStopNotificationsRequest ensures the
355 // notification subscription is released. 369 // notification subscription is released.
356 // We pass in the characteristic so that ResolveOrSendStopNotificationsRequest 370 // We pass in the characteristic so that ResolveOrSendStopNotificationsRequest
357 // can remove the characteristic from ActiveNotificationSubscriptions. 371 // can remove the characteristic from ActiveNotificationSubscriptions.
358 ResolveOrSendStopNotificationsRequest(QueueNotificationRequest( 372 ResolveOrSendStopNotificationsRequest(QueueNotificationRequest(
359 characteristic_instance_id.utf8(), characteristic, 373 frame_routing_id, characteristic_instance_id.utf8(), characteristic,
360 nullptr /* callbacks */, NotificationsRequestType::STOP)); 374 nullptr /* callbacks */, NotificationsRequestType::STOP));
361 } 375 }
362 376
363 void BluetoothDispatcher::registerCharacteristicObject( 377 void BluetoothDispatcher::registerCharacteristicObject(
378 int frame_routing_id,
364 const blink::WebString& characteristic_instance_id, 379 const blink::WebString& characteristic_instance_id,
365 blink::WebBluetoothGATTCharacteristic* characteristic) { 380 blink::WebBluetoothGATTCharacteristic* characteristic) {
366 // TODO(ortuno): After the Object manager is implemented, there will 381 // TODO(ortuno): After the Object manager is implemented, there will
367 // only be one object per characteristic. But for now we remove 382 // only be one object per characteristic. But for now we remove
368 // the previous object. 383 // the previous object.
369 // https://crbug.com/495270 384 // https://crbug.com/495270
370 active_characteristics_.erase(characteristic_instance_id.utf8()); 385 active_characteristics_.erase(characteristic_instance_id.utf8());
371 386
372 active_characteristics_.insert( 387 active_characteristics_.insert(
373 std::make_pair(characteristic_instance_id.utf8(), characteristic)); 388 std::make_pair(characteristic_instance_id.utf8(), characteristic));
374 389
375 Send(new BluetoothHostMsg_RegisterCharacteristic( 390 Send(new BluetoothHostMsg_RegisterCharacteristic(
376 CurrentWorkerId(), characteristic_instance_id.utf8())); 391 CurrentWorkerId(), frame_routing_id, characteristic_instance_id.utf8()));
377 } 392 }
378 393
379 void BluetoothDispatcher::WillStopCurrentWorkerThread() { 394 void BluetoothDispatcher::WillStopCurrentWorkerThread() {
380 delete this; 395 delete this;
381 } 396 }
382 397
383 int BluetoothDispatcher::QueueNotificationRequest( 398 int BluetoothDispatcher::QueueNotificationRequest(
399 int frame_routing_id,
384 const std::string& characteristic_instance_id, 400 const std::string& characteristic_instance_id,
385 blink::WebBluetoothGATTCharacteristic* characteristic, 401 blink::WebBluetoothGATTCharacteristic* characteristic,
386 blink::WebBluetoothNotificationsCallbacks* callbacks, 402 blink::WebBluetoothNotificationsCallbacks* callbacks,
387 NotificationsRequestType type) { 403 NotificationsRequestType type) {
388 int request_id = 404 int request_id =
389 pending_notifications_requests_.Add(new BluetoothNotificationsRequest( 405 pending_notifications_requests_.Add(new BluetoothNotificationsRequest(
390 characteristic_instance_id, characteristic, callbacks, type)); 406 frame_routing_id, characteristic_instance_id, characteristic,
407 callbacks, type));
391 notification_requests_queues_[characteristic_instance_id].push(request_id); 408 notification_requests_queues_[characteristic_instance_id].push(request_id);
392 409
393 return request_id; 410 return request_id;
394 } 411 }
395 412
396 void BluetoothDispatcher::PopNotificationRequestQueueAndProcessNext( 413 void BluetoothDispatcher::PopNotificationRequestQueueAndProcessNext(
397 int request_id) { 414 int request_id) {
398 BluetoothNotificationsRequest* old_request = 415 BluetoothNotificationsRequest* old_request =
399 pending_notifications_requests_.Lookup(request_id); 416 pending_notifications_requests_.Lookup(request_id);
400 417
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 DCHECK(!HasActiveNotificationSubscription(characteristic_instance_id)); 483 DCHECK(!HasActiveNotificationSubscription(characteristic_instance_id));
467 return true; 484 return true;
468 } 485 }
469 return false; 486 return false;
470 } 487 }
471 488
472 void BluetoothDispatcher::ResolveOrSendStartNotificationRequest( 489 void BluetoothDispatcher::ResolveOrSendStartNotificationRequest(
473 int request_id) { 490 int request_id) {
474 BluetoothNotificationsRequest* request = 491 BluetoothNotificationsRequest* request =
475 pending_notifications_requests_.Lookup(request_id); 492 pending_notifications_requests_.Lookup(request_id);
493 const int frame_routing_id = request->frame_routing_id;
476 const std::string& characteristic_instance_id = 494 const std::string& characteristic_instance_id =
477 request->characteristic_instance_id; 495 request->characteristic_instance_id;
478 blink::WebBluetoothGATTCharacteristic* characteristic = 496 blink::WebBluetoothGATTCharacteristic* characteristic =
479 request->characteristic; 497 request->characteristic;
480 blink::WebBluetoothNotificationsCallbacks* callbacks = 498 blink::WebBluetoothNotificationsCallbacks* callbacks =
481 request->callbacks.get(); 499 request->callbacks.get();
482 500
483 // If an object is already subscribed to notifications from the characteristic 501 // If an object is already subscribed to notifications from the characteristic
484 // no need to send an IPC again. 502 // no need to send an IPC again.
485 if (HasActiveNotificationSubscription(characteristic_instance_id)) { 503 if (HasActiveNotificationSubscription(characteristic_instance_id)) {
486 // The object could have been destroyed while we waited. 504 // The object could have been destroyed while we waited.
487 if (characteristic != nullptr) { 505 if (characteristic != nullptr) {
488 AddToActiveNotificationSubscriptions(characteristic_instance_id, 506 AddToActiveNotificationSubscriptions(characteristic_instance_id,
489 characteristic); 507 characteristic);
490 } 508 }
491 callbacks->onSuccess(); 509 callbacks->onSuccess();
492 510
493 PopNotificationRequestQueueAndProcessNext(request_id); 511 PopNotificationRequestQueueAndProcessNext(request_id);
494 return; 512 return;
495 } 513 }
496 514
497 Send(new BluetoothHostMsg_StartNotifications(CurrentWorkerId(), request_id, 515 Send(new BluetoothHostMsg_StartNotifications(CurrentWorkerId(), request_id,
516 frame_routing_id,
498 characteristic_instance_id)); 517 characteristic_instance_id));
499 } 518 }
500 519
501 void BluetoothDispatcher::ResolveOrSendStopNotificationsRequest( 520 void BluetoothDispatcher::ResolveOrSendStopNotificationsRequest(
502 int request_id) { 521 int request_id) {
503 // The Notification subscription's state can change after a request 522 // The Notification subscription's state can change after a request
504 // finishes. To avoid resolving with a soon-to-be-invalid state we queue 523 // finishes. To avoid resolving with a soon-to-be-invalid state we queue
505 // requests. 524 // requests.
506 BluetoothNotificationsRequest* request = 525 BluetoothNotificationsRequest* request =
507 pending_notifications_requests_.Lookup(request_id); 526 pending_notifications_requests_.Lookup(request_id);
527 const int frame_routing_id = request->frame_routing_id;
508 const std::string& characteristic_instance_id = 528 const std::string& characteristic_instance_id =
509 request->characteristic_instance_id; 529 request->characteristic_instance_id;
510 blink::WebBluetoothGATTCharacteristic* characteristic = 530 blink::WebBluetoothGATTCharacteristic* characteristic =
511 request->characteristic; 531 request->characteristic;
512 blink::WebBluetoothNotificationsCallbacks* callbacks = 532 blink::WebBluetoothNotificationsCallbacks* callbacks =
513 request->callbacks.get(); 533 request->callbacks.get();
514 534
515 // If removing turns the subscription inactive then stop. 535 // If removing turns the subscription inactive then stop.
516 if (RemoveFromActiveNotificationSubscriptions(characteristic_instance_id, 536 if (RemoveFromActiveNotificationSubscriptions(characteristic_instance_id,
517 characteristic)) { 537 characteristic)) {
518 Send(new BluetoothHostMsg_StopNotifications(CurrentWorkerId(), request_id, 538 Send(new BluetoothHostMsg_StopNotifications(CurrentWorkerId(), request_id,
539 frame_routing_id,
519 characteristic_instance_id)); 540 characteristic_instance_id));
520 return; 541 return;
521 } 542 }
522 543
523 // We could be processing a request with nullptr callbacks due to: 544 // We could be processing a request with nullptr callbacks due to:
524 // 1) OnStartNotificationSuccess queues a Stop request because the object 545 // 1) OnStartNotificationSuccess queues a Stop request because the object
525 // got destroyed in characteristicObjectRemoved. 546 // got destroyed in characteristicObjectRemoved.
526 // 2) The last characteristic object that held this subscription got 547 // 2) The last characteristic object that held this subscription got
527 // destroyed in characteristicObjectRemoved. 548 // destroyed in characteristicObjectRemoved.
528 if (callbacks != nullptr) { 549 if (callbacks != nullptr) {
529 callbacks->onSuccess(); 550 callbacks->onSuccess();
530 } 551 }
531 PopNotificationRequestQueueAndProcessNext(request_id); 552 PopNotificationRequestQueueAndProcessNext(request_id);
532 } 553 }
533 554
534 void BluetoothDispatcher::UnregisterCharacteristicObject( 555 void BluetoothDispatcher::UnregisterCharacteristicObject(
556 int frame_routing_id,
535 const blink::WebString& characteristic_instance_id) { 557 const blink::WebString& characteristic_instance_id) {
536 int removed = 558 int removed =
537 active_characteristics_.erase(characteristic_instance_id.utf8()); 559 active_characteristics_.erase(characteristic_instance_id.utf8());
538 if (removed != 0) { 560 if (removed != 0) {
539 Send(new BluetoothHostMsg_UnregisterCharacteristic( 561 Send(new BluetoothHostMsg_UnregisterCharacteristic(
540 CurrentWorkerId(), characteristic_instance_id.utf8())); 562 CurrentWorkerId(), frame_routing_id,
563 characteristic_instance_id.utf8()));
541 } 564 }
542 } 565 }
543 566
544 void BluetoothDispatcher::OnRequestDeviceSuccess( 567 void BluetoothDispatcher::OnRequestDeviceSuccess(
545 int thread_id, 568 int thread_id,
546 int request_id, 569 int request_id,
547 const BluetoothDevice& device) { 570 const BluetoothDevice& device) {
548 DCHECK(pending_requests_.Lookup(request_id)) << request_id; 571 DCHECK(pending_requests_.Lookup(request_id)) << request_id;
549 572
550 WebVector<WebString> uuids(device.uuids.size()); 573 WebVector<WebString> uuids(device.uuids.size());
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 724
702 // The object requesting the notification could have been destroyed 725 // The object requesting the notification could have been destroyed
703 // while waiting for the subscription. characteristicRemoved 726 // while waiting for the subscription. characteristicRemoved
704 // nulls the characteristic when the corresponding js object gets destroyed. 727 // nulls the characteristic when the corresponding js object gets destroyed.
705 // A Stop request must be issued as the subscription is no longer needed. 728 // A Stop request must be issued as the subscription is no longer needed.
706 // The Stop requets is added to the end of the queue in case another 729 // The Stop requets is added to the end of the queue in case another
707 // Start request exists in the queue from another characteristic object, 730 // Start request exists in the queue from another characteristic object,
708 // which would result in the subscription continuing. 731 // which would result in the subscription continuing.
709 if (request->characteristic == nullptr) { 732 if (request->characteristic == nullptr) {
710 QueueNotificationRequest( 733 QueueNotificationRequest(
711 request->characteristic_instance_id, nullptr /* characteristic */, 734 request->frame_routing_id, request->characteristic_instance_id,
712 nullptr /* callbacks */, NotificationsRequestType::STOP); 735 nullptr /* characteristic */, nullptr /* callbacks */,
736 NotificationsRequestType::STOP);
713 } 737 }
714 738
715 request->callbacks->onSuccess(); 739 request->callbacks->onSuccess();
716 740
717 PopNotificationRequestQueueAndProcessNext(request_id); 741 PopNotificationRequestQueueAndProcessNext(request_id);
718 } 742 }
719 743
720 void BluetoothDispatcher::OnStartNotificationsError(int thread_id, 744 void BluetoothDispatcher::OnStartNotificationsError(int thread_id,
721 int request_id, 745 int request_id,
722 WebBluetoothError error) { 746 WebBluetoothError error) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 int thread_id, 786 int thread_id,
763 const std::string& characteristic_instance_id, 787 const std::string& characteristic_instance_id,
764 const std::vector<uint8_t> new_value) { 788 const std::vector<uint8_t> new_value) {
765 auto active_iter = active_characteristics_.find(characteristic_instance_id); 789 auto active_iter = active_characteristics_.find(characteristic_instance_id);
766 if (active_iter != active_characteristics_.end()) { 790 if (active_iter != active_characteristics_.end()) {
767 active_iter->second->dispatchCharacteristicValueChanged(new_value); 791 active_iter->second->dispatchCharacteristicValueChanged(new_value);
768 } 792 }
769 } 793 }
770 794
771 } // namespace content 795 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698