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

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

Powered by Google App Engine
This is Rietveld 408576698