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 #include <vector> |
14 | 14 |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
19 #include "content/common/bluetooth/web_bluetooth_device_id.h" | 19 #include "content/common/bluetooth/web_bluetooth_device_id.h" |
20 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
21 #include "mojo/public/cpp/bindings/associated_binding.h" | 21 #include "mojo/public/cpp/bindings/associated_binding.h" |
22 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetooth.h" | 22 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetooth.h" |
23 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj
om.h" | 23 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj
om.h" |
24 | 24 |
25 namespace blink { | 25 namespace blink { |
26 class WebBluetoothRemoteGATTCharacteristic; | 26 class WebBluetoothRemoteGATTCharacteristic; |
27 } | 27 } |
28 | 28 |
29 namespace shell { | 29 namespace service_manager { |
30 class InterfaceProvider; | 30 class InterfaceProvider; |
31 } | 31 } |
32 | 32 |
33 namespace content { | 33 namespace content { |
34 | 34 |
35 class BluetoothDispatcher; | 35 class BluetoothDispatcher; |
36 class ThreadSafeSender; | 36 class ThreadSafeSender; |
37 | 37 |
38 // Implementation of blink::WebBluetooth. Passes calls through to the thread | 38 // Implementation of blink::WebBluetooth. Passes calls through to the thread |
39 // specific BluetoothDispatcher. | 39 // specific BluetoothDispatcher. |
40 class CONTENT_EXPORT WebBluetoothImpl | 40 class CONTENT_EXPORT WebBluetoothImpl |
41 : NON_EXPORTED_BASE(public blink::mojom::WebBluetoothServiceClient), | 41 : NON_EXPORTED_BASE(public blink::mojom::WebBluetoothServiceClient), |
42 NON_EXPORTED_BASE(public blink::WebBluetooth) { | 42 NON_EXPORTED_BASE(public blink::WebBluetooth) { |
43 public: | 43 public: |
44 WebBluetoothImpl(shell::InterfaceProvider* remote_interfaces); | 44 WebBluetoothImpl(service_manager::InterfaceProvider* remote_interfaces); |
45 ~WebBluetoothImpl() override; | 45 ~WebBluetoothImpl() override; |
46 | 46 |
47 // blink::WebBluetooth interface: | 47 // blink::WebBluetooth interface: |
48 void requestDevice( | 48 void requestDevice( |
49 const blink::WebRequestDeviceOptions& options, | 49 const blink::WebRequestDeviceOptions& options, |
50 blink::WebBluetoothRequestDeviceCallbacks* callbacks) override; | 50 blink::WebBluetoothRequestDeviceCallbacks* callbacks) override; |
51 void connect( | 51 void connect( |
52 const blink::WebString& device_id, | 52 const blink::WebString& device_id, |
53 blink::WebBluetoothDevice* device, | 53 blink::WebBluetoothDevice* device, |
54 blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) override; | 54 blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) override; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks, | 123 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks, |
124 blink::mojom::WebBluetoothResult result); | 124 blink::mojom::WebBluetoothResult result); |
125 void OnStopNotificationsComplete( | 125 void OnStopNotificationsComplete( |
126 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks); | 126 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks); |
127 | 127 |
128 void DispatchCharacteristicValueChanged( | 128 void DispatchCharacteristicValueChanged( |
129 const std::string& characteristic_instance_id, | 129 const std::string& characteristic_instance_id, |
130 const std::vector<uint8_t>& value); | 130 const std::vector<uint8_t>& value); |
131 | 131 |
132 blink::mojom::WebBluetoothService& GetWebBluetoothService(); | 132 blink::mojom::WebBluetoothService& GetWebBluetoothService(); |
133 shell::InterfaceProvider* const remote_interfaces_; | 133 service_manager::InterfaceProvider* const remote_interfaces_; |
134 blink::mojom::WebBluetoothServicePtr web_bluetooth_service_; | 134 blink::mojom::WebBluetoothServicePtr web_bluetooth_service_; |
135 | 135 |
136 // Map of characteristic_instance_ids to | 136 // Map of characteristic_instance_ids to |
137 // WebBluetoothRemoteGATTCharacteristics. When characteristicObjectRemoved is | 137 // WebBluetoothRemoteGATTCharacteristics. When characteristicObjectRemoved is |
138 // called the characteristic should be removed from the map. | 138 // called the characteristic should be removed from the map. |
139 // Keeps track of what characteristics have listeners. | 139 // Keeps track of what characteristics have listeners. |
140 std::unordered_map<std::string, blink::WebBluetoothRemoteGATTCharacteristic*> | 140 std::unordered_map<std::string, blink::WebBluetoothRemoteGATTCharacteristic*> |
141 active_characteristics_; | 141 active_characteristics_; |
142 | 142 |
143 // Map of device_ids to WebBluetoothDevices. Added in connect() and removed in | 143 // Map of device_ids to WebBluetoothDevices. Added in connect() and removed in |
144 // disconnect(). This means a device may not actually be connected while in | 144 // disconnect(). This means a device may not actually be connected while in |
145 // this map, but that it will definitely be removed when the page navigates. | 145 // this map, but that it will definitely be removed when the page navigates. |
146 std::unordered_map<WebBluetoothDeviceId, | 146 std::unordered_map<WebBluetoothDeviceId, |
147 blink::WebBluetoothDevice*, | 147 blink::WebBluetoothDevice*, |
148 WebBluetoothDeviceIdHash> | 148 WebBluetoothDeviceIdHash> |
149 connected_devices_; | 149 connected_devices_; |
150 | 150 |
151 // Binding associated with |web_bluetooth_service_|. | 151 // Binding associated with |web_bluetooth_service_|. |
152 mojo::AssociatedBinding<blink::mojom::WebBluetoothServiceClient> binding_; | 152 mojo::AssociatedBinding<blink::mojom::WebBluetoothServiceClient> binding_; |
153 | 153 |
154 DISALLOW_COPY_AND_ASSIGN(WebBluetoothImpl); | 154 DISALLOW_COPY_AND_ASSIGN(WebBluetoothImpl); |
155 }; | 155 }; |
156 | 156 |
157 } // namespace content | 157 } // namespace content |
158 | 158 |
159 #endif // CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_ | 159 #endif // CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_ |
OLD | NEW |