OLD | NEW |
---|---|
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/common/content_export.h" | 15 #include "content/common/content_export.h" |
15 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
16 #include "device/bluetooth/bluetooth_adapter.h" | 17 #include "device/bluetooth/bluetooth_adapter.h" |
17 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 18 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
18 #include "device/bluetooth/bluetooth_gatt_notify_session.h" | 19 #include "device/bluetooth/bluetooth_gatt_notify_session.h" |
19 #include "device/bluetooth/bluetooth_gatt_service.h" | 20 #include "device/bluetooth/bluetooth_gatt_service.h" |
20 #include "mojo/public/cpp/bindings/binding.h" | 21 #include "mojo/public/cpp/bindings/binding.h" |
21 #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" |
22 | 23 |
23 namespace url { | 24 namespace url { |
24 class Origin; | 25 class Origin; |
25 } // namespace url | 26 } // namespace url |
26 | 27 |
27 namespace content { | 28 namespace content { |
28 | 29 |
30 struct CacheQueryResult; | |
Jeffrey Yasskin
2016/04/22 01:16:38
You only need one of the #include or the forward d
ortuno
2016/04/25 15:29:45
Done.
| |
31 | |
29 class BluetoothDispatcherHost; | 32 class BluetoothDispatcherHost; |
30 class RenderFrameHost; | 33 class RenderFrameHost; |
31 class RenderProcessHost; | 34 class RenderProcessHost; |
32 | 35 |
33 // Implementation of Mojo WebBluetoothService located in | 36 // Implementation of Mojo WebBluetoothService located in |
34 // third_party/WebKit/public/platform/modules/bluetooth. | 37 // third_party/WebKit/public/platform/modules/bluetooth. |
35 // It handles Web Bluetooth API requests coming from Blink / renderer | 38 // It handles Web Bluetooth API requests coming from Blink / renderer |
36 // process and uses the platform abstraction of device/bluetooth. | 39 // process and uses the platform abstraction of device/bluetooth. |
37 // WebBluetoothServiceImpl is not thread-safe and should be created on the | 40 // WebBluetoothServiceImpl is not thread-safe and should be created on the |
38 // UI thread as required by device/bluetooth. | 41 // UI thread as required by device/bluetooth. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 // Notifies the WebBluetoothServiceClient that characteristic | 73 // Notifies the WebBluetoothServiceClient that characteristic |
71 // |characteristic_instance_id| changed it's value. We only do this for | 74 // |characteristic_instance_id| changed it's value. We only do this for |
72 // characteristics that have been returned to the client in the past. | 75 // characteristics that have been returned to the client in the past. |
73 void NotifyCharacteristicValueChanged( | 76 void NotifyCharacteristicValueChanged( |
74 const std::string& characteristic_instance_id, | 77 const std::string& characteristic_instance_id, |
75 std::vector<uint8_t> value); | 78 std::vector<uint8_t> value); |
76 | 79 |
77 // WebBluetoothService methods: | 80 // WebBluetoothService methods: |
78 void SetClient( | 81 void SetClient( |
79 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo client) override; | 82 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo client) override; |
80 | 83 void RemoteServiceGetCharacteristics( |
81 // WebBluetoothService methods: | 84 const mojo::String& service_instance_id, |
85 bool single_characteristic, | |
86 const mojo::String& characteristics_uuid, | |
87 const RemoteServiceGetCharacteristicsCallback& callback) override; | |
82 void RemoteCharacteristicReadValue( | 88 void RemoteCharacteristicReadValue( |
83 const mojo::String& characteristic_instance_id, | 89 const mojo::String& characteristic_instance_id, |
84 const RemoteCharacteristicReadValueCallback& callback) override; | 90 const RemoteCharacteristicReadValueCallback& callback) override; |
85 void RemoteCharacteristicWriteValue( | 91 void RemoteCharacteristicWriteValue( |
86 const mojo::String& characteristic_instance_id, | 92 const mojo::String& characteristic_instance_id, |
87 mojo::Array<uint8_t> value, | 93 mojo::Array<uint8_t> value, |
88 const RemoteCharacteristicWriteValueCallback& callback) override; | 94 const RemoteCharacteristicWriteValueCallback& callback) override; |
89 void RemoteCharacteristicStartNotifications( | 95 void RemoteCharacteristicStartNotifications( |
90 const mojo::String& characteristic_instance_id, | 96 const mojo::String& characteristic_instance_id, |
91 const RemoteCharacteristicStartNotificationsCallback& callback) override; | 97 const RemoteCharacteristicStartNotificationsCallback& callback) override; |
(...skipping 21 matching lines...) Expand all Loading... | |
113 std::unique_ptr<device::BluetoothGattNotifySession> notify_session); | 119 std::unique_ptr<device::BluetoothGattNotifySession> notify_session); |
114 void OnStartNotifySessionFailed( | 120 void OnStartNotifySessionFailed( |
115 const RemoteCharacteristicStartNotificationsCallback& callback, | 121 const RemoteCharacteristicStartNotificationsCallback& callback, |
116 device::BluetoothGattService::GattErrorCode error_code); | 122 device::BluetoothGattService::GattErrorCode error_code); |
117 | 123 |
118 // Callback for BluetoothGattNotifySession::Stop. | 124 // Callback for BluetoothGattNotifySession::Stop. |
119 void OnStopNotifySessionComplete( | 125 void OnStopNotifySessionComplete( |
120 const std::string& characteristic_instance_id, | 126 const std::string& characteristic_instance_id, |
121 const RemoteCharacteristicStopNotificationsCallback& callback); | 127 const RemoteCharacteristicStopNotificationsCallback& callback); |
122 | 128 |
129 // Functions to query the platform cache for the bluetooth object. | |
130 // result.outcome == CacheQueryOutcome::SUCCESS if the object was found in the | |
131 // cache. Otherwise result.outcome that can used to record the outcome and | |
132 // result.error will contain the error that should be send to the renderer. | |
133 // One of the possible outcomes is BAD_RENDERER. In this case we crash the | |
134 // renderer, record the reason and close the pipe, so it's safe to drop | |
135 // any callbacks. | |
136 | |
137 // Queries the platform cache for a characteristic with | |
138 // |characteristic_instance_id|. Fills in the |outcome| field, and |device|, | |
139 // |service| and |characteristic| fields if successful. | |
140 CacheQueryResult QueryCacheForCharacteristic( | |
141 const std::string& characteristic_instance_id); | |
142 | |
123 RenderProcessHost* GetRenderProcessHost(); | 143 RenderProcessHost* GetRenderProcessHost(); |
124 BluetoothDispatcherHost* GetBluetoothDispatcherHost(); | 144 BluetoothDispatcherHost* GetBluetoothDispatcherHost(); |
125 void CrashRendererAndClosePipe(bad_message::BadMessageReason reason); | 145 void CrashRendererAndClosePipe(bad_message::BadMessageReason reason); |
126 url::Origin GetOrigin(); | 146 url::Origin GetOrigin(); |
127 | 147 |
128 // Clears all state (maps, sets, etc). | 148 // Clears all state (maps, sets, etc). |
129 void ClearState(); | 149 void ClearState(); |
130 | 150 |
151 // Maps to get the object's parent based on it's instanceID. | |
152 // Map of characteristic_instance_id to service_instance_id. | |
153 std::unordered_map<std::string, std::string> characteristic_to_service_; | |
154 | |
131 // Map to keep track of the characteristics' notify sessions. | 155 // Map to keep track of the characteristics' notify sessions. |
132 std::unordered_map<std::string, | 156 std::unordered_map<std::string, |
133 std::unique_ptr<device::BluetoothGattNotifySession>> | 157 std::unique_ptr<device::BluetoothGattNotifySession>> |
134 characteristic_id_to_notify_session_; | 158 characteristic_id_to_notify_session_; |
135 | 159 |
136 // The RFH that owns this instance. | 160 // The RFH that owns this instance. |
137 RenderFrameHost* render_frame_host_; | 161 RenderFrameHost* render_frame_host_; |
138 | 162 |
139 // Proxy to the WebBluetoothServiceClient to send device events to. | 163 // Proxy to the WebBluetoothServiceClient to send device events to. |
140 blink::mojom::WebBluetoothServiceClientAssociatedPtr client_; | 164 blink::mojom::WebBluetoothServiceClientAssociatedPtr client_; |
141 | 165 |
142 // The lifetime of this instance is exclusively managed by the RFH that | 166 // The lifetime of this instance is exclusively managed by the RFH that |
143 // owns it so we use a "Binding" as opposed to a "StrongBinding" which deletes | 167 // owns it so we use a "Binding" as opposed to a "StrongBinding" which deletes |
144 // the service on pipe connection errors. | 168 // the service on pipe connection errors. |
145 mojo::Binding<blink::mojom::WebBluetoothService> binding_; | 169 mojo::Binding<blink::mojom::WebBluetoothService> binding_; |
146 | 170 |
147 base::WeakPtrFactory<WebBluetoothServiceImpl> weak_ptr_factory_; | 171 base::WeakPtrFactory<WebBluetoothServiceImpl> weak_ptr_factory_; |
148 | 172 |
149 DISALLOW_COPY_AND_ASSIGN(WebBluetoothServiceImpl); | 173 DISALLOW_COPY_AND_ASSIGN(WebBluetoothServiceImpl); |
150 }; | 174 }; |
151 | 175 |
152 } // namespace content | 176 } // namespace content |
153 | 177 |
154 #endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ | 178 #endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ |
OLD | NEW |