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/content_export.h" | 20 #include "content/common/content_export.h" |
20 #include "mojo/public/cpp/bindings/associated_binding.h" | 21 #include "mojo/public/cpp/bindings/associated_binding.h" |
21 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetooth.h" | 22 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetooth.h" |
22 #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" |
23 | 24 |
24 namespace blink { | 25 namespace blink { |
25 class WebBluetoothRemoteGATTCharacteristic; | 26 class WebBluetoothRemoteGATTCharacteristic; |
26 } | 27 } |
27 | 28 |
28 namespace shell { | 29 namespace shell { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 void registerCharacteristicObject( | 82 void registerCharacteristicObject( |
82 const blink::WebString& characteristic_instance_id, | 83 const blink::WebString& characteristic_instance_id, |
83 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) override; | 84 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) override; |
84 | 85 |
85 private: | 86 private: |
86 struct GetCharacteristicsCallback; | 87 struct GetCharacteristicsCallback; |
87 // WebBluetoothServiceClient methods: | 88 // WebBluetoothServiceClient methods: |
88 void RemoteCharacteristicValueChanged( | 89 void RemoteCharacteristicValueChanged( |
89 const mojo::String& characteristic_instance_id, | 90 const mojo::String& characteristic_instance_id, |
90 mojo::Array<uint8_t> value) override; | 91 mojo::Array<uint8_t> value) override; |
91 void GattServerDisconnected(const mojo::String& device_id) override; | 92 void GattServerDisconnected(const WebBluetoothDeviceId& device_id) override; |
92 | 93 |
93 // Callbacks for WebBluetoothService calls: | 94 // Callbacks for WebBluetoothService calls: |
94 void OnRequestDeviceComplete( | 95 void OnRequestDeviceComplete( |
95 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks, | 96 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks, |
96 const blink::mojom::WebBluetoothError error, | 97 const blink::mojom::WebBluetoothError error, |
97 blink::mojom::WebBluetoothDevicePtr device); | 98 blink::mojom::WebBluetoothDevicePtr device); |
98 void OnConnectComplete( | 99 void OnConnectComplete( |
99 std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks> | 100 std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks> |
100 callbacks, | 101 callbacks, |
101 blink::mojom::WebBluetoothError error); | 102 blink::mojom::WebBluetoothError error); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // Map of characteristic_instance_ids to | 136 // Map of characteristic_instance_ids to |
136 // WebBluetoothRemoteGATTCharacteristics. When characteristicObjectRemoved is | 137 // WebBluetoothRemoteGATTCharacteristics. When characteristicObjectRemoved is |
137 // called the characteristic should be removed from the map. | 138 // called the characteristic should be removed from the map. |
138 // Keeps track of what characteristics have listeners. | 139 // Keeps track of what characteristics have listeners. |
139 std::unordered_map<std::string, blink::WebBluetoothRemoteGATTCharacteristic*> | 140 std::unordered_map<std::string, blink::WebBluetoothRemoteGATTCharacteristic*> |
140 active_characteristics_; | 141 active_characteristics_; |
141 | 142 |
142 // 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 |
143 // 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 |
144 // 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. |
145 std::unordered_map<std::string, blink::WebBluetoothDevice*> | 146 std::unordered_map<WebBluetoothDeviceId, |
| 147 blink::WebBluetoothDevice*, |
| 148 WebBluetoothDeviceIdHash> |
146 connected_devices_; | 149 connected_devices_; |
147 | 150 |
148 // Binding associated with |web_bluetooth_service_|. | 151 // Binding associated with |web_bluetooth_service_|. |
149 mojo::AssociatedBinding<blink::mojom::WebBluetoothServiceClient> binding_; | 152 mojo::AssociatedBinding<blink::mojom::WebBluetoothServiceClient> binding_; |
150 | 153 |
151 DISALLOW_COPY_AND_ASSIGN(WebBluetoothImpl); | 154 DISALLOW_COPY_AND_ASSIGN(WebBluetoothImpl); |
152 }; | 155 }; |
153 | 156 |
154 } // namespace content | 157 } // namespace content |
155 | 158 |
156 #endif // CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_ | 159 #endif // CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_ |
OLD | NEW |