OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ |
| 6 #define CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "content/browser/bad_message.h" |
| 10 #include "content/common/content_export.h" |
| 11 #include "device/bluetooth/bluetooth_gatt_service.h" |
| 12 #include "mojo/public/cpp/bindings/binding.h" |
| 13 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj
om.h" |
| 14 |
| 15 namespace url { |
| 16 class Origin; |
| 17 } // namespace url |
| 18 |
| 19 namespace content { |
| 20 |
| 21 class BluetoothDispatcherHost; |
| 22 class RenderFrameHost; |
| 23 class RenderProcessHost; |
| 24 |
| 25 // Implementation of Mojo WebBluetoothService located in |
| 26 // third_party/WebKit/public/platform/modules/bluetooth. |
| 27 // It handles Web Bluetooth API requests coming from Blink / renderer |
| 28 // process and uses the platform abstraction of device/bluetooth. |
| 29 // WebBluetoothServiceImpl is not thread-safe and should be created on the |
| 30 // UI thread as required by device/bluetooth. |
| 31 // This class is instantiated on-demand via Mojo's ConnectToRemoteService |
| 32 // from the renderer when the first Web Bluetooth API request is handled. |
| 33 // RenderFrameHostImpl will create an instance of this class and keep |
| 34 // ownership of it. |
| 35 class WebBluetoothServiceImpl : public blink::mojom::WebBluetoothService { |
| 36 public: |
| 37 // |render_frame_host|: The RFH that owns this instance. |
| 38 // |request|: The instance will be bound to this request's pipe. |
| 39 WebBluetoothServiceImpl(RenderFrameHost* render_frame_host, |
| 40 blink::mojom::WebBluetoothServiceRequest request); |
| 41 ~WebBluetoothServiceImpl() override; |
| 42 |
| 43 private: |
| 44 // WebBluetoothService methods: |
| 45 void RemoteCharacteristicWriteValue( |
| 46 const mojo::String& characteristic_instance_id, |
| 47 mojo::Array<uint8_t> value, |
| 48 const RemoteCharacteristicWriteValueCallback& callback) override; |
| 49 |
| 50 // Callbacks for BluetoothGattCharacteristic::WriteRemoteCharacteristic. |
| 51 void OnWriteValueSuccess( |
| 52 const RemoteCharacteristicWriteValueCallback& callback); |
| 53 void OnWriteValueFailed( |
| 54 const RemoteCharacteristicWriteValueCallback& callback, |
| 55 device::BluetoothGattService::GattErrorCode error_code); |
| 56 |
| 57 RenderProcessHost* GetRenderProcessHost(); |
| 58 BluetoothDispatcherHost* GetBluetoothDispatcherHost(); |
| 59 void CrashRendererAndClosePipe(bad_message::BadMessageReason reason); |
| 60 url::Origin GetOrigin(); |
| 61 |
| 62 // The RFH that owns this instance. |
| 63 RenderFrameHost* render_frame_host_; |
| 64 |
| 65 // The lifetime of this instance is exclusively managed by the RFH that |
| 66 // owns it so we use a "Binding" as opposed to a "StrongBinding" which deletes |
| 67 // the service on pipe connection errors. |
| 68 mojo::Binding<blink::mojom::WebBluetoothService> binding_; |
| 69 |
| 70 base::WeakPtrFactory<WebBluetoothServiceImpl> weak_ptr_factory_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(WebBluetoothServiceImpl); |
| 73 }; |
| 74 |
| 75 } // namespace content |
| 76 |
| 77 #endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ |
OLD | NEW |