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> |
(...skipping 19 matching lines...) Expand all Loading... |
30 class BluetoothDispatcher; | 30 class BluetoothDispatcher; |
31 class ThreadSafeSender; | 31 class ThreadSafeSender; |
32 class ServiceRegistry; | 32 class ServiceRegistry; |
33 | 33 |
34 // Implementation of blink::WebBluetooth. Passes calls through to the thread | 34 // Implementation of blink::WebBluetooth. Passes calls through to the thread |
35 // specific BluetoothDispatcher. | 35 // specific BluetoothDispatcher. |
36 class CONTENT_EXPORT WebBluetoothImpl | 36 class CONTENT_EXPORT WebBluetoothImpl |
37 : NON_EXPORTED_BASE(public blink::mojom::WebBluetoothServiceClient), | 37 : NON_EXPORTED_BASE(public blink::mojom::WebBluetoothServiceClient), |
38 NON_EXPORTED_BASE(public blink::WebBluetooth) { | 38 NON_EXPORTED_BASE(public blink::WebBluetooth) { |
39 public: | 39 public: |
40 WebBluetoothImpl(ServiceRegistry* service_registry, | 40 WebBluetoothImpl(ServiceRegistry* service_registry); |
41 ThreadSafeSender* thread_safe_sender, | |
42 int frame_routing_id); | |
43 ~WebBluetoothImpl() override; | 41 ~WebBluetoothImpl() override; |
44 | 42 |
45 // blink::WebBluetooth interface: | 43 // blink::WebBluetooth interface: |
46 void requestDevice( | 44 void requestDevice( |
47 const blink::WebRequestDeviceOptions& options, | 45 const blink::WebRequestDeviceOptions& options, |
48 blink::WebBluetoothRequestDeviceCallbacks* callbacks) override; | 46 blink::WebBluetoothRequestDeviceCallbacks* callbacks) override; |
49 void connect( | 47 void connect( |
50 const blink::WebString& device_id, | 48 const blink::WebString& device_id, |
51 blink::WebBluetoothDevice* device, | 49 blink::WebBluetoothDevice* device, |
52 blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) override; | 50 blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) override; |
(...skipping 27 matching lines...) Expand all Loading... |
80 | 78 |
81 private: | 79 private: |
82 struct GetCharacteristicsCallback; | 80 struct GetCharacteristicsCallback; |
83 // WebBluetoothServiceClient methods: | 81 // WebBluetoothServiceClient methods: |
84 void RemoteCharacteristicValueChanged( | 82 void RemoteCharacteristicValueChanged( |
85 const mojo::String& characteristic_instance_id, | 83 const mojo::String& characteristic_instance_id, |
86 mojo::Array<uint8_t> value) override; | 84 mojo::Array<uint8_t> value) override; |
87 void GattServerDisconnected(const mojo::String& device_id) override; | 85 void GattServerDisconnected(const mojo::String& device_id) override; |
88 | 86 |
89 // Callbacks for WebBluetoothService calls: | 87 // Callbacks for WebBluetoothService calls: |
| 88 void OnRequestDeviceComplete( |
| 89 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks, |
| 90 const blink::mojom::WebBluetoothError error, |
| 91 blink::mojom::WebBluetoothDevicePtr device); |
90 void OnConnectComplete( | 92 void OnConnectComplete( |
91 std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks> | 93 std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks> |
92 callbacks, | 94 callbacks, |
93 blink::mojom::WebBluetoothError error); | 95 blink::mojom::WebBluetoothError error); |
94 void OnGetPrimaryServiceComplete( | 96 void OnGetPrimaryServiceComplete( |
95 const blink::WebString& device_id, | 97 const blink::WebString& device_id, |
96 std::unique_ptr<blink::WebBluetoothGetPrimaryServiceCallbacks> callbacks, | 98 std::unique_ptr<blink::WebBluetoothGetPrimaryServiceCallbacks> callbacks, |
97 blink::mojom::WebBluetoothError error, | 99 blink::mojom::WebBluetoothError error, |
98 blink::mojom::WebBluetoothRemoteGATTServicePtr service); | 100 blink::mojom::WebBluetoothRemoteGATTServicePtr service); |
99 void OnGetCharacteristicsComplete( | 101 void OnGetCharacteristicsComplete( |
(...skipping 13 matching lines...) Expand all Loading... |
113 void OnStartNotificationsComplete( | 115 void OnStartNotificationsComplete( |
114 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks, | 116 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks, |
115 blink::mojom::WebBluetoothError error); | 117 blink::mojom::WebBluetoothError error); |
116 void OnStopNotificationsComplete( | 118 void OnStopNotificationsComplete( |
117 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks); | 119 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks); |
118 | 120 |
119 void DispatchCharacteristicValueChanged( | 121 void DispatchCharacteristicValueChanged( |
120 const std::string& characteristic_instance_id, | 122 const std::string& characteristic_instance_id, |
121 const std::vector<uint8_t>& value); | 123 const std::vector<uint8_t>& value); |
122 | 124 |
123 BluetoothDispatcher* GetDispatcher(); | |
124 | |
125 blink::mojom::WebBluetoothService& GetWebBluetoothService(); | 125 blink::mojom::WebBluetoothService& GetWebBluetoothService(); |
126 ServiceRegistry* const service_registry_; | 126 ServiceRegistry* const service_registry_; |
127 blink::mojom::WebBluetoothServicePtr web_bluetooth_service_; | 127 blink::mojom::WebBluetoothServicePtr web_bluetooth_service_; |
128 | 128 |
129 // Map of characteristic_instance_ids to | 129 // Map of characteristic_instance_ids to |
130 // WebBluetoothRemoteGATTCharacteristics. When characteristicObjectRemoved is | 130 // WebBluetoothRemoteGATTCharacteristics. When characteristicObjectRemoved is |
131 // called the characteristic should be removed from the map. | 131 // called the characteristic should be removed from the map. |
132 // Keeps track of what characteristics have listeners. | 132 // Keeps track of what characteristics have listeners. |
133 std::unordered_map<std::string, blink::WebBluetoothRemoteGATTCharacteristic*> | 133 std::unordered_map<std::string, blink::WebBluetoothRemoteGATTCharacteristic*> |
134 active_characteristics_; | 134 active_characteristics_; |
135 | 135 |
136 // Map of device_ids to WebBluetoothDevices. Added in connect() and removed in | 136 // Map of device_ids to WebBluetoothDevices. Added in connect() and removed in |
137 // disconnect(). This means a device may not actually be connected while in | 137 // disconnect(). This means a device may not actually be connected while in |
138 // this map, but that it will definitely be removed when the page navigates. | 138 // this map, but that it will definitely be removed when the page navigates. |
139 std::unordered_map<std::string, blink::WebBluetoothDevice*> | 139 std::unordered_map<std::string, blink::WebBluetoothDevice*> |
140 connected_devices_; | 140 connected_devices_; |
141 | 141 |
142 // Binding associated with |web_bluetooth_service_|. | 142 // Binding associated with |web_bluetooth_service_|. |
143 mojo::AssociatedBinding<blink::mojom::WebBluetoothServiceClient> binding_; | 143 mojo::AssociatedBinding<blink::mojom::WebBluetoothServiceClient> binding_; |
144 | 144 |
145 const scoped_refptr<ThreadSafeSender> thread_safe_sender_; | |
146 const int frame_routing_id_; | |
147 | |
148 DISALLOW_COPY_AND_ASSIGN(WebBluetoothImpl); | 145 DISALLOW_COPY_AND_ASSIGN(WebBluetoothImpl); |
149 }; | 146 }; |
150 | 147 |
151 } // namespace content | 148 } // namespace content |
152 | 149 |
153 #endif // CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_ | 150 #endif // CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_ |
OLD | NEW |