OLD | NEW |
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 #ifndef CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_ |
6 #define CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_ | 6 #define CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 #include <unordered_map> | 12 #include <unordered_map> |
| 13 #include <vector> |
13 | 14 |
14 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
15 #include "base/macros.h" | 16 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/thread_task_runner_handle.h" |
17 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
18 #include "mojo/public/cpp/bindings/associated_binding.h" | 20 #include "mojo/public/cpp/bindings/associated_binding.h" |
19 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetooth.h" | 21 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetooth.h" |
20 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj
om.h" | 22 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj
om.h" |
21 | 23 |
22 namespace blink { | 24 namespace blink { |
23 class WebBluetoothRemoteGATTCharacteristic; | 25 class WebBluetoothRemoteGATTCharacteristic; |
24 } | 26 } |
25 | 27 |
26 namespace content { | 28 namespace content { |
(...skipping 26 matching lines...) Expand all Loading... |
53 const blink::WebString& service_uuid, | 55 const blink::WebString& service_uuid, |
54 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) override; | 56 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) override; |
55 void getCharacteristic( | 57 void getCharacteristic( |
56 const blink::WebString& service_instance_id, | 58 const blink::WebString& service_instance_id, |
57 const blink::WebString& characteristic_uuid, | 59 const blink::WebString& characteristic_uuid, |
58 blink::WebBluetoothGetCharacteristicCallbacks* callbacks) override; | 60 blink::WebBluetoothGetCharacteristicCallbacks* callbacks) override; |
59 void getCharacteristics( | 61 void getCharacteristics( |
60 const blink::WebString& service_instance_id, | 62 const blink::WebString& service_instance_id, |
61 const blink::WebString& characteristics_uuid, | 63 const blink::WebString& characteristics_uuid, |
62 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) override; | 64 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) override; |
63 | |
64 void readValue(const blink::WebString& characteristic_instance_id, | 65 void readValue(const blink::WebString& characteristic_instance_id, |
65 blink::WebBluetoothReadValueCallbacks* callbacks) override; | 66 blink::WebBluetoothReadValueCallbacks* callbacks) override; |
66 void writeValue(const blink::WebString& characteristic_instance_id, | 67 void writeValue(const blink::WebString& characteristic_instance_id, |
67 const blink::WebVector<uint8_t>& value, | 68 const blink::WebVector<uint8_t>& value, |
68 blink::WebBluetoothWriteValueCallbacks*) override; | 69 blink::WebBluetoothWriteValueCallbacks*) override; |
69 void startNotifications( | 70 void startNotifications( |
70 const blink::WebString& characteristic_instance_id, | 71 const blink::WebString& characteristic_instance_id, |
71 blink::WebBluetoothNotificationsCallbacks*) override; | 72 blink::WebBluetoothNotificationsCallbacks*) override; |
72 void stopNotifications( | 73 void stopNotifications( |
73 const blink::WebString& characteristic_instance_id, | 74 const blink::WebString& characteristic_instance_id, |
74 blink::WebBluetoothNotificationsCallbacks*) override; | 75 blink::WebBluetoothNotificationsCallbacks*) override; |
75 void characteristicObjectRemoved( | 76 void characteristicObjectRemoved( |
76 const blink::WebString& characteristic_instance_id, | 77 const blink::WebString& characteristic_instance_id, |
77 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) override; | 78 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) override; |
78 void registerCharacteristicObject( | 79 void registerCharacteristicObject( |
79 const blink::WebString& characteristic_instance_id, | 80 const blink::WebString& characteristic_instance_id, |
80 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) override; | 81 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) override; |
81 | 82 |
82 private: | 83 private: |
83 // WebBluetoothServiceClient methods: | 84 // WebBluetoothServiceClient methods: |
84 void RemoteCharacteristicValueChanged( | 85 void RemoteCharacteristicValueChanged( |
85 const mojo::String& characteristic_instance_id, | 86 const mojo::String& characteristic_instance_id, |
86 mojo::Array<uint8_t> value) override; | 87 mojo::Array<uint8_t> value) override; |
87 | 88 |
88 // Callbacks for WebBluetoothService calls: | 89 // Callbacks for WebBluetoothService calls: |
| 90 void OnReadValueComplete( |
| 91 std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks, |
| 92 blink::mojom::WebBluetoothError error, |
| 93 mojo::Array<uint8_t> value); |
89 void OnWriteValueComplete( | 94 void OnWriteValueComplete( |
90 const blink::WebVector<uint8_t>& value, | 95 const blink::WebVector<uint8_t>& value, |
91 std::unique_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks, | 96 std::unique_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks, |
92 blink::mojom::WebBluetoothError error); | 97 blink::mojom::WebBluetoothError error); |
93 void OnStartNotificationsComplete( | 98 void OnStartNotificationsComplete( |
94 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks, | 99 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks, |
95 blink::mojom::WebBluetoothError error); | 100 blink::mojom::WebBluetoothError error); |
96 void OnStopNotificationsComplete( | 101 void OnStopNotificationsComplete( |
97 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks); | 102 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks); |
98 | 103 |
| 104 void DispatchCharacteristicValueChanged( |
| 105 const std::string& characteristic_instance_id, |
| 106 const std::vector<uint8_t>& value); |
| 107 |
99 BluetoothDispatcher* GetDispatcher(); | 108 BluetoothDispatcher* GetDispatcher(); |
100 | 109 |
101 blink::mojom::WebBluetoothService& GetWebBluetoothService(); | 110 blink::mojom::WebBluetoothService& GetWebBluetoothService(); |
102 ServiceRegistry* const service_registry_; | 111 ServiceRegistry* const service_registry_; |
103 blink::mojom::WebBluetoothServicePtr web_bluetooth_service_; | 112 blink::mojom::WebBluetoothServicePtr web_bluetooth_service_; |
104 | 113 |
105 // Map of characteristic_instance_ids to | 114 // Map of characteristic_instance_ids to |
106 // WebBluetoothRemoteGATTCharacteristics. When characteristicObjectRemoved is | 115 // WebBluetoothRemoteGATTCharacteristics. When characteristicObjectRemoved is |
107 // called the characteristic should be removed from the map. | 116 // called the characteristic should be removed from the map. |
108 // Keeps track of what characteristics have listeners. | 117 // Keeps track of what characteristics have listeners. |
109 std::unordered_map<std::string, blink::WebBluetoothRemoteGATTCharacteristic*> | 118 std::unordered_map<std::string, blink::WebBluetoothRemoteGATTCharacteristic*> |
110 active_characteristics_; | 119 active_characteristics_; |
111 | 120 |
112 // Binding associated with |web_bluetooth_service_|. | 121 // Binding associated with |web_bluetooth_service_|. |
113 mojo::AssociatedBinding<blink::mojom::WebBluetoothServiceClient> binding_; | 122 mojo::AssociatedBinding<blink::mojom::WebBluetoothServiceClient> binding_; |
114 | 123 |
115 const scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 124 const scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
116 const int frame_routing_id_; | 125 const int frame_routing_id_; |
117 | 126 |
118 DISALLOW_COPY_AND_ASSIGN(WebBluetoothImpl); | 127 DISALLOW_COPY_AND_ASSIGN(WebBluetoothImpl); |
119 }; | 128 }; |
120 | 129 |
121 } // namespace content | 130 } // namespace content |
122 | 131 |
123 #endif // CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_ | 132 #endif // CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_ |
OLD | NEW |