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

Side by Side Diff: content/browser/bluetooth/web_bluetooth_service_impl.h

Issue 1902153003: bluetooth: Move connect/disconnect to mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-separate-connection-tests
Patch Set: Fix gypi Created 4 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ 5 #ifndef CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_
6 #define CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ 6 #define CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "content/browser/bad_message.h" 13 #include "content/browser/bad_message.h"
14 #include "content/browser/bluetooth/cache_query_result.h" 14 #include "content/browser/bluetooth/cache_query_result.h"
15 #include "content/common/content_export.h" 15 #include "content/common/content_export.h"
16 #include "content/public/browser/web_contents_observer.h" 16 #include "content/public/browser/web_contents_observer.h"
17 #include "device/bluetooth/bluetooth_adapter.h" 17 #include "device/bluetooth/bluetooth_adapter.h"
18 #include "device/bluetooth/bluetooth_gatt_connection.h"
18 #include "device/bluetooth/bluetooth_gatt_notify_session.h" 19 #include "device/bluetooth/bluetooth_gatt_notify_session.h"
19 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" 20 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
20 #include "device/bluetooth/bluetooth_remote_gatt_service.h" 21 #include "device/bluetooth/bluetooth_remote_gatt_service.h"
21 #include "mojo/public/cpp/bindings/binding.h" 22 #include "mojo/public/cpp/bindings/binding.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 url { 25 namespace url {
25 class Origin; 26 class Origin;
26 } // namespace url 27 } // namespace url
27 28
28 namespace content { 29 namespace content {
29 30
30 class BluetoothDispatcherHost; 31 class BluetoothDispatcherHost;
32 class FrameConnectedBluetoothDevices;
31 class RenderFrameHost; 33 class RenderFrameHost;
32 class RenderProcessHost; 34 class RenderProcessHost;
33 35
34 // Implementation of Mojo WebBluetoothService located in 36 // Implementation of Mojo WebBluetoothService located in
35 // third_party/WebKit/public/platform/modules/bluetooth. 37 // third_party/WebKit/public/platform/modules/bluetooth.
36 // It handles Web Bluetooth API requests coming from Blink / renderer 38 // It handles Web Bluetooth API requests coming from Blink / renderer
37 // process and uses the platform abstraction of device/bluetooth. 39 // process and uses the platform abstraction of device/bluetooth.
38 // WebBluetoothServiceImpl is not thread-safe and should be created on the 40 // WebBluetoothServiceImpl is not thread-safe and should be created on the
39 // UI thread as required by device/bluetooth. 41 // UI thread as required by device/bluetooth.
40 // This class is instantiated on-demand via Mojo's ConnectToRemoteService 42 // This class is instantiated on-demand via Mojo's ConnectToRemoteService
(...skipping 18 matching lines...) Expand all
59 PrimaryServicesRequestCallback; 61 PrimaryServicesRequestCallback;
60 62
61 // WebContentsObserver: 63 // WebContentsObserver:
62 // These functions should always check that the affected RenderFrameHost 64 // These functions should always check that the affected RenderFrameHost
63 // is this->render_frame_host_ and not some other frame in the same tab. 65 // is this->render_frame_host_ and not some other frame in the same tab.
64 void DidFinishNavigation(NavigationHandle* navigation_handle) override; 66 void DidFinishNavigation(NavigationHandle* navigation_handle) override;
65 67
66 // BluetoothAdapter::Observer: 68 // BluetoothAdapter::Observer:
67 void AdapterPresentChanged(device::BluetoothAdapter* adapter, 69 void AdapterPresentChanged(device::BluetoothAdapter* adapter,
68 bool present) override; 70 bool present) override;
71 void DeviceChanged(device::BluetoothAdapter* adapter,
72 device::BluetoothDevice* device) override;
69 void GattServicesDiscovered(device::BluetoothAdapter* adapter, 73 void GattServicesDiscovered(device::BluetoothAdapter* adapter,
70 device::BluetoothDevice* device) override; 74 device::BluetoothDevice* device) override;
71 void GattCharacteristicValueChanged( 75 void GattCharacteristicValueChanged(
72 device::BluetoothAdapter* adapter, 76 device::BluetoothAdapter* adapter,
73 device::BluetoothRemoteGattCharacteristic* characteristic, 77 device::BluetoothRemoteGattCharacteristic* characteristic,
74 const std::vector<uint8_t>& value) override; 78 const std::vector<uint8_t>& value) override;
75 79
76 // Notifies the WebBluetoothServiceClient that characteristic 80 // Notifies the WebBluetoothServiceClient that characteristic
77 // |characteristic_instance_id| changed it's value. We only do this for 81 // |characteristic_instance_id| changed it's value. We only do this for
78 // characteristics that have been returned to the client in the past. 82 // characteristics that have been returned to the client in the past.
79 void NotifyCharacteristicValueChanged( 83 void NotifyCharacteristicValueChanged(
80 const std::string& characteristic_instance_id, 84 const std::string& characteristic_instance_id,
81 std::vector<uint8_t> value); 85 std::vector<uint8_t> value);
82 86
83 // WebBluetoothService methods: 87 // WebBluetoothService methods:
84 void SetClient( 88 void SetClient(
85 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo client) override; 89 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo client) override;
90 void RemoteServerConnect(
91 const mojo::String& device_id,
92 const RemoteServerConnectCallback& callback) override;
93 void RemoteServerDisconnect(const mojo::String& device_id) override;
86 void RemoteServerGetPrimaryService( 94 void RemoteServerGetPrimaryService(
87 const mojo::String& device_id, 95 const mojo::String& device_id,
88 const mojo::String& service_uuid, 96 const mojo::String& service_uuid,
89 const RemoteServerGetPrimaryServiceCallback& callback) override; 97 const RemoteServerGetPrimaryServiceCallback& callback) override;
90 void RemoteServiceGetCharacteristics( 98 void RemoteServiceGetCharacteristics(
91 const mojo::String& service_instance_id, 99 const mojo::String& service_instance_id,
92 blink::mojom::WebBluetoothGATTQueryQuantity quantity, 100 blink::mojom::WebBluetoothGATTQueryQuantity quantity,
93 const mojo::String& characteristics_uuid, 101 const mojo::String& characteristics_uuid,
94 const RemoteServiceGetCharacteristicsCallback& callback) override; 102 const RemoteServiceGetCharacteristicsCallback& callback) override;
95 void RemoteCharacteristicReadValue( 103 void RemoteCharacteristicReadValue(
(...skipping 10 matching lines...) Expand all
106 const mojo::String& characteristic_instance_id, 114 const mojo::String& characteristic_instance_id,
107 const RemoteCharacteristicStopNotificationsCallback& callback) override; 115 const RemoteCharacteristicStopNotificationsCallback& callback) override;
108 116
109 // Should only be run after the services have been discovered for 117 // Should only be run after the services have been discovered for
110 // |device_address|. 118 // |device_address|.
111 void RemoteServerGetPrimaryServiceImpl( 119 void RemoteServerGetPrimaryServiceImpl(
112 const std::string& service_uuid, 120 const std::string& service_uuid,
113 const RemoteServerGetPrimaryServiceCallback& callback, 121 const RemoteServerGetPrimaryServiceCallback& callback,
114 device::BluetoothDevice* device); 122 device::BluetoothDevice* device);
115 123
124 // Callbacks for BluetoothDevice::CreateGattConnection.
125 void OnCreateGATTConnectionSuccess(
126 const std::string& device_id,
127 base::TimeTicks start_time,
128 const RemoteServerConnectCallback& callback,
129 std::unique_ptr<device::BluetoothGattConnection> connection);
130 void OnCreateGATTConnectionFailed(
131 const std::string& device_id,
132 base::TimeTicks start_time,
133 const RemoteServerConnectCallback& callback,
134 device::BluetoothDevice::ConnectErrorCode error_code);
135
116 // Callbacks for BluetoothRemoteGattCharacteristic::ReadRemoteCharacteristic. 136 // Callbacks for BluetoothRemoteGattCharacteristic::ReadRemoteCharacteristic.
117 void OnReadValueSuccess(const RemoteCharacteristicReadValueCallback& callback, 137 void OnReadValueSuccess(const RemoteCharacteristicReadValueCallback& callback,
118 const std::vector<uint8_t>& value); 138 const std::vector<uint8_t>& value);
119 void OnReadValueFailed( 139 void OnReadValueFailed(
120 const RemoteCharacteristicReadValueCallback& callback, 140 const RemoteCharacteristicReadValueCallback& callback,
121 device::BluetoothRemoteGattService::GattErrorCode error_code); 141 device::BluetoothRemoteGattService::GattErrorCode error_code);
122 142
123 // Callbacks for BluetoothRemoteGattCharacteristic::WriteRemoteCharacteristic. 143 // Callbacks for BluetoothRemoteGattCharacteristic::WriteRemoteCharacteristic.
124 void OnWriteValueSuccess( 144 void OnWriteValueSuccess(
125 const RemoteCharacteristicWriteValueCallback& callback); 145 const RemoteCharacteristicWriteValueCallback& callback);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 void CrashRendererAndClosePipe(bad_message::BadMessageReason reason); 183 void CrashRendererAndClosePipe(bad_message::BadMessageReason reason);
164 url::Origin GetOrigin(); 184 url::Origin GetOrigin();
165 185
166 // Clears all state (maps, sets, etc). 186 // Clears all state (maps, sets, etc).
167 void ClearState(); 187 void ClearState();
168 188
169 // Maps to get the object's parent based on its instanceID. 189 // Maps to get the object's parent based on its instanceID.
170 std::unordered_map<std::string, std::string> service_id_to_device_address_; 190 std::unordered_map<std::string, std::string> service_id_to_device_address_;
171 std::unordered_map<std::string, std::string> characteristic_id_to_service_id_; 191 std::unordered_map<std::string, std::string> characteristic_id_to_service_id_;
172 192
193 // Map to keep track of the connected Bluetooth devices.
194 std::unique_ptr<FrameConnectedBluetoothDevices> connected_devices_;
195
173 // Maps a device address to callbacks that are waiting for services to 196 // Maps a device address to callbacks that are waiting for services to
174 // be discovered for that device. 197 // be discovered for that device.
175 std::unordered_map<std::string, std::vector<PrimaryServicesRequestCallback>> 198 std::unordered_map<std::string, std::vector<PrimaryServicesRequestCallback>>
176 pending_primary_services_requests_; 199 pending_primary_services_requests_;
177 200
178 // Map to keep track of the characteristics' notify sessions. 201 // Map to keep track of the characteristics' notify sessions.
179 std::unordered_map<std::string, 202 std::unordered_map<std::string,
180 std::unique_ptr<device::BluetoothGattNotifySession>> 203 std::unique_ptr<device::BluetoothGattNotifySession>>
181 characteristic_id_to_notify_session_; 204 characteristic_id_to_notify_session_;
182 205
183 // The RFH that owns this instance. 206 // The RFH that owns this instance.
184 RenderFrameHost* render_frame_host_; 207 RenderFrameHost* render_frame_host_;
185 208
186 // Proxy to the WebBluetoothServiceClient to send device events to. 209 // Proxy to the WebBluetoothServiceClient to send device events to.
187 blink::mojom::WebBluetoothServiceClientAssociatedPtr client_; 210 blink::mojom::WebBluetoothServiceClientAssociatedPtr client_;
188 211
189 // The lifetime of this instance is exclusively managed by the RFH that 212 // The lifetime of this instance is exclusively managed by the RFH that
190 // owns it so we use a "Binding" as opposed to a "StrongBinding" which deletes 213 // owns it so we use a "Binding" as opposed to a "StrongBinding" which deletes
191 // the service on pipe connection errors. 214 // the service on pipe connection errors.
192 mojo::Binding<blink::mojom::WebBluetoothService> binding_; 215 mojo::Binding<blink::mojom::WebBluetoothService> binding_;
193 216
194 base::WeakPtrFactory<WebBluetoothServiceImpl> weak_ptr_factory_; 217 base::WeakPtrFactory<WebBluetoothServiceImpl> weak_ptr_factory_;
195 218
196 DISALLOW_COPY_AND_ASSIGN(WebBluetoothServiceImpl); 219 DISALLOW_COPY_AND_ASSIGN(WebBluetoothServiceImpl);
197 }; 220 };
198 221
199 } // namespace content 222 } // namespace content
200 223
201 #endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ 224 #endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698