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

Unified Diff: content/renderer/bluetooth/bluetooth_dispatcher.h

Issue 1334763002: bluetooth: Subscribe to notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-origin
Patch Set: Add a comment about queueing system Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/bluetooth/bluetooth_dispatcher.h
diff --git a/content/renderer/bluetooth/bluetooth_dispatcher.h b/content/renderer/bluetooth/bluetooth_dispatcher.h
index 4109414400c2bd31b62e9309db61f11cbd7e9227..9ed3f59ea2a186efde53d3c3fd6d2ca6cf5f71c1 100644
--- a/content/renderer/bluetooth/bluetooth_dispatcher.h
+++ b/content/renderer/bluetooth/bluetooth_dispatcher.h
@@ -5,6 +5,8 @@
#ifndef CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_
#define CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_
+#include <queue>
+
#include "base/id_map.h"
#include "base/memory/ref_counted.h"
#include "content/common/bluetooth/bluetooth_device.h"
@@ -17,12 +19,17 @@ class MessageLoop;
class TaskRunner;
}
+namespace blink {
+class WebBluetoothGATTCharacteristic;
+}
+
namespace IPC {
class Message;
}
struct BluetoothCharacteristicRequest;
struct BluetoothPrimaryServiceRequest;
+struct BluetoothNotificationsRequest;
namespace content {
class ThreadSafeSender;
@@ -69,11 +76,67 @@ class BluetoothDispatcher : public WorkerThread::Observer {
void writeValue(const blink::WebString& characteristic_instance_id,
const std::vector<uint8_t>& value,
blink::WebBluetoothWriteValueCallbacks*);
+ void startNotifications(const blink::WebString& characteristic_instance_id,
+ blink::WebBluetoothGATTCharacteristic* delegate,
+ blink::WebBluetoothNotificationsCallbacks*);
+ void stopNotifications(const blink::WebString& characteristic_instance_id,
+ blink::WebBluetoothGATTCharacteristic* delegate,
+ blink::WebBluetoothNotificationsCallbacks*);
+ void characteristicObjectRemoved(
+ const blink::WebString& characteristic_instance_id,
+ blink::WebBluetoothGATTCharacteristic* delegate);
// WorkerThread::Observer implementation.
void WillStopCurrentWorkerThread() override;
+ enum class NotificationsRequestType { START = 0, STOP = 1 };
+
private:
+ // To avoid races and sending innecessary IPC messages we implement
Jeffrey Yasskin 2015/09/25 23:03:20 s/innecessary/unnecessary/
ortuno 2015/09/29 22:47:36 Done.
+ // a queueing system for notification requests. When receiving
+ // a notification request, the request is immediately queued. If
+ // there are no other pending requests then the request is processed.
+ // When an characteristic object gets destroyed BluetoothDispatcher
Jeffrey Yasskin 2015/09/25 23:03:20 s/an/a/
ortuno 2015/09/29 22:47:36 Done.
+ // gets notified by characteristicObjectRemoved. When this happens
+ // a stop request should be issued if the characterisic was susbscribed
Jeffrey Yasskin 2015/09/25 23:03:20 sp: characterisic, susbscribed
ortuno 2015/09/29 22:47:36 Done.
+ // to notifications.
+ std::map<std::string, std::queue<int>> queued_notification_requests_;
Jeffrey Yasskin 2015/09/25 23:03:20 Move this down to the section of data members. We
Jeffrey Yasskin 2015/09/25 23:03:20 Comment what the std::string and int mean.
ortuno 2015/09/29 22:47:36 Done.
+ // Helper functions for notification requests queue.
+ // Creates a notification request and queues it.
+ int QueueNotificationRequest(
+ const std::string& characteristic_instance_id,
+ blink::WebBluetoothGATTCharacteristic* characteristic,
+ blink::WebBluetoothNotificationsCallbacks* callbacks,
+ NotificationsRequestType type);
+ // Pops the last requests and runs the next request in the queue.
+ void ProcessQueuedNotificationRequests(int request_id);
+ // Check if there is more than one request in the queue i.e. if there
+ // are other requests besides the one being processed.
+ bool PendingNotificationRequest(
+ const std::string& characteristic_instance_id);
+ // Check if there are any objects subscribed to the characteristic's
+ // notifications.
+ bool HasActiveNotificationSubscription(
+ const std::string& characteristic_instance_id);
+ // Add the object to the set of subscribed objects to a characteristic's
+ // notifications.
+ void AddToActiveNotificationSubscriptions(
+ const std::string& characteristic_instance_id,
+ blink::WebBluetoothGATTCharacteristic* characteristic);
+ // Remove the object from the set of subscribed object to the
+ // characteristic's notifications. Returns if the subscription
+ // becomes inactive.
+ bool RemoveFromActiveNotificationSubscriptions(
+ const std::string& characteristic_instance_id,
+ blink::WebBluetoothGATTCharacteristic* characteristic);
+
+ // The following functions decide whether to resolve the request immediately
+ // or send an IPC to change the subscription state.
+ // You should never call this functions if PendingNotificationRequest
+ // is true since there is currently another request being processed.
+ void processStartNotificationsRequest(int request_id);
+ void processStopNotificationsRequest(int request_id);
+
// IPC Handlers, see definitions in bluetooth_messages.h.
void OnRequestDeviceSuccess(int thread_id,
int request_id,
@@ -81,11 +144,9 @@ class BluetoothDispatcher : public WorkerThread::Observer {
void OnRequestDeviceError(int thread_id,
int request_id,
blink::WebBluetoothError error);
-
void OnConnectGATTSuccess(int thread_id,
int request_id,
const std::string& message);
-
void OnConnectGATTError(int thread_id,
int request_id,
blink::WebBluetoothError error);
@@ -112,6 +173,11 @@ class BluetoothDispatcher : public WorkerThread::Observer {
void OnWriteValueError(int thread_id,
int request_id,
blink::WebBluetoothError error);
+ void OnStartNotificationsSuccess(int thread_id, int request_id);
+ void OnStartNotificationsError(int thread_id,
+ int request_id,
+ blink::WebBluetoothError error);
+ void OnStopNotificationsSuccess(int thread_id, int request_id);
scoped_refptr<ThreadSafeSender> thread_safe_sender_;
@@ -135,6 +201,11 @@ class BluetoothDispatcher : public WorkerThread::Observer {
pending_read_value_requests_;
IDMap<blink::WebBluetoothWriteValueCallbacks, IDMapOwnPointer>
pending_write_value_requests_;
+ IDMap<BluetoothNotificationsRequest, IDMapOwnPointer>
+ pending_notifications_requests_;
+
+ std::map<std::string, std::set<blink::WebBluetoothGATTCharacteristic*>>
Jeffrey Yasskin 2015/09/25 23:03:20 You lost the comment saying what these strings mea
ortuno 2015/09/29 22:47:36 Done.
+ active_notification_subscriptions_;
DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcher);
};

Powered by Google App Engine
This is Rietveld 408576698